Skip to content

[crypto]: add DEK with AES-256-GCM encrypt/decrypt#236

Open
pseudomuto wants to merge 1 commit into
mainfrom
add_crypto_dek
Open

[crypto]: add DEK with AES-256-GCM encrypt/decrypt#236
pseudomuto wants to merge 1 commit into
mainfrom
add_crypto_dek

Conversation

@pseudomuto

Copy link
Copy Markdown

Introduces a new crypto package containing a Data Encryption Key (DEK) abstraction. A DEK wraps a randomly generated 256-bit key and exposes Encrypt/Decrypt using AES-256-GCM, with the per-call nonce prepended to the ciphertext so callers don't need to track it separately.

This is the first building block for envelope encryption: subsequent work will introduce a KEK that wraps a DEK for at-rest storage, which is why DEKMaterial (KEK ID plus the encrypted DEK) is defined alongside the key itself.

Introduces a new crypto package containing a Data Encryption Key (DEK)
abstraction. A DEK wraps a randomly generated 256-bit key and exposes
Encrypt/Decrypt using AES-256-GCM, with the per-call nonce prepended to
the ciphertext so callers don't need to track it separately.

This is the first building block for envelope encryption: subsequent
work will introduce a KEK that wraps a DEK for at-rest storage, which
is why DEKMaterial (KEK ID plus the encrypted DEK) is defined alongside
the key itself.
@pseudomuto pseudomuto requested a review from a team as a code owner June 8, 2026 17:50
Comment thread crypto/dek.go

// Encrypt encrypts the plaintext pt using AES-256-GCM. The returned ciphertext
// is prefixed with the randomly generated nonce.
func (d *DEK) Encrypt(ctx context.Context, pt []byte) ([]byte, error) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctx unused?

Comment thread crypto/dek_test.go
d2, err := crypto.NewDEK()
require.NoError(t, err)

require.NotEqual(t, d1, d2)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this only compares pointers differ, should also compare contents differ?

Comment thread crypto/dek_test.go

d, err := crypto.NewDEK()
require.NoError(t, err)
require.NotEqual(t, crypto.DEK{}, d)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compare value against pointer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants