LAWS.bend open laws/TODOs
raw source on the hub · import bend-osdev-cipher-core@0.1.0.0/LAWS.bend as LAWS
Laws about cipher-core's public interface: 64-bit blocks survive their byte form, the 64-bit modes refuse what is not whole blocks; and the lemmas the ciphers' proofs share (XOR undone, the rotations and byte swaps on bits undone, Feistel rounds undone, the 64-bit modes' layers), as laws.
4 imports
import Base import bend-osdev-bytes@0.1.1.0/bytes.bend as B import ./cipher_core.bend as L import ./modes64.bend as X
Laws
law block64_octets_round_trip provedin PROOF.bendsource · line 13 · raw
@+b:0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64 -> {0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64.of_octets(0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64.to_octets(b)) == Some{b} : Maybe<&2, 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64>}64-bit blocks as bytes: a block read back from its 8 bytes is itself, 8 bytes read as a block are written back as those bytes, and a list of blocks read back from its bytes is itself
law block64_octets_dual provedin PROOF.bendsource · line 17 · raw
@+o:0xe0217e1ab38629fddf738452c1f2a82e/bytes.Octets -> @+b:0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64 -> @e:{0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64.of_octets(o) == Some{b} : Maybe<&2, 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64>} -> {0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64.to_octets(b) == o : 0xe0217e1ab38629fddf738452c1f2a82e/bytes.Octets}
law blocks64_octets_round_trip provedin PROOF.bendsource · line 23 · raw
@+bs:List<&2, 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64> -> {0x5c26418ab13c9e565c5b1309d2f085a0/modes64.Lc64.blocks_of(0x5c26418ab13c9e565c5b1309d2f085a0/modes64.Lc64.octets_of(bs)) == Done{bs} : Result<&2, &2, 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcError, List<&2, 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64>>}
law word_xor_cancel provedin PROOF.bendsource · line 33 · raw
@n:Nat -> @a:Word(n) -> @b:Word(n) -> {a == Word.xor(n, Word.xor(n, a, b), b) : Word(n)}XOR undone, for every word of any width, every 32-bit word and every 64-bit block
law u32_xor_cancel provedin PROOF.bendsource · line 39 · raw
@a:U32 -> @b:U32 -> {a == U32.xor(U32.xor(a, b), b) : U32}
law block64_xor_cancel provedin PROOF.bendsource · line 44 · raw
@a:0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64 -> @b:0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64 -> {b == 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64.xor(a, 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64.xor(a, b)) : 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64}
law rotl1_rotl31 provedin PROOF.bendsource · line 51 · raw
@x:U32 -> {x == 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.lc.rotl1.bits(0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.lc.rotl31.bits(x)) : U32}the rotations by 1 and 31 bits on bits undo each other, and the byte swap on bits undoes itself, for every word
law rotl31_rotl1 provedin PROOF.bendsource · line 55 · raw
@x:U32 -> {x == 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.lc.rotl31.bits(0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.lc.rotl1.bits(x)) : U32}
law bswap_bswap provedin PROOF.bendsource · line 59 · raw
@x:U32 -> {x == 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.lc.bswap.bits(0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.lc.bswap.bits(x)) : U32}
law feistel_unrun_run provedin PROOF.bendsource · line 65 · raw
@-RK:Data -> @-f:(@_:RK -> @_:U32 -> U32) -> @ks:List<&2, RK> -> @+b:0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64 -> {b == 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.lc.fe.unrun(RK, f, ks, 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.lc.fe.run(RK, f, ks, b)) : 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64}Feistel rounds over any round function f and any round keys: the rounds undone last to first undo the rounds, and the other way round
law feistel_run_unrun provedin PROOF.bendsource · line 72 · raw
@-RK:Data -> @-f:(@_:RK -> @_:U32 -> U32) -> @ks:List<&2, RK> -> @+b:0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64 -> {b == 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.lc.fe.run(RK, f, ks, 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.lc.fe.unrun(RK, f, ks, b)) : 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64}
law modes64_ecb_blocks provedin PROOF.bendsource · line 84 · raw
@-K:Data -> @-enc:(@_:K -> @_:0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64 -> 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64) -> @-dec:(@_:K -> @_:0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64 -> 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64) -> @+k:K -> @+bs:List<&2, 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64> -> {0x5c26418ab13c9e565c5b1309d2f085a0/modes64.m64.ecb(K, dec, k, 0x5c26418ab13c9e565c5b1309d2f085a0/modes64.m64.ecb(K, enc, k, bs)) == 0x5c26418ab13c9e565c5b1309d2f085a0/modes64.Lc64.ecb_decrypt_blocks(K, dec, k, 0x5c26418ab13c9e565c5b1309d2f085a0/modes64.Lc64.ecb_encrypt_blocks(K, enc, k, bs)) : List<&2, 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64>}The 64-bit modes over any cipher: decryption after encryption on blocks is the structural forms' (X.m64.ecb, X.m64.cbc.enc, X.m64.cbc.dec), over which a cipher's own round trip proves the mode's by induction; and on bytes, for the bytes of a list of blocks under the bytes of an IV, it is the block layer's
law modes64_cbc_blocks provedin PROOF.bendsource · line 92 · raw
@-K:Data -> @-enc:(@_:K -> @_:0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64 -> 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64) -> @-dec:(@_:K -> @_:0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64 -> 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64) -> @+k:K -> @+iv:0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64 -> @+bs:List<&2, 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64> -> {0x5c26418ab13c9e565c5b1309d2f085a0/modes64.m64.cbc.dec(K, dec, k, 0x5c26418ab13c9e565c5b1309d2f085a0/modes64.m64.cbc.enc(K, enc, k, bs, iv), iv) == 0x5c26418ab13c9e565c5b1309d2f085a0/modes64.Lc64.cbc_decrypt_blocks(K, dec, k, iv, 0x5c26418ab13c9e565c5b1309d2f085a0/modes64.Lc64.cbc_encrypt_blocks(K, enc, k, iv, bs)) : List<&2, 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64>}
law modes64_ecb_octets provedin PROOF.bendsource · line 101 · raw
@-K:Data -> @-enc:(@_:K -> @_:0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64 -> 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64) -> @-dec:(@_:K -> @_:0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64 -> 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64) -> @+k:K -> @+bs:List<&2, 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64> -> {Done{0x5c26418ab13c9e565c5b1309d2f085a0/modes64.Lc64.octets_of(0x5c26418ab13c9e565c5b1309d2f085a0/modes64.Lc64.ecb_decrypt_blocks(K, dec, k, 0x5c26418ab13c9e565c5b1309d2f085a0/modes64.Lc64.ecb_encrypt_blocks(K, enc, k, bs)))} == Result.bind(&2, &2, 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcError, 0xe0217e1ab38629fddf738452c1f2a82e/bytes.Octets, 0xe0217e1ab38629fddf738452c1f2a82e/bytes.Octets, 0x5c26418ab13c9e565c5b1309d2f085a0/modes64.Lc64.ecb_encrypt(K, enc, k, 0x5c26418ab13c9e565c5b1309d2f085a0/modes64.Lc64.octets_of(bs)), c => 0x5c26418ab13c9e565c5b1309d2f085a0/modes64.Lc64.ecb_decrypt(K, dec, k, c)) : Result<&2, &2, 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcError, 0xe0217e1ab38629fddf738452c1f2a82e/bytes.Octets>}
law modes64_cbc_octets provedin PROOF.bendsource · line 109 · raw
@-K:Data -> @-enc:(@_:K -> @_:0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64 -> 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64) -> @-dec:(@_:K -> @_:0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64 -> 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64) -> @+k:K -> @+iv:0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64 -> @+bs:List<&2, 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64> -> {Done{0x5c26418ab13c9e565c5b1309d2f085a0/modes64.Lc64.octets_of(0x5c26418ab13c9e565c5b1309d2f085a0/modes64.Lc64.cbc_decrypt_blocks(K, dec, k, iv, 0x5c26418ab13c9e565c5b1309d2f085a0/modes64.Lc64.cbc_encrypt_blocks(K, enc, k, iv, bs)))} == Result.bind(&2, &2, 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcError, 0xe0217e1ab38629fddf738452c1f2a82e/bytes.Octets, 0xe0217e1ab38629fddf738452c1f2a82e/bytes.Octets, 0x5c26418ab13c9e565c5b1309d2f085a0/modes64.Lc64.cbc_encrypt(K, enc, k, 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64.to_octets(iv), 0x5c26418ab13c9e565c5b1309d2f085a0/modes64.Lc64.octets_of(bs)), c => 0x5c26418ab13c9e565c5b1309d2f085a0/modes64.Lc64.cbc_decrypt(K, dec, k, 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64.to_octets(iv), c)) : Result<&2, &2, 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcError, 0xe0217e1ab38629fddf738452c1f2a82e/bytes.Octets>}
law modes64_not_whole_blocks provedin PROOF.bendsource · line 120 · raw
{Result.map(&2, &2, 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcError, List<&2, 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcBlock64>, Unit, bs => Unit{}, 0x5c26418ab13c9e565c5b1309d2f085a0/modes64.Lc64.blocks_of(0xe0217e1ab38629fddf738452c1f2a82e/bytes.Octets.zeros(12n))) == Fail{0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcNotBlockMultiple{12n}} : Result<&2, &2, 0x5c26418ab13c9e565c5b1309d2f085a0/cipher_core.LcError, Unit>}the 64-bit modes refuse a message that is not whole blocks