def sp.sop
import bend-osdev-legacy-ciphers@0.1.0.0/serpent.bend as Serpentimport Base
import bend-osdev-cipher-modes@0.1.0.0/cipher_modes.bend as M
158# the S-box layer (or its inverse) on the state X0..X3
159def sp.sop(+b: LcSpBox, +inv: Bool, s: M.CmBlock) -> M.CmBlock:
160 match s:
161 case M.CmBlock{U32{w0}, U32{w1}, U32{w2}, U32{w3}}:
162 +r = sp.layer(b, inv, 32n, LcSpQ{w0, w1, w2, w3})
163 M.CmBlock{U32{sp.qa(32n, r)}, U32{sp.qb(32n, r)}, U32{sp.qc(32n, r)}, U32{sp.qd(32n, r)}}