package chacha20

import "git.sr.ht/~pingoo/stdx/crypto/chacha20"

Package chacha20 implements the ChaCha20 / XChaCha20 stream chipher. Notice that one specific key-nonce combination must be unique for all time.

There are three versions of ChaCha20: - ChaCha20 with a 64 bit nonce (en/decrypt up to 2^64 * 64 bytes for one key-nonce combination) - ChaCha20 with a 96 bit nonce (en/decrypt up to 2^32 * 64 bytes (~256 GB) for one key-nonce combination) - XChaCha20 with a 192 bit nonce (en/decrypt up to 2^64 * 64 bytes for one key-nonce combination)

Index

Constants

const (
	KeySize   = 32
	NonceSize = 8
)
const (
	NonceSizeX = 24
)

Variables

var (
	ErrBadKeyLength   = errors.New("chacha20: bad key length. 32 bytes required")
	ErrBadNonceLength = errors.New("chacha20: bad nonce length for ChaCha20. 8 bytes required")
)
var (
	ErrBadNonceXLength = errors.New("chacha20: bad nonce length for XChaCha20. 24 bytes required")
)

Types

type StreamCipher

type StreamCipher interface {
	cipher.Stream
	SetCounter(n uint32)
}

func New

func New(key, nonce []byte) (StreamCipher, error)

func NewX

func NewX(key, nonce []byte) (StreamCipher, error)

NewX returns a new instance of the XChaCha20 stream cipher. as of now we use the IETF chacha20 variant with 96-bit nonces

Source Files

chacha20.go chacha20_amd64.go xchacha20.go

Version
v0.0.0-20240218134121-094174641f6e (latest)
Published
Feb 18, 2024
Platform
linux/amd64
Imports
3 packages
Last checked
4 months ago

Tools for package owners.