Documentation
¶
Overview ¶
Package aeadutil provides pure AES-GCM helpers shared across runtime/crypto and adapters/vault. All functions are stateless, have zero external dependencies (stdlib only), and follow the same nonce-handling and error- sanitisation conventions as google/tink-go aead/subtle and kubernetes/kubernetes kmsv2/envelope.go.
ref: google/tink-go aead/subtle/aes_gcm.go — AEAD function signature convention ref: kubernetes/kubernetes kmsv2/envelope.go — envelope encryption pattern ref: aws/aws-sdk-go s3crypto — split nonce storage convention
Index ¶
- func DecryptGCM(key, ciphertext, nonce, aad []byte) (plaintext []byte, err error)
- func DecryptGCMSelfContained(key, blob, aad []byte) (plaintext []byte, err error)
- func EncryptGCM(key, plaintext, aad []byte) (ciphertext, nonce []byte, err error)
- func EncryptGCMSelfContained(key, plaintext, aad []byte) (blob []byte, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecryptGCM ¶
DecryptGCM decrypts rawCiphertext (not nonce-prefixed) using key, nonce, and aad. The aad must match exactly what was used in EncryptGCM; any mismatch causes AES-GCM authentication failure. Errors are sanitized — the message never contains key material or plaintext.
ref: google/tink-go aead/subtle/aes_gcm.go ref: kubernetes/kubernetes kmsv2/envelope.go — Transformer.TransformFromStorage
func DecryptGCMSelfContained ¶
DecryptGCMSelfContained decrypts a nonce-prefixed self-contained blob produced by EncryptGCMSelfContained.
Returns an error containing "blob too short" if the blob is smaller than the AES-GCM nonce size.
ref: google/tink-go aead/subtle/aes_gcm.go
func EncryptGCM ¶
EncryptGCM encrypts plaintext with key and aad using AES-GCM. Returns (ciphertext, nonce, error). The nonce is NOT prepended to the ciphertext — it is returned separately so callers can store it in a dedicated column (value_nonce). This matches the split-storage convention used by AWS S3 crypto and kubernetes/kubernetes kmsv2/envelope.go.
The nonce is generated internally via crypto/rand; its length is derived from gcm.NonceSize() (standard AES-GCM = 12 bytes).
ref: google/tink-go aead/subtle/aes_gcm.go — AEAD function signature ref: aws/aws-sdk-go s3crypto — split nonce/ciphertext storage
func EncryptGCMSelfContained ¶
EncryptGCMSelfContained encrypts plaintext and returns a nonce-prefixed self-contained blob: nonce || ciphertext. Suitable for storing a single opaque blob (e.g. wrapped DEK in value_edk) where a separate nonce column is inconvenient.
ref: google/tink-go aead/subtle/aes_gcm.go — NewAESGCM prepends nonce ref: kubernetes/kubernetes kmsv2/envelope.go — self-contained wrapped DEK
Types ¶
This section is empty.