Documentation
¶
Overview ¶
Package sealer encrypts and authenticates small payloads with keys shared by a group of servers, so that a value sealed by one server can be opened by any other server holding one of the same keys.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalid = errors.New("sealer: invalid sealed value")
ErrInvalid is returned by Open for any sealed value it cannot open: truncated, tampered with, sealed with an unknown key, or opened with different associated data. The causes are deliberately indistinguishable.
Functions ¶
This section is empty.
Types ¶
type AESGCM ¶
type AESGCM struct {
// contains filtered or unexported fields
}
AESGCM is a Sealer using AES-256-GCM with a random 96-bit nonce per Seal.
Wire format: nonce (12 bytes) | ciphertext (len(plain) bytes) | tag (16 bytes). Each AES key is the SHA-256 of a configured key string.
It holds a list of keys to allow rotation: Seal uses the first key, and Open tries each key in order. To rotate, deploy with the new key added last, then move it first, then drop the old one, waiting at each step for the rollout and for values sealed with the old key to expire.
Each Seal draws a fresh random nonce, which keeps a key safe for about 2^32 seals.
func NewAESGCM ¶
NewAESGCM returns an AESGCM sealing with keys[0] and opening with any of keys. It fails if keys is empty or holds an empty key.
Keys are secrets: use high-entropy values. To use one secret for several purposes, bind the purpose into aad, so that a value sealed for one purpose doesn't open for another.
type Sealer ¶
type Sealer interface {
// Seal encrypts and authenticates plain, authenticates aad, and appends the result to dst.
// aad is not part of the output: Open must be given the same aad.
// The result is self-contained: it carries everything Open needs besides the key and aad.
// Sealing the same input twice gives different results.
// dst, including its spare capacity, must not overlap plain or aad.
Seal(dst, plain, aad []byte) ([]byte, error)
// Open authenticates and decrypts sealed, a value returned by Seal, and appends the plaintext to dst.
// It returns ErrInvalid if sealed was not produced by Seal with an accepted key and the same aad.
// dst, including its spare capacity, must not overlap sealed or aad. This holds even when
// the value opens: a failed attempt with an earlier key may clear dst's spare capacity.
Open(dst, sealed, aad []byte) ([]byte, error)
// Overhead is the number of bytes Seal adds to the plaintext.
Overhead() int
}
Sealer encrypts and authenticates data.
Implementations are safe for concurrent use.