Skip to content

Commit

Permalink
Kyber: fixes to configure and wolfSSL_get_curve_name
Browse files Browse the repository at this point in the history
Remote original-only option for kyber in configure.ac.
Default is ML-KEM only.
original is Kyber only.
ml-lem is ML-KEM.
to have both: all,original,ml-kem.

Use WOLFSSL_NO_ML_KEM* instead of WOLFSSL_WC_ML_KEM_* which requires the
inclusion of kyber headers.
  • Loading branch information
SparkiDev committed Nov 13, 2024
1 parent 878cf3a commit fc304e4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
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

0 comments on commit fc304e4

Please sign in to comment.