def sp.layer

bend-osdev-legacy-ciphers@0.1.0.0 · serpent.bend:146

import bend-osdev-legacy-ciphers@0.1.0.0/serpent.bend as Serpent
import Base

146# the S-box (or its inverse) at every bit position of four m-bit words
147def sp.layer(+b: LcSpBox, +inv: Bool, m: Nat, q: LcSpQ<m>) -> LcSpQ<m>:
148  match m:
149    case 0n:
150      q
151    case 1n+p:
152      match q:
153        case LcSpQ{WCon{x0, t0}, WCon{x1, t1}, WCon{x2, t2}, WCon{x3, t3}}:
154          +o = sp.nib(b, inv, LcSpNib{x0, x1, x2, x3})
155          +r = sp.layer(b, inv, p, LcSpQ{t0, t1, t2, t3})
156          LcSpQ{WCon{sp.na(o), sp.qa(p, r)}, WCon{sp.nb(o), sp.qb(p, r)}, WCon{sp.nc(o), sp.qc(p, r)}, WCon{sp.nd(o), sp.qd(p, r)}}

Uses (15)

Used by (4)