def cast.f

bend-osdev-legacy-ciphers@0.1.0.0 · cast5.bend:337

import bend-osdev-legacy-ciphers@0.1.0.0/cast5.bend as Cast5
import Base
import bend-osdev-legacy-ciphers@0.1.0.0/legacy_ciphers.bend as L

337# f of type ty on data d, with masking key km and rotation kr (0 to 31)
338def cast.f(ty: LcCastTy, +t: LcCastTabs, d: U32, km: U32, +kr: U32) -> U32:
339  match ty:
340    case LcCastF1{}:
341      +i = L.lc.rotl(U32.add(km, d), U32.to_nat(kr))
342      U32.add(U32.sub(U32.xor(cast.lookup(t, i, 0n), cast.lookup(t, i, 1n)), cast.lookup(t, i, 2n)), cast.lookup(t, i, 3n))
343    case LcCastF2{}:
344      +i = L.lc.rotl(U32.xor(km, d), U32.to_nat(kr))
345      U32.xor(U32.add(U32.sub(cast.lookup(t, i, 0n), cast.lookup(t, i, 1n)), cast.lookup(t, i, 2n)), cast.lookup(t, i, 3n))
346    case LcCastF3{}:
347      +i = L.lc.rotl(U32.sub(km, d), U32.to_nat(kr))
348      U32.sub(U32.xor(U32.add(cast.lookup(t, i, 0n), cast.lookup(t, i, 1n)), cast.lookup(t, i, 2n)), cast.lookup(t, i, 3n))

Uses (9)

Used by (10)