-
Notifications
You must be signed in to change notification settings - Fork 215
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
Improperly sized array in crypto_kem_keypair_derand #97
Comments
Thanks for pointing out the issue with the size of the cmp array. I just fixed this. |
Hi, As for the change in hashing input seeding material, you don't sound happy about it either. If the system RNG is compromised (and I remember such a case from a few years ago with Debian and OpenSSL), this could cause a catastrophic failure. Though hashing a seed does not 'add more entropy' obviously, it does negate bias in the seed material that might be attacked directly, and I have to suppose that may have been the intent behind the change made by NIST. There is a simple solution however, one that restores the security potential; change randombytes, make it more secure. I will post the code below to an improved randombytes, one that undoes this change without altering the specification, that can be dropped right into this project. You will have to test the *nix versions, but what I have done is request 2x the entropy from the provider (typically AES or ChaCha based PRNG used in OS implementations) to approximate post-quantum security, then hashed it with SHAKE256. Sorry for the formatting, I tried to fix it, to no avail. #ifdef _WIN32 include <windows.h>include <wincrypt.h>#else include <fcntl.h>include <errno.h>ifdef linuxdefine _GNU_SOURCEinclude <unistd.h>include <sys/syscall.h>elseinclude <unistd.h>endif#endif #define SECURE_ZERO(ptr, len) int32_t randombytes(uint8_t* out, size_t outlen)
#ifdef _WIN32
#elif defined(linux) && defined(SYS_getrandom)
#else
#endif
} Time to live up to the moniker my friend ;o) Cheers, |
The cmp array is oversized by symbytes:
uint8_t cmp[KYBER_CIPHERTEXTBYTES+KYBER_SYMBYTES]; should be: uint8_t cmp[KYBER_CIPHERTEXTBYTES];
This is passed as the first parameter to indcpa_enc which is declared:
void indcpa_enc(uint8_t c[KYBER_INDCPA_BYTES],
const uint8_t m[KYBER_INDCPA_MSGBYTES],
const uint8_t pk[KYBER_INDCPA_PUBLICKEYBYTES],
const uint8_t coins[KYBER_SYMBYTES]);
With: #define KYBER_CIPHERTEXTBYTES (KYBER_INDCPA_BYTES)
Looks like you were passing cmp to keccak absorb after copying in the key to the first 32 bytes, but chose instead to create a custom Keccak absorb to avoid the memcpy (you should rename modified Keccak functions for clarity btw).
This issue exists in the ref and avx versions.
I also see that you are no longer hashing coins on keygen and the shared secret, binding the security more closely to the output of the system entropy provider, this assumes the output from the provider is equivalent to the security of this construction, is that really wise?
Cheers,
John
The text was updated successfully, but these errors were encountered: