mirror of
https://github.com/urbit/shrub.git
synced 2024-12-13 16:03:36 +03:00
Various fixes and improvements.
This commit is contained in:
parent
79598968f4
commit
592e076125
807
arvo/junk.hoon
807
arvo/junk.hoon
@ -113,22 +113,6 @@
|
||||
++ ring @ :: private key
|
||||
++ rule _|=(nail *edge) :: parsing rule
|
||||
++ spot {p/path q/pint} :: range in file
|
||||
++ tang (list tank) :: bottom-first error
|
||||
++ tank $% {$leaf p/tape} :: printing formats
|
||||
$: $palm :: backstep list
|
||||
p/{p/tape q/tape r/tape s/tape} ::
|
||||
q/(list tank) ::
|
||||
== ::
|
||||
$: $rose :: flat list
|
||||
p/{p/tape q/tape r/tape} :: mid open close
|
||||
q/(list tank) ::
|
||||
== ::
|
||||
== ::
|
||||
++ tanq :: future tank
|
||||
$? {$~ p/(list tanq)} :: list of printables
|
||||
{$~ $~ p/tape} :: simple string
|
||||
(pair @tas tanq) :: captioned
|
||||
== ::
|
||||
++ tape (list char) :: string as list
|
||||
++ term @tas :: ascii symbol
|
||||
++ tiki :: test case
|
||||
@ -505,130 +489,6 @@
|
||||
(~(put by r) q ?~(- 1 +(u.-)))
|
||||
?> ?=(^ -)
|
||||
?:(=(0 u.-) (~(del by r) q) (~(put by r) q (dec u.-)))
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
:: section 2cH, urbit time ::
|
||||
::
|
||||
++ year :: date to @d
|
||||
|= det/date
|
||||
^- @da
|
||||
=+ ^= yer
|
||||
?: a.det
|
||||
(add 292.277.024.400 y.det)
|
||||
(sub 292.277.024.400 (dec y.det))
|
||||
=+ day=(yawn yer m.det d.t.det)
|
||||
(yule day h.t.det m.t.det s.t.det f.t.det)
|
||||
::
|
||||
++ yore :: @d to date
|
||||
|= now/@da
|
||||
^- date
|
||||
=+ rip=(yell now)
|
||||
=+ ger=(yall d.rip)
|
||||
:- ?: (gth y.ger 292.277.024.400)
|
||||
[a=& y=(sub y.ger 292.277.024.400)]
|
||||
[a=| y=+((sub 292.277.024.400 y.ger))]
|
||||
[m.ger d.ger h.rip m.rip s.rip f.rip]
|
||||
::
|
||||
++ yell :: tarp from @d
|
||||
|= now/@d
|
||||
^- tarp
|
||||
=+ sec=(rsh 6 1 now)
|
||||
=+ ^= fan
|
||||
=+ [muc=4 raw=(end 6 1 now)]
|
||||
|- ^- (list @ux)
|
||||
?: |(=(0 raw) =(0 muc))
|
||||
~
|
||||
=> .(muc (dec muc))
|
||||
[(cut 4 [muc 1] raw) $(raw (end 4 muc raw))]
|
||||
=+ day=(div sec day:yo)
|
||||
=> .(sec (mod sec day:yo))
|
||||
=+ hor=(div sec hor:yo)
|
||||
=> .(sec (mod sec hor:yo))
|
||||
=+ mit=(div sec mit:yo)
|
||||
=> .(sec (mod sec mit:yo))
|
||||
[day hor mit sec fan]
|
||||
::
|
||||
++ yule :: time atom
|
||||
|= rip/tarp
|
||||
^- @d
|
||||
=+ ^= sec ;: add
|
||||
(mul d.rip day:yo)
|
||||
(mul h.rip hor:yo)
|
||||
(mul m.rip mit:yo)
|
||||
s.rip
|
||||
==
|
||||
=+ ^= fac =+ muc=4
|
||||
|- ^- @
|
||||
?~ f.rip
|
||||
0
|
||||
=> .(muc (dec muc))
|
||||
(add (lsh 4 muc i.f.rip) $(f.rip t.f.rip))
|
||||
(con (lsh 6 1 sec) fac)
|
||||
::
|
||||
++ yall :: day / to day of year
|
||||
|= day/@ud
|
||||
^- {y/@ud m/@ud d/@ud}
|
||||
=+ [era=0 cet=0 lep=*?]
|
||||
=> .(era (div day era:yo), day (mod day era:yo))
|
||||
=> ^+ .
|
||||
?: (lth day +(cet:yo))
|
||||
.(lep &, cet 0)
|
||||
=> .(lep |, cet 1, day (sub day +(cet:yo)))
|
||||
.(cet (add cet (div day cet:yo)), day (mod day cet:yo))
|
||||
=+ yer=(add (mul 400 era) (mul 100 cet))
|
||||
|- ^- {y/@ud m/@ud d/@ud}
|
||||
=+ dis=?:(lep 366 365)
|
||||
?. (lth day dis)
|
||||
=+ ner=+(yer)
|
||||
$(yer ner, day (sub day dis), lep =(0 (end 0 2 ner)))
|
||||
|- ^- {y/@ud m/@ud d/@ud}
|
||||
=+ [mot=0 cah=?:(lep moy:yo moh:yo)]
|
||||
|- ^- {y/@ud m/@ud d/@ud}
|
||||
=+ zis=(snag mot cah)
|
||||
?: (lth day zis)
|
||||
[yer +(mot) +(day)]
|
||||
$(mot +(mot), day (sub day zis))
|
||||
::
|
||||
++ yawn :: days since Jesus
|
||||
|= {yer/@ud mot/@ud day/@ud}
|
||||
^- @ud
|
||||
=> .(mot (dec mot), day (dec day))
|
||||
=> ^+ .
|
||||
%= .
|
||||
day
|
||||
=+ cah=?:((yelp yer) moy:yo moh:yo)
|
||||
|- ^- @ud
|
||||
?: =(0 mot)
|
||||
day
|
||||
$(mot (dec mot), cah (slag 1 cah), day (add day (snag 0 cah)))
|
||||
==
|
||||
|- ^- @ud
|
||||
?. =(0 (mod yer 4))
|
||||
=+ ney=(dec yer)
|
||||
$(yer ney, day (add day ?:((yelp ney) 366 365)))
|
||||
?. =(0 (mod yer 100))
|
||||
=+ nef=(sub yer 4)
|
||||
$(yer nef, day (add day ?:((yelp nef) 1.461 1.460)))
|
||||
?. =(0 (mod yer 400))
|
||||
=+ nec=(sub yer 100)
|
||||
$(yer nec, day (add day ?:((yelp nec) 36.525 36.524)))
|
||||
(add day (mul (div yer 400) (add 1 (mul 4 36.524))))
|
||||
::
|
||||
++ yelp :: leap year
|
||||
|= yer/@ud ^- ?
|
||||
&(=(0 (mod yer 4)) |(!=(0 (mod yer 100)) =(0 (mod yer 400))))
|
||||
::
|
||||
++ yo :: time constants
|
||||
|% ++ cet 36.524 :: (add 24 (mul 100 365))
|
||||
++ day 86.400 :: (mul 24 hor)
|
||||
++ era 146.097 :: (add 1 (mul 4 cet))
|
||||
++ hor 3.600 :: (mul 60 mit)
|
||||
++ jes 106.751.991.084.417 :: (mul 730.692.561 era)
|
||||
++ mit 60
|
||||
++ moh `(list @ud)`[31 28 31 30 31 30 31 31 30 31 30 31 ~]
|
||||
++ moy `(list @ud)`[31 29 31 30 31 30 31 31 30 31 30 31 ~]
|
||||
++ qad 126.144.001 :: (add 1 (mul 4 yer))
|
||||
++ yer 31.536.000 :: (mul 365 day)
|
||||
--
|
||||
:::::::::::::::::::::::::::::::::::::::::::::::::::::: ::
|
||||
:::: chapter 2d, containers ::::
|
||||
:: ::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
@ -2068,111 +1928,6 @@
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
:: section 2eN, pseudo-cryptography ::
|
||||
::
|
||||
++ un :: =(x (wred (wren x)))
|
||||
|%
|
||||
++ wren :: conceal structure
|
||||
|= pyn/@ ^- @
|
||||
=+ len=(met 3 pyn)
|
||||
?: =(0 len)
|
||||
0
|
||||
=> .(len (dec len))
|
||||
=+ mig=(zaft (xafo len (cut 3 [len 1] pyn)))
|
||||
%+ can 3
|
||||
%- flop ^- (list {@ @})
|
||||
:- [1 mig]
|
||||
|- ^- (list {@ @})
|
||||
?: =(0 len)
|
||||
~
|
||||
=> .(len (dec len))
|
||||
=+ mog=(zyft :(mix mig (end 3 1 len) (cut 3 [len 1] pyn)))
|
||||
[[1 mog] $(mig mog)]
|
||||
::
|
||||
++ wred :: restore structure
|
||||
|= cry/@ ^- @
|
||||
=+ len=(met 3 cry)
|
||||
?: =(0 len)
|
||||
0
|
||||
=> .(len (dec len))
|
||||
=+ mig=(cut 3 [len 1] cry)
|
||||
%+ can 3
|
||||
%- flop ^- (list {@ @})
|
||||
:- [1 (xaro len (zart mig))]
|
||||
|- ^- (list {@ @})
|
||||
?: =(0 len)
|
||||
~
|
||||
=> .(len (dec len))
|
||||
=+ mog=(cut 3 [len 1] cry)
|
||||
[[1 :(mix mig (end 3 1 len) (zyrt mog))] $(mig mog)]
|
||||
::
|
||||
++ xafo |=({a/@ b/@} +((mod (add (dec b) a) 255)))
|
||||
++ xaro |=({a/@ b/@} +((mod (add (dec b) (sub 255 (mod a 255))) 255)))
|
||||
::
|
||||
++ zaft :: forward 255-sbox
|
||||
|= a/@D
|
||||
=+ ^= b
|
||||
0xcc.75bc.86c8.2fb1.9a42.f0b3.79a0.92ca.21f6.1e41.cde5.fcc0.
|
||||
7e85.51ae.1005.c72d.1246.07e8.7c64.a914.8d69.d9f4.59c2.8038.
|
||||
1f4a.dca2.6fdf.66f9.f561.a12e.5a16.f7b0.a39f.364e.cb70.7318.
|
||||
1de1.ad31.63d1.abd4.db68.6a33.134d.a760.edee.5434.493a.e323.
|
||||
930d.8f3d.3562.bb81.0b24.43cf.bea5.a6eb.52b4.0229.06b2.6704.
|
||||
78c9.45ec.d75e.58af.c577.b7b9.c40e.017d.90c3.87f8.96fa.1153.
|
||||
0372.7f30.1c32.ac83.ff17.c6e4.d36d.6b55.e2ce.8c71.8a5b.b6f3.
|
||||
9d4b.eab5.8b3c.e7f2.a8fe.9574.5de0.bf20.3f15.9784.9939.5f9c.
|
||||
e609.564f.d8a4.b825.9819.94aa.2c08.8e4c.9b22.477a.2840.3ed6.
|
||||
3750.6ef1.44dd.89ef.6576.d00a.fbda.9ed2.3b6c.7b0c.bde9.2ade.
|
||||
5c88.c182.481a.1b0f.2bfd.d591.2726.57ba
|
||||
(cut 3 [(dec a) 1] b)
|
||||
::
|
||||
++ zart :: reverse 255-sbox
|
||||
|= a/@D
|
||||
=+ ^= b
|
||||
0x68.4f07.ea1c.73c9.75c2.efc8.d559.5125.f621.a7a8.8591.5613.
|
||||
dd52.40eb.65a2.60b7.4bcb.1123.ceb0.1bd6.3c84.2906.b164.19b3.
|
||||
1e95.5fec.ffbc.f187.fbe2.6680.7c77.d30e.e94a.9414.fd9a.017d.
|
||||
3a7e.5a55.8ff5.8bf9.c181.e5b6.6ab2.35da.50aa.9293.3bc0.cdc6.
|
||||
f3bf.1a58.4130.f844.3846.744e.36a0.f205.789e.32d8.5e54.5c22.
|
||||
0f76.fce7.4569.0d99.d26e.e879.dc16.2df4.887f.1ffe.4dba.6f5d.
|
||||
bbcc.2663.1762.aed7.af8a.ca20.dbb4.9bc7.a942.834c.105b.c4d4.
|
||||
8202.3e61.a671.90e6.273d.bdab.3157.cfa4.0c2e.df86.2496.f7ed.
|
||||
2b48.2a9d.5318.a343.d128.be9c.a5ad.6bb5.6dfa.c5e1.3408.128d.
|
||||
2c04.0339.97a1.2ff0.49d0.eeb8.6c0a.0b37.b967.c347.d9ac.e072.
|
||||
e409.7b9f.1598.1d3f.33de.8ce3.8970.8e7a
|
||||
(cut 3 [(dec a) 1] b)
|
||||
::
|
||||
++ zyft :: forward 256-sbox
|
||||
|= a/@D
|
||||
=+ ^= b
|
||||
0xbb49.b71f.b881.b402.17e4.6b86.69b5.1647.115f.dddb.7ca5.
|
||||
8371.4bd5.19a9.b092.605d.0d9b.e030.a0cc.78ba.5706.4d2d.
|
||||
986a.768c.f8e8.c4c7.2f1c.effe.3cae.01c0.253e.65d3.3872.
|
||||
ce0e.7a74.8ac6.daac.7e5c.6479.44ec.4143.3d20.4af0.ee6c.
|
||||
c828.deca.0377.249f.ffcd.7b4f.eb7d.66f2.8951.042e.595a.
|
||||
8e13.f9c3.a79a.f788.6199.9391.7fab.6200.4ce5.0758.e2f1.
|
||||
7594.c945.d218.4248.afa1.e61a.54fb.1482.bea4.96a2.3473.
|
||||
63c2.e7cb.155b.120a.4ed7.bfd8.b31b.4008.f329.fca3.5380.
|
||||
9556.0cb2.8722.2bea.e96e.3ac5.d1bc.10e3.2c52.a62a.b1d6.
|
||||
35aa.d05e.f6a8.0f3b.31ed.559d.09ad.f585.6d21.fd1d.8d67.
|
||||
370b.26f4.70c1.b923.4684.6fbd.cf8b.5036.0539.9cdc.d93f.
|
||||
9068.1edf.8f33.b632.d427.97fa.9ee1
|
||||
(cut 3 [a 1] b)
|
||||
::
|
||||
++ zyrt :: reverse 256-sbox
|
||||
|= a/@D
|
||||
=+ ^= b
|
||||
0x9fc8.2753.6e02.8fcf.8b35.2b20.5598.7caa.c9a9.30b0.9b48.
|
||||
47ce.6371.80f6.407d.00dd.0aa5.ed10.ecb7.0f5a.5c3a.e605.
|
||||
c077.4337.17bd.9eda.62a4.79a7.ccb8.44cd.8e64.1ec4.5b6b.
|
||||
1842.ffd8.1dfb.fd07.f2f9.594c.3be3.73c6.2cb6.8438.e434.
|
||||
8d3d.ea6a.5268.72db.a001.2e11.de8c.88d3.0369.4f7a.87e2.
|
||||
860d.0991.25d0.16b9.978a.4bf4.2a1a.e96c.fa50.85b5.9aeb.
|
||||
9dbb.b2d9.a2d1.7bba.66be.e81f.1946.29a8.f5d2.f30c.2499.
|
||||
c1b3.6583.89e1.ee36.e0b4.6092.937e.d74e.2f6f.513e.9615.
|
||||
9c5d.d581.e7ab.fe74.f01b.78b1.ae75.af57.0ec2.adc7.3245.
|
||||
12bf.2314.3967.0806.31dc.cb94.d43f.493c.54a6.0421.c3a1.
|
||||
1c4a.28ac.fc0b.26ca.5870.e576.f7f1.616d.905f.ef41.33bc.
|
||||
df4d.225e.2d56.7fd6.1395.a3f8.c582
|
||||
(cut 3 [a 1] b)
|
||||
--
|
||||
::
|
||||
++ ob
|
||||
|%
|
||||
@ -2244,6 +1999,7 @@
|
||||
6f5f.ab8e.88b9.c089.b2dc.95a6.aed5.e3a4
|
||||
==
|
||||
--
|
||||
--
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
:: section 2eO, virtualization ::
|
||||
::
|
||||
@ -2760,42 +2516,6 @@
|
||||
e
|
||||
$(c +(c), d (shax d))
|
||||
::
|
||||
++ fo :: modulo prime
|
||||
|_ a/@
|
||||
++ dif
|
||||
|= {b/@ c/@}
|
||||
(sit (sub (add a b) (sit c)))
|
||||
::
|
||||
++ exp
|
||||
|= {b/@ c/@}
|
||||
?: =(0 b)
|
||||
1
|
||||
=+ d=$(b (rsh 0 1 b))
|
||||
=+ e=(pro d d)
|
||||
?:(=(0 (end 0 1 b)) e (pro c e))
|
||||
::
|
||||
++ fra
|
||||
|= {b/@ c/@}
|
||||
(pro b (inv c))
|
||||
::
|
||||
++ inv
|
||||
|= b/@
|
||||
=+ c=(dul:si u:(egcd b a) a)
|
||||
c
|
||||
::
|
||||
++ pro
|
||||
|= {b/@ c/@}
|
||||
(sit (mul b c))
|
||||
::
|
||||
++ sit
|
||||
|= b/@
|
||||
(mod b a)
|
||||
::
|
||||
++ sum
|
||||
|= {b/@ c/@}
|
||||
(sit (add b c))
|
||||
--
|
||||
::
|
||||
++ ga :: GF (bex p.a)
|
||||
|= a/{p/@ q/@ r/@} :: dim poly gen
|
||||
=+ si=(bex p.a)
|
||||
@ -2888,202 +2608,6 @@
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
:: section 2eX, jetted crypto ::
|
||||
::
|
||||
++ aesc :: AES-256
|
||||
~% %aesc + ~
|
||||
|%
|
||||
++ en :: ECB enc
|
||||
~/ %en
|
||||
|= {a/@I b/@H} ^- @uxH
|
||||
=+ ahem
|
||||
(be & (ex a) b)
|
||||
++ de :: ECB dec
|
||||
~/ %de
|
||||
|= {a/@I b/@H} ^- @uxH
|
||||
=+ ahem
|
||||
(be | (ix (ex a)) b)
|
||||
--
|
||||
++ ahem :: AES helpers
|
||||
:: XX should be in aesc, isn't for performance reasons
|
||||
=>
|
||||
=+ =+ [gr=(ga 8 0x11b 3) few==>(fe .(a 5))]
|
||||
=+ [pro=pro.gr dif=dif.gr pow=pow.gr ror=ror.few]
|
||||
[pro=pro dif=dif pow=pow ror=ror nnk=8 nnb=4 nnr=14]
|
||||
=> |%
|
||||
++ cipa :: AES params
|
||||
$_ ^? |%
|
||||
++ co *{p/@ q/@ r/@ s/@} :: col coefs
|
||||
++ ix |~(a/@ *@) :: key index
|
||||
++ ro *{p/@ q/@ r/@ s/@} :: row shifts
|
||||
++ su *@ :: s-box
|
||||
--
|
||||
--
|
||||
|%
|
||||
++ pen :: encrypt
|
||||
^- cipa
|
||||
|%
|
||||
++ co [0x2 0x3 1 1]
|
||||
++ ix |~(a/@ a)
|
||||
++ ro [0 1 2 3]
|
||||
++ su 0x16bb.54b0.0f2d.9941.6842.e6bf.0d89.a18c.
|
||||
df28.55ce.e987.1e9b.948e.d969.1198.f8e1.
|
||||
9e1d.c186.b957.3561.0ef6.0348.66b5.3e70.
|
||||
8a8b.bd4b.1f74.dde8.c6b4.a61c.2e25.78ba.
|
||||
08ae.7a65.eaf4.566c.a94e.d58d.6d37.c8e7.
|
||||
79e4.9591.62ac.d3c2.5c24.0649.0a3a.32e0.
|
||||
db0b.5ede.14b8.ee46.8890.2a22.dc4f.8160.
|
||||
7319.5d64.3d7e.a7c4.1744.975f.ec13.0ccd.
|
||||
d2f3.ff10.21da.b6bc.f538.9d92.8f40.a351.
|
||||
a89f.3c50.7f02.f945.8533.4d43.fbaa.efd0.
|
||||
cf58.4c4a.39be.cb6a.5bb1.fc20.ed00.d153.
|
||||
842f.e329.b3d6.3b52.a05a.6e1b.1a2c.8309.
|
||||
75b2.27eb.e280.1207.9a05.9618.c323.c704.
|
||||
1531.d871.f1e5.a534.ccf7.3f36.2693.fdb7.
|
||||
c072.a49c.afa2.d4ad.f047.59fa.7dc9.82ca.
|
||||
76ab.d7fe.2b67.0130.c56f.6bf2.7b77.7c63
|
||||
--
|
||||
::
|
||||
++ pin :: decrypt
|
||||
^- cipa
|
||||
|%
|
||||
++ co [0xe 0xb 0xd 0x9]
|
||||
++ ix |~(a/@ (sub nnr a))
|
||||
++ ro [0 3 2 1]
|
||||
++ su 0x7d0c.2155.6314.69e1.26d6.77ba.7e04.2b17.
|
||||
6199.5383.3cbb.ebc8.b0f5.2aae.4d3b.e0a0.
|
||||
ef9c.c993.9f7a.e52d.0d4a.b519.a97f.5160.
|
||||
5fec.8027.5910.12b1.31c7.0788.33a8.dd1f.
|
||||
f45a.cd78.fec0.db9a.2079.d2c6.4b3e.56fc.
|
||||
1bbe.18aa.0e62.b76f.89c5.291d.711a.f147.
|
||||
6edf.751c.e837.f9e2.8535.ade7.2274.ac96.
|
||||
73e6.b4f0.cecf.f297.eadc.674f.4111.913a.
|
||||
6b8a.1301.03bd.afc1.020f.3fca.8f1e.2cd0.
|
||||
0645.b3b8.0558.e4f7.0ad3.bc8c.00ab.d890.
|
||||
849d.8da7.5746.155e.dab9.edfd.5048.706c.
|
||||
92b6.655d.cc5c.a4d4.1698.6886.64f6.f872.
|
||||
25d1.8b6d.49a2.5b76.b224.d928.66a1.2e08.
|
||||
4ec3.fa42.0b95.4cee.3d23.c2a6.3294.7b54.
|
||||
cbe9.dec4.4443.8e34.87ff.2f9b.8239.e37c.
|
||||
fbd7.f381.9ea3.40bf.38a5.3630.d56a.0952
|
||||
--
|
||||
::
|
||||
++ mcol
|
||||
|= {a/(list @) b/{p/@ q/@ r/@ s/@}} ^- (list @)
|
||||
=+ c=[p=*@ q=*@ r=*@ s=*@]
|
||||
|- ^- (list @)
|
||||
?~ a ~
|
||||
=> .(p.c (cut 3 [0 1] i.a))
|
||||
=> .(q.c (cut 3 [1 1] i.a))
|
||||
=> .(r.c (cut 3 [2 1] i.a))
|
||||
=> .(s.c (cut 3 [3 1] i.a))
|
||||
:_ $(a t.a)
|
||||
%+ rep 3
|
||||
%+ turn
|
||||
%- limo
|
||||
:~ [[p.c p.b] [q.c q.b] [r.c r.b] [s.c s.b]]
|
||||
[[p.c s.b] [q.c p.b] [r.c q.b] [s.c r.b]]
|
||||
[[p.c r.b] [q.c s.b] [r.c p.b] [s.c q.b]]
|
||||
[[p.c q.b] [q.c r.b] [r.c s.b] [s.c p.b]]
|
||||
==
|
||||
|= {a/{@ @} b/{@ @} c/{@ @} d/{@ @}}
|
||||
:(dif (pro a) (pro b) (pro c) (pro d))
|
||||
::
|
||||
++ pode :: explode to block
|
||||
|= {a/bloq b/@ c/@} ^- (list @)
|
||||
=+ d=(rip a c)
|
||||
=+ m=(met a c)
|
||||
|-
|
||||
?: =(m b)
|
||||
d
|
||||
$(m +(m), d (weld d (limo [0 ~])))
|
||||
++ sube :: s-box word
|
||||
|= {a/@ b/@} ^- @
|
||||
(rep 3 (turn (pode 3 4 a) |=(c/@ (cut 3 [c 1] b))))
|
||||
--
|
||||
|%
|
||||
++ be :: block cipher
|
||||
|= {a/? b/@ c/@H} ^- @uxH
|
||||
~| %be-aesc
|
||||
=> %= .
|
||||
+
|
||||
=> +
|
||||
|%
|
||||
++ ankh
|
||||
|= {a/cipa b/@ c/@}
|
||||
(pode 5 nnb (cut 5 [(mul (ix.a b) nnb) nnb] c))
|
||||
++ sark
|
||||
|= {c/(list @) d/(list @)} ^- (list @)
|
||||
?~ c ~
|
||||
?~ d !!
|
||||
[(mix i.c i.d) $(c t.c, d t.d)]
|
||||
++ srow
|
||||
|= {a/cipa b/(list @)} ^- (list @)
|
||||
=+ [c=0 d=~ e=ro.a]
|
||||
|-
|
||||
?: =(c nnb)
|
||||
d
|
||||
:_ $(c +(c))
|
||||
%+ rep 3
|
||||
%+ turn
|
||||
(limo [0 p.e] [1 q.e] [2 r.e] [3 s.e] ~)
|
||||
|= {f/@ g/@}
|
||||
(cut 3 [f 1] (snag (mod (add g c) nnb) b))
|
||||
++ subs
|
||||
|= {a/cipa b/(list @)} ^- (list @)
|
||||
?~ b ~
|
||||
[(sube i.b su.a) $(b t.b)]
|
||||
--
|
||||
==
|
||||
=+ [d=?:(a pen pin) e=(pode 5 nnb c) f=1]
|
||||
=> .(e (sark e (ankh d 0 b)))
|
||||
|-
|
||||
?. =(nnr f)
|
||||
=> .(e (subs d e))
|
||||
=> .(e (srow d e))
|
||||
=> .(e (mcol e co.d))
|
||||
=> .(e (sark e (ankh d f b)))
|
||||
$(f +(f))
|
||||
=> .(e (subs d e))
|
||||
=> .(e (srow d e))
|
||||
=> .(e (sark e (ankh d nnr b)))
|
||||
(rep 5 e)
|
||||
::
|
||||
++ ex :: key expand
|
||||
|= a/@I ^- @
|
||||
=+ [b=a c=0 d=su:pen i=nnk]
|
||||
|-
|
||||
?: =(i (mul nnb +(nnr)))
|
||||
b
|
||||
=> .(c (cut 5 [(dec i) 1] b))
|
||||
=> ?: =(0 (mod i nnk))
|
||||
=> .(c (ror 3 1 c))
|
||||
=> .(c (sube c d))
|
||||
.(c (mix c (pow (dec (div i nnk)) 2)))
|
||||
?: &((gth nnk 6) =(4 (mod i nnk)))
|
||||
.(c (sube c d))
|
||||
.
|
||||
=> .(c (mix c (cut 5 [(sub i nnk) 1] b)))
|
||||
=> .(b (can 5 [i b] [1 c] ~))
|
||||
$(i +(i))
|
||||
::
|
||||
++ ix :: key expand, inv
|
||||
|= a/@ ^- @
|
||||
=+ [i=1 j=*@ b=*@ c=co:pin]
|
||||
|-
|
||||
?: =(nnr i)
|
||||
a
|
||||
=> .(b (cut 7 [i 1] a))
|
||||
=> .(b (rep 5 (mcol (pode 5 4 b) c)))
|
||||
=> .(j (sub nnr i))
|
||||
%= $
|
||||
i +(i)
|
||||
a
|
||||
%+ can 7
|
||||
:~ [i (cut 7 [0 i] a)]
|
||||
[1 b]
|
||||
[j (cut 7 [+(i) j] a)]
|
||||
==
|
||||
==
|
||||
--
|
||||
::
|
||||
++ curt :: curve25519
|
||||
|= {a/@ b/@}
|
||||
@ -3482,335 +3006,6 @@
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
:: section 2eY, SHA-256 (move me) ::
|
||||
::
|
||||
++ shad |=(ruz/@ (shax (shax ruz))) :: double sha-256
|
||||
++ shaf :: half sha-256
|
||||
|= {sal/@ ruz/@}
|
||||
=+ haz=(shas sal ruz)
|
||||
(mix (end 7 1 haz) (rsh 7 1 haz))
|
||||
::
|
||||
++ shak :: XX shd be PBKDF
|
||||
|= {who/@p wud/@}
|
||||
(shas (mix %shak who) wud)
|
||||
::
|
||||
++ sham :: 128bit noun hash
|
||||
|= yux/* ^- @uvH ^- @
|
||||
?@ yux
|
||||
(shaf %mash yux)
|
||||
(shaf %sham (jam yux))
|
||||
::
|
||||
++ shas :: salted hash
|
||||
|= {sal/@ ruz/@}
|
||||
(shax (mix sal (shax ruz)))
|
||||
::
|
||||
++ shax :: sha-256
|
||||
~/ %shax
|
||||
|= ruz/@ ^- @
|
||||
(shay [(met 3 ruz) ruz])
|
||||
::
|
||||
++ shay :: sha-256 with length
|
||||
~/ %shay
|
||||
|= {len/@u ruz/@} ^- @
|
||||
~| %sha
|
||||
=> .(ruz (cut 3 [0 len] ruz))
|
||||
=+ [few==>(fe .(a 5)) wac=|=({a/@ b/@} (cut 5 [a 1] b))]
|
||||
=+ [sum=sum.few ror=ror.few net=net.few inv=inv.few]
|
||||
=+ ral=(lsh 0 3 len)
|
||||
=+ ^= ful
|
||||
%+ can 0
|
||||
:~ [ral ruz]
|
||||
[8 128]
|
||||
[(mod (sub 960 (mod (add 8 ral) 512)) 512) 0]
|
||||
[64 (~(net fe 6) ral)]
|
||||
==
|
||||
=+ lex=(met 9 ful)
|
||||
=+ ^= kbx 0xc671.78f2.bef9.a3f7.a450.6ceb.90be.fffa.
|
||||
8cc7.0208.84c8.7814.78a5.636f.748f.82ee.
|
||||
682e.6ff3.5b9c.ca4f.4ed8.aa4a.391c.0cb3.
|
||||
34b0.bcb5.2748.774c.1e37.6c08.19a4.c116.
|
||||
106a.a070.f40e.3585.d699.0624.d192.e819.
|
||||
c76c.51a3.c24b.8b70.a81a.664b.a2bf.e8a1.
|
||||
9272.2c85.81c2.c92e.766a.0abb.650a.7354.
|
||||
5338.0d13.4d2c.6dfc.2e1b.2138.27b7.0a85.
|
||||
1429.2967.06ca.6351.d5a7.9147.c6e0.0bf3.
|
||||
bf59.7fc7.b003.27c8.a831.c66d.983e.5152.
|
||||
76f9.88da.5cb0.a9dc.4a74.84aa.2de9.2c6f.
|
||||
240c.a1cc.0fc1.9dc6.efbe.4786.e49b.69c1.
|
||||
c19b.f174.9bdc.06a7.80de.b1fe.72be.5d74.
|
||||
550c.7dc3.2431.85be.1283.5b01.d807.aa98.
|
||||
ab1c.5ed5.923f.82a4.59f1.11f1.3956.c25b.
|
||||
e9b5.dba5.b5c0.fbcf.7137.4491.428a.2f98
|
||||
=+ ^= hax 0x5be0.cd19.1f83.d9ab.9b05.688c.510e.527f.
|
||||
a54f.f53a.3c6e.f372.bb67.ae85.6a09.e667
|
||||
=+ i=0
|
||||
|- ^- @
|
||||
?: =(i lex)
|
||||
(rep 5 (turn (rip 5 hax) net))
|
||||
=+ ^= wox
|
||||
=+ dux=(cut 9 [i 1] ful)
|
||||
=+ wox=(rep 5 (turn (rip 5 dux) net))
|
||||
=+ j=16
|
||||
|- ^- @
|
||||
?: =(64 j)
|
||||
wox
|
||||
=+ :* l=(wac (sub j 15) wox)
|
||||
m=(wac (sub j 2) wox)
|
||||
n=(wac (sub j 16) wox)
|
||||
o=(wac (sub j 7) wox)
|
||||
==
|
||||
=+ x=:(mix (ror 0 7 l) (ror 0 18 l) (rsh 0 3 l))
|
||||
=+ y=:(mix (ror 0 17 m) (ror 0 19 m) (rsh 0 10 m))
|
||||
=+ z=:(sum n x o y)
|
||||
$(wox (con (lsh 5 j z) wox), j +(j))
|
||||
=+ j=0
|
||||
=+ :* a=(wac 0 hax)
|
||||
b=(wac 1 hax)
|
||||
c=(wac 2 hax)
|
||||
d=(wac 3 hax)
|
||||
e=(wac 4 hax)
|
||||
f=(wac 5 hax)
|
||||
g=(wac 6 hax)
|
||||
h=(wac 7 hax)
|
||||
==
|
||||
|- ^- @
|
||||
?: =(64 j)
|
||||
%= ^$
|
||||
i +(i)
|
||||
hax %+ rep 5
|
||||
:~ (sum a (wac 0 hax))
|
||||
(sum b (wac 1 hax))
|
||||
(sum c (wac 2 hax))
|
||||
(sum d (wac 3 hax))
|
||||
(sum e (wac 4 hax))
|
||||
(sum f (wac 5 hax))
|
||||
(sum g (wac 6 hax))
|
||||
(sum h (wac 7 hax))
|
||||
==
|
||||
==
|
||||
=+ l=:(mix (ror 0 2 a) (ror 0 13 a) (ror 0 22 a)) :: s0
|
||||
=+ m=:(mix (dis a b) (dis a c) (dis b c)) :: maj
|
||||
=+ n=(sum l m) :: t2
|
||||
=+ o=:(mix (ror 0 6 e) (ror 0 11 e) (ror 0 25 e)) :: s1
|
||||
=+ p=(mix (dis e f) (dis (inv e) g)) :: ch
|
||||
=+ q=:(sum h o p (wac j kbx) (wac j wox)) :: t1
|
||||
$(j +(j), a (sum q n), b a, c b, d c, e (sum d q), f e, g f, h g)
|
||||
::
|
||||
++ shaw :: hash to nbits
|
||||
|= {sal/@ len/@ ruz/@}
|
||||
(~(raw og (shas sal (mix len ruz))) len)
|
||||
::
|
||||
++ og :: shax-powered rng
|
||||
~/ %og
|
||||
|_ a/@
|
||||
++ rad :: random in range
|
||||
|= b/@ ^- @
|
||||
=+ c=(raw (met 0 b))
|
||||
?:((lth c b) c $(a +(a)))
|
||||
::
|
||||
++ rads :: random continuation
|
||||
|= b/@
|
||||
=+ r=(rad b)
|
||||
[r +>.$(a (shas %og-s r))]
|
||||
::
|
||||
++ raw :: random bits
|
||||
~/ %raw
|
||||
|= b/@ ^- @
|
||||
%+ can
|
||||
0
|
||||
=+ c=(shas %og-a (mix b a))
|
||||
|- ^- (list {@ @})
|
||||
?: =(0 b)
|
||||
~
|
||||
=+ d=(shas %og-b (mix b (mix a c)))
|
||||
?: (lth b 256)
|
||||
[[b (end 0 b d)] ~]
|
||||
[[256 d] $(c d, b (sub b 256))]
|
||||
::
|
||||
++ raws :: random bits
|
||||
|= b/@ :: continuation
|
||||
=+ r=(raw b)
|
||||
[r +>.$(a (shas %og-s r))]
|
||||
--
|
||||
++ shaz :: sha-512
|
||||
|= ruz/@ ^- @
|
||||
(shal [(met 3 ruz) ruz])
|
||||
::
|
||||
++ shal :: sha-512 with length
|
||||
~/ %shal
|
||||
|= {len/@ ruz/@} ^- @
|
||||
=> .(ruz (cut 3 [0 len] ruz))
|
||||
=+ [few==>(fe .(a 6)) wac=|=({a/@ b/@} (cut 6 [a 1] b))]
|
||||
=+ [sum=sum.few ror=ror.few net=net.few inv=inv.few]
|
||||
=+ ral=(lsh 0 3 len)
|
||||
=+ ^= ful
|
||||
%+ can 0
|
||||
:~ [ral ruz]
|
||||
[8 128]
|
||||
[(mod (sub 1.920 (mod (add 8 ral) 1.024)) 1.024) 0]
|
||||
[128 (~(net fe 7) ral)]
|
||||
==
|
||||
=+ lex=(met 10 ful)
|
||||
=+ ^= kbx 0x6c44.198c.4a47.5817.5fcb.6fab.3ad6.faec.
|
||||
597f.299c.fc65.7e2a.4cc5.d4be.cb3e.42b6.
|
||||
431d.67c4.9c10.0d4c.3c9e.be0a.15c9.bebc.
|
||||
32ca.ab7b.40c7.2493.28db.77f5.2304.7d84.
|
||||
1b71.0b35.131c.471b.113f.9804.bef9.0dae.
|
||||
0a63.7dc5.a2c8.98a6.06f0.67aa.7217.6fba.
|
||||
f57d.4f7f.ee6e.d178.eada.7dd6.cde0.eb1e.
|
||||
d186.b8c7.21c0.c207.ca27.3ece.ea26.619c.
|
||||
c671.78f2.e372.532b.bef9.a3f7.b2c6.7915.
|
||||
a450.6ceb.de82.bde9.90be.fffa.2363.1e28.
|
||||
8cc7.0208.1a64.39ec.84c8.7814.a1f0.ab72.
|
||||
78a5.636f.4317.2f60.748f.82ee.5def.b2fc.
|
||||
682e.6ff3.d6b2.b8a3.5b9c.ca4f.7763.e373.
|
||||
4ed8.aa4a.e341.8acb.391c.0cb3.c5c9.5a63.
|
||||
34b0.bcb5.e19b.48a8.2748.774c.df8e.eb99.
|
||||
1e37.6c08.5141.ab53.19a4.c116.b8d2.d0c8.
|
||||
106a.a070.32bb.d1b8.f40e.3585.5771.202a.
|
||||
d699.0624.5565.a910.d192.e819.d6ef.5218.
|
||||
c76c.51a3.0654.be30.c24b.8b70.d0f8.9791.
|
||||
a81a.664b.bc42.3001.a2bf.e8a1.4cf1.0364.
|
||||
9272.2c85.1482.353b.81c2.c92e.47ed.aee6.
|
||||
766a.0abb.3c77.b2a8.650a.7354.8baf.63de.
|
||||
5338.0d13.9d95.b3df.4d2c.6dfc.5ac4.2aed.
|
||||
2e1b.2138.5c26.c926.27b7.0a85.46d2.2ffc.
|
||||
1429.2967.0a0e.6e70.06ca.6351.e003.826f.
|
||||
d5a7.9147.930a.a725.c6e0.0bf3.3da8.8fc2.
|
||||
bf59.7fc7.beef.0ee4.b003.27c8.98fb.213f.
|
||||
a831.c66d.2db4.3210.983e.5152.ee66.dfab.
|
||||
76f9.88da.8311.53b5.5cb0.a9dc.bd41.fbd4.
|
||||
4a74.84aa.6ea6.e483.2de9.2c6f.592b.0275.
|
||||
240c.a1cc.77ac.9c65.0fc1.9dc6.8b8c.d5b5.
|
||||
efbe.4786.384f.25e3.e49b.69c1.9ef1.4ad2.
|
||||
c19b.f174.cf69.2694.9bdc.06a7.25c7.1235.
|
||||
80de.b1fe.3b16.96b1.72be.5d74.f27b.896f.
|
||||
550c.7dc3.d5ff.b4e2.2431.85be.4ee4.b28c.
|
||||
1283.5b01.4570.6fbe.d807.aa98.a303.0242.
|
||||
ab1c.5ed5.da6d.8118.923f.82a4.af19.4f9b.
|
||||
59f1.11f1.b605.d019.3956.c25b.f348.b538.
|
||||
e9b5.dba5.8189.dbbc.b5c0.fbcf.ec4d.3b2f.
|
||||
7137.4491.23ef.65cd.428a.2f98.d728.ae22
|
||||
=+ ^= hax 0x5be0.cd19.137e.2179.1f83.d9ab.fb41.bd6b.
|
||||
9b05.688c.2b3e.6c1f.510e.527f.ade6.82d1.
|
||||
a54f.f53a.5f1d.36f1.3c6e.f372.fe94.f82b.
|
||||
bb67.ae85.84ca.a73b.6a09.e667.f3bc.c908
|
||||
=+ i=0
|
||||
|- ^- @
|
||||
?: =(i lex)
|
||||
(rep 6 (turn (rip 6 hax) net))
|
||||
=+ ^= wox
|
||||
=+ dux=(cut 10 [i 1] ful)
|
||||
=+ wox=(rep 6 (turn (rip 6 dux) net))
|
||||
=+ j=16
|
||||
|- ^- @
|
||||
?: =(80 j)
|
||||
wox
|
||||
=+ :* l=(wac (sub j 15) wox)
|
||||
m=(wac (sub j 2) wox)
|
||||
n=(wac (sub j 16) wox)
|
||||
o=(wac (sub j 7) wox)
|
||||
==
|
||||
=+ x=:(mix (ror 0 1 l) (ror 0 8 l) (rsh 0 7 l))
|
||||
=+ y=:(mix (ror 0 19 m) (ror 0 61 m) (rsh 0 6 m))
|
||||
=+ z=:(sum n x o y)
|
||||
$(wox (con (lsh 6 j z) wox), j +(j))
|
||||
=+ j=0
|
||||
=+ :* a=(wac 0 hax)
|
||||
b=(wac 1 hax)
|
||||
c=(wac 2 hax)
|
||||
d=(wac 3 hax)
|
||||
e=(wac 4 hax)
|
||||
f=(wac 5 hax)
|
||||
g=(wac 6 hax)
|
||||
h=(wac 7 hax)
|
||||
==
|
||||
|- ^- @
|
||||
?: =(80 j)
|
||||
%= ^$
|
||||
i +(i)
|
||||
hax %+ rep 6
|
||||
:~ (sum a (wac 0 hax))
|
||||
(sum b (wac 1 hax))
|
||||
(sum c (wac 2 hax))
|
||||
(sum d (wac 3 hax))
|
||||
(sum e (wac 4 hax))
|
||||
(sum f (wac 5 hax))
|
||||
(sum g (wac 6 hax))
|
||||
(sum h (wac 7 hax))
|
||||
==
|
||||
==
|
||||
=+ l=:(mix (ror 0 28 a) (ror 0 34 a) (ror 0 39 a)) :: S0
|
||||
=+ m=:(mix (dis a b) (dis a c) (dis b c)) :: maj
|
||||
=+ n=(sum l m) :: t2
|
||||
=+ o=:(mix (ror 0 14 e) (ror 0 18 e) (ror 0 41 e)) :: S1
|
||||
=+ p=(mix (dis e f) (dis (inv e) g)) :: ch
|
||||
=+ q=:(sum h o p (wac j kbx) (wac j wox)) :: t1
|
||||
$(j +(j), a (sum q n), b a, c b, d c, e (sum d q), f e, g f, h g)
|
||||
::
|
||||
++ shan :: sha-1 (deprecated)
|
||||
|= ruz/@
|
||||
=+ [few==>(fe .(a 5)) wac=|=({a/@ b/@} (cut 5 [a 1] b))]
|
||||
=+ [sum=sum.few ror=ror.few rol=rol.few net=net.few inv=inv.few]
|
||||
=+ ral=(lsh 0 3 (met 3 ruz))
|
||||
=+ ^= ful
|
||||
%+ can 0
|
||||
:~ [ral ruz]
|
||||
[8 128]
|
||||
[(mod (sub 960 (mod (add 8 ral) 512)) 512) 0]
|
||||
[64 (~(net fe 6) ral)]
|
||||
==
|
||||
=+ lex=(met 9 ful)
|
||||
=+ kbx=0xca62.c1d6.8f1b.bcdc.6ed9.eba1.5a82.7999
|
||||
=+ hax=0xc3d2.e1f0.1032.5476.98ba.dcfe.efcd.ab89.6745.2301
|
||||
=+ i=0
|
||||
|-
|
||||
?: =(i lex)
|
||||
(rep 5 (flop (rip 5 hax)))
|
||||
=+ ^= wox
|
||||
=+ dux=(cut 9 [i 1] ful)
|
||||
=+ wox=(rep 5 (turn (rip 5 dux) net))
|
||||
=+ j=16
|
||||
|- ^- @
|
||||
?: =(80 j)
|
||||
wox
|
||||
=+ :* l=(wac (sub j 3) wox)
|
||||
m=(wac (sub j 8) wox)
|
||||
n=(wac (sub j 14) wox)
|
||||
o=(wac (sub j 16) wox)
|
||||
==
|
||||
=+ z=(rol 0 1 :(mix l m n o))
|
||||
$(wox (con (lsh 5 j z) wox), j +(j))
|
||||
=+ j=0
|
||||
=+ :* a=(wac 0 hax)
|
||||
b=(wac 1 hax)
|
||||
c=(wac 2 hax)
|
||||
d=(wac 3 hax)
|
||||
e=(wac 4 hax)
|
||||
==
|
||||
|- ^- @
|
||||
?: =(80 j)
|
||||
%= ^$
|
||||
i +(i)
|
||||
hax %+ rep 5
|
||||
:~
|
||||
(sum a (wac 0 hax))
|
||||
(sum b (wac 1 hax))
|
||||
(sum c (wac 2 hax))
|
||||
(sum d (wac 3 hax))
|
||||
(sum e (wac 4 hax))
|
||||
==
|
||||
==
|
||||
=+ fx=(con (dis b c) (dis (not 5 1 b) d))
|
||||
=+ fy=:(mix b c d)
|
||||
=+ fz=:(con (dis b c) (dis b d) (dis c d))
|
||||
=+ ^= tem
|
||||
?: &((gte j 0) (lte j 19))
|
||||
:(sum (rol 0 5 a) fx e (wac 0 kbx) (wac j wox))
|
||||
?: &((gte j 20) (lte j 39))
|
||||
:(sum (rol 0 5 a) fy e (wac 1 kbx) (wac j wox))
|
||||
?: &((gte j 40) (lte j 59))
|
||||
:(sum (rol 0 5 a) fz e (wac 2 kbx) (wac j wox))
|
||||
:(sum (rol 0 5 a) fy e (wac 3 kbx) (wac j wox))
|
||||
$(j +(j), a tem, b a, c (rol 0 30 b), d c, e d)
|
||||
::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
:: section 2eZ, OLD rendering (kill me) ::
|
||||
|
1028
arvo/test.hoon
1028
arvo/test.hoon
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user