[crypto]: add DEK with AES-256-GCM encrypt/decrypt#236
Open
pseudomuto wants to merge 1 commit into
Open
Conversation
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.
hehaifengcn
reviewed
Jun 10, 2026
|
|
||
| // 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) { |
| d2, err := crypto.NewDEK() | ||
| require.NoError(t, err) | ||
|
|
||
| require.NotEqual(t, d1, d2) |
Collaborator
There was a problem hiding this comment.
this only compares pointers differ, should also compare contents differ?
|
|
||
| d, err := crypto.NewDEK() | ||
| require.NoError(t, err) | ||
| require.NotEqual(t, crypto.DEK{}, d) |
Collaborator
There was a problem hiding this comment.
compare value against pointer?
hehaifengcn
approved these changes
Jun 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.