2title = "2e: Insecure Hashing"
11Hashes an atom with the 32-bit FNV non-cryptographic hash algorithm. Multiplies
12`a` by the prime number 16,777,619 and then takes the [block](@/docs/hoon/reference/stdlib/2c.md) of size
135 off the product's end, producing an atom.
26 ++ fnv |=(a=@ (end 5 1 (mul 16.777.619 a)))
48Hashes `a` with the 31-bit murmur3 non-cryptographic hash algorithm,
62++ mug :: mug with murmur3
65 |^ (trim ?@(a a (mix $(a -.a) (mix 0x7fff.ffff $(a +.a)))))
66 ++ trim :: 31-bit nonzero
70 =+ haz=(muk syd (met 3 key) key)
71 =+ ham=(mix (rsh 0 31 haz) (end 0 31 haz))
72 ?.(=(0 ham) ham $(syd +(syd)))
101Implementation of the 32-bit
102[MurmurHash3](https://en.wikipedia.org/wiki/MurmurHash#Algorithm)
103non-cryptographic hash algorithm. Takes `a` as the seed, `b` as the key length
104in [blocks](@/docs/hoon/reference/stdlib/2c.md) of size 3, and `c` as the key, producing an atom.
124 |= [syd=@ len=@ key=@]
125 ?> &((lte (met 5 syd) 1) (lte (met 0 len) 31))
126 =/ pad (sub len (met 3 key))
127 =/ data (weld (rip 3 key) (reap pad 0))
128 =/ nblocks (div len 4) :: intentionally off-by-one
130 =+ [c1=0xcc9e.2d51 c2=0x1b87.3593]
131 =/ blocks (rip 5 key)
134 ?: =(0 i) hi :: negative array index
135 =/ k1 (snag (sub nblocks i) blocks)
136 =. k1 (sit (mul k1 c1))
138 =. k1 (sit (mul k1 c2))
141 =. hi (sum (sit (mul hi 5)) 0xe654.6b64)
143 =/ tail (slag (mul 4 nblocks) data)
147 ?+ tlen h1 :: fallthrough switch
148 $3 =. k1 (mix k1 (lsh 0 16 (snag 2 tail)))
149 =. k1 (mix k1 (lsh 0 8 (snag 1 tail)))
150 =. k1 (mix k1 (snag 0 tail))
151 =. k1 (sit (mul k1 c1))
153 =. k1 (sit (mul k1 c2))
155 $2 =. k1 (mix k1 (lsh 0 8 (snag 1 tail)))
156 =. k1 (mix k1 (snag 0 tail))
157 =. k1 (sit (mul k1 c1))
159 =. k1 (sit (mul k1 c2))
161 $1 =. k1 (mix k1 (snag 0 tail))
162 =. k1 (sit (mul k1 c1))
164 =. k1 (sit (mul k1 c2))
171 =. h (mix h (rsh 0 16 h))
172 =. h (sit (mul h 0x85eb.ca6b))
173 =. h (mix h (rsh 0 13 h))
174 =. h (sit (mul h 0xc2b2.ae35))
175 =. h (mix h (rsh 0 16 h))
204 > =e (cut 3 [0 2] eny) :: `eny` is 512 bits of entropy (a random number).
21631-bit MurmurHash3 scrambler
218Hashes `a` with the 31-bit MurmurHash3 non-cryptographic hash algorithm,
235 |^ (trim ?@(a a (mix $(a -.a) (mix 0x7fff.ffff $(a +.a)))))
240 =+ haz=(muk syd (met 3 key) key)
241 =+ ham=(mix (rsh 0 31 haz) (end 0 31 haz))
242 ?.(=(0 ham) ham $(syd +(syd)))
263 > (mum [1 2 3 4 5 ~])
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list