Skip to content

proposal: crypto/mlkem: support derandomized encapsulation in tests #73627

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

Open
chrisfenner opened this issue May 7, 2025 · 3 comments
Open
Labels
Proposal Proposal-Crypto Proposal related to crypto packages or other security issues
Milestone

Comments

@chrisfenner
Copy link

Proposal Details

MLKEM encapsulation takes no arguments and reads m from drbg

In tests only, I would like to be able to inject the randomness so that production Go code can be tested using test vectors for a protocol that builds on top of ML-KEM.

I appreciate how this was done for OAEP, where the library asserts that derandomized OAEP is not happening outside of tests.

If it is acceptable to support derandomized encapsulation, there are a few ways I can think of to do it:

  1. Breaking change to the API (add an optional io.Reader that we read from instead of drbg if not nil, and use boring.UnreachableExceptTests() to ensure that it is only used in tests.
  2. Non-breaking mildly awkward change to the API (add m as a ...byte) that we check is length messageSize and use instead of reading from drbg if not zero-length, and use boring.UnreachableExceptTests() to ensure that it is only not zero-length in tests.
  3. New API (introduce a new EncapsulateWithMyReader (not an actual name suggestion) that reads from an optional io.reader, using drbg if nil, and use boring.UnreachableExceptTests() to ensure that it is only not nil in tests)
@gopherbot gopherbot added this to the Proposal milestone May 7, 2025
@mateusz834
Copy link
Member

Related: #70942

@FiloSottile
Copy link
Contributor

Indeed, the easiest way will be to add an EncapsulateWithTestReader method that takes a RandReader from #70942.

I appreciate how this was done for OAEP, where the library asserts that derandomized OAEP is not happening outside of tests.

Note that this applies only to Go+BoringCrypto.

@chrisfenner
Copy link
Author

Indeed, the easiest way will be to add an EncapsulateWithTestReader method that takes a RandReader from #70942.

That would work for me. Would you like me to send a PR?

@FiloSottile FiloSottile added the Proposal-Crypto Proposal related to crypto packages or other security issues label May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Proposal Proposal-Crypto Proposal related to crypto packages or other security issues
Projects
None yet
Development

No branches or pull requests

4 participants