chacha20

package module
Version: v0.0.0-...-7ce890d Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2019 License: AGPL-3.0 Imports: 7 Imported by: 4

README

chacha20 - ChaCha20

Yawning Angel (yawning at schwanenlied dot me)

Yet another Go ChaCha20 implementation. Everything else I found was slow, didn't support all the variants I need to use, or relied on cgo to go fast.

Features:

  • 20 round, 256 bit key only. Everything else is pointless and stupid.
  • IETF 96 bit nonce variant.
  • XChaCha 24 byte nonce variant.
  • SSSE3 and AVX2 support on amd64 targets.
  • Incremental encrypt/decrypt support, unlike golang.org/x/crypto/salsa20.

Documentation

Overview

Package chacha20 implements the ChaCha20 stream cipher.

Index

Constants

View Source
const (
	// BlockSize is the size of a ChaCha20 block in bytes.
	BlockSize = api.BlockSize

	// KeySize is the ChaCha20 key size in bytes.
	KeySize = 32

	// NonceSize is the ChaCha20 nonce size in bytes.
	NonceSize = 8

	// INonceSize is the IETF ChaCha20 nonce size in bytes.
	INonceSize = 12

	// XNonceSize is the XChaCha20 nonce size in bytes.
	XNonceSize = 24

	// HNonceSize is the HChaCha20 nonce size in bytes.
	HNonceSize = 16
)

Variables

View Source
var (
	// ErrInvalidKey is the error returned when the key is invalid.
	ErrInvalidKey = errors.New("chacha20: key length must be KeySize bytes")

	// ErrInvalidNonce is the error returned when the nonce is invalid.
	ErrInvalidNonce = errors.New("chacha20: nonce length must be NonceSize/INonceSize/XNonceSize bytes")

	// ErrInvalidCounter is the error returned when the counter is invalid.
	ErrInvalidCounter = errors.New("chacha20: block counter is invalid (out of range)")
)

Functions

func HChaCha

func HChaCha(key, nonce []byte, dst *[32]byte)

HChaCha is the HChaCha20 hash function used to make XChaCha.

Types

type Cipher

type Cipher struct {
	// contains filtered or unexported fields
}

Cipher is an instance of ChaCha20/XChaCha20 using a particular key and nonce.

func New

func New(key, nonce []byte) (*Cipher, error)

New returns a new ChaCha20/XChaCha20 instance.

func (*Cipher) KeyStream

func (c *Cipher) KeyStream(dst []byte)

KeyStream sets dst to the raw keystream.

func (*Cipher) ReKey

func (c *Cipher) ReKey(key, nonce []byte) error

ReKey reinitializes the ChaCha20/XChaCha20 instance with the provided key and nonce.

func (*Cipher) Reset

func (c *Cipher) Reset()

Reset zeros the key data so that it will no longer appear in the process's memory.

func (*Cipher) Seek

func (c *Cipher) Seek(blockCounter uint64) error

Seek sets the block counter to a given offset.

func (*Cipher) XORKeyStream

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

XORKeyStream sets dst to the result of XORing src with the key stream. Dst and src may be the same slice but otherwise should not overlap.

Source Files

Directories

Path Synopsis
internal
api
Package api provides the ChaCha20 implementation abstract interface.
Package api provides the ChaCha20 implementation abstract interface.
hardware
Package hardware provides the hardware accelerated ChaCha20 implementations.
Package hardware provides the hardware accelerated ChaCha20 implementations.
ref
Package ref provides the portable ChaCha20 implementation.
Package ref provides the portable ChaCha20 implementation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto