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

Kyber: fixes to configure and wolfSSL_get_curve_name #8183

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,7 @@ AC_ARG_ENABLE([kyber],
)

ENABLED_WC_KYBER=no
ENABLED_ML_KEM=yes
ENABLED_ML_KEM=unset
for v in `echo $ENABLED_KYBER | tr "," " "`
do
case $v in
Expand All @@ -1335,9 +1335,8 @@ do
original)
ENABLED_ORIGINAL=yes
;;
original-only)
ENABLED_ORIGINAL=yes
ENABLED_ML_KEM=no
ml-kem)
ENABLED_ML_KEM=yes
;;
*)
AC_MSG_ERROR([Invalid choice for KYBER []: $ENABLED_KYBER.])
Expand Down Expand Up @@ -1366,6 +1365,12 @@ then
if test "$ENABLED_KYBER1024" = ""; then
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_NO_KYBER1024"
fi
if test "$ENABLED_ML_KEM" = "unset"; then
ENABLED_ML_KEM=no
fi
fi
if test "$ENABLED_ML_KEM" = "unset"; then
ENABLED_ML_KEM=yes
fi
if test "$ENABLED_ML_KEM" = "yes"; then
if test "$ENABLED_KYBER512" = ""; then
Expand Down
6 changes: 3 additions & 3 deletions src/ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -14572,19 +14572,19 @@ const char* wolfSSL_get_curve_name(WOLFSSL* ssl)
case WOLFSSL_P521_ML_KEM_1024:
return "P521_ML_KEM_1024";
#elif defined(WOLFSSL_WC_KYBER)
#ifdef WOLFSSL_WC_ML_KEM_512
#ifndef WOLFSSL_NO_ML_KEM_512
case WOLFSSL_ML_KEM_512:
return "ML_KEM_512";
case WOLFSSL_P256_ML_KEM_512:
return "P256_ML_KEM_512";
#endif
#ifdef WOLFSSL_WC_ML_KEM_768
#ifndef WOLFSSL_NO_ML_KEM_768
case WOLFSSL_ML_KEM_768:
return "ML_KEM_768";
case WOLFSSL_P384_ML_KEM_768:
return "P384_ML_KEM_768";
#endif
#ifdef WOLFSSL_WC_ML_KEM_1024
#ifndef WOLFSSL_NO_ML_KEM_1024
case WOLFSSL_ML_KEM_1024:
return "ML_KEM_1024";
case WOLFSSL_P521_ML_KEM_1024:
Expand Down
24 changes: 12 additions & 12 deletions src/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -7984,17 +7984,17 @@ static int kyber_id2type(int id, int *type)

