def tf.pad.pick

bend-osdev-legacy-ciphers@0.1.0.0 · twofish.bend:345

import bend-osdev-legacy-ciphers@0.1.0.0/twofish.bend as Twofish
import Base
import bend-osdev-bytes@0.1.0.0/bytes.bend as B
import bend-osdev-legacy-ciphers@0.1.0.0/legacy_ciphers.bend as L

345# the key padded with zero bytes to 16, 24 or 32 bytes (section 4.3: keys
346# shorter than 256 bits are padded with zeros to the next defined length)
347def tf.pad.pick(n16: Bool, n24: Bool, n32: Bool, +n: Nat, +xs: List<&2, U32>) -> Result<&2, &2, L.LcError, LcTwofishKey>:
348  match n16 n24 n32:
349    case True{} _ _:
350      Done{tf.key(2n, B.append(xs, B.zeros(Nat.sub(16n, n))))}
351    case False{} True{} _:
352      Done{tf.key(3n, B.append(xs, B.zeros(Nat.sub(24n, n))))}
353    case False{} False{} True{}:
354      Done{tf.key(4n, B.append(xs, B.zeros(Nat.sub(32n, n))))}
355    case False{} False{} False{}:
356      Fail{L.LcBadKeyLength{n}}

Uses (11)

Used by (1)