~/bend-docscommunity

PROOF.bend source

PROOF.bend on the hub · documented module

import Baseimport bend-osdev-bytes@0.1.1.0/bytes.bend as Bimport bend-osdev-cipher-core@0.1.0.0/cipher_core.bend as Limport bend-osdev-cipher-core@0.1.0.0/LAWS.bend as CoreLimport bend-osdev-cipher-core@0.1.0.0/PROOF.bend as CorePimport ./blowfish.bend as BFimport ./LAWS.bend as Laws# Blowfish: a round and the final step, each undone by XOR whatever F isdef bf_unop_op(o: BF.LcBfOp, b: L.LcBlock64) -> {b == BF.bf.unop(o, BF.bf.op(o, b)) : L.LcBlock64}:  match o:    case BF.LcBfRound{+p, +t}:      match b:        case L.LcBlock64{+l, +r}:          %CoreL.u32_xor_cancel(l, p) : {L.LcBlock64{l, r} == L.LcBlock64{_, U32.xor(U32.xor(r, BF.bf.f(t, U32.xor(l, p))), BF.bf.f(t, U32.xor(l, p)))} : L.LcBlock64}          %CoreL.u32_xor_cancel(r, BF.bf.f(t, U32.xor(l, p))) : {L.LcBlock64{l, r} == L.LcBlock64{l, _} : L.LcBlock64}          {==}    case BF.LcBfFinal{+p17, +p18}:      match b:        case L.LcBlock64{+l, +r}:          %CoreL.u32_xor_cancel(l, p17) : {L.LcBlock64{l, r} == L.LcBlock64{_, U32.xor(U32.xor(r, p18), p18)} : L.LcBlock64}          %CoreL.u32_xor_cancel(r, p18) : {L.LcBlock64{l, r} == L.LcBlock64{l, _} : L.LcBlock64}          {==}def bf_op_unop(o: BF.LcBfOp, b: L.LcBlock64) -> {b == BF.bf.op(o, BF.bf.unop(o, b)) : L.LcBlock64}:  match o:    case BF.LcBfRound{+p, +t}:      match b:        case L.LcBlock64{+x, +y}:          %CoreL.u32_xor_cancel(y, p) : {L.LcBlock64{x, y} == L.LcBlock64{U32.xor(U32.xor(x, BF.bf.f(t, y)), BF.bf.f(t, _)), _} : L.LcBlock64}          %CoreL.u32_xor_cancel(x, BF.bf.f(t, y)) : {L.LcBlock64{x, y} == L.LcBlock64{_, y} : L.LcBlock64}          {==}    case BF.LcBfFinal{+p17, +p18}:      match b:        case L.LcBlock64{+x, +y}:          %CoreL.u32_xor_cancel(x, p18) : {L.LcBlock64{x, y} == L.LcBlock64{_, U32.xor(U32.xor(y, p17), p17)} : L.LcBlock64}          %CoreL.u32_xor_cancel(y, p17) : {L.LcBlock64{x, y} == L.LcBlock64{x, _} : L.LcBlock64}          {==}def bf_unrun_run(os: List<&2, BF.LcBfOp>, +b: L.LcBlock64) -> {b == BF.bf.unrun(os, BF.bf.run(os, b)) : L.LcBlock64}:  match os:    case Nil{}:      {==}    case Con{+o, +t}:      %bf_unrun_run(t, BF.bf.op(o, b)) : {b == BF.bf.unop(o, _) : L.LcBlock64}      bf_unop_op(o, b)def bf_run_unrun(os: List<&2, BF.LcBfOp>, +b: L.LcBlock64) -> {b == BF.bf.run(os, BF.bf.unrun(os, b)) : L.LcBlock64}:  match os:    case Nil{}:      {==}    case Con{+o, +t}:      %bf_op_unop(o, BF.bf.unrun(t, b)) : {b == BF.bf.run(t, _) : L.LcBlock64}      bf_run_unrun(t, b)def Laws.blowfish_round_trip(k, b):  match k:    case BF.LcBlowfishKey{+ops}:      Equal.sym(L.LcBlock64, b, BF.bf.unrun(ops, BF.bf.run(ops, b)), bf_unrun_run(ops, b))def Laws.blowfish_round_trip_dual(k, b):  match k:    case BF.LcBlowfishKey{+ops}:      Equal.sym(L.LcBlock64, b, BF.bf.run(ops, BF.bf.unrun(ops, b)), bf_run_unrun(ops, b))# BEGIN GENERATED by gen/vectors.py: vectorsdef Laws.blowfish_bad_key_length():  {==}# END GENERATED: vectors