Skip to content

Conversation

@L-series
Copy link
Contributor

@L-series L-series commented Dec 1, 2025

  • API: add failure mode support for randombytes()
  • autogen: run to update randombytes declaration
  • randombytes: add example to test failure

@L-series L-series requested a review from a team as a code owner December 1, 2025 22:01
@L-series L-series marked this pull request as draft December 1, 2025 23:04
@L-series L-series force-pushed the randombytes branch 3 times, most recently from 7733e4f to 6bbabfa Compare January 5, 2026 02:02
@L-series L-series marked this pull request as ready for review January 5, 2026 02:07
@hanno-becker
Copy link
Contributor

@L-series Do you need help debugging the CBMC and AWS-LC failures in CI, or are you fine investigating this?

@L-series L-series force-pushed the randombytes branch 4 times, most recently from e42d879 to 226364d Compare January 12, 2026 04:02
@L-series
Copy link
Contributor Author

Hi @hanno-becker, the CBMC proofs are fixed and the integration should now be on par with mldsa, however im still seeing an issue with the aws-lc tests after writing a post_import.patch file. Please let me know if you have any idea why the tests re failing.

@hanno-becker hanno-becker self-assigned this Jan 12, 2026
@hanno-becker hanno-becker self-requested a review January 12, 2026 05:57
-static MLK_INLINE void mlk_randombytes(void *ptr, size_t len) {
- RAND_bytes(ptr, len);
+static MLK_INLINE int mlk_randombytes(void *ptr, size_t len) {
+ return RAND_bytes(ptr, len);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the source in AWS-LC https://github.com/aws/aws-lc/blob/8238483a40b413c56b6a4a1dc336a9cc83b1b21c/crypto/fipsmodule/rand/rand.c#L524 it looks like RAND_bytes returns 1 upon success.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Edited the patch file to reflect this and now CI is passing.

Copy link
Contributor

@hanno-becker hanno-becker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AWS-LC tests likely fail because RAND_bytes has a different error code convention.

Change randombytes() to return int (0 on success, non-zero on failure)
instead of void, allowing callers to detect and handle RNG failures.

This commit:

* Updates function signatures.
* All call sites to check return values.
* Changes test files to use CHECK macro.
* Adds documentation of the new failure mode to sign.h and
  mlkem_native.h
* Adds a new error code MLK_ERR_RNG_FAIL.
* Declares src/randombytes with MLK_MUST_CHECK_RETURN_VALUE.

Signed-off-by: Andreas Hatziiliou <[email protected]>
Tests that crypto_kem_enc and crypto_kem_keypair,
correctly return MLD_ERR_RNG_FAIL when randombytes()
fails. We systematically inject failures at each
invocation point. This test is based off the work from
the test_alloc implementation.

Signed-off-by: Andreas Hatziiliou <[email protected]>
Add the rng failure test to the CI.

Signed-off-by: Andreas Hatziiliou <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants