Merge commit '84d1ee8' into relearning

This commit is contained in:
C. Guy Yarvin 2016-09-02 15:26:18 -07:00
commit 1aa86242b8

View File

@ -1307,24 +1307,21 @@
|_ {key/@H mod/bloq ctr/@H} |_ {key/@H mod/bloq ctr/@H}
++ en ++ en
~/ %en ~/ %en
|= txt/@ ^- @ux |= txt/@
=+ pts=?:(=(txt 0) `(list @)`~[0] (flop (rip 3 txt))) ^- @ux
=| cts/(list @) =/ encrypt ~(en ecba key)
=+ str=(flop (rip 3 (~(en ecba key) ctr))) =/ blocks (met 7 txt)
%+ rep 3 =. blocks ?:(=(0 blocks) 1 blocks)
:: logically, flop twice here =/ bytes (met 3 txt)
|- ^- (list @) =. bytes ?:(=(0 bytes) 1 bytes)
?~ pts %+ mix txt
cts %^ rsh 3 (sub (mul 16 blocks) bytes)
?~ str %+ rep 7
=+ nctr=(inc mod ctr) %- flop :: stupid backwards AES
$(str (flop (rip 3 (~(en ecba key) nctr))), ctr nctr) |- ^- (list @ux)
%= $ ?: =(blocks 0) ~
cts :_ cts :- (encrypt ctr)
(mix i.str i.pts) $(ctr (inc mod ctr), blocks (dec blocks))
str t.str
pts t.pts
==
++ de en ++ de en
-- --
:: ::
@ -1333,24 +1330,21 @@
|_ {key/@I mod/bloq ctr/@H} |_ {key/@I mod/bloq ctr/@H}
++ en ++ en
~/ %en ~/ %en
|= txt/@ ^- @ux |= txt/@
=+ pts=?:(=(txt 0) `(list @)`~[0] (flop (rip 3 txt))) ^- @ux
=| cts/(list @) =/ encrypt ~(en ecbb key)
=+ str=(flop (rip 3 (~(en ecbb key) ctr))) =/ blocks (met 7 txt)
%+ rep 3 =. blocks ?:(=(0 blocks) 1 blocks)
:: logically, flop twice here =/ bytes (met 3 txt)
|- ^- (list @) =. bytes ?:(=(0 bytes) 1 bytes)
?~ pts %+ mix txt
cts %^ rsh 3 (sub (mul 16 blocks) bytes)
?~ str %+ rep 7
=+ nctr=(inc mod ctr) %- flop :: stupid backwards AES
$(str (flop (rip 3 (~(en ecbb key) nctr))), ctr nctr) |- ^- (list @ux)
%= $ ?: =(blocks 0) ~
cts :_ cts :- (encrypt ctr)
(mix i.str i.pts) $(ctr (inc mod ctr), blocks (dec blocks))
str t.str
pts t.pts
==
++ de en ++ de en
-- --
:: ::
@ -1359,24 +1353,21 @@
|_ {key/@I mod/bloq ctr/@H} |_ {key/@I mod/bloq ctr/@H}
++ en ++ en
~/ %en ~/ %en
|= txt/@ ^- @ux |= txt/@
=+ pts=?:(=(txt 0) `(list @)`~[0] (flop (rip 3 txt))) ^- @ux
=| cts/(list @) =/ encrypt ~(en ecbc key)
=+ str=(flop (rip 3 (~(en ecbc key) ctr))) =/ blocks (met 7 txt)
%+ rep 3 =. blocks ?:(=(0 blocks) 1 blocks)
:: logically, flop twice here =/ bytes (met 3 txt)
|- ^- (list @) =. bytes ?:(=(0 bytes) 1 bytes)
?~ pts %+ mix txt
cts %^ rsh 3 (sub (mul 16 blocks) bytes)
?~ str %+ rep 7
=+ nctr=(inc mod ctr) %- flop :: stupid backwards AES
$(str (flop (rip 3 (~(en ecbc key) nctr))), ctr nctr) |- ^- (list @ux)
%= $ ?: =(blocks 0) ~
cts :_ cts :- (encrypt ctr)
(mix i.str i.pts) $(ctr (inc mod ctr), blocks (dec blocks))
str t.str
pts t.pts
==
++ de en ++ de en
-- --
:: ::
@ -1539,7 +1530,7 @@
++ en ++ en
~/ %en ~/ %en
|= txt/@ |= txt/@
^- {@uxH @ux} ^- (pair @uxH @ux)
=+ [k1=(rsh 7 1 key) k2=(end 7 1 key)] =+ [k1=(rsh 7 1 key) k2=(end 7 1 key)]
=+ iv=(s2va k1 (weld vec (limo ~[txt]))) =+ iv=(s2va k1 (weld vec (limo ~[txt])))
:- :-
@ -1563,7 +1554,7 @@
++ en ++ en
~/ %en ~/ %en
|= txt/@ |= txt/@
^- {@uxH @ux} ^- (pair @uxH @ux)
=+ [k1=(rsh 5 3 key) k2=(end 5 3 key)] =+ [k1=(rsh 5 3 key) k2=(end 5 3 key)]
=+ iv=(s2vb k1 (weld vec (limo ~[txt]))) =+ iv=(s2vb k1 (weld vec (limo ~[txt])))
:- :-
@ -1587,7 +1578,7 @@
++ en ++ en
~/ %en ~/ %en
|= txt/@ |= txt/@
^- {@uxH @ux} ^- (pair @uxH @ux)
=+ [k1=(rsh 8 1 key) k2=(end 8 1 key)] =+ [k1=(rsh 8 1 key) k2=(end 8 1 key)]
=+ iv=(s2vc k1 (weld vec (limo ~[txt]))) =+ iv=(s2vc k1 (weld vec (limo ~[txt])))
:- :-
@ -1804,50 +1795,52 @@
++ as ++ as
|% |%
++ sign ++ sign
|= {nonc/@ msg/@} |= {@ msg/@}
^- @ux ^- @ux
?~ sek ~| %pubkey-only !! ?~ sek ~| %pubkey-only !!
=+ nms=(jam [nonc msg]) (jam [(sign:ed msg sgn.u.sek) msg])
(jam [(sign:ed nms sgn.u.sek) nms])
++ sure ++ sure
|= {nonc/@ txt/@} |= {@ txt/@}
^- (unit @ux) ^- (unit @ux)
=+ ((hard {sig/@ nms/@}) (cue txt)) =+ ((hard {sig/@ msg/@}) (cue txt))
?. (veri:ed sig nms sgn.pub) ~ ?. (veri:ed sig msg sgn.pub) ~
=+ ((hard {n/@ msg/@}) (cue nms))
?. =(nonc n) ~
(some msg) (some msg)
++ seal ++ seal
|= {bpk/pass nonc/@ msg/@} |= {bpk/pass m1/@ m2/@}
^- @ux ^- @ux
?~ sek ~| %pubkey-only !! ?~ sek ~| %pubkey-only !!
?> =('b' (end 3 1 bpk)) ?> =('b' (end 3 1 bpk))
=+ pk=(rsh 8 1 (rsh 3 1 bpk)) =+ pk=(rsh 8 1 (rsh 3 1 bpk))
=+ shar=(shax (shar:ed pk cry.u.sek)) =+ shar=(shax (shar:ed pk cry.u.sek))
(jam [nonc (~(en siva:aes shar ~[nonc]) msg)]) =+ msg=(jam m1 m2)
=+ smsg=(sign ~ msg)
(jam (~(en siva:aes shar ~) smsg))
++ tear ++ tear
|= {bpk/pass txt/@} |= {bpk/pass txt/@}
^- (unit {@ux @ux}) ^- (unit (pair @ux @ux))
?~ sek ~| %pubkey-only !! ?~ sek ~| %pubkey-only !!
?> =('b' (end 3 1 bpk)) ?> =('b' (end 3 1 bpk))
=+ pk=(rsh 8 1 (rsh 3 1 bpk)) =+ pk=(rsh 8 1 (rsh 3 1 bpk))
=+ shar=(shax (shar:ed pk cry.u.sek)) =+ shar=(shax (shar:ed pk cry.u.sek))
=+ ((hard {nonc/@ iv/@ cph/@}) (cue txt)) =+ ((hard {iv/@ cph/@}) (cue txt))
%+ both (some nonc) =+ try=(~(de siva:aes shar ~) iv cph)
(~(de siva:aes shar ~[nonc]) iv cph) ?~ try ~
=+ veri=(sure:as:(com:nu:crub bpk) ~ u.try)
?~ veri ~
(some ((hard (pair @ux @ux)) (cue u.veri)))
-- --
++ de ++ de
|= {key/@I cph/@} |= {key/@J cph/@}
^- (unit @ux) ^- (unit @ux)
%+ ~(de siva:aes key ~) %+ ~(de sivc:aes (shaz key) ~)
(end 7 1 cph) (end 7 1 cph)
(rsh 7 1 cph) (rsh 7 1 cph)
:: ::
++ dy |=({key/@I cph/@} (need (de key cph))) ++ dy |=({key/@I cph/@} (need (de key cph)))
++ en ++ en
|= {key/@I msg/@} |= {key/@J msg/@}
^- @ux ^- @ux
(cat 7 (~(en siva:aes key ~) msg)) (cat 7 (~(en sivc:aes (shaz key) ~) msg))
++ ex ++ ex
|% |%
++ fig ^- @uvH (shaf %bfig sgn.^pub) ++ fig ^- @uvH (shaf %bfig sgn.^pub)
@ -1861,53 +1854,45 @@
|% |%
++ pit ++ pit
|= {w/@ seed/@} |= {w/@ seed/@}
=+ bits=(shaz seed) :: need 512 bits =+ wid=(add (div w 8) ?:(=((mod w 8) 0) 0 1))
=+ [c=(rsh 8 1 seed) s=(end 8 1 seed)] =+ bits=(shal wid seed)
=+ [c=(rsh 8 1 bits) s=(end 8 1 bits)]
..nu(pub [cry=(puck:ed c) sgn=(puck:ed s)], sek `[cry=c sgn=s]) ..nu(pub [cry=(puck:ed c) sgn=(puck:ed s)], sek `[cry=c sgn=s])
++ nol ++ nol
|= a/ring |= a/ring
=+ [c=(rsh 8 1 a) s=(end 8 1 a)] =+ [mag=(end 3 1 a) bod=(rsh 3 1 a)]
~| %not-crub-seckey ?> =('B' mag)
=+ [c=(rsh 8 1 bod) s=(end 8 1 bod)]
..nu(pub [cry=(puck:ed c) sgn=(puck:ed s)], sek `[cry=c sgn=s]) ..nu(pub [cry=(puck:ed c) sgn=(puck:ed s)], sek `[cry=c sgn=s])
++ com ++ com
|= a/pass |= a/pass
..nu(pub [cry=(rsh 8 1 a) sgn=(end 8 1 a)], sek ~) =+ [mag=(end 3 1 a) bod=(rsh 3 1 a)]
~| %not-crub-pubkey ?> =('b' mag)
..nu(pub [cry=(rsh 8 1 bod) sgn=(end 8 1 bod)], sek ~)
-- --
-- --
:: ::
++ brew :: create keypair ++ trub :: test crub
|= {a/@ b/@} :: width seed |= msg/@t
^- acru :: make acru cores
(pit:nu:crub a b) =/ ali (pit:nu:crub 512 (shaz 'Alice'))
:: =/ ali-pub (com:nu:crub pub:ex.ali)
++ hail :: activate public key =/ bob (pit:nu:crub 512 (shaz 'Robert'))
|= a/pass =/ bob-pub (com:nu:crub pub:ex.bob)
^- acru :: alice signs and encrypts a symmetric key to bob
=+ [mag=(end 3 1 a) bod=(rsh 3 1 a)] =/ secret-key %- shaz
?> =('b' mag) 'Let there be no duplicity when taking a stand against him.'
(com:nu:crub bod) =/ signed-key (sign:as.ali ~ secret-key)
:: =/ crypted-key (seal:as.ali pub:ex.bob-pub ~ signed-key)
++ wear :: activate secret key :: bob decrypts and verifies
|= a/ring =/ decrypt-key-attempt (tear:as.bob pub:ex.ali-pub crypted-key)
^- acru =/ decrypted-key ~| %decrypt-fail (need decrypt-key-attempt)
=+ [mag=(end 3 1 a) bod=(rsh 3 1 a)] =/ verify-key-attempt (sure:as.ali-pub ~ q.decrypted-key)
?> =('B' mag) =/ verified-key ~| %verify-fail (need verify-key-attempt)
(nol:nu:crub bod) :: bob encrypts with symmetric key
:: =/ crypted-msg (en.bob verified-key msg)
++ trub :: test ed :: alice decrypts with same key
|= msg/@tas `@t`(dy.ali secret-key crypted-msg)
^- @
=+ ali=(brew 1.024 (cat 8 (shax 'ali') (shad 'ali')))
=+ bob=(brew 1.024 (cat 8 (shax 'bob') (shad 'bob')))
=+ tef=(sign:as.ali [0 msg])
=+ lov=(sure:as.ali [0 tef])
?. &(?=(^ lov) =(msg u.lov))
~|(%test-fail-sign !!)
=+ key=(shax (shax (shax msg)))
=+ sax=(seal:as.ali pub:ex.bob key msg)
=+ tin=(tear:as.bob pub:ex.ali sax)
?. &(?=(^ tin) =(key p.u.tin) =(msg q.u.tin))
~|(%test-fail-seal !!)
msg
:: ::
++ hmac :: HMAC-SHA1 ++ hmac :: HMAC-SHA1
|= {key/@ mes/@} |= {key/@ mes/@}