~/bend-docscommunity

LAWS.bend source

LAWS.bend on the hub · documented module

# Laws about CAST-128 (cast5.bend): for every key (every key size) and# block, decryption undoes encryption and encryption undoes decryption; and# RFC 2144 B.1's 128-bit vector 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 ./cast5.bend as C5# CAST-128 (RFC 2144), every key sizelaw cast5_round_trip:  for k: C5.LcCast5Key  for +b: L.LcBlock64  {C5.LcCast5.decrypt(k, C5.LcCast5.encrypt(k, b)) == b : L.LcBlock64}law cast5_round_trip_dual:  for k: C5.LcCast5Key  for +b: L.LcBlock64  {C5.LcCast5.encrypt(k, C5.LcCast5.decrypt(k, b)) == b : L.LcBlock64}# Vectors: the specification's test values and refusals, proved by# computation (gen/vectors.py)# BEGIN GENERATED by gen/vectors.py: vectors# RFC 2144, Appendix B.1: CAST-128 with the 128-bit key# 0123456712345678234567893456789A, plaintext 0123456789ABCDEF, ciphertext# 238B4FE5847E44B2law cast5_rfc2144:  {Result.map(&2, &2, L.LcError, C5.LcCast5Key, L.LcBlock64, k => C5.LcCast5.encrypt(k, L.LcBlock64{19088743, 2309737967}), C5.LcCast5.key(B.Octets.of_list([1, 35, 69, 103, 18, 52, 86, 120, 35, 69, 103, 137, 52, 86, 120, 154]))) == Done{L.LcBlock64{596332517, 2222867634}} : Result<&2, &2, L.LcError, L.LcBlock64>}# a CAST-128 key of 4 bytes is refused (40 bits at least)law cast5_bad_key_length:  {Result.map(&2, &2, L.LcError, C5.LcCast5Key, Unit, k => Unit{}, C5.LcCast5.key(B.Octets.of_list([0, 0, 0, 0]))) == Fail{L.LcBadKeyLength{4n}} : Result<&2, &2, L.LcError, Unit>}# END GENERATED: vectors