Don't use shared secret directly as encryption key #2
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
in-progress
invalid
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
vxfemboy/purrcrypt#2
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Shared secret as encryption key
Hewwo, fren! Just wanted to point out a teeny, fuzzy issue in your project! It looks like the shared secret is being used directly as an encryption key! 🫣
github.com/vxfemboy/purrcrypt@3e430180b2/src/keys.rs (L113-L116)According to the elliptic-curve docs, raw secrets aren't all that purr-fect for encryption! 🚨
A shared secret isn't all snuggly and safe by itself - AES needs it to be uniformly random! If we don't boop it through a KDF first, we're left with a cryptographic weakness (oh no! 😿). Even big-brain cryptography hoomans like NIST recommend always deriving keys properly!
Shared secret as nonce
Oh nyoo! Not only is the shared secret used as a key, but part of it is also being used as a nonce! 😵
github.com/vxfemboy/purrcrypt@3e430180b2/src/keys.rs (L120)Reusing key material like this can lead to unexpected cryptographic chaos! 😿
Solution
No need to hiss in distress! 🐍 We can fix this by deriving both the encryption key and nonce properly using a KDF! And guess what? The elliptic curve SharedSecret type already has a built-in API for this! ✨
Here's a pawsome example of how to do it (not tested, but looks fluff-tastic!):
Stay fluffy and secure! 🐾
Meowy thanks, @G1gg1L3s ! I had just spotted this, so you saved mew some writing.
I have just a couple small things to nyadd on that specific though:
this is safe, as it would be very difficult1 to find multiple shared secrets which produce the same encryption key but distinct nonces.
A compatibility break would also be a good timew address some other issues:
Equivalently, the likelyhood of random secp256k1 points being mapped (by the encoding and KDF) to the same 256b AES key but distinct 96b nonces, is negligible (less than the PRF–PRP gap) as long as the KDF is a PRF. ↩︎