Documentation ¶
Overview ¶
Package spn implements a generic SPN block ciphers with 128-bit blocks and 8-bit S-boxes.
An affine layer, denoted by an A, treats its input as an element of GF(2)^n and applies a fixed, invertible affine transformation over this space. An S-box layer, denoted by an S, applies possibly independent 8-bit S-boxes to consecutive chunks of its input. The layers are concatenated as in function composition notation. A block cipher E with structure ASAS implies E = A(S(A(S(x)))).
An efficient cryptanalysis of many of these block ciphers is implemented in the cryptanalysis/spn package.
"Structural Cryptanalysis of SASAS" by Alex Biryukov and Adi Shamir, https://www.iacr.org/archive/eurocrypt2001/20450392.pdf
Example (Encrypt) ¶
constr := NewSPN(rand.Reader, SAS) // crypto/rand.Reader dst, src := make([]byte, 16), make([]byte, 16) constr.Encrypt(dst, src)
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Construction ¶
type Construction encoding.ComposedBlocks
func NewSPN ¶
func NewSPN(rand io.Reader, structure Structure) Construction
NewSPN generates a random SPN instance using the random source random (for example, crypto/rand.Reader), with the specified structure.
func Parse ¶
func Parse(in []byte, structure Structure) (constr Construction)
Parse parses a byte array into an SPN construction with the specificed structure. It panics if the byte array is malformed.
func (Construction) BlockSize ¶
func (constr Construction) BlockSize() int
BlockSize returns the block size of the cipher. (Necessary to implement cipher.Block.)
func (Construction) Decrypt ¶
func (constr Construction) Decrypt(dst, src []byte)
Decrypt decrypts the first block in src into dst. Dst and src may point at the same memory.
func (Construction) Encrypt ¶
func (constr Construction) Encrypt(dst, src []byte)
Encrypt encrypts the first block in src into dst. Dst and src may point at the same memory.
func (*Construction) Serialize ¶
func (constr *Construction) Serialize() (out []byte)
Serialize serializes an SPN construction into a byte slice.