chacha20

package
v0.0.0-...-98622c7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HChaCha20

func HChaCha20(key [32]byte, nonce [16]byte) [32]byte

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

func NewDjb(key [32]byte, nonce [8]byte) Cipher

NewDjb creates a ChaCha20 (original DJB) stream cipher with the given 32-byte key and 8-byte nonce.

func NewIetf

func NewIetf(key [32]byte, nonce [12]byte) Cipher

NewIetf creates a ChaCha20 (IETF) stream cipher with the given 32-byte key and 12-byte nonce.

func (*Cipher) SetCounter

func (cipher *Cipher) SetCounter(counter uint64)

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

func (cipher *Cipher) XORKeyStream(dst, src []byte)

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL