chacha20poly1305

package module
Version: v0.0.0-...-41b24f7 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2019 License: CC0-1.0 Imports: 6 Imported by: 1

Documentation

Overview

Package chacha20poly1305 implemnets the RFC 7539 AEAD_CHACHA20_POLY1305 construct. It depends on my ChaCha20 and Poly1305 libraries (and not golang.org/x/crypto for the latter), and attempts to be correct and easy to read over fast.

When the golang.org/x/crypto maintainers feel like providing a sane interface to the Poly1305 code, this will switch to using that, but not before then.

Index

Constants

View Source
const (
	// KeySize is the key length in bytes (32 bytes, 256 bits).
	KeySize = chacha20.KeySize

	// NonceSize is the nonce (IV) length in bytes (12 bytes, 96 bits).
	NonceSize = chacha20.INonceSize

	// Overhead is the tag length in bytes (16 bytes, 128 bits).
	Overhead = poly1305.Size
)

Variables

View Source
var (
	// ErrOpen is the error returned when an Open fails.
	ErrOpen = errors.New("chacha20poly1305: message authentication failed")
)

Functions

This section is empty.

Types

type ChaCha20Poly1305

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

ChaCha20Poly1305 is an AEAD_CHACHA20_POLY1305 instance.

func New

func New(key []byte) (*ChaCha20Poly1305, error)

New returns a new ChaCha20Poly1305 instance, keyed with a given key.

func (*ChaCha20Poly1305) NonceSize

func (a *ChaCha20Poly1305) NonceSize() int

NonceSize returns the size of the nonce that must be passed to Seal and Open.

func (*ChaCha20Poly1305) Open

func (a *ChaCha20Poly1305) Open(dst, nonce, ciphertext, additionalData []byte) ([]byte, error)

Open decrypts and authenticates ciphertext, authenticates the additional data and, if successful, appends the resulting plaintext to dst, returning the updated slice. The nonce must be NonceSize() bytes long and both it and the additional data must match the value passed to Seal.

Even if the function fails, the contents of dst, up to its capacity, may be overwritten.

func (*ChaCha20Poly1305) Overhead

func (a *ChaCha20Poly1305) Overhead() int

Overhead returns the maximum difference between the lengths of a plaintext and its ciphertext.

func (*ChaCha20Poly1305) Reset

func (a *ChaCha20Poly1305) Reset()

Reset clears all sensitive cryptographic material from a given instance so that it is no longer resident in memory.

func (*ChaCha20Poly1305) Seal

func (a *ChaCha20Poly1305) Seal(dst, nonce, plaintext, additionalData []byte) []byte

Seal encrypts and authenticates plaintext, authenticates the additional data and appends the result to dst, returning the updated slice. The nonce must be NonceSize() bytes long and unique for all time, for a given key.

Source Files

Jump to

Keyboard shortcuts

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