mirror of
https://github.com/urbit/shrub.git
synced 2025-01-07 13:37:36 +03:00
Add length parameter to AES CTR modes
This commit is contained in:
parent
b17d033e84
commit
38ff23eb6b
@ -430,7 +430,7 @@
|
|||||||
::
|
::
|
||||||
++ ctra :: AES-128 CTR
|
++ ctra :: AES-128 CTR
|
||||||
~% %ctra +> ~
|
~% %ctra +> ~
|
||||||
|_ {key/@H mod/bloq ctr/@H}
|
|_ {key/@H mod/bloq len/@ ctr/@H}
|
||||||
++ en
|
++ en
|
||||||
~/ %en
|
~/ %en
|
||||||
|= txt/@
|
|= txt/@
|
||||||
@ -438,10 +438,9 @@
|
|||||||
=/ encrypt ~(en ecba key)
|
=/ encrypt ~(en ecba key)
|
||||||
=/ blocks (met 7 txt)
|
=/ blocks (met 7 txt)
|
||||||
=. blocks ?:(=(0 blocks) 1 blocks)
|
=. blocks ?:(=(0 blocks) 1 blocks)
|
||||||
=/ bytes (met 3 txt)
|
?> (gte len (met 3 txt))
|
||||||
=. bytes ?:(=(0 bytes) 1 bytes)
|
|
||||||
%+ mix txt
|
%+ mix txt
|
||||||
%^ rsh 3 (sub (mul 16 blocks) bytes)
|
%^ rsh 3 (sub (mul 16 blocks) len)
|
||||||
%+ rep 7
|
%+ rep 7
|
||||||
%- flop :: stupid backwards AES
|
%- flop :: stupid backwards AES
|
||||||
|- ^- (list @ux)
|
|- ^- (list @ux)
|
||||||
@ -453,7 +452,7 @@
|
|||||||
::
|
::
|
||||||
++ ctrb :: AES-192 CTR
|
++ ctrb :: AES-192 CTR
|
||||||
~% %ctrb +> ~
|
~% %ctrb +> ~
|
||||||
|_ {key/@I mod/bloq ctr/@H}
|
|_ {key/@I mod/bloq len/@ ctr/@H}
|
||||||
++ en
|
++ en
|
||||||
~/ %en
|
~/ %en
|
||||||
|= txt/@
|
|= txt/@
|
||||||
@ -461,10 +460,9 @@
|
|||||||
=/ encrypt ~(en ecbb key)
|
=/ encrypt ~(en ecbb key)
|
||||||
=/ blocks (met 7 txt)
|
=/ blocks (met 7 txt)
|
||||||
=. blocks ?:(=(0 blocks) 1 blocks)
|
=. blocks ?:(=(0 blocks) 1 blocks)
|
||||||
=/ bytes (met 3 txt)
|
?> (gte len (met 3 txt))
|
||||||
=. bytes ?:(=(0 bytes) 1 bytes)
|
|
||||||
%+ mix txt
|
%+ mix txt
|
||||||
%^ rsh 3 (sub (mul 16 blocks) bytes)
|
%^ rsh 3 (sub (mul 16 blocks) len)
|
||||||
%+ rep 7
|
%+ rep 7
|
||||||
%- flop :: stupid backwards AES
|
%- flop :: stupid backwards AES
|
||||||
|- ^- (list @ux)
|
|- ^- (list @ux)
|
||||||
@ -476,7 +474,7 @@
|
|||||||
::
|
::
|
||||||
++ ctrc :: AES-256 CTR
|
++ ctrc :: AES-256 CTR
|
||||||
~% %ctrc +> ~
|
~% %ctrc +> ~
|
||||||
|_ {key/@I mod/bloq ctr/@H}
|
|_ {key/@I mod/bloq len/@ ctr/@H}
|
||||||
++ en
|
++ en
|
||||||
~/ %en
|
~/ %en
|
||||||
|= txt/@
|
|= txt/@
|
||||||
@ -484,10 +482,9 @@
|
|||||||
=/ encrypt ~(en ecbc key)
|
=/ encrypt ~(en ecbc key)
|
||||||
=/ blocks (met 7 txt)
|
=/ blocks (met 7 txt)
|
||||||
=. blocks ?:(=(0 blocks) 1 blocks)
|
=. blocks ?:(=(0 blocks) 1 blocks)
|
||||||
=/ bytes (met 3 txt)
|
?> (gte len (met 3 txt))
|
||||||
=. bytes ?:(=(0 bytes) 1 bytes)
|
|
||||||
%+ mix txt
|
%+ mix txt
|
||||||
%^ rsh 3 (sub (mul 16 blocks) bytes)
|
%^ rsh 3 (sub (mul 16 blocks) len)
|
||||||
%+ rep 7
|
%+ rep 7
|
||||||
%- flop :: stupid backwards AES
|
%- flop :: stupid backwards AES
|
||||||
|- ^- (list @ux)
|
|- ^- (list @ux)
|
||||||
@ -656,19 +653,21 @@
|
|||||||
++ en
|
++ en
|
||||||
~/ %en
|
~/ %en
|
||||||
|= txt/@
|
|= txt/@
|
||||||
^- (pair @uxH @ux)
|
^- (trel @uxH @ud @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])))
|
||||||
:-
|
=+ len=(met 3 txt)
|
||||||
|
:+
|
||||||
iv
|
iv
|
||||||
(~(en ctra k2 7 (dis iv 0xffff.ffff.ffff.ffff.7fff.ffff.7fff.ffff)) txt)
|
len
|
||||||
|
(~(en ctra k2 7 len (dis iv 0xffff.ffff.ffff.ffff.7fff.ffff.7fff.ffff)) txt)
|
||||||
++ de
|
++ de
|
||||||
~/ %de
|
~/ %de
|
||||||
|= {iv/@H txt/@}
|
|= {iv/@H len/@ txt/@}
|
||||||
^- (unit @ux)
|
^- (unit @ux)
|
||||||
=+ [k1=(rsh 7 1 key) k2=(end 7 1 key)]
|
=+ [k1=(rsh 7 1 key) k2=(end 7 1 key)]
|
||||||
=+ ^= pln
|
=+ ^= pln
|
||||||
(~(de ctra k2 7 (dis iv 0xffff.ffff.ffff.ffff.7fff.ffff.7fff.ffff)) txt)
|
(~(de ctra k2 7 len (dis iv 0xffff.ffff.ffff.ffff.7fff.ffff.7fff.ffff)) txt)
|
||||||
?. =((s2va k1 (weld vec (limo ~[pln]))) iv)
|
?. =((s2va k1 (weld vec (limo ~[pln]))) iv)
|
||||||
~
|
~
|
||||||
`pln
|
`pln
|
||||||
@ -680,19 +679,21 @@
|
|||||||
++ en
|
++ en
|
||||||
~/ %en
|
~/ %en
|
||||||
|= txt/@
|
|= txt/@
|
||||||
^- (pair @uxH @ux)
|
^- (trel @uxH @ud @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])))
|
||||||
:-
|
=+ len=(met 3 txt)
|
||||||
|
:+
|
||||||
iv
|
iv
|
||||||
(~(en ctrb k2 7 (dis iv 0xffff.ffff.ffff.ffff.7fff.ffff.7fff.ffff)) txt)
|
len
|
||||||
|
(~(en ctrb k2 7 len (dis iv 0xffff.ffff.ffff.ffff.7fff.ffff.7fff.ffff)) txt)
|
||||||
++ de
|
++ de
|
||||||
~/ %de
|
~/ %de
|
||||||
|= {iv/@H txt/@}
|
|= {iv/@H len/@ txt/@}
|
||||||
^- (unit @ux)
|
^- (unit @ux)
|
||||||
=+ [k1=(rsh 5 3 key) k2=(end 5 3 key)]
|
=+ [k1=(rsh 5 3 key) k2=(end 5 3 key)]
|
||||||
=+ ^= pln
|
=+ ^= pln
|
||||||
(~(de ctrb k2 7 (dis iv 0xffff.ffff.ffff.ffff.7fff.ffff.7fff.ffff)) txt)
|
(~(de ctrb k2 7 len (dis iv 0xffff.ffff.ffff.ffff.7fff.ffff.7fff.ffff)) txt)
|
||||||
?. =((s2vb k1 (weld vec (limo ~[pln]))) iv)
|
?. =((s2vb k1 (weld vec (limo ~[pln]))) iv)
|
||||||
~
|
~
|
||||||
`pln
|
`pln
|
||||||
@ -704,19 +705,21 @@
|
|||||||
++ en
|
++ en
|
||||||
~/ %en
|
~/ %en
|
||||||
|= txt/@
|
|= txt/@
|
||||||
^- (pair @uxH @ux)
|
^- (trel @uxH @ud @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])))
|
||||||
:-
|
=+ len=(met 3 txt)
|
||||||
|
:+
|
||||||
iv
|
iv
|
||||||
(~(en ctrc k2 7 (dis iv 0xffff.ffff.ffff.ffff.7fff.ffff.7fff.ffff)) txt)
|
len
|
||||||
|
(~(en ctrc k2 7 len (dis iv 0xffff.ffff.ffff.ffff.7fff.ffff.7fff.ffff)) txt)
|
||||||
++ de
|
++ de
|
||||||
~/ %de
|
~/ %de
|
||||||
|= {iv/@H txt/@}
|
|= {iv/@H len/@ txt/@}
|
||||||
^- (unit @ux)
|
^- (unit @ux)
|
||||||
=+ [k1=(rsh 8 1 key) k2=(end 8 1 key)]
|
=+ [k1=(rsh 8 1 key) k2=(end 8 1 key)]
|
||||||
=+ ^= pln
|
=+ ^= pln
|
||||||
(~(de ctrc k2 7 (dis iv 0xffff.ffff.ffff.ffff.7fff.ffff.7fff.ffff)) txt)
|
(~(de ctrc k2 7 len (dis iv 0xffff.ffff.ffff.ffff.7fff.ffff.7fff.ffff)) txt)
|
||||||
?. =((s2vc k1 (weld vec (limo ~[pln]))) iv)
|
?. =((s2vc k1 (weld vec (limo ~[pln]))) iv)
|
||||||
~
|
~
|
||||||
`pln
|
`pln
|
||||||
@ -948,24 +951,26 @@
|
|||||||
?> =('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 {iv/@ cph/@}) (cue txt))
|
=+ ((hard {iv/@ len/@ cph/@}) (cue txt))
|
||||||
=+ try=(~(de siva:aes shar ~) iv cph)
|
=+ try=(~(de siva:aes shar ~) iv len cph)
|
||||||
?~ try ~
|
?~ try ~
|
||||||
=+ veri=(sure:as:(com:nu:crub bpk) ~ u.try)
|
=+ veri=(sure:as:(com:nu:crub bpk) ~ u.try)
|
||||||
?~ veri ~
|
?~ veri ~
|
||||||
(some ((hard (pair @ux @ux)) (cue u.veri)))
|
(some ((hard (pair @ux @ux)) (cue u.veri)))
|
||||||
--
|
--
|
||||||
++ de
|
++ de
|
||||||
|= {key/@J cph/@}
|
|= {key/@J txt/@}
|
||||||
^- (unit @ux)
|
^- (unit @ux)
|
||||||
%+ ~(de sivc:aes (shaz key) ~)
|
=+ ((hard {iv/@ len/@ cph/@}) (cue txt))
|
||||||
(end 7 1 cph)
|
%^ ~(de sivc:aes (shaz key) ~)
|
||||||
(rsh 7 1 cph)
|
iv
|
||||||
|
len
|
||||||
|
cph
|
||||||
++ dy |=({key/@I cph/@} (need (de key cph)))
|
++ dy |=({key/@I cph/@} (need (de key cph)))
|
||||||
++ en
|
++ en
|
||||||
|= {key/@J msg/@}
|
|= {key/@J msg/@}
|
||||||
^- @ux
|
^- @ux
|
||||||
(cat 7 (~(en sivc:aes (shaz key) ~) msg))
|
(jam (~(en sivc:aes (shaz key) ~) msg))
|
||||||
++ ex
|
++ ex
|
||||||
|%
|
|%
|
||||||
++ fig ^- @uvH (shaf %bfig sgn.^pub)
|
++ fig ^- @uvH (shaf %bfig sgn.^pub)
|
||||||
|
Loading…
Reference in New Issue
Block a user