Documentation
¶
Overview ¶
Package encoding defines interfaces to be implemented by bijective, invertible functions. Implementing a common interface over the building blocks of a construction or cryptanalysis gives a simple way to compose, concatenate, and invert them.
Index ¶
- func EquivalentBytes(a, b Byte) bool
- func ProbablyEquivalentBlocks(a, b Block) bool
- func ProbablyEquivalentDoubles(a, b Double) bool
- func ProbablyEquivalentWords(a, b Word) bool
- func SerializeByte(e Byte) []byte
- func XOR(dst, a, b []byte) int
- type Block
- type BlockAdditive
- type BlockAffine
- type BlockLinear
- type BlockTable
- type Byte
- type ByteAdditive
- type ByteAffine
- type ByteLinear
- type ByteMultiplication
- type ByteTable
- type ComposedBlocks
- type ComposedBytes
- type ComposedDoubles
- type ComposedWords
- type ConcatenatedBlock
- type ConcatenatedByte
- type ConcatenatedDouble
- type ConcatenatedWord
- type Double
- type DoubleAdditive
- type DoubleAffine
- type DoubleLinear
- type DoubleToByteTable
- type DoubleToWordTable
- type IdentityBlock
- type IdentityByte
- type IdentityDouble
- type IdentityWord
- type InverseBlock
- type InverseByte
- type InverseDouble
- type InverseWord
- type Nibble
- type NibbleTable
- type SBox
- type Shuffle
- type Word
- type WordAdditive
- type WordAffine
- type WordLinear
- type WordTable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EquivalentBytes ¶
EquivalentBytes returns true if two Byte encodings are identical and false if not.
func ProbablyEquivalentBlocks ¶
ProbablyEquivalentBlocks returns true if two Block encodings are probably equivalent and false if they're definitely not.
func ProbablyEquivalentDoubles ¶
ProbablyEquivalentDoubles returns true if two Double encodings are probably equivalent and false if they're definitely not.
func ProbablyEquivalentWords ¶
ProbablyEquivalentWords returns true if two Word encodings are probably equivalent and false if they're definitely not.
func SerializeByte ¶
SerializeByte serializes a Byte encoding to a byte slice.
Types ¶
type BlockAdditive ¶
type BlockAdditive [16]byte
BlockAdditive implements the Block interface over XORing with a fixed value.
func (BlockAdditive) Decode ¶
func (ba BlockAdditive) Decode(in [16]byte) [16]byte
func (BlockAdditive) Encode ¶
func (ba BlockAdditive) Encode(in [16]byte) [16]byte
type BlockAffine ¶
type BlockAffine struct { BlockLinear BlockAdditive }
BlockAffine implements the Block interface over an affine transformation (a linear transformation composed with an additive one).
func DecomposeBlockAffine ¶
func DecomposeBlockAffine(in Block) (BlockAffine, bool)
DecomposeBlockAffine decomposes an opaque Block encoding into a BlockAffine encoding.
func NewBlockAffine ¶
func NewBlockAffine(forwards matrix.Matrix, constant [16]byte) BlockAffine
NewBlockAffine constructs a new BlockAffine encoding from a matrix and a constant.
func (BlockAffine) Decode ¶
func (ba BlockAffine) Decode(in [16]byte) [16]byte
func (BlockAffine) Encode ¶
func (ba BlockAffine) Encode(in [16]byte) [16]byte
type BlockLinear ¶
type BlockLinear struct { // Forwards is the matrix to multiply by in the forwards (encoding) direction. Forwards matrix.Matrix // Backwards is the matrix to multiply by in the backwards (decoding) direction. It should be the inverse of Forwards. Backwards matrix.Matrix }
BlockLinear implements the Block interface over a 128x128 linear transformation.
func DecomposeBlockLinear ¶
func DecomposeBlockLinear(in Block) (BlockLinear, bool)
DecomposeBlockLinear decomposes an opaque Block encoding into a BlockLinear encoding.
func NewBlockLinear ¶
func NewBlockLinear(forwards matrix.Matrix) BlockLinear
NewBlockLinear constructs a new BlockLinear encoding from a given matrix.
func (BlockLinear) Decode ¶
func (bl BlockLinear) Decode(in [16]byte) (out [16]byte)
func (BlockLinear) Encode ¶
func (bl BlockLinear) Encode(in [16]byte) (out [16]byte)
type BlockTable ¶
BlockTable implements the table.Block interface over another Block table with a Byte encoding on its input and a Block encoding on its output.
func (BlockTable) Get ¶
func (bt BlockTable) Get(i byte) [16]byte
type ByteAdditive ¶
type ByteAdditive byte
ByteAdditive implements the Byte interface over XORing with a fixed value.
func (ByteAdditive) Decode ¶
func (ba ByteAdditive) Decode(in byte) byte
func (ByteAdditive) Encode ¶
func (ba ByteAdditive) Encode(in byte) byte
type ByteAffine ¶
type ByteAffine struct { ByteLinear ByteAdditive }
ByteAffine implements the Byte interface over an affine transformation (a linear transformation composed with an additive one).
func DecomposeByteAffine ¶
func DecomposeByteAffine(in Byte) (ByteAffine, bool)
DecomposeByteAffine decomposes an opaque Byte encoding into a ByteAffine encoding.
func NewByteAffine ¶
func NewByteAffine(forwards matrix.Matrix, constant byte) ByteAffine
NewByteAffine constructs a new ByteAffine encoding from a matrix and a constant.
func (ByteAffine) Decode ¶
func (ba ByteAffine) Decode(in byte) byte
func (ByteAffine) Encode ¶
func (ba ByteAffine) Encode(in byte) byte
type ByteLinear ¶
type ByteLinear struct { // Forwards is the matrix to multiply by in the forwards (encoding) direction. Forwards matrix.Matrix // Backwards is the matrix to multiply by in the backwards (decoding) direction. It should be the inverse of Forwards. Backwards matrix.Matrix }
ByteLinear implements the Byte interface over an 8x8 linear transformation.
func DecomposeByteLinear ¶
func DecomposeByteLinear(in Byte) (ByteLinear, bool)
DecomposeByteLinear decomposes an opaque Byte encoding into a ByteLinear encoding.
func NewByteLinear ¶
func NewByteLinear(forwards matrix.Matrix) ByteLinear
NewByteLinear constructs a new ByteLinear encoding from a given matrix.
func (ByteLinear) Decode ¶
func (bl ByteLinear) Decode(in byte) byte
func (ByteLinear) Encode ¶
func (bl ByteLinear) Encode(in byte) byte
type ByteMultiplication ¶
type ByteMultiplication struct { // Forwards is the number to multiply by in the forwards (encoding) direction. Forwards number.ByteFieldElem // Backwards is the number to multiply by in the backwards (decoding) direction. It should be the inverse of Forwards. Backwards number.ByteFieldElem }
ByteMultiplication implements the Byte interface over multiplication by an element of GF(2^8).
func NewByteMultiplication ¶
func NewByteMultiplication(forwards number.ByteFieldElem) ByteMultiplication
NewByteMultiplication constructs a new ByteMultiplication encoding from a field element.
func (ByteMultiplication) Decode ¶
func (bm ByteMultiplication) Decode(i byte) byte
func (ByteMultiplication) Encode ¶
func (bm ByteMultiplication) Encode(i byte) byte
type ByteTable ¶
ByteTable implements the table.Byte interface over another Byte table with Byte encodings on its input and output.
type ComposedBlocks ¶
type ComposedBlocks []Block
ComposedBlocks converts an array of Block encodings into one by chaining them. See ComposedBytes.
func (ComposedBlocks) Decode ¶
func (cb ComposedBlocks) Decode(i [16]byte) (out [16]byte)
func (ComposedBlocks) Encode ¶
func (cb ComposedBlocks) Encode(i [16]byte) (out [16]byte)
type ComposedBytes ¶
type ComposedBytes []Byte
ComposedBytes converts an array of Byte encodings into one by chaining them. Functions are chained in REVERSE order than they would be in function composition notation.
Example:
f := ComposedBytes([]Byte{A, B, C}) // f(x) = C(B(A(x)))
func (ComposedBytes) Decode ¶
func (cb ComposedBytes) Decode(i byte) byte
func (ComposedBytes) Encode ¶
func (cb ComposedBytes) Encode(i byte) byte
type ComposedDoubles ¶
type ComposedDoubles []Double
ComposedDoubles converts an array of Double encodings into one by chaining them. See ComposedBytes.
func (ComposedDoubles) Decode ¶
func (cd ComposedDoubles) Decode(i [2]byte) (out [2]byte)
func (ComposedDoubles) Encode ¶
func (cd ComposedDoubles) Encode(i [2]byte) (out [2]byte)
type ComposedWords ¶
type ComposedWords []Word
ComposedWords converts an array of Word encodings into one by chaining them. See ComposedBytes.
func (ComposedWords) Decode ¶
func (cw ComposedWords) Decode(i [4]byte) (out [4]byte)
func (ComposedWords) Encode ¶
func (cw ComposedWords) Encode(i [4]byte) (out [4]byte)
type ConcatenatedBlock ¶
type ConcatenatedBlock [16]Byte
ConcatenatedBlock builds a Block encoding by concatenating sixteen Byte encodings. The Byte encoding in position i is the one applied to position i of the input.
func DecomposeConcatenatedBlock ¶
func DecomposeConcatenatedBlock(in Block) (out ConcatenatedBlock)
DecomposeConcatenatedBlock decomposes an opaque concatenated Block encoding into an explicit one.
func (ConcatenatedBlock) Decode ¶
func (cb ConcatenatedBlock) Decode(i [16]byte) (out [16]byte)
func (ConcatenatedBlock) Encode ¶
func (cb ConcatenatedBlock) Encode(i [16]byte) (out [16]byte)
type ConcatenatedByte ¶
type ConcatenatedByte [2]Nibble
ConcatenatedByte builds a Byte encoding by concatenating two Nibble encodings. The Nibble encoding in position 0 is applied to the upper half of the byte and the one in position 1 is applied to the lower half.
func (ConcatenatedByte) Decode ¶
func (cb ConcatenatedByte) Decode(i byte) byte
func (ConcatenatedByte) Encode ¶
func (cb ConcatenatedByte) Encode(i byte) byte
type ConcatenatedDouble ¶
type ConcatenatedDouble [2]Byte
ConcatenatedDouble builds a Double encoding by Concatenating two Byte encodings. The Byte encoding in position i is the one applied to position i of the input.
func (ConcatenatedDouble) Decode ¶
func (cd ConcatenatedDouble) Decode(i [2]byte) [2]byte
func (ConcatenatedDouble) Encode ¶
func (cd ConcatenatedDouble) Encode(i [2]byte) [2]byte
type ConcatenatedWord ¶
type ConcatenatedWord [4]Byte
ConcatenatedWord builds a Word encoding by concatenating four Byte encodings. The Byte encoding in position i is the one applied to position i of the input.
func (ConcatenatedWord) Decode ¶
func (cw ConcatenatedWord) Decode(i [4]byte) [4]byte
func (ConcatenatedWord) Encode ¶
func (cw ConcatenatedWord) Encode(i [4]byte) [4]byte
type DoubleAdditive ¶
type DoubleAdditive [2]byte
DoubleAdditive implements the Double interface over XORing with a fixed value.
func (DoubleAdditive) Decode ¶
func (da DoubleAdditive) Decode(in [2]byte) [2]byte
func (DoubleAdditive) Encode ¶
func (da DoubleAdditive) Encode(in [2]byte) [2]byte
type DoubleAffine ¶
type DoubleAffine struct { DoubleLinear DoubleAdditive }
DoubleAffine implements the Double interface over an affine transformation (a linear transformation composed with an additive one).
func DecomposeDoubleAffine ¶
func DecomposeDoubleAffine(in Double) (DoubleAffine, bool)
DecomposeDoubleAffine decomposes an opaque Double encoding into a DoubleAffine encoding.
func NewDoubleAffine ¶
func NewDoubleAffine(forwards matrix.Matrix, constant [2]byte) DoubleAffine
NewDoubleAffine constructs a new DoubleAffine encoding from a matrix and a constant.
func (DoubleAffine) Decode ¶
func (da DoubleAffine) Decode(in [2]byte) [2]byte
func (DoubleAffine) Encode ¶
func (da DoubleAffine) Encode(in [2]byte) [2]byte
type DoubleLinear ¶
type DoubleLinear struct { // Forwards is the matrix to multiply by in the forwards (encoding) direction. Forwards matrix.Matrix // Backwards is the matrix to multiply by in the backwards (decoding) direction. It should be the inverse of Forwards. Backwards matrix.Matrix }
DoubleLinear implements the Double interface over a 16x16 linear transformation.
func DecomposeDoubleLinear ¶
func DecomposeDoubleLinear(in Double) (DoubleLinear, bool)
DecomposeDoubleLinear decomposes an opaque Double encoding into a DoubleLinear encoding.
func NewDoubleLinear ¶
func NewDoubleLinear(forwards matrix.Matrix) DoubleLinear
NewDoubleLinear constructs a new DoubleLinear encoding from a given matrix.
func (DoubleLinear) Decode ¶
func (dl DoubleLinear) Decode(in [2]byte) (out [2]byte)
func (DoubleLinear) Encode ¶
func (dl DoubleLinear) Encode(in [2]byte) (out [2]byte)
type DoubleToByteTable ¶
type DoubleToByteTable struct { In Double Out Byte Hidden table.DoubleToByte }
DoubleToByteTable implements the table.DoubleToByte interface over another DoubleToByte table with a Double encoding on its input and a Byte encoding on its output.
func (DoubleToByteTable) Get ¶
func (dtbt DoubleToByteTable) Get(i [2]byte) byte
type DoubleToWordTable ¶
type DoubleToWordTable struct { In Double Out Word Hidden table.DoubleToWord }
DoubleToWordTable implements the table.DoubleToWord interface over another DoubleToWord table with a Double encoding on its input and a Word encoding on its output.
func (DoubleToWordTable) Get ¶
func (dtwt DoubleToWordTable) Get(i [2]byte) [4]byte
type IdentityBlock ¶
type IdentityBlock struct{}
IdentityBlock is the identity operation on blocks.
func (IdentityBlock) Decode ¶
func (ib IdentityBlock) Decode(i [16]byte) (out [16]byte)
func (IdentityBlock) Encode ¶
func (ib IdentityBlock) Encode(i [16]byte) (out [16]byte)
type IdentityByte ¶
type IdentityByte struct{}
IdentityByte is the identity operation on bytes. It is used in place of an IdentityNibble encoding.
func (IdentityByte) Decode ¶
func (ib IdentityByte) Decode(i byte) byte
func (IdentityByte) Encode ¶
func (ib IdentityByte) Encode(i byte) byte
type IdentityDouble ¶
type IdentityDouble struct{}
IdentityDouble is the identity operation on doubles.
func (IdentityDouble) Decode ¶
func (id IdentityDouble) Decode(i [2]byte) [2]byte
func (IdentityDouble) Encode ¶
func (id IdentityDouble) Encode(i [2]byte) [2]byte
type IdentityWord ¶
type IdentityWord struct{}
IdentityWord is the identity operation on words.
func (IdentityWord) Decode ¶
func (iw IdentityWord) Decode(i [4]byte) (out [4]byte)
func (IdentityWord) Encode ¶
func (iw IdentityWord) Encode(i [4]byte) (out [4]byte)
type InverseBlock ¶
type InverseBlock struct{ Block }
InverseBlock swaps the Encode and Decode methods of a Block encoding.
func (InverseBlock) Decode ¶
func (ib InverseBlock) Decode(i [16]byte) [16]byte
func (InverseBlock) Encode ¶
func (ib InverseBlock) Encode(i [16]byte) [16]byte
type InverseByte ¶
type InverseByte struct{ Byte }
InverseByte swaps the Encode and Decode methods of a Byte encoding.
func (InverseByte) Decode ¶
func (ib InverseByte) Decode(i byte) byte
func (InverseByte) Encode ¶
func (ib InverseByte) Encode(i byte) byte
type InverseDouble ¶
type InverseDouble struct{ Double }
InverseDouble swaps the Encode and Decode methods of a Double encoding.
func (InverseDouble) Decode ¶
func (id InverseDouble) Decode(i [2]byte) [2]byte
func (InverseDouble) Encode ¶
func (id InverseDouble) Encode(i [2]byte) [2]byte
type InverseWord ¶
type InverseWord struct{ Word }
InverseWord swaps the Encode and Decode methods of a Word encoding.
func (InverseWord) Decode ¶
func (iw InverseWord) Decode(i [4]byte) [4]byte
func (InverseWord) Encode ¶
func (iw InverseWord) Encode(i [4]byte) [4]byte
type Nibble ¶
type Nibble interface { Encode(i byte) byte // Encode(i nibble) nibble Decode(i byte) byte // Decode(i nibble) nibble }
Nibble is the same interface as Byte. A function implementing Nibble shouldn't accept inputs or give outputs over 16.
type NibbleTable ¶
NibbleTable implements the table.Nibble interface over another Nibble table with a Byte encoding on its input and a Nibble encoding on its output.
func (NibbleTable) Get ¶
func (nt NibbleTable) Get(i byte) byte
type SBox ¶
type SBox struct {
EncKey, DecKey [256]byte
}
SBox implements a random 8-bit bijection.
func GenerateSBox ¶
GenerateSBox generates a random 8-bit bijection using the random source random (for example, crypto/rand.Reader).
func (SBox) Permutation ¶
Permutation returns the SBox's permutation.
type Shuffle ¶
type Shuffle struct {
EncKey, DecKey [16]byte
}
Shuffle implements a random 4-bit bijection.
func GenerateShuffle ¶
GenerateShuffle generates a random 4-bit bijection using the random source random (for example, crypto/rand.Reader).
func (Shuffle) Permutation ¶
Permutation returns the shuffle's permutation.
type WordAdditive ¶
type WordAdditive [4]byte
WordAdditive implements the Word interface over XORing with a fixed value.
func (WordAdditive) Decode ¶
func (wa WordAdditive) Decode(in [4]byte) [4]byte
func (WordAdditive) Encode ¶
func (wa WordAdditive) Encode(in [4]byte) [4]byte
type WordAffine ¶
type WordAffine struct { WordLinear WordAdditive }
WordAffine implements the Word interface over an affine transformation (a linear transformation composed with an additive one).
func DecomposeWordAffine ¶
func DecomposeWordAffine(in Word) (WordAffine, bool)
DecomposeWordAffine decomposes an opaque Word encoding into a WordAffine encoding.
func NewWordAffine ¶
func NewWordAffine(forwards matrix.Matrix, constant [4]byte) WordAffine
NewWordAffine constructs a new WordAffine encoding from a matrix and a constant.
func (WordAffine) Decode ¶
func (wa WordAffine) Decode(in [4]byte) [4]byte
func (WordAffine) Encode ¶
func (wa WordAffine) Encode(in [4]byte) [4]byte
type WordLinear ¶
type WordLinear struct { // Forwards is the matrix to multiply by in the forwards (encoding) direction. Forwards matrix.Matrix // Backwards is the matrix to multiply by in the backwards (decoding) direction. It should be the inverse of Forwards. Backwards matrix.Matrix }
WordLinear implements the Word interface over a 32x32 linear transformation.
func DecomposeWordLinear ¶
func DecomposeWordLinear(in Word) (WordLinear, bool)
DecomposeWordLinear decomposes an opaque Word encoding into a WordLinear encoding.
func NewWordLinear ¶
func NewWordLinear(forwards matrix.Matrix) WordLinear
NewWordLinear constructs a new WordLinear encoding from a given matrix.
func (WordLinear) Decode ¶
func (wl WordLinear) Decode(in [4]byte) (out [4]byte)
func (WordLinear) Encode ¶
func (wl WordLinear) Encode(in [4]byte) (out [4]byte)