on 140ac0e help sign in
345 lines 9.9 kB history raw
1# 3d: SHA hash family
3### `++og`
5 ++ og :: shax-powered rng
6 ~/ %og
7 |_ a/@
9XX document
11### `++rad`
13 ++ rad :: random in range
14 |= b/@ ^- @
15 =+ c=(raw (met 0 b))
16 ?:((lth c b) c $(a +(a)))
17 ::
19XX document
21### `++rads`
23 ++ rads :: random continuation
24 |= b/@
25 =+ r=(rad b)
26 [r +>.$(a (shas %og-s r))]
28XX document
30### `++raw`
32 ++ raw :: random bits
33 ~/ %raw
34 |= b/@ ^- @
35 %+ can
36 0
37 =+ c=(shas %og-a (mix b a))
38 |- ^- (list [@ @])
39 ?: =(0 b)
40 ~
41 =+ d=(shas %og-b (mix b (mix a c)))
42 ?: (lth b 256)
43 [[b (end 0 b d)] ~]
44 [[256 d] $(c d, b (sub b 256))]
46XX document
48### `++raws`
50 ++ raws :: random bits continuation
51 |= b/@
52 =+ r=(raw b)
53 [r +>.$(a (shas %og-s r))]
54 --
58***
59### `++shad`
61 ++ shad |=(ruz/@ (shax (shax ruz))) :: double sha-256
64XX document
68***
69### `++shaf`
71 ++ shaf :: half sha-256
72 |= [sal/@ ruz/@]
73 =+ haz=(shas sal ruz)
74 (mix (end 7 1 haz) (rsh 7 1 haz))
75 ::
77XX document
81***
82### `++shak`
84 ++ shak :: XX shd be PBKDF
85 |= [who/@p wud/@]
86 (shas (mix %shak who) wud)
87 ::
89XX document
93***
94### `++shal`
96 ++ shal :: sha-512 with length
97 ~/ %shal
98 |= {len/@ ruz/@} ^- @
99 => .(ruz (cut 3 [0 len] ruz))
100 =+ [few==>(fe .(a 6)) wac=|=({a/@ b/@} (cut 6 [a 1] b))]
101 =+ [sum=sum.few ror=ror.few net=net.few inv=inv.few]
102 =+ ral=(lsh 0 3 len)
103 =+ ^= ful
104 %+ can 0
105 :~ [ral ruz]
106 [8 128]
107 [(mod (sub 1.920 (mod (add 8 ral) 1.024)) 1.024) 0]
108 [128 (~(net fe 7) ral)]
109 ==
110 =+ lex=(met 10 ful)
111 =+ ^= kbx 0x6c44.198c.4a47.5817.5fcb.6fab.3ad6.faec.
112 597f.299c.fc65.7e2a.4cc5.d4be.cb3e.42b6.
113 431d.67c4.9c10.0d4c.3c9e.be0a.15c9.bebc.
114 32ca.ab7b.40c7.2493.28db.77f5.2304.7d84.
115 1b71.0b35.131c.471b.113f.9804.bef9.0dae.
116 0a63.7dc5.a2c8.98a6.06f0.67aa.7217.6fba.
117 f57d.4f7f.ee6e.d178.eada.7dd6.cde0.eb1e.
118 d186.b8c7.21c0.c207.ca27.3ece.ea26.619c.
119 c671.78f2.e372.532b.bef9.a3f7.b2c6.7915.
120 a450.6ceb.de82.bde9.90be.fffa.2363.1e28.
121 8cc7.0208.1a64.39ec.84c8.7814.a1f0.ab72.
122 78a5.636f.4317.2f60.748f.82ee.5def.b2fc.
123 682e.6ff3.d6b2.b8a3.5b9c.ca4f.7763.e373.
124 4ed8.aa4a.e341.8acb.391c.0cb3.c5c9.5a63.
125 34b0.bcb5.e19b.48a8.2748.774c.df8e.eb99.
126 1e37.6c08.5141.ab53.19a4.c116.b8d2.d0c8.
127 106a.a070.32bb.d1b8.f40e.3585.5771.202a.
128 d699.0624.5565.a910.d192.e819.d6ef.5218.
129 c76c.51a3.0654.be30.c24b.8b70.d0f8.9791.
130 a81a.664b.bc42.3001.a2bf.e8a1.4cf1.0364.
131 9272.2c85.1482.353b.81c2.c92e.47ed.aee6.
132 766a.0abb.3c77.b2a8.650a.7354.8baf.63de.
133 5338.0d13.9d95.b3df.4d2c.6dfc.5ac4.2aed.
134 2e1b.2138.5c26.c926.27b7.0a85.46d2.2ffc.
135 1429.2967.0a0e.6e70.06ca.6351.e003.826f.
136 d5a7.9147.930a.a725.c6e0.0bf3.3da8.8fc2.
137 bf59.7fc7.beef.0ee4.b003.27c8.98fb.213f.
138 a831.c66d.2db4.3210.983e.5152.ee66.dfab.
139 76f9.88da.8311.53b5.5cb0.a9dc.bd41.fbd4.
140 4a74.84aa.6ea6.e483.2de9.2c6f.592b.0275.
141 240c.a1cc.77ac.9c65.0fc1.9dc6.8b8c.d5b5.
142 efbe.4786.384f.25e3.e49b.69c1.9ef1.4ad2.
143 c19b.f174.cf69.2694.9bdc.06a7.25c7.1235.
144 80de.b1fe.3b16.96b1.72be.5d74.f27b.896f.
145 550c.7dc3.d5ff.b4e2.2431.85be.4ee4.b28c.
146 1283.5b01.4570.6fbe.d807.aa98.a303.0242.
147 ab1c.5ed5.da6d.8118.923f.82a4.af19.4f9b.
148 59f1.11f1.b605.d019.3956.c25b.f348.b538.
149 e9b5.dba5.8189.dbbc.b5c0.fbcf.ec4d.3b2f.
150 7137.4491.23ef.65cd.428a.2f98.d728.ae22
151 =+ ^= hax 0x5be0.cd19.137e.2179.1f83.d9ab.fb41.bd6b.
152 9b05.688c.2b3e.6c1f.510e.527f.ade6.82d1.
153 a54f.f53a.5f1d.36f1.3c6e.f372.fe94.f82b.
154 bb67.ae85.84ca.a73b.6a09.e667.f3bc.c908
155 =+ i=0
156 |- ^- @
157 ?: =(i lex)
158 (rep 6 (turn (rip 6 hax) net))
159 =+ ^= wox
160 =+ dux=(cut 10 [i 1] ful)
161 =+ wox=(rep 6 (turn (rip 6 dux) net))
162 =+ j=16
163 |- ^- @
164 ?: =(80 j)
165 wox
166 =+ :* l=(wac (sub j 15) wox)
167 m=(wac (sub j 2) wox)
168 n=(wac (sub j 16) wox)
169 o=(wac (sub j 7) wox)
170 ==
171 =+ x=:(mix (ror 0 1 l) (ror 0 8 l) (rsh 0 7 l))
172 =+ y=:(mix (ror 0 19 m) (ror 0 61 m) (rsh 0 6 m))
173 =+ z=:(sum n x o y)
174 $(wox (con (lsh 6 j z) wox), j +(j))
175 =+ j=0
176 =+ :* a=(wac 0 hax)
177 b=(wac 1 hax)
178 c=(wac 2 hax)
179 d=(wac 3 hax)
180 e=(wac 4 hax)
181 f=(wac 5 hax)
182 g=(wac 6 hax)
183 h=(wac 7 hax)
184 ==
185 |- ^- @
186 ?: =(80 j)
187 %= ^$
188 i +(i)
189 hax %+ rep 6
190 :~ (sum a (wac 0 hax))
191 (sum b (wac 1 hax))
192 (sum c (wac 2 hax))
193 (sum d (wac 3 hax))
194 (sum e (wac 4 hax))
195 (sum f (wac 5 hax))
196 (sum g (wac 6 hax))
197 (sum h (wac 7 hax))
198 ==
199 ==
200 =+ l=:(mix (ror 0 28 a) (ror 0 34 a) (ror 0 39 a)) :: S0
201 =+ m=:(mix (dis a b) (dis a c) (dis b c)) :: maj
202 =+ n=(sum l m) :: t2
203 =+ o=:(mix (ror 0 14 e) (ror 0 18 e) (ror 0 41 e)) :: S1
204 =+ p=(mix (dis e f) (dis (inv e) g)) :: ch
205 =+ q=:(sum h o p (wac j kbx) (wac j wox)) :: t1
206 $(j +(j), a (sum q n), b a, c b, d c, e (sum d q), f e, g f, h g)
207 ::
209XX document
213***
214### `++sham`
216 ++ sham :: noun hash
217 |= yux/* ^- @uvH ^- @
218 ?@ yux
219 (shaf %mash yux)
220 (shaf %sham (jam yux))
221 ::
223XX document
227***
228### `++shan`
230 ++ shan :: sha-1 (deprecated)
231 |= ruz/@
232 =+ [few==>(fe .(a 5)) wac=|=({a/@ b/@} (cut 5 [a 1] b))]
233 =+ [sum=sum.few ror=ror.few rol=rol.few net=net.few inv=inv.few]
234 =+ ral=(lsh 0 3 (met 3 ruz))
235 =+ ^= ful
236 %+ can 0
237 :~ [ral ruz]
238 [8 128]
239 [(mod (sub 960 (mod (add 8 ral) 512)) 512) 0]
240 [64 (~(net fe 6) ral)]
241 ==
242 =+ lex=(met 9 ful)
243 =+ kbx=0xca62.c1d6.8f1b.bcdc.6ed9.eba1.5a82.7999
244 =+ hax=0xc3d2.e1f0.1032.5476.98ba.dcfe.efcd.ab89.6745.2301
245 =+ i=0
246 |-
247 ?: =(i lex)
248 (rep 5 (flop (rip 5 hax)))
249 =+ ^= wox
250 =+ dux=(cut 9 [i 1] ful)
251 =+ wox=(rep 5 (turn (rip 5 dux) net))
252 =+ j=16
253 |- ^- @
254 ?: =(80 j)
255 wox
256 =+ :* l=(wac (sub j 3) wox)
257 m=(wac (sub j 8) wox)
258 n=(wac (sub j 14) wox)
259 o=(wac (sub j 16) wox)
260 ==
261 =+ z=(rol 0 1 :(mix l m n o))
262 $(wox (con (lsh 5 j z) wox), j +(j))
263 =+ j=0
264 =+ :* a=(wac 0 hax)
265 b=(wac 1 hax)
266 c=(wac 2 hax)
267 d=(wac 3 hax)
268 e=(wac 4 hax)
269 ==
270 |- ^- @
271 ?: =(80 j)
272 %= ^$
273 i +(i)
274 hax %+ rep 5
275 :~
276 (sum a (wac 0 hax))
277 (sum b (wac 1 hax))
278 (sum c (wac 2 hax))
279 (sum d (wac 3 hax))
280 (sum e (wac 4 hax))
281 ==
282 ==
283 =+ fx=(con (dis b c) (dis (not 5 1 b) d))
284 =+ fy=:(mix b c d)
285 =+ fz=:(con (dis b c) (dis b d) (dis c d))
286 =+ ^= tem
287 ?: &((gte j 0) (lte j 19))
288 :(sum (rol 0 5 a) fx e (wac 0 kbx) (wac j wox))
289 ?: &((gte j 20) (lte j 39))
290 :(sum (rol 0 5 a) fy e (wac 1 kbx) (wac j wox))
291 ?: &((gte j 40) (lte j 59))
292 :(sum (rol 0 5 a) fz e (wac 2 kbx) (wac j wox))
293 :(sum (rol 0 5 a) fy e (wac 3 kbx) (wac j wox))
294 $(j +(j), a tem, b a, c (rol 0 30 b), d c, e d)
295 ::
297XX document
301***
302### `++shas`
304 ++ shas :: salted hash
305 |= [sal/@ ruz/@]
306 (shax (mix sal (shax ruz)))
307 ::
309XX document
313***
314### `++shaw`
316 ++ shaw :: hash to nbits
317 |= [sal/@ len/@ ruz/@]
318 (~(raw og (shas sal (mix len ruz))) len)
319 ::
323***
324### `++shax`
326++ shax :: sha-256
327 ~/ %shax
328 |= ruz/@ ^- @
329 (shay [(met 3 ruz) ruz])
330::
332XX document
336***
337### `++shaz`
339 ++ shaz :: sha-512
340 |= ruz/@ ^- @
341 (shal [(met 3 ruz) ruz])
345***