gcmsiv

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package gcmsiv implements AES-256-GCM-SIV, the nonce-misuse-resistant AEAD of RFC 8452. It is a self-contained pure-Go implementation (no cgo): AES is the standard library's constant-time/hardware AES, and the POLYVAL universal hash is implemented here with a constant-time, limb-based carry-less multiply (see polyval.go and design note D4 — this is the project's riskiest self-written crypto surface).

Only the 256-bit key variant is provided, the only one the Signal protocol's sealed-sender v2 uses. Every step cites the relevant RFC 8452 section.

Reuse evaluation (recorded per design requirement)

Before writing this, vetted pure-Go reuse was evaluated: the Go standard library and golang.org/x/crypto ship no public AES-GCM-SIV; the only third-party pure-Go ports found (secure-io/siv-go, ericlagergren/siv) are tiny (<10 stars), unreleased, unaudited, and one is self-described as an experimental proof-of-concept "not optimized for ... (side channel) security" — none meet the vetted/maintained/constant-time bar (D4). Outcome: implement in-repo, as the plan anticipated.

Index

Constants

View Source
const (
	// KeySize is the AES-256-GCM-SIV key length in bytes (the key-generating
	// key, RFC 8452 §4).
	KeySize = 32
	// NonceSize is the GCM-SIV nonce length: 96 bits (RFC 8452 §4).
	NonceSize = 12
	// TagSize is the GCM-SIV authentication tag length: 128 bits (RFC 8452 §4).
	TagSize = 16
)

Variables

View Source
var (
	// ErrKeySize is returned when the key is not KeySize bytes.
	ErrKeySize = errors.New("gcmsiv: invalid key size")
	// ErrNonceSize is returned when the nonce is not NonceSize bytes.
	ErrNonceSize = errors.New("gcmsiv: invalid nonce size")
	// ErrOpen is returned when authentication fails or the ciphertext is too
	// short to contain a tag.
	ErrOpen = errors.New("gcmsiv: message authentication failed")
	// ErrInputTooLong is returned when plaintext or additional data exceeds the
	// RFC 8452 §6 limits.
	ErrInputTooLong = errors.New("gcmsiv: input exceeds RFC 8452 length limit")
)

Sentinel errors. ErrOpen is intentionally singular for every authentication failure (wrong key/nonce/AAD/tag or tampered ciphertext) so the cases are not distinguishable to an attacker, matching GCM-SIV's all-or-nothing decryption.

Functions

func Open

func Open(key, nonce, ciphertextAndTag, additionalData []byte) ([]byte, error)

Open verifies and decrypts ciphertextAndTag (ciphertext || 16-byte tag) with the given key, nonce, and additional data, returning the plaintext (RFC 8452 §4). On any authentication failure it returns ErrOpen and no plaintext. It does not mutate any input slice.

func Seal

func Seal(key, nonce, plaintext, additionalData []byte) ([]byte, error)

Seal encrypts and authenticates plaintext with the given 32-byte key, 12-byte nonce, and additional data, returning ciphertext || tag (RFC 8452 §4). It does not mutate any input slice.

Types

This section is empty.

Jump to

Keyboard shortcuts

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