LAWS.bend source
LAWS.bend on the hub · documented module
# Laws about Blowfish (blowfish.bend): for every key and block, decryption# undoes encryption and encryption undoes decryption; and a refused key,# proved by computation.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 ./blowfish.bend as BF# Blowfish (Schneier), every keylaw blowfish_round_trip: for k: BF.LcBlowfishKey for +b: L.LcBlock64 {BF.LcBlowfish.decrypt(k, BF.LcBlowfish.encrypt(k, b)) == b : L.LcBlock64}law blowfish_round_trip_dual: for k: BF.LcBlowfishKey for +b: L.LcBlock64 {BF.LcBlowfish.encrypt(k, BF.LcBlowfish.decrypt(k, b)) == b : L.LcBlock64}# A refusal, proved by computation (gen/vectors.py); Schneier's vectors run# in check.bend (README.md, Laws)# BEGIN GENERATED by gen/vectors.py: vectors# a Blowfish key of 3 bytes is refused (32 bits at least)law blowfish_bad_key_length: {Result.map(&2, &2, L.LcError, BF.LcBlowfishKey, Unit, k => Unit{}, BF.LcBlowfish.key(B.Octets.of_list([0, 0, 0]))) == Fail{L.LcBadKeyLength{3n}} : Result<&2, &2, L.LcError, Unit>}# END GENERATED: vectors