-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
crypto_kdf_derive_from_key ctx argument is very easy to get wrong #944
Comments
I have now recompiled libsodium with In GCC:
In Clang:
|
This is the purpose of the Contexts have to match that size. |
This has been clarified in the documentation, thanks! |
The fact that the
ctx
argument tocrypto_kdf_derive_from_key
has to be exactly 8 bytes long is very tricky, prone to getting wrong, and under-documented. It would be much better to use something like a\0
-delimited string, and limit its maximum length in documentation, especially given that the personal data that actually goes to blake2b is padded with 0s to 16 bytes anyway.This is not very clearly explained in the documentation, and all the examples are "magically" exactly 8-bytes long (i.e.
"__auth__"
,"username"
and the like). Someone might not notice that all the strings are of this length and that the requirement is that they must be exactly that. A quick search on github shows at least one such occurrence where someone uses too short a string"rxtx"
asctx
: https://github.com/matteomonti/leaf/blob/57aba45036ef58ba7a008308cd9638d65ddaf66c/src/drop/crypto/keyexchanger.cpp#L31Using a shorter string results in code that unexpectedly produces different results depending on how it was compiled, and may lead to all sorts of incompatibilities, undecryptable messages and other nastiness. Here's what I mean, the same program compiled with GCC produces a different key than when compiled with clang:
The text was updated successfully, but these errors were encountered: