Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cipher ¶
type Cipher struct {
// contains filtered or unexported fields
}
Cipher is a stateful ChaCha20 stream cipher supporting both the original DJB layout (64-bit counter at words 12-13, 8-byte nonce at words 14-15) and the IETF / RFC 8439 layout (32-bit counter at word 12, 12-byte nonce at words 13-15). It implements cipher.Stream.
It keeps the ChaCha20 state as a plain [16]uint32 so that different SIMD backends (4-block, 8-block, 16-block, ...) can each rebuild their own vector layout from it on demand, and a portable scalar backend can run on platforms where SIMD is unavailable.
func NewDjb ¶
NewDjb creates a ChaCha20 (original DJB) stream cipher with the given 32-byte key and 8-byte nonce.
func NewIetf ¶
NewIetf creates a ChaCha20 (IETF) stream cipher with the given 32-byte key and 12-byte nonce.
func (*Cipher) SetCounter ¶
SetCounter sets the block counter (words 12-13 for the DJB layout, word 12 for the IETF layout) and drops any buffered leftover key stream. It allows moving the counter forward or backward in the key stream.
func (*Cipher) XORKeyStream ¶
XORKeyStream XORs each byte of src with the key stream and writes the result to dst. It maintains state across calls: leftover key stream from a previous call is consumed first, and any unused key stream from the final partial block is retained for the next call.
dst and src must overlap entirely or not at all; len(dst) must be >= len(src).