Skip to content
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

ML-KEM/Kyber: improvements #8467

Merged
merged 1 commit into from
Feb 20, 2025
Merged

Conversation

SparkiDev
Copy link
Contributor

Description

ML-KEM/Kyber:
MakeKey call generate random once only for all data.
Allow MakeKey/Encapsulate/Decapsulate to be compiled separately.
Pull out public key decoding common to public and private key decode.
Put references to FIPS 140-3 into code. Rename variables to match FIPS 140-3.
Fix InvNTT assembly code for x64 - more reductions.
Split out ML-KEM/Kyber tests from api.c.

TLSX:
Store the object instead of the private key when WOLFSSL_MLKEM_CACHE_A is defined or WOLFSSL_TLSX_PQC_MLKEM_STORE_OBJ. Faster decapsulation when A is cached and object stored.
To store private key as normal define
WOLFSSL_TLSX_PQC_MLKEM_STORE_PRIV_KEY.

misc.c: when Intel x64 build, assume able to read/write unaligned

Testing

Regression tested ML-KEM/Kyber

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@SparkiDev SparkiDev self-assigned this Feb 18, 2025
@SparkiDev SparkiDev force-pushed the kyber_improv_2 branch 2 times, most recently from 11b6e3a to 255afc9 Compare February 18, 2025 21:55
@SparkiDev SparkiDev assigned wolfSSL-Bot and unassigned SparkiDev Feb 18, 2025
Copy link
Contributor

@JacobBarthelmeh JacobBarthelmeh left a comment

Choose a reason for hiding this comment

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

./configure CC="clang-15 -fsanitize=address" --enable-kyber=make

  CC       examples/benchmark/tls_bench.o
src/tls.c:7998:39: error: unused parameter 'type' [-Werror,-Wunused-parameter]
static int kyber_id2type(int id, int *type)
                                      ^
1 error generated.

Similar warning with ./configure CC="clang-15 -fsanitize=address" --enable-kyber=enc

./configure CC="clang-15 -fsanitize=address" --enable-kyber=dec

wolfcrypt/src/wc_kyber.c:1207:30: error: variable 'compVecSz' is uninitialized when used here [-Werror,-Wuninitialized]
        const byte* c2 = c + compVecSz;
                             ^~~~~~~~~
wolfcrypt/src/wc_kyber.c:1138:27: note: initialize the variable 'compVecSz' to silence this warning
    unsigned int compVecSz;
                          ^
                           = 0
1 error generated.
make[2]: *** [Makefile:8200: wolfcrypt/src/src_libwolfssl_la-wc_kyber.lo] Error 1

`

@SparkiDev
Copy link
Contributor Author

SparkiDev commented Feb 18, 2025

./configure CC="clang-15 -fsanitize=address" --enable-kyber=make

  CC       examples/benchmark/tls_bench.o
src/tls.c:7998:39: error: unused parameter 'type' [-Werror,-Wunused-parameter]
static int kyber_id2type(int id, int *type)
                                      ^
1 error generated.

Similar warning with ./configure CC="clang-15 -fsanitize=address" --enable-kyber=enc

./configure CC="clang-15 -fsanitize=address" --enable-kyber=dec

wolfcrypt/src/wc_kyber.c:1207:30: error: variable 'compVecSz' is uninitialized when used here [-Werror,-Wuninitialized]
        const byte* c2 = c + compVecSz;
                             ^~~~~~~~~
wolfcrypt/src/wc_kyber.c:1138:27: note: initialize the variable 'compVecSz' to silence this warning
    unsigned int compVecSz;
                          ^
                           = 0
1 error generated.
make[2]: *** [Makefile:8200: wolfcrypt/src/src_libwolfssl_la-wc_kyber.lo] Error 1

`

Need to specify --enable-kyber=512,768,1024,enc

Changed the header files to detect whether a key length has been specified.
Also whether an operation has been specified.

@SparkiDev SparkiDev force-pushed the kyber_improv_2 branch 2 times, most recently from 221280a to d6e41c0 Compare February 19, 2025 03:02
@dgarske dgarske assigned SparkiDev and unassigned dgarske and JacobBarthelmeh Feb 19, 2025
ML-KEM/Kyber:
  MakeKey call generate random once only for all data.
  Allow MakeKey/Encapsulate/Decapsulate to be compiled separately.
  Pull out public key decoding common to public and private key decode.
Put references to FIPS 140-3 into code. Rename variables to match FIPS
140-3.
  Fix InvNTT assembly code for x64 - more reductions.
  Split out ML-KEM/Kyber tests from api.c.

TLSX:
Store the object instead of the private key when WOLFSSL_MLKEM_CACHE_A
is defined or WOLFSSL_TLSX_PQC_MLKEM_STORE_OBJ. Faster decapsulation
when A is cached and object stored.
To store private key as normal define
WOLFSSL_TLSX_PQC_MLKEM_STORE_PRIV_KEY.

misc.c: when Intel x64 build, assume able to read/write unaligned
@dgarske dgarske self-assigned this Feb 19, 2025
@dgarske
Copy link
Contributor

dgarske commented Feb 19, 2025

Retest this please: "Found unhandled org.jenkinsci.plugins.workflow.support.steps.AgentOfflineException exception:"

@dgarske dgarske merged commit 93000e5 into wolfSSL:master Feb 20, 2025
178 checks passed
@SparkiDev SparkiDev removed the request for review from wolfSSL-Bot February 20, 2025 00:47
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.

4 participants