aegis128x4

package
v0.2.13 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Example
if !common.Available {
	return
}
key := make([]byte, KeySize)
rand.Read(key)
aead, err := New(key, 16)
if err != nil {
	panic(err)
}

nonce := make([]byte, aead.NonceSize())
rand.Read(nonce)

ciphertext := aead.Seal(nil, nonce, []byte("hello, world!"), nil)

plaintext, err := aead.Open(nil, nonce, ciphertext, nil)
if err != nil {
	panic(err)
}

fmt.Println(string(plaintext))
Output:

hello, world!

Index

Examples

Constants

View Source
const (
	KeySize   = 16
	NonceSize = 16
)

Variables

This section is empty.

Functions

func New

func New(key []byte, tagLen int) (cipher.AEAD, error)

New returns a new AEAD that uses the provided key and tag length. The key must be 16 bytes long. The tag length must be 16 or 32.

Types

type Aegis128X4

type Aegis128X4 struct {
	common.Aegis
}

func (*Aegis128X4) NonceSize

func (aead *Aegis128X4) NonceSize() int

The nonce size, in bytes.

func (*Aegis128X4) Open

func (aead *Aegis128X4) Open(plaintext, nonce, ciphertext, additionalData []byte) ([]byte, error)

func (*Aegis128X4) Seal

func (aead *Aegis128X4) Seal(dst, nonce, cleartext, additionalData []byte) []byte

type Decrypter added in v0.2.13

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

Decrypter provides incremental authenticated decryption using AEGIS-128X4. Create one using NewDecrypter, call Decrypt or DecryptTo for each chunk of ciphertext, then call Final to verify the authentication tag.

IMPORTANT: The decrypted plaintext MUST NOT be used or revealed until Final returns nil. If Final returns an error, all decrypted data must be discarded as it may have been tampered with.

func NewDecrypter added in v0.2.13

func NewDecrypter(key, nonce, additionalData []byte, tagLen int) (*Decrypter, error)

NewDecrypter creates a new incremental decrypter. The key must be KeySize (16) bytes. The nonce must be at most NonceSize (16) bytes; shorter nonces are padded with zeros. The additionalData must match what was used during encryption. The tagLen must match what was used during encryption (16 or 32).

func (*Decrypter) Decrypt added in v0.2.13

func (d *Decrypter) Decrypt(ciphertext []byte) []byte

Decrypt decrypts ciphertext and returns plaintext of the same length. Can be called multiple times for streaming decryption.

WARNING: The returned plaintext MUST NOT be used until Final returns nil. If Final returns an error, all decrypted data must be discarded.

Panics if called after Final.

func (*Decrypter) DecryptTo added in v0.2.13

func (d *Decrypter) DecryptTo(dst, ciphertext []byte) []byte

DecryptTo decrypts ciphertext and writes plaintext to dst. The dst slice must have capacity for at least len(ciphertext) bytes. Returns the plaintext slice (a subslice of dst). If dst is nil or has insufficient capacity, a new slice is allocated.

WARNING: The plaintext MUST NOT be used until Final returns nil. If Final returns an error, all decrypted data must be discarded.

Panics if called after Final.

func (*Decrypter) Final added in v0.2.13

func (d *Decrypter) Final(tag []byte) error

Final verifies the authentication tag. The tag must be tagLen bytes (as specified when creating the Decrypter). Returns nil if the tag is valid, or ErrAuth if verification fails.

If this returns an error, all previously decrypted data MUST be discarded as it may have been tampered with.

The Decrypter must not be used after calling Final.

type Encrypter added in v0.2.13

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

Encrypter provides incremental authenticated encryption using AEGIS-128X4. Create one using NewEncrypter, call Encrypt or EncryptTo for each chunk of plaintext, then call Final to get the authentication tag.

func NewEncrypter added in v0.2.13

func NewEncrypter(key, nonce, additionalData []byte, tagLen int) (*Encrypter, error)

NewEncrypter creates a new incremental encrypter. The key must be KeySize (16) bytes. The nonce must be at most NonceSize (16) bytes; shorter nonces are padded with zeros. The additionalData is authenticated but not encrypted. The tagLen must be 16 or 32.

func (*Encrypter) Encrypt added in v0.2.13

func (e *Encrypter) Encrypt(plaintext []byte) []byte

Encrypt encrypts plaintext and returns ciphertext of the same length. Can be called multiple times for streaming encryption. Panics if called after Final.

func (*Encrypter) EncryptTo added in v0.2.13

func (e *Encrypter) EncryptTo(dst, plaintext []byte) []byte

EncryptTo encrypts plaintext and writes ciphertext to dst. The dst slice must have capacity for at least len(plaintext) bytes. Returns the ciphertext slice (a subslice of dst). If dst is nil or has insufficient capacity, a new slice is allocated. Panics if called after Final.

func (*Encrypter) Final added in v0.2.13

func (e *Encrypter) Final() []byte

Final finalizes the encryption and returns the authentication tag. The tag length was specified when creating the Encrypter. The Encrypter must not be used after calling Final.

Jump to

Keyboard shortcuts

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