switch (id) {
#ifndef WOLFSSL_NO_ML_KEM
#ifdef WOLFSSL_WC_ML_KEM_512
#ifndef WOLFSSL_NO_ML_KEM_512
case WOLFSSL_ML_KEM_512:
*type = WC_ML_KEM_512;
break;
#endif
#ifdef WOLFSSL_WC_ML_KEM_768
#ifndef WOLFSSL_NO_ML_KEM_768
case WOLFSSL_ML_KEM_768:
*type = WC_ML_KEM_768;
break;
#endif
#ifdef WOLFSSL_WC_ML_KEM_1024
#ifndef WOLFSSL_NO_ML_KEM_1024
case WOLFSSL_ML_KEM_1024:
*type = WC_ML_KEM_1024;
break;
Expand Down Expand Up @@ -9694,15 +9694,15 @@ static int TLSX_KeyShare_IsSupported(int namedGroup)
#ifdef WOLFSSL_HAVE_KYBER
#ifndef WOLFSSL_NO_ML_KEM
#ifdef WOLFSSL_WC_KYBER
#ifdef WOLFSSL_WC_ML_KEM_512
#ifndef WOLFSSL_NO_ML_KEM_512
case WOLFSSL_ML_KEM_512:
case WOLFSSL_P256_ML_KEM_512:
#endif
#ifdef WOLFSSL_WC_ML_KEM_768
#ifndef WOLFSSL_NO_ML_KEM_768
case WOLFSSL_ML_KEM_768:
case WOLFSSL_P384_ML_KEM_768:
#endif
#ifdef WOLFSSL_WC_ML_KEM_1024
#ifndef WOLFSSL_NO_ML_KEM_1024
case WOLFSSL_ML_KEM_1024:
case WOLFSSL_P521_ML_KEM_1024:
#endif
Expand Down Expand Up @@ -9816,15 +9816,15 @@ static const word16 preferredGroup[] = {
#endif
#ifndef WOLFSSL_NO_ML_KEM
#ifdef WOLFSSL_WC_KYBER
#ifdef WOLFSSL_WC_ML_KEM_512
#ifndef WOLFSSL_NO_ML_KEM_512
WOLFSSL_ML_KEM_512,
WOLFSSL_P256_ML_KEM_512,
#endif
#ifdef WOLFSSL_WC_ML_KEM_768
#ifndef WOLFSSL_NO_ML_KEM_768
WOLFSSL_ML_KEM_768,
WOLFSSL_P384_ML_KEM_768,
#endif
#ifdef WOLFSSL_WC_ML_KEM_1024
#ifndef WOLFSSL_NO_ML_KEM_1024
WOLFSSL_ML_KEM_1024,
WOLFSSL_P521_ML_KEM_1024,
#endif
Expand Down Expand Up @@ -13484,23 +13484,23 @@ static int TLSX_PopulateSupportedGroups(WOLFSSL* ssl, TLSX** extensions)
#ifdef WOLFSSL_HAVE_KYBER
#ifndef WOLFSSL_NO_ML_KEM
#ifdef WOLFSSL_WC_KYBER
#ifdef WOLFSSL_WC_ML_KEM_512
#ifndef WOLFSSL_NO_ML_KEM_512
if (ret == WOLFSSL_SUCCESS)
ret = TLSX_UseSupportedCurve(extensions, WOLFSSL_ML_KEM_512,
ssl->heap);
if (ret == WOLFSSL_SUCCESS)
ret = TLSX_UseSupportedCurve(extensions, WOLFSSL_P256_ML_KEM_512,
ssl->heap);
#endif
#ifdef WOLFSSL_WC_ML_KEM_768
#ifndef WOLFSSL_NO_ML_KEM_768
if (ret == WOLFSSL_SUCCESS)
ret = TLSX_UseSupportedCurve(extensions, WOLFSSL_ML_KEM_768,
ssl->heap);
if (ret == WOLFSSL_SUCCESS)
ret = TLSX_UseSupportedCurve(extensions, WOLFSSL_P384_ML_KEM_768,
ssl->heap);
#endif
#ifdef WOLFSSL_WC_ML_KEM_1024
#ifndef WOLFSSL_NO_ML_KEM_1024
if (ret == WOLFSSL_SUCCESS)
ret = TLSX_UseSupportedCurve(extensions, WOLFSSL_ML_KEM_1024,
ssl->heap);
Expand Down
9 changes: 9 additions & 0 deletions tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -95512,7 +95512,11 @@ static int test_dtls13_frag_ch_pq(void)
const char *test_str = "test";
int test_str_size;
byte buf[255];
#ifdef WOLFSSL_KYBER_ORIGINAL
int group = WOLFSSL_KYBER_LEVEL5;
#else
int group = WOLFSSL_ML_KEM_1024;
#endif

XMEMSET(&test_ctx, 0, sizeof(test_ctx));
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
Expand All @@ -95522,8 +95526,13 @@ static int test_dtls13_frag_ch_pq(void)
ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, group), WOLFSSL_SUCCESS);
ExpectIntEQ(wolfSSL_dtls13_allow_ch_frag(ssl_s, 1), WOLFSSL_SUCCESS);
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
#ifdef WOLFSSL_KYBER_ORIGINAL
ExpectStrEQ(wolfSSL_get_curve_name(ssl_c), "KYBER_LEVEL5");
ExpectStrEQ(wolfSSL_get_curve_name(ssl_s), "KYBER_LEVEL5");
#else
ExpectStrEQ(wolfSSL_get_curve_name(ssl_c), "ML_KEM_1024");
ExpectStrEQ(wolfSSL_get_curve_name(ssl_s), "ML_KEM_1024");
#endif
test_str_size = XSTRLEN("test") + 1;
ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size);
ExpectIntEQ(wolfSSL_read(ssl_s, buf, sizeof(buf)), test_str_size);
Expand Down
Loading