Skip to content

Comments

Add ML-KEM768 KATs from BoringSSL#25938

Closed
andrewkdinh wants to merge 3 commits intoopenssl:feature/ml-kemfrom
andrewkdinh:mlkem-kats
Closed

Add ML-KEM768 KATs from BoringSSL#25938
andrewkdinh wants to merge 3 commits intoopenssl:feature/ml-kemfrom
andrewkdinh:mlkem-kats

Conversation

@andrewkdinh
Copy link
Contributor

@andrewkdinh andrewkdinh commented Nov 13, 2024

Add KATs for ML-KEM768 under CCLA from https://boringssl.googlesource.com/boringssl/

Please advise for how I should credit BoringSSL in the test files.

These KATs test key generation, encapsulation, and decapsulation for the ML-KEM768 provider.

Relevant notes:

Checklist
  • tests are added or updated

@andrewkdinh andrewkdinh force-pushed the mlkem-kats branch 4 times, most recently from 54e6661 to 0b41144 Compare November 13, 2024 13:18
@github-actions github-actions bot added the severity: fips change The pull request changes FIPS provider sources label Nov 13, 2024
@t8m t8m added approval: review pending This pull request needs review by a committer triaged: feature The issue/pr requests/adds a feature tests: present The PR has suitable tests present labels Nov 13, 2024
@t8m
Copy link
Member

t8m commented Nov 13, 2024

CI is relevant.

Copy link
Contributor

@baentsch baentsch left a comment

Choose a reason for hiding this comment

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

Some nits, one basic design question.

if (params == NULL)
return 1;

if ((p = OSSL_PARAM_locate_const(params, OSSL_KEM_PARAM_MLKEM_ENC_ENTROPY)) != NULL
Copy link
Contributor

Choose a reason for hiding this comment

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

Design question: Is this parameter OK to make available for general use? Or is there some mechanism I didn't spot that only makes this active during testing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't use any mechanism to make this available only for testing (i.e. it's available for general use). But as whether to make this available to general use, I guess that's up to us. As far as I can tell, other providers don't usually hide params like this. However, BoringSSL doesn't make it available for general use (plus some other functions as shown here).

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm also undecided on that -- let's try to resolve that as part of the documentation as discussed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Now spent some time on this: FIPS 203 section 3.3 IMO is pretty clear on these parameters: "The interfaces for these functions should not be made available to applications other than for testing purposes".

"Funny" of course is that violating this is the basis for https://datatracker.ietf.org/doc/draft-ietf-lamps-kyber-certificates/06/. I'm a bit wary wading into this: How far is OpenSSL willing to go supporting draft specs that are not final, @mattcaswell @t8m?

How can we make these params "test-time only" until that is sorted, @andrewkdinh ?

Copy link
Contributor

Choose a reason for hiding this comment

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

@vdukhovni tagging you for input as discussed today...

Copy link
Member

Choose a reason for hiding this comment

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

From the presentation I linked above:

image

@t8m the consensus among implementers right now can be summarized as:

image

Copy link
Member

Choose a reason for hiding this comment

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

For the other issues emerged when interpreting FIPS 203 & co, this is a good overall summary:

image

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @t8m. This isn't a problem for now. Solve it later. It might mean we make this kind of interface available in the default provider, but not the FIPS provider.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, I'll then document these params. Besides, a "should not" is not a "must not". Thanks for linking the presentation @romen .

Copy link
Member

Choose a reason for hiding this comment

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

We can document them as a "should not" and explain they are intended for test purposes etc

@andrewkdinh
Copy link
Contributor Author

@baentsch @nhorman PR comments have been addressed and failing CI should be resolved now

@andrewkdinh andrewkdinh requested a review from baentsch November 14, 2024 15:20
@baentsch
Copy link
Contributor

@baentsch @nhorman PR comments have been addressed and failing CI should be resolved now

Not quite. Style checks still failing. Running ./util/check-format.pl crypto/mlkem/mlkem768.c should highlight all issues prior to CI.

@andrewkdinh
Copy link
Contributor Author

andrewkdinh commented Nov 14, 2024

Not quite. Style checks still failing. Running ./util/check-format.pl crypto/mlkem/mlkem768.c should highlight all issues prior to CI.

Resolved. As a side note, running util/check-format.pl test/evp_test.c reveals a lot of unrelated errors

Edit: looks like there's still CI issues... will look into it

@baentsch
Copy link
Contributor

a side note, running util/check-format.pl test/evp_test.c reveals a lot of unrelated errors

Many files do that (fail check-format.pl) but the approach is to not touch them to avoid unnecessary back-porting hardships.

Thanks for the other fixes. Please let me know if your QUIC obligations don't leave you time to keep working on this any more.

@andrewkdinh andrewkdinh force-pushed the mlkem-kats branch 2 times, most recently from 6bae839 to 8af0118 Compare November 15, 2024 21:24
@nhorman
Copy link
Contributor

nhorman commented Nov 16, 2024

looks like you've got one more inadvertent memory leak:
https://github.com/openssl/openssl/actions/runs/11863681710/job/33065620963?pr=25938

Its not the result of your code, but rather an idiosyncrasy of how the test tries to be more efficient in tracking generated keys. In the test file evppkey_mlkem768_keygen.txt, each test stanza denotes a new key to generate, but doesn't provide a KeyName field for any of the keys. While thats fine, since these tests don't reuse keys at all (which is what the KeyName field appears to be meant to do), it seems to trigger a long standing bug stemming from the fact that every other test case appears to always assign a name to a key.

In keygen_test_run, iff a KeyName field is provided, it gets added to to the public_keys and private_keys arrays for later lookup, and freeing at the end of the test. If you don't provide a name however, keygen_test_run skips adding to those arrays (see test/evp_test.c line 4292). By not adding to those arrays however, the newly generated key leaks when the pkey stack value goes out of scope.

I guess the choices for fix here are to either:
a) Add a KeyName field to every stanza in the evppkey_mlkem768_keygen.txt test file so that the keys are properly tracked and freed
or
b) modify keygen_test_run, such that if keygen->keyname is NULL, you free the pkey value at the end of the function unilaterally

