Documentation ¶
Overview ¶
This is free and unencumbered software released into the public domain. See the UNLICENSE file for details.
This is free and unencumbered software released into the public domain. See the UNLICENSE file for details.
Index ¶
- Constants
- Variables
- func ClrBit(ary []byte, bit uint) []byte
- func DecryptMachine(ecm Cryptor, left chan CipherBlock) chan CipherBlock
- func EncryptMachine(ecm Cryptor, left chan CipherBlock) chan CipherBlock
- func GetBit(ary []byte, bit uint) bool
- func SetBit(ary []byte, bit uint) []byte
- type CipherBlock
- type Counter
- type Cryptor
- type Cycle
- type Permutator
- func (p *Permutator) ApplyF(blk CipherBlock) CipherBlock
- func (p *Permutator) ApplyG(blk CipherBlock) CipherBlock
- func (p *Permutator) Index() *big.Int
- func (p *Permutator) New(cycleSize int, randp []byte) *Permutator
- func (p *Permutator) SetIndex(idx *big.Int)
- func (p *Permutator) String() string
- func (p *Permutator) Update(random *Rand)
- type Rand
- type Rotor
- func (r *Rotor) ApplyF(blk CipherBlock) CipherBlock
- func (r *Rotor) ApplyG(blk CipherBlock) CipherBlock
- func (r *Rotor) Index() *big.Int
- func (r *Rotor) New(size, start, step int, rotor []byte) *Rotor
- func (r *Rotor) SetIndex(idx *big.Int)
- func (r *Rotor) String() string
- func (r *Rotor) Update(random *Rand)
- type TntEngine
- func (e *TntEngine) BuildCipherMachine()
- func (e *TntEngine) CloseCipherMachine()
- func (e *TntEngine) CounterKey() string
- func (e *TntEngine) Engine() []Cryptor
- func (e *TntEngine) EngineType() string
- func (e *TntEngine) Index() (cntr *big.Int)
- func (e *TntEngine) Init(secret []byte)
- func (e *TntEngine) Left() chan CipherBlock
- func (e *TntEngine) MaximalStates() *big.Int
- func (e *TntEngine) Right() chan CipherBlock
- func (e *TntEngine) SetEngineType(engineType string)
- func (e *TntEngine) SetIndex(iCnt *big.Int)
Constants ¶
const ( BitsPerByte int = 8 CipherBlockSize int = 256 // bits CipherBlockBytes int = CipherBlockSize / BitsPerByte )
Define constants needed for tntengine
const (
EngineLayout = "rrprrprr" // 'r' is rotor, 'p' is permutator
)
const (
NumberPermutationCycles int = 1
)
Variables ¶
var ( // BigZero - the big int value for zero. BigZero = big.NewInt(0) // BigOne - the big int value for one. BigOne = big.NewInt(1) )
Functions ¶
func DecryptMachine ¶
func DecryptMachine(ecm Cryptor, left chan CipherBlock) chan CipherBlock
DecryptMachine - set up a rotor, permutator, or counter to decrypt a block read from the left (input channel) and send it out on the right (output channel)
func EncryptMachine ¶
func EncryptMachine(ecm Cryptor, left chan CipherBlock) chan CipherBlock
EncryptMachine - set up a rotor, permutator, or counter to encrypt a block read from the left (input channel) and send it out on the right (output channel)
Types ¶
type CipherBlock ¶ added in v1.5.0
type CipherBlock []byte
CipherBlock is the data processed by the cryptors (rotors and permutators). It consists of the length in bytes to process and the (32 bytes of) data to process.
func AddBlock ¶
func AddBlock(blk, key CipherBlock) CipherBlock
AddBlock - adds (not XOR) the data to be encrypted with the key.
func SubBlock ¶
func SubBlock(blk, key CipherBlock) CipherBlock
SubBlock - subtracts (not XOR) the key from the data to be decrypted
func (CipherBlock) String ¶ added in v1.5.0
func (cblk CipherBlock) String() string
String formats a string representing the CipherBlock.
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter is a Cryptor that does not encrypt/decrypt any data but counts the number of blocks that were encrypted.
func (*Counter) ApplyF ¶
func (cntr *Counter) ApplyF(blk CipherBlock) CipherBlock
ApplyF - increments the counter for each block that is encrypted.
func (*Counter) ApplyG ¶
func (cntr *Counter) ApplyG(blk CipherBlock) CipherBlock
ApplyG - this function does nothing for a Counter during decryption.
type Cryptor ¶ added in v1.7.0
type Cryptor interface { Update(*Rand) // function to update the rotor/permutator SetIndex(*big.Int) // setter for the index value Index() *big.Int // getter for the index value ApplyF(CipherBlock) CipherBlock // encryption function ApplyG(CipherBlock) CipherBlock // decryption function }
Cryptor interface
type Cycle ¶
type Cycle struct { Start int // The starting point (into randp) for this cycle. Length int // The length of the cycle. Current int // The point in the cycle [0 .. cycle.length-1] to start }
Cycle describes a cycle for the permutator so it can adjust the permutation table used to permute the block. TNT currently uses a single cycle to rearrange Randp into bitPerm
type Permutator ¶
type Permutator struct { CurrentState int // Current number of cycles for this permutator. MaximalStates int // Maximum number of cycles this permutator can have before repeating. Cycle Cycle // Cycles ordered by the current permutation. Randp []byte // Values 0 - 255 in a random order. // contains filtered or unexported fields }
Permutator is a type that defines a permutation crypter in TNT.
func (*Permutator) ApplyF ¶
func (p *Permutator) ApplyF(blk CipherBlock) CipherBlock
ApplyF performs forward permutation on the 32 byte block of data. Note: if the length of the incoming block is less than CipherBlockBytes in length, then the permutation is not applied. This allows files whose length is not a multiple of 32 bytes to be correctly enrypted/decrypted.
func (*Permutator) ApplyG ¶
func (p *Permutator) ApplyG(blk CipherBlock) CipherBlock
ApplyG performs the reverse permutation on the 32 byte block of data. Note: if the length of the incoming block is less than CipherBlockBytes in length, then the permutation is not applied. This allows files whose length is not a multiple of 32 bytes to be correctly enrypted/decrypted.
func (*Permutator) Index ¶
func (p *Permutator) Index() *big.Int
Index returns the current index of the cryptor. For permeutators, this returns nil.
func (*Permutator) New ¶ added in v1.4.0
func (p *Permutator) New(cycleSize int, randp []byte) *Permutator
New creates a permutator and initializes it
func (*Permutator) SetIndex ¶
func (p *Permutator) SetIndex(idx *big.Int)
SetIndex - set the Permutator to the state it would be in after encoding 'idx - 1' blocks of data.
func (*Permutator) String ¶
func (p *Permutator) String() string
String formats a string representing the permutator (as Go source code).
func (*Permutator) Update ¶
func (p *Permutator) Update(random *Rand)
Update will update the given (proForma) permutator in place using (psudo-)random data generated by the TNT encryption engine Rand object.
type Rand ¶
type Rand struct {
// contains filtered or unexported fields
}
func (*Rand) Int15n ¶ added in v1.6.0
Int15n returns, as an int16, a non-negative pseudo-random number in the half-open interval [0,n). It panics if n <= 0.
func (*Rand) Int31n ¶ added in v1.6.0
Int31n returns, as an int32, a non-negative pseudo-random number in the half-open interval [0,n). It panics if n <= 0.
func (*Rand) Int63n ¶
Int63n returns, as an int64, a non-negative pseudo-random number in the half-open interval [0,n). It panics if n <= 0.
func (*Rand) Intn ¶
Intn returns, as an int, a non-negative pseudo-random number in the half-open interval [0,n) from the tntengine. It panics if n <= 0.
type Rotor ¶
type Rotor struct { Size int // the size in bits for this rotor Start int // the initial starting position of the rotor Step int // the step size in bits for this rotor Current int // the current position of this rotor Rotor []byte // the rotor }
Rotor is the type of a TNT rotor
func (*Rotor) ApplyF ¶
func (r *Rotor) ApplyF(blk CipherBlock) CipherBlock
ApplyF encrypts the given block of data using the rotor r.
func (*Rotor) ApplyG ¶
func (r *Rotor) ApplyG(blk CipherBlock) CipherBlock
ApplyG decrypts the given block of data using the rotor r.
func (*Rotor) New ¶ added in v1.4.0
New fills the (empty) rotor r with the given size, start, step and rotor data.
func (*Rotor) SetIndex ¶
SetIndex positions the rotor to the position it would be in after processing idx number of blocks.
type TntEngine ¶
type TntEngine struct {
// contains filtered or unexported fields
}
TntEngine type defines the encryption/decryption machine (rotors and permutators).
func (*TntEngine) BuildCipherMachine ¶
func (e *TntEngine) BuildCipherMachine()
BuildCipherMachine will create a "machine" to encrypt or decrypt data sent to the left channel and outputted on the right channel for the TntEngine. The engineType determines wither a encrypt machine or a decrypt machine will be created.
func (*TntEngine) CloseCipherMachine ¶ added in v1.5.0
func (e *TntEngine) CloseCipherMachine()
CloseCipherMachine will close down the cipher machine by exiting the go function that performs the encryption/decryption using the individual rotors/permutators. This is done by passing the CipherMachine a CipherBlock with a length of zero (0).
func (*TntEngine) CounterKey ¶
CounterKey is a getter that returns the SHAKE256 hash for the secret key. This is used to set/retrieve that next block to use in encrypting data from the file used to save the next block to use..
func (*TntEngine) Engine ¶
Engine is a getter function that returns a slice containing the rotors and permutators for the TntEngine.
func (*TntEngine) EngineType ¶
EngineType is a getter function that returns the engine type of the TntMachine.
func (*TntEngine) Index ¶
Index is a getter that returns the block number of the next block to be encrypted.
func (*TntEngine) Init ¶
Init will initialize the TntEngine generating new Rotors and Permutators using the proForma rotors and permutators in complex way, updating the rotors and permutators in place.
func (*TntEngine) Left ¶
func (e *TntEngine) Left() chan CipherBlock
Left is a getter that returns the input channel for the TntEngine.
func (*TntEngine) MaximalStates ¶ added in v1.1.2
MaximalStates is a getter function that returns maximum number of states that the engine can be in before repeating.
func (*TntEngine) Right ¶
func (e *TntEngine) Right() chan CipherBlock
Right is a getter that returns the output channel for the TntEngine.
func (*TntEngine) SetEngineType ¶
SetEngineType is a setter function that sets the engineType [D)ecrypt or E)ncrypt] of the TntEngine.