Closed iamyohann closed 2 years ago
Envelope encryption is also discussed here (and we're generally migrating more and more documentation to this site): https://developers.google.com/tink/client-side-encryption.
On that page there's a callout that speaks to your concern specifically:
Note: Tink's envelope encryption generates a unique DEK for each message you encrypt...
As you found in the code snippet you posted, Tink generates a unique data encryption key (DEK) upon every call to KMSEnvelopeAEAD.Encrypt()
.
Then, as you can see in the wire format documentation, the DEK is embedded alongside the ciphertext. Then, during decryption, the DEK is extracted and decrypted via a KMS decrypt call, as you see in the implementation of KMSEnvelopeAEAD.Decrypt()
.
I'd like to confirm a few things about data key generation during envelope encryption.
Based on the envelope example in the documentation here: https://github.com/google/tink/blob/master/docs/GOLANG-HOWTO.md#envelope-encryption
The example generates a key handle
kh
and a AEAD primitivea
(viaaead.New
)The docs on envelope encryption don't go into much detail on DEK generation.
Could we confirm if a new DEK is generated on each call to the same instance of
a.Encrypt
? (i.e. no need to re-instantiate AEAD primitive or key handle/key set over and over again)If thats the case, I presume:
a.Encrypt(..)
would generate new data keys each time, i.e. cipher texts generated will each have their own separate DEK / data keys embedded.I've looked through some of the Tink library code, specifically these lines: https://github.com/google/tink/blob/master/go/aead/kms_envelope_aead.go#L58-L71
And it definitely looks like its generating a separate data key on each
a.Encrypt
call (on the same AEAD primitive instance). Using GCP KMS, I was able to debug and see it calling KMS Encrypt API whenremote.Encrypt
was called, so it does look like its generating DEKs on the fly (and encrypting them via KMS API for each call), through a single instance of the AEAD Primitive (aead.New(...)
, i.e. no need to re-instantiate)I raised this issue to double check the approach to ensure that we have separate DEK's embedded per cipher text generated.
Regards