I think (b) is probably the best solution here, as having a KeyName isn't a requirement for the test

@t8m
Copy link
Member

t8m commented Nov 20, 2024

@nhorman please reconfirm as this was force-pushed

@nhorman
Copy link
Contributor

nhorman commented Nov 20, 2024

ACK, approval holds

@mattcaswell mattcaswell added approval: done This pull request has the required number of approvals and removed approval: review pending This pull request needs review by a committer labels Nov 21, 2024
@t8m t8m added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: done This pull request has the required number of approvals labels Nov 22, 2024
@t8m
Copy link
Member

t8m commented Nov 22, 2024

Squashed and merged to the feature branch. Thank you.

@t8m t8m closed this Nov 22, 2024
openssl-machine pushed a commit that referenced this pull request Nov 22, 2024
Add KATs for ML-KEM-768 under CCLA from https://boringssl.googlesource.com/boringssl/

These KATs test key generation, encapsulation, and decapsulation for the
ML-KEM-768 algorithm.

Relevant notes:
- Added functionality to the ML-KEM key management to export/import. These may not
  be fully implemented yet (see #25885)
- Exposed some more low-level ML-KEM API's to the provider implementation to
  allow for deterministic encapsulation/key generation
- Actually run 'mlkem_internal_test' with `make test`

Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #25938)
@andrewkdinh andrewkdinh deleted the mlkem-kats branch November 25, 2024 19:32
vdukhovni pushed a commit to vdukhovni/openssl that referenced this pull request Jan 7, 2025
Add KATs for ML-KEM-768 under CCLA from https://boringssl.googlesource.com/boringssl/

These KATs test key generation, encapsulation, and decapsulation for the
ML-KEM-768 algorithm.

Relevant notes:
- Added functionality to the ML-KEM key management to export/import. These may not
  be fully implemented yet (see openssl#25885)
- Exposed some more low-level ML-KEM API's to the provider implementation to
  allow for deterministic encapsulation/key generation
- Actually run 'mlkem_internal_test' with `make test`

Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#25938)
t8m pushed a commit to t8m/openssl that referenced this pull request Jan 7, 2025
Add KATs for ML-KEM-768 under CCLA from https://boringssl.googlesource.com/boringssl/

These KATs test key generation, encapsulation, and decapsulation for the
ML-KEM-768 algorithm.

Relevant notes:
- Added functionality to the ML-KEM key management to export/import. These may not
  be fully implemented yet (see openssl#25885)
- Exposed some more low-level ML-KEM API's to the provider implementation to
  allow for deterministic encapsulation/key generation
- Actually run 'mlkem_internal_test' with `make test`

Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#25938)
vdukhovni pushed a commit to vdukhovni/openssl that referenced this pull request Jan 8, 2025
Add KATs for ML-KEM-768 under CCLA from https://boringssl.googlesource.com/boringssl/

These KATs test key generation, encapsulation, and decapsulation for the
ML-KEM-768 algorithm.

Relevant notes:
- Added functionality to the ML-KEM key management to export/import. These may not
  be fully implemented yet (see openssl#25885)
- Exposed some more low-level ML-KEM API's to the provider implementation to
  allow for deterministic encapsulation/key generation
- Actually run 'mlkem_internal_test' with `make test`

Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#25938)
vdukhovni pushed a commit to vdukhovni/openssl that referenced this pull request Jan 14, 2025
Add KATs for ML-KEM-768 under CCLA from https://boringssl.googlesource.com/boringssl/

These KATs test key generation, encapsulation, and decapsulation for the
ML-KEM-768 algorithm.

Relevant notes:
- Added functionality to the ML-KEM key management to export/import. These may not
  be fully implemented yet (see openssl#25885)
- Exposed some more low-level ML-KEM API's to the provider implementation to
  allow for deterministic encapsulation/key generation
- Actually run 'mlkem_internal_test' with `make test`

Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#25938)
vdukhovni pushed a commit to vdukhovni/openssl that referenced this pull request Jan 14, 2025
Add KATs for ML-KEM-768 under CCLA from https://boringssl.googlesource.com/boringssl/

These KATs test key generation, encapsulation, and decapsulation for the
ML-KEM-768 algorithm.

Relevant notes:
- Added functionality to the ML-KEM key management to export/import. These may not
  be fully implemented yet (see openssl#25885)
- Exposed some more low-level ML-KEM API's to the provider implementation to
  allow for deterministic encapsulation/key generation
- Actually run 'mlkem_internal_test' with `make test`

Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#25938)
openssl-machine pushed a commit that referenced this pull request Jan 17, 2025
Add KATs for ML-KEM-768 under CCLA from https://boringssl.googlesource.com/boringssl/

These KATs test key generation, encapsulation, and decapsulation for the
ML-KEM-768 algorithm.

Relevant notes:
- Added functionality to the ML-KEM key management to export/import. These may not
  be fully implemented yet (see #25885)
- Exposed some more low-level ML-KEM API's to the provider implementation to
  allow for deterministic encapsulation/key generation
- Actually run 'mlkem_internal_test' with `make test`

Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #25938)
openssl-machine pushed a commit that referenced this pull request Jan 19, 2025
Add KATs for ML-KEM-768 under CCLA from https://boringssl.googlesource.com/boringssl/

These KATs test key generation, encapsulation, and decapsulation for the
ML-KEM-768 algorithm.

Relevant notes:
- Added functionality to the ML-KEM key management to export/import. These may not
  be fully implemented yet (see #25885)
- Exposed some more low-level ML-KEM API's to the provider implementation to
  allow for deterministic encapsulation/key generation
- Actually run 'mlkem_internal_test' with `make test`

Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #25938)
openssl-machine pushed a commit that referenced this pull request Jan 21, 2025
Add KATs for ML-KEM-768 under CCLA from https://boringssl.googlesource.com/boringssl/

These KATs test key generation, encapsulation, and decapsulation for the
ML-KEM-768 algorithm.

Relevant notes:
- Added functionality to the ML-KEM key management to export/import. These may not
  be fully implemented yet (see #25885)
- Exposed some more low-level ML-KEM API's to the provider implementation to
  allow for deterministic encapsulation/key generation
- Actually run 'mlkem_internal_test' with `make test`

Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #25938)
openssl-machine pushed a commit that referenced this pull request Jan 22, 2025
Add KATs for ML-KEM-768 under CCLA from https://boringssl.googlesource.com/boringssl/

These KATs test key generation, encapsulation, and decapsulation for the
ML-KEM-768 algorithm.

Relevant notes:
- Added functionality to the ML-KEM key management to export/import. These may not
  be fully implemented yet (see #25885)
- Exposed some more low-level ML-KEM API's to the provider implementation to
  allow for deterministic encapsulation/key generation
- Actually run 'mlkem_internal_test' with `make test`

Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #25938)
openssl-machine pushed a commit that referenced this pull request Jan 25, 2025
Add KATs for ML-KEM-768 under CCLA from https://boringssl.googlesource.com/boringssl/

These KATs test key generation, encapsulation, and decapsulation for the
ML-KEM-768 algorithm.

Relevant notes:
- Added functionality to the ML-KEM key management to export/import. These may not
  be fully implemented yet (see #25885)
- Exposed some more low-level ML-KEM API's to the provider implementation to
  allow for deterministic encapsulation/key generation
- Actually run 'mlkem_internal_test' with `make test`

Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #25938)
openssl-machine pushed a commit that referenced this pull request Feb 5, 2025
Add KATs for ML-KEM-768 under CCLA from https://boringssl.googlesource.com/boringssl/

These KATs test key generation, encapsulation, and decapsulation for the
ML-KEM-768 algorithm.

Relevant notes:
- Added functionality to the ML-KEM key management to export/import. These may not
  be fully implemented yet (see #25885)
- Exposed some more low-level ML-KEM API's to the provider implementation to
  allow for deterministic encapsulation/key generation
- Actually run 'mlkem_internal_test' with `make test`

Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #25938)
openssl-machine pushed a commit that referenced this pull request Feb 7, 2025
Add KATs for ML-KEM-768 under CCLA from https://boringssl.googlesource.com/boringssl/

These KATs test key generation, encapsulation, and decapsulation for the
ML-KEM-768 algorithm.

Relevant notes:
- Added functionality to the ML-KEM key management to export/import. These may not
  be fully implemented yet (see #25885)
- Exposed some more low-level ML-KEM API's to the provider implementation to
  allow for deterministic encapsulation/key generation
- Actually run 'mlkem_internal_test' with `make test`

Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #25938)
vdukhovni pushed a commit to vdukhovni/openssl that referenced this pull request Feb 12, 2025
Add KATs for ML-KEM-768 under CCLA from https://boringssl.googlesource.com/boringssl/

These KATs test key generation, encapsulation, and decapsulation for the
ML-KEM-768 algorithm.

Relevant notes:
- Added functionality to the ML-KEM key management to export/import. These may not
  be fully implemented yet (see openssl#25885)
- Exposed some more low-level ML-KEM API's to the provider implementation to
  allow for deterministic encapsulation/key generation
- Actually run 'mlkem_internal_test' with `make test`

Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#25938)
openssl-machine pushed a commit that referenced this pull request Feb 14, 2025
Add KATs for ML-KEM-768 under CCLA from https://boringssl.googlesource.com/boringssl/

These KATs test key generation, encapsulation, and decapsulation for the
ML-KEM-768 algorithm.

Relevant notes:
- Added functionality to the ML-KEM key management to export/import. These may not
  be fully implemented yet (see #25885)
- Exposed some more low-level ML-KEM API's to the provider implementation to
  allow for deterministic encapsulation/key generation
- Actually run 'mlkem_internal_test' with `make test`

Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #25938)
definability pushed a commit to definability/openssl that referenced this pull request Feb 25, 2025
Add KATs for ML-KEM-768 under CCLA from https://boringssl.googlesource.com/boringssl/

These KATs test key generation, encapsulation, and decapsulation for the
ML-KEM-768 algorithm.

Relevant notes:
- Added functionality to the ML-KEM key management to export/import. These may not
  be fully implemented yet (see openssl#25885)
- Exposed some more low-level ML-KEM API's to the provider implementation to
  allow for deterministic encapsulation/key generation
- Actually run 'mlkem_internal_test' with `make test`

Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#25938)
quarckster pushed a commit to quarckster/openssl-fork that referenced this pull request Feb 27, 2025
Add KATs for ML-KEM-768 under CCLA from https://boringssl.googlesource.com/boringssl/

These KATs test key generation, encapsulation, and decapsulation for the
ML-KEM-768 algorithm.

Relevant notes:
- Added functionality to the ML-KEM key management to export/import. These may not
  be fully implemented yet (see openssl#25885)
- Exposed some more low-level ML-KEM API's to the provider implementation to
  allow for deterministic encapsulation/key generation
- Actually run 'mlkem_internal_test' with `make test`

Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#25938)
DDvO pushed a commit to siemens/openssl that referenced this pull request Jun 16, 2025
Add KATs for ML-KEM-768 under CCLA from https://boringssl.googlesource.com/boringssl/

These KATs test key generation, encapsulation, and decapsulation for the
ML-KEM-768 algorithm.

Relevant notes:
- Added functionality to the ML-KEM key management to export/import. These may not
  be fully implemented yet (see openssl#25885)
- Exposed some more low-level ML-KEM API's to the provider implementation to
  allow for deterministic encapsulation/key generation
- Actually run 'mlkem_internal_test' with `make test`

Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#25938)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: ready to merge The 24 hour grace period has passed, ready to merge severity: fips change The pull request changes FIPS provider sources tests: present The PR has suitable tests present triaged: feature The issue/pr requests/adds a feature

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

6 participants