2title = "2e: Insecure Hashing"
5aliases = ["/docs/reference/library/2e"]
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/library/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 nonzero FNV-1a non-cryptographic hash algorithm,
66 =+ b=[p=$(a -.a) q=$(a +.a)]
68 =+ c=(fnv (mix p.b (fnv q.b)))
69 =+ d=(mix (rsh 0 31 c) (end 0 31 c))
78 =+ f=(mix (rsh 0 31 c) (end 0 31 c))
81 $(c (fnv (mix c (cut 3 [d 1] a))), d +(d))
109Implementation of the 32-bit
110[MurmurHash3](https://en.wikipedia.org/wiki/MurmurHash#Algorithm)
111non-cryptographic hash algorithm. Takes `a` as the seed, `b` as the key length
112in [blocks](@/docs/hoon/library/2c.md) of size 3, and `c` as the key, producing an atom.
132 |= [syd=@ len=@ key=@]
133 ?> &((lte (met 5 syd) 1) (lte (met 0 len) 31))
134 =/ pad (sub len (met 3 key))
135 =/ data (weld (rip 3 key) (reap pad 0))
136 =/ nblocks (div len 4) :: intentionally off-by-one
138 =+ [c1=0xcc9e.2d51 c2=0x1b87.3593]
139 =/ blocks (rip 5 key)
142 ?: =(0 i) hi :: negative array index
143 =/ k1 (snag (sub nblocks i) blocks)
144 =. k1 (sit (mul k1 c1))
146 =. k1 (sit (mul k1 c2))
149 =. hi (sum (sit (mul hi 5)) 0xe654.6b64)
151 =/ tail (slag (mul 4 nblocks) data)
155 ?+ tlen h1 :: fallthrough switch
156 $3 =. k1 (mix k1 (lsh 0 16 (snag 2 tail)))
157 =. k1 (mix k1 (lsh 0 8 (snag 1 tail)))
158 =. k1 (mix k1 (snag 0 tail))
159 =. k1 (sit (mul k1 c1))
161 =. k1 (sit (mul k1 c2))
163 $2 =. k1 (mix k1 (lsh 0 8 (snag 1 tail)))
164 =. k1 (mix k1 (snag 0 tail))
165 =. k1 (sit (mul k1 c1))
167 =. k1 (sit (mul k1 c2))
169 $1 =. k1 (mix k1 (snag 0 tail))
170 =. k1 (sit (mul k1 c1))
172 =. k1 (sit (mul k1 c2))
179 =. h (mix h (rsh 0 16 h))
180 =. h (sit (mul h 0x85eb.ca6b))
181 =. h (mix h (rsh 0 13 h))
182 =. h (sit (mul h 0xc2b2.ae35))
183 =. h (mix h (rsh 0 16 h))
212 > =e (cut 3 [0 2] eny) :: `eny` is 512 bits of entropy (a random number).
22431-bit MurmurHash3 scrambler
226Hashes `a` with the 31-bit MurmurHash3 non-cryptographic hash algorithm,
243 |^ (trim ?@(a a (mix $(a -.a) (mix 0x7fff.ffff $(a +.a)))))
248 =+ haz=(muk syd (met 3 key) key)
249 =+ ham=(mix (rsh 0 31 haz) (end 0 31 haz))
250 ?.(=(0 ham) ham $(syd +(syd)))
271 > (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