Skip to content

Commit b9619c3

Browse files
Merge pull request #7343 from douzzer/20240315-pq-experimental
20240315-pq-experimental
2 parents 50b1044 + 924887b commit b9619c3

File tree

5 files changed

+62
-30
lines changed

5 files changed

+62
-30
lines changed

configure.ac

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,18 @@ else
102102
REPRODUCIBLE_BUILD_DEFAULT=no
103103
fi
104104

105+
# Allow experimental settings
106+
AC_ARG_ENABLE([experimental],
107+
[AS_HELP_STRING([--enable-experimental],[Allow experimental settings in the configuration (default: disabled)])],
108+
[ ENABLED_EXPERIMENTAL=$enableval ],
109+
[ ENABLED_EXPERIMENTAL=no ]
110+
)
111+
if test "$ENABLED_EXPERIMENTAL" = "yes"
112+
then
113+
AS_IF([ test "$ENABLED_DISTRO" = "yes" && test "$ENABLED_EXPERIMENTAL" = "yes" ],[ AC_MSG_ERROR([--enable-distro and --enable-experimental are mutually exclusive.]) ])
114+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_EXPERIMENTAL_SETTINGS"
115+
AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_EXPERIMENTAL_SETTINGS"
116+
fi
105117

106118
AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h netdb.h netinet/in.h stddef.h time.h sys/ioctl.h sys/socket.h sys/time.h errno.h sys/un.h])
107119
AC_CHECK_LIB([network],[socket])
@@ -1057,8 +1069,9 @@ fi
10571069
ENABLED_LIBOQS="no"
10581070
tryliboqsdir=""
10591071
AC_ARG_WITH([liboqs],
1060-
[AS_HELP_STRING([--with-liboqs=PATH],[Path to liboqs install (default /usr/local) EXPERIMENTAL!])],
1072+
[AS_HELP_STRING([--with-liboqs=PATH],[Path to liboqs install (default /usr/local) (requires --enable-experimental)])],
10611073
[
1074+
AS_IF([ test "$ENABLED_EXPERIMENTAL" != "yes" ],[ AC_MSG_ERROR([LIBOQS requires --enable-experimental.]) ])
10621075
AC_MSG_CHECKING([for liboqs])
10631076
LIBS="$LIBS -loqs"
10641077
@@ -1105,7 +1118,7 @@ AC_ARG_WITH([liboqs],
11051118
# - SHA3, Shake128 and Shake256, or
11061119
# - SHA256, SHA512, AES-CTR
11071120
AC_ARG_ENABLE([kyber],
1108-
[AS_HELP_STRING([--enable-kyber],[Enable KYBER (default: disabled)])],
1121+
[AS_HELP_STRING([--enable-kyber],[Enable KYBER (requires --enable-experimental) (default: disabled)])],
11091122
[ ENABLED_KYBER=$enableval ],
11101123
[ ENABLED_KYBER=no ]
11111124
)
@@ -1141,6 +1154,7 @@ done
11411154

11421155
if test "$ENABLED_KYBER" != "no"
11431156
then
1157+
AS_IF([ test "$ENABLED_EXPERIMENTAL" != "yes" ],[ AC_MSG_ERROR([KYBER requires --enable-experimental.]) ])
11441158
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_HAVE_KYBER"
11451159
# Use liboqs if specified.
11461160
if test "$ENABLED_LIBOQS" = "no"; then
@@ -1220,8 +1234,9 @@ fi
12201234
ENABLED_LIBXMSS="no"
12211235
trylibxmssdir=""
12221236
AC_ARG_WITH([libxmss],
1223-
[AS_HELP_STRING([--with-libxmss=PATH],[PATH to xmss-reference root dir. EXPERIMENTAL!])],
1237+
[AS_HELP_STRING([--with-libxmss=PATH],[PATH to xmss-reference root dir. (requires --enable-experimental)!])],
12241238
[
1239+
AS_IF([ test "$ENABLED_EXPERIMENTAL" != "yes" ],[ AC_MSG_ERROR([libxmss requires --enable-experimental.]) ])
12251240
AC_MSG_CHECKING([for libxmss])
12261241
12271242
trylibxmssdir=$withval
@@ -1318,8 +1333,9 @@ fi
13181333
ENABLED_LIBLMS="no"
13191334
tryliblmsdir=""
13201335
AC_ARG_WITH([liblms],
1321-
[AS_HELP_STRING([--with-liblms=PATH],[PATH to hash-sigs LMS/HSS install (default /usr/local) EXPERIMENTAL!])],
1336+
[AS_HELP_STRING([--with-liblms=PATH],[PATH to hash-sigs LMS/HSS install (default /usr/local) (requires --enable-experimental)!])],
13221337
[
1338+
AS_IF([ test "$ENABLED_EXPERIMENTAL" != "yes" ],[ AC_MSG_ERROR([liblms requires --enable-experimental.]) ])
13231339
AC_MSG_CHECKING([for liblms])
13241340
13251341
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <hss.h>]], [[ param_set_t lm_type; param_set_t lm_ots_type; hss_get_public_key_len(4, &lm_type, &lm_ots_type); ]])], [ liblms_linked=yes ],[ liblms_linked=no ])
@@ -8185,11 +8201,13 @@ AC_ARG_ENABLE([sys-ca-certs],
81858201
)
81868202

81878203
AC_ARG_ENABLE([dual-alg-certs],
8188-
[AS_HELP_STRING([--enable-dual-alg-certs],[Enable support for dual key/signature certificates in TLS 1.3 as defined in X9.146 (default: disabled)])],
8204+
[AS_HELP_STRING([--enable-dual-alg-certs],[Enable support for dual key/signature certificates in TLS 1.3 as defined in X9.146 (requires --enable-experimental) (default: disabled)])],
81898205
[ ENABLED_DUAL_ALG_CERTS=$enableval ],
81908206
[ ENABLED_DUAL_ALG_CERTS=no ]
81918207
)
81928208

8209+
AS_IF([ test "$ENABLED_DUAL_ALG_CERTS" != "no" && test "$ENABLED_EXPERIMENTAL" != "yes" ],[ AC_MSG_ERROR([dual-alg-certs requires --enable-experimental.]) ])
8210+
81938211
# check if should run the trusted peer certs test
81948212
# (for now checking both C_FLAGS and C_EXTRA_FLAGS)
81958213
AS_CASE(["$CFLAGS $CPPFLAGS"],[*'WOLFSSL_TRUST_PEER_CERT'*],[ENABLED_TRUSTED_PEER_CERT=yes])
@@ -9430,6 +9448,12 @@ echo " * SIMD+FPU enable as flags: $ASFLAGS_FPUSIMD_ENABLE" && \
94309448
echo " * Linux kernel module PIE: $ENABLED_LINUXKM_PIE"
94319449
echo " * Linux kernel module bench: $ENABLED_LINUXKM_BENCHMARKS"
94329450

9451+
if test "$ENABLED_EXPERIMENTAL" = "yes"
9452+
then
9453+
echo " * Experimental settings: Allowed"
9454+
else
9455+
echo " * Experimental settings: Forbidden"
9456+
fi
94339457
echo " * Debug enabled: $ax_enable_debug"
94349458
echo " * Coverage enabled: $ax_enable_coverage"
94359459
echo " * Warnings as failure: $ac_cv_warnings_as_errors"

tests/api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54328,7 +54328,7 @@ static int test_tls13_apis(void)
5432854328
#endif
5432954329
#if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
5433054330
"P-256"
54331-
#ifdef HAVE_PQC
54331+
#if defined(HAVE_PQC) && defined(HAVE_LIBOQS)
5433254332
":P256_KYBER_LEVEL1"
5433354333
#endif
5433454334
#endif

wolfcrypt/src/wc_kyber_poly.c

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,10 +1015,9 @@ static int kyber_xof_squeezeblocks(wc_Shake* shake128, byte* out, int blocks)
10151015
*
10161016
* @param [in, out] shake256 SHAKE-256 object.
10171017
*/
1018-
void kyber_prf_init(wc_Shake* shake256)
1018+
void kyber_prf_init(wc_Shake* prf)
10191019
{
1020-
XMEMSET(shake256->s, 0, sizeof(shake256->s));
1021-
1020+
XMEMSET(prf->s, 0, sizeof(prf->s));
10221021
}
10231022

10241023
/* New/Initialize SHAKE-256 object.
@@ -1028,18 +1027,18 @@ void kyber_prf_init(wc_Shake* shake256)
10281027
* @param [in] devId Device id.
10291028
* @return 0 on success always.
10301029
*/
1031-
int kyber_prf_new(wc_Shake* shake256, void* heap, int devId)
1030+
int kyber_prf_new(wc_Shake* prf, void* heap, int devId)
10321031
{
1033-
return wc_InitShake256(shake256, heap, devId);
1032+
return wc_InitShake256(prf, heap, devId);
10341033
}
10351034

10361035
/* Free SHAKE-256 object.
10371036
*
10381037
* @param [in, out] shake256 SHAKE-256 object.
10391038
*/
1040-
void kyber_prf_free(wc_Shake* shake256)
1039+
void kyber_prf_free(wc_Shake* prf)
10411040
{
1042-
wc_Shake256_Free(shake256);
1041+
wc_Shake256_Free(prf);
10431042
}
10441043

10451044
/* Create pseudo-random data from the key using SHAKE-256.
@@ -1340,8 +1339,8 @@ int kyber_gen_matrix(KYBER_PRF_T* prf, sword16* a, int kp, byte* seed,
13401339
* @return Difference of the two values with range 0..2.
13411340
*/
13421341
#define ETA2_SUB(d, i) \
1343-
(((sword16)((d >> ((i) * 4 + 0)) & 0x3)) - \
1344-
((sword16)((d >> ((i) * 4 + 2)) & 0x3)))
1342+
(((sword16)(((d) >> ((i) * 4 + 0)) & 0x3)) - \
1343+
((sword16)(((d) >> ((i) * 4 + 2)) & 0x3)))
13451344

13461345
/* Compute polynomial with coefficients distributed according to a centered
13471346
* binomial distribution with parameter eta2 from uniform random bytes.
@@ -1448,8 +1447,8 @@ static void kyber_cbd_eta2(sword16* p, const byte* r)
14481447
* @return Difference of the two values with range 0..3.
14491448
*/
14501449
#define ETA3_SUB(d, i) \
1451-
(((sword16)((d >> ((i) * 6 + 0)) & 0x7)) - \
1452-
((sword16)((d >> ((i) * 6 + 3)) & 0x7)))
1450+
(((sword16)(((d) >> ((i) * 6 + 0)) & 0x7)) - \
1451+
((sword16)(((d) >> ((i) * 6 + 3)) & 0x7)))
14531452

14541453
/* Compute polynomial with coefficients distributed according to a centered
14551454
* binomial distribution with parameter eta3 from uniform random bytes.
@@ -2041,7 +2040,7 @@ static KYBER_NOINLINE void kyber_csubq_c(sword16* p)
20412040
* @return Compressed value.
20422041
*/
20432042
#define TO_COMP_WORD_10(v, i, j, k) \
2044-
((((KYBER_V54 << 10) * v[i * KYBER_N + j + k]) + KYBER_V54_HALF) >> 54)
2043+
((((KYBER_V54 << 10) * (v)[(i) * KYBER_N + (j) + (k)]) + KYBER_V54_HALF) >> 54)
20452044

20462045
/* Compress value to 11 bits.
20472046
*
@@ -2055,7 +2054,7 @@ static KYBER_NOINLINE void kyber_csubq_c(sword16* p)
20552054
* @return Compressed value.
20562055
*/
20572056
#define TO_COMP_WORD_11(v, i, j, k) \
2058-
((((KYBER_V53 << 11) * v[i * KYBER_N + j + k]) + KYBER_V53_HALF) >> 53)
2057+
((((KYBER_V53 << 11) * (v)[(i) * KYBER_N + (j) + (k)]) + KYBER_V53_HALF) >> 53)
20592058

20602059
#endif /* CONV_WITH_DIV */
20612060

@@ -2241,8 +2240,8 @@ void kyber_vec_compress_11(byte* r, sword16* v)
22412240
* @return Decompressed value.
22422241
*/
22432242
#define DECOMP_10(v, i, j, k, t) \
2244-
v[i * KYBER_N + 4 * j + k] = \
2245-
(word16)((((word32)(t & 0x3ff) * KYBER_Q) + 512) >> 10)
2243+
v[(i) * KYBER_N + 4 * (j) + (k)] = \
2244+
(word16)((((word32)((t) & 0x3ff) * KYBER_Q) + 512) >> 10)
22462245

22472246
/* Decompress an 11 bit value.
22482247
*
@@ -2254,8 +2253,8 @@ void kyber_vec_compress_11(byte* r, sword16* v)
22542253
* @return Decompressed value.
22552254
*/
22562255
#define DECOMP_11(v, i, j, k, t) \
2257-
v[i * KYBER_N + 8 * j + k] = \
2258-
(word16)((((word32)(t & 0x7ff) * KYBER_Q) + 1024) >> 11)
2256+
v[(i) * KYBER_N + 8 * (j) + (k)] = \
2257+
(word16)((((word32)((t) & 0x7ff) * KYBER_Q) + 1024) >> 11)
22592258

22602259
#if defined(WOLFSSL_KYBER512) || defined(WOLFSSL_KYBER768)
22612260
/* Decompress the byte array of packed 10 bits into vector of polynomials.
@@ -2474,7 +2473,7 @@ void kyber_vec_decompress_11(sword16* v, const unsigned char* b)
24742473
* @return Compressed value.
24752474
*/
24762475
#define TO_COMP_WORD_4(p, i, j) \
2477-
((((KYBER_V28 << 4) * p[i + j]) + KYBER_V28_HALF) >> 28)
2476+
((((KYBER_V28 << 4) * (p)[(i) + (j)]) + KYBER_V28_HALF) >> 28)
24782477

24792478
/* Compress value to 5 bits.
24802479
*
@@ -2486,7 +2485,7 @@ void kyber_vec_decompress_11(sword16* v, const unsigned char* b)
24862485
* @return Compressed value.
24872486
*/
24882487
#define TO_COMP_WORD_5(p, i, j) \
2489-
((((KYBER_V27 << 5) * p[i + j]) + KYBER_V27_HALF) >> 27)
2488+
((((KYBER_V27 << 5) * (p)[(i) + (j)]) + KYBER_V27_HALF) >> 27)
24902489

24912490
#endif /* CONV_WITH_DIV */
24922491

@@ -2644,7 +2643,7 @@ void kyber_compress_5(byte* b, sword16* p)
26442643
* @return Decompressed value.
26452644
*/
26462645
#define DECOMP_4(p, i, j, t) \
2647-
p[i + j] = ((word16)((t) * KYBER_Q) + 8) >> 4
2646+
p[(i) + (j)] = ((word16)((t) * KYBER_Q) + 8) >> 4
26482647

26492648
/* Decompress a 5 bit value.
26502649
*
@@ -2655,7 +2654,7 @@ void kyber_compress_5(byte* b, sword16* p)
26552654
* @return Decompressed value.
26562655
*/
26572656
#define DECOMP_5(p, i, j, t) \
2658-
p[i + j] = (((word32)((t) & 0x1f) * KYBER_Q) + 16) >> 5
2657+
p[(i) + (j)] = (((word32)((t) & 0x1f) * KYBER_Q) + 16) >> 5
26592658

26602659
#if defined(WOLFSSL_KYBER512) || defined(WOLFSSL_KYBER768)
26612660
/* Decompress the byte array of packed 4 bits into polynomial.
@@ -2781,7 +2780,7 @@ void kyber_decompress_5(sword16* p, const unsigned char* b)
27812780
* @param [in] j Index of bit in byte.
27822781
*/
27832782
#define FROM_MSG_BIT(p, msg, i, j) \
2784-
p[8 * i + j] = ((sword16)0 - (sword16)((msg[i] >> j) & 1)) & KYBER_Q_1_HALF
2783+
p[8 * (i) + (j)] = ((sword16)0 - (sword16)(((msg)[i] >> (j)) & 1)) & KYBER_Q_1_HALF
27852784

27862785
/* Convert message to polynomial.
27872786
*
@@ -2864,7 +2863,7 @@ void kyber_from_msg(sword16* p, const byte* msg)
28642863
* @param [in] j Index of bit in byte.
28652864
*/
28662865
#define TO_MSG_BIT(m, p, i, j) \
2867-
m[i] |= ((word32)((KYBER_V31_2 * p[8 * i + j]) + KYBER_V31_HALF) >> 31) << j
2866+
(m)[i] |= ((word32)((KYBER_V31_2 * (p)[8 * (i) + (j)]) + KYBER_V31_HALF) >> 31) << (j)
28682867

28692868
#endif /* CONV_WITH_DIV */
28702869

wolfssl/wolfcrypt/settings.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3262,6 +3262,15 @@ extern void uITRON4_free(void *p) ;
32623262
#define WOLFSSL_NO_KYBER1024
32633263
#endif
32643264

3265+
#if (defined(HAVE_LIBOQS) || \
3266+
defined(WOLFSSL_WC_KYBER) || \
3267+
defined(HAVE_LIBXMSS) || \
3268+
defined(HAVE_LIBLMS) || \
3269+
defined(WOLFSSL_DUAL_ALG_CERTS)) && \
3270+
!defined(WOLFSSL_EXPERIMENTAL_SETTINGS)
3271+
#error Experimental settings without WOLFSSL_EXPERIMENTAL_SETTINGS
3272+
#endif
3273+
32653274
#if defined(HAVE_PQC) && !defined(HAVE_LIBOQS) && !defined(HAVE_PQM4) && \
32663275
!defined(WOLFSSL_HAVE_KYBER)
32673276
#error Please do not define HAVE_PQC yourself.

wolfssl/wolfcrypt/wc_kyber.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ struct KyberKey {
112112
void* heap;
113113
#if defined(WOLF_CRYPTO_CB)
114114
/* Device Id. */
115-
int* devId;
115+
int devId;
116116
#endif
117117
/* Flags indicating what is stored in the key. */
118118
int flags;

0 commit comments

Comments
 (0)