Skip to content

Commit defcaa1

Browse files
authored
Merge pull request #8582 from douzzer/20250321-Wdeclaration-after-statements-and-Kyber-fixes
20250321-Wdeclaration-after-statements-and-Kyber-fixes
2 parents 9a3ea6f + e3fe575 commit defcaa1

File tree

10 files changed

+92
-84
lines changed

10 files changed

+92
-84
lines changed

.github/workflows/pq-all.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
matrix:
1919
config: [
2020
# Add new configs here
21-
'--enable-intelasm --enable-sp-asm --enable-all --enable-testcert --enable-acert --enable-dtls13 --enable-dtls-mtu --enable-dtls-frag-ch --enable-dtlscid --enable-quic --with-sys-crypto-policy --enable-experimental --enable-kyber=yes,original --enable-lms --enable-xmss --enable-dilithium --enable-dual-alg-certs --disable-qt CPPFLAGS="-pedantic -DWOLFCRYPT_TEST_LINT -DNO_WOLFSSL_CIPHER_SUITE_TEST"'
21+
'--enable-intelasm --enable-sp-asm --enable-all --enable-testcert --enable-acert --enable-dtls13 --enable-dtls-mtu --enable-dtls-frag-ch --enable-dtlscid --enable-quic --with-sys-crypto-policy --enable-experimental --enable-kyber=yes,original --enable-lms --enable-xmss --enable-dilithium --enable-dual-alg-certs --disable-qt CPPFLAGS="-pedantic -Wdeclaration-after-statement -DWOLFCRYPT_TEST_LINT -DNO_WOLFSSL_CIPHER_SUITE_TEST"'
2222
]
2323
name: make check
2424
if: github.repository_owner == 'wolfssl'

configure.ac

+15-14
Original file line numberDiff line numberDiff line change
@@ -1416,14 +1416,14 @@ AC_ARG_WITH([liboqs],
14161416
# Used:
14171417
# - SHA3, Shake128 and Shake256
14181418
AC_ARG_ENABLE([kyber],
1419-
[AS_HELP_STRING([--enable-kyber],[Enable MLKEM (default: disabled)])],
1419+
[AS_HELP_STRING([--enable-kyber],[Enable Kyber/MLKEM (default: disabled)])],
14201420
[ ENABLED_MLKEM=$enableval ],
14211421
[ ENABLED_MLKEM=no ]
14221422
)
1423+
# note, inherits default from "kyber" clause above.
14231424
AC_ARG_ENABLE([mlkem],
1424-
[AS_HELP_STRING([--enable-kyber],[Enable MLKEM (default: disabled)])],
1425-
[ ENABLED_MLKEM=$enableval ],
1426-
[ ENABLED_MLKEM=no ]
1425+
[AS_HELP_STRING([--enable-mlkem],[Enable MLKEM (default: disabled)])],
1426+
[ ENABLED_MLKEM=$enableval ]
14271427
)
14281428

14291429
ENABLED_WC_MLKEM=no
@@ -1434,13 +1434,18 @@ ENABLED_MLKEM_DECAPSULATE=no
14341434
for v in `echo $ENABLED_MLKEM | tr "," " "`
14351435
do
14361436
case $v in
1437-
yes)
1437+
yes|all)
14381438
ENABLED_MLKEM512=yes
14391439
ENABLED_MLKEM768=yes
14401440
ENABLED_MLKEM1024=yes
14411441
ENABLED_MLKEM_MAKE_KEY=yes
14421442
ENABLED_MLKEM_ENCAPSULATE=yes
14431443
ENABLED_MLKEM_DECAPSULATE=yes
1444+
if test "$v" = "all"
1445+
then
1446+
ENABLED_ML_KEM=yes
1447+
ENABLED_ORIGINAL=yes
1448+
fi
14441449
;;
14451450
no)
14461451
;;
@@ -1468,11 +1473,6 @@ do
14681473
decapsulate|dec)
14691474
ENABLED_MLKEM_DECAPSULATE=yes
14701475
;;
1471-
all)
1472-
ENABLED_MLKEM_MAKE_KEY=yes
1473-
ENABLED_MLKEM_ENCAPSULATE=yes
1474-
ENABLED_MLKEM_DECAPSULATE=yes
1475-
;;
14761476
original|kyber)
14771477
ENABLED_ORIGINAL=yes
14781478
;;
@@ -5673,7 +5673,8 @@ AS_CASE([$FIPS_VERSION],
56735673
-DHAVE_FIPS_VERSION_MINOR=$HAVE_FIPS_VERSION_MINOR \
56745674
-DHAVE_FIPS_VERSION_PATCH=$HAVE_FIPS_VERSION_PATCH \
56755675
-DNO_BIG_INT \
5676-
-DWC_RNG_SEED_CB"
5676+
-DWC_RNG_SEED_CB \
5677+
-DNO_PBKDF2"
56775678
56785679
# optimizations section
56795680
@@ -5700,9 +5701,9 @@ AS_CASE([$FIPS_VERSION],
57005701
(test "$FIPS_VERSION" != "lean-aesgcm-dev" || test "$enable_hkdf" != "yes")],
57015702
[enable_hkdf="no"; ENABLED_HKDF="no"; AM_CFLAGS="$AM_CFLAGS -UHAVE_HKDF"])
57025703
5703-
AS_IF([test "$ENABLED_PWDBASED" != "yes" &&
5704-
(test "$FIPS_VERSION" != "lean-aesgcm-dev" || test "$enable_pwdbased" != "no")],
5705-
[enable_pwdbased="yes"; ENABLED_PWDBASED="yes"; AM_CFLAGS="$AM_CFLAGS -DHAVE_PBKDF2"])
5704+
AS_IF([test "$ENABLED_PWDBASED" != "no" &&
5705+
(test "$FIPS_VERSION" != "lean-aesgcm-dev" || test "$enable_pwdbased" != "yes")],
5706+
[enable_pwdbased="no"; ENABLED_PWDBASED="no"])
57065707
57075708
AS_IF([test "$ENABLED_SRTP" != "no" &&
57085709
(test "$FIPS_VERSION" != "lean-aesgcm-dev" || test "$enable_srtp" != "yes")],

src/tls.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -10894,10 +10894,11 @@ int TLSX_CKS_Set(WOLFSSL* ssl, TLSX** extensions)
1089410894
int TLSX_CKS_Parse(WOLFSSL* ssl, byte* input, word16 length,
1089510895
TLSX** extensions)
1089610896
{
10897-
(void) extensions;
1089810897
int ret;
1089910898
int i, j;
1090010899

10900+
(void) extensions;
10901+
1090110902
/* Validating the input. */
1090210903
if (length == 0)
1090310904
return BUFFER_ERROR;

tests/api.c

+8-6
Original file line numberDiff line numberDiff line change
@@ -29768,14 +29768,16 @@ static int msgSrvCb(SSL_CTX *ctx, SSL *ssl)
2976829768
#endif
2976929769

2977029770
#if defined(OPENSSL_ALL) && defined(SESSION_CERTS) && !defined(NO_BIO)
29771-
WOLFSSL_X509* peer = NULL;
29771+
{
29772+
WOLFSSL_X509* peer = NULL;
2977229773

29773-
ExpectNotNull(peer= wolfSSL_get_peer_certificate(ssl));
29774-
ExpectNotNull(bio = BIO_new_fp(stderr, BIO_NOCLOSE));
29774+
ExpectNotNull(peer= wolfSSL_get_peer_certificate(ssl));
29775+
ExpectNotNull(bio = BIO_new_fp(stderr, BIO_NOCLOSE));
2977529776

29776-
fprintf(stderr, "Peer Certificate = :\n");
29777-
X509_print(bio,peer);
29778-
X509_free(peer);
29777+
fprintf(stderr, "Peer Certificate = :\n");
29778+
X509_print(bio,peer);
29779+
X509_free(peer);
29780+
}
2977929781

2978029782
ExpectNotNull(sk = SSL_get_peer_cert_chain(ssl));
2978129783
if (sk == NULL) {

tests/api/test_evp.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ int test_wolfSSL_EVP_CIPHER_type_string(void)
7474
EXPECT_DECLS;
7575
#ifdef OPENSSL_EXTRA
7676
const char* cipherStr;
77-
77+
7878
/* Test with valid cipher types */
79-
#ifndef NO_AES
79+
#ifdef HAVE_AES_CBC
8080
#ifdef WOLFSSL_AES_128
8181
cipherStr = wolfSSL_EVP_CIPHER_type_string(WC_AES_128_CBC_TYPE);
8282
ExpectNotNull(cipherStr);
@@ -94,7 +94,7 @@ int test_wolfSSL_EVP_CIPHER_type_string(void)
9494
cipherStr = wolfSSL_EVP_CIPHER_type_string(WC_NULL_CIPHER_TYPE);
9595
ExpectNotNull(cipherStr);
9696
ExpectStrEQ(cipherStr, "NULL");
97-
97+
9898
/* Test with invalid cipher type */
9999
cipherStr = wolfSSL_EVP_CIPHER_type_string(0xFFFF);
100100
ExpectNull(cipherStr);

wolfcrypt/benchmark/benchmark.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -9675,8 +9675,10 @@ static void bench_mlkem_keygen(int type, const char* name, int keySize,
96759675
#ifdef MLKEM_NONDETERMINISTIC
96769676
ret = wc_KyberKey_MakeKey(key, &gRng);
96779677
#else
9678-
unsigned char rand[WC_ML_KEM_MAKEKEY_RAND_SZ] = {0,};
9679-
ret = wc_KyberKey_MakeKeyWithRandom(key, rand, sizeof(rand));
9678+
{
9679+
unsigned char rand[WC_ML_KEM_MAKEKEY_RAND_SZ] = {0,};
9680+
ret = wc_KyberKey_MakeKeyWithRandom(key, rand, sizeof(rand));
9681+
}
96809682
#endif
96819683
if (ret != 0)
96829684
goto exit;

wolfcrypt/src/asn.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -21236,11 +21236,12 @@ static int DecodeAltSigAlg(const byte* input, int sz, DecodedCert* cert)
2123621236
* like a traditional signature in the certificate. */
2123721237
static int DecodeAltSigVal(const byte* input, int sz, DecodedCert* cert)
2123821238
{
21239-
(void)cert;
2124021239
int ret = 0;
2124121240
word32 idx = 0;
2124221241
int len = 0;
2124321242

21243+
(void)cert;
21244+
2124421245
WOLFSSL_ENTER("DecodeAltSigVal");
2124521246

2124621247
if (ret == 0) {
@@ -32238,15 +32239,14 @@ int wc_MakeSigWithBitStr(byte *sig, int sigSz, int sType, byte* buf,
3223832239
falcon_key* falconKey = NULL;
3223932240
dilithium_key* dilithiumKey = NULL;
3224032241
sphincs_key* sphincsKey = NULL;
32241-
32242-
WOLFSSL_ENTER("wc_MakeSigWithBitStr");
32243-
3224432242
int ret = 0;
3224532243
int headerSz;
3224632244
void* heap = NULL;
3224732245
CertSignCtx certSignCtx_lcl;
3224832246
CertSignCtx* certSignCtx = &certSignCtx_lcl;
3224932247

32248+
WOLFSSL_ENTER("wc_MakeSigWithBitStr");
32249+
3225032250
if ((sig == NULL) || (sigSz <= 0)) {
3225132251
return BAD_FUNC_ARG;
3225232252
}

wolfcrypt/src/wc_mlkem.c

+41-48
Original file line numberDiff line numberDiff line change
@@ -672,10 +672,8 @@ static int mlkemkey_encapsulate(MlKemKey* key, const byte* m, byte* r, byte* c)
672672
sword16 y[3 * MLKEM_MAX_K * MLKEM_N];
673673
#endif
674674
#endif
675-
#ifdef WOLFSSL_MLKEM_ENCAPSULATE_SMALL_MEM
676675
sword16* u;
677676
sword16* v;
678-
#endif
679677

680678
/* Establish parameters based on key type. */
681679
switch (key->type) {
@@ -741,21 +739,15 @@ static int mlkemkey_encapsulate(MlKemKey* key, const byte* m, byte* r, byte* c)
741739
}
742740
#endif
743741

744-
if (ret == 0) {
745742
#ifndef WOLFSSL_MLKEM_ENCAPSULATE_SMALL_MEM
743+
if (ret == 0) {
746744
/* Assign allocated dynamic memory to pointers.
747745
* y (b) | a (m) | mu (p) | e1 (p) | e2 (v) | u (v) | v (p) */
748746
a = y + MLKEM_N * k;
749747
mu = a + MLKEM_N * k * k;
750748
e1 = mu + MLKEM_N;
751749
e2 = e1 + MLKEM_N * k;
752-
#else
753-
/* Assign allocated dynamic memory to pointers.
754-
* y (v) | a (v) | u (v) */
755-
a = y + MLKEM_N * k;
756-
#endif
757750

758-
#ifndef WOLFSSL_MLKEM_ENCAPSULATE_SMALL_MEM
759751
/* Convert msg to a polynomial.
760752
* Step 20: mu <- Decompress_1(ByteDecode_1(m)) */
761753
mlkem_from_msg(mu, m);
@@ -767,7 +759,7 @@ static int mlkemkey_encapsulate(MlKemKey* key, const byte* m, byte* r, byte* c)
767759
*/
768760
ret = mlkem_get_noise(&key->prf, k, y, e1, e2, r);
769761
}
770-
#ifdef WOLFSSL_MLKEM_CACHE_A
762+
#ifdef WOLFSSL_MLKEM_CACHE_A
771763
if ((ret == 0) && ((key->flags & MLKEM_FLAG_A_SET) != 0)) {
772764
unsigned int i;
773765
/* Transpose matrix.
@@ -782,25 +774,28 @@ static int mlkemkey_encapsulate(MlKemKey* key, const byte* m, byte* r, byte* c)
782774
}
783775
}
784776
else
785-
#endif
777+
#endif /* WOLFSSL_MLKEM_CACHE_A */
786778
if (ret == 0) {
787779
/* Generate the transposed matrix.
788780
* Step 4-8: generate matrix A_hat */
789781
ret = mlkem_gen_matrix(&key->prf, a, k, key->pubSeed, 1);
790782
}
791783
if (ret == 0) {
792-
sword16* u;
793-
sword16* v;
794-
795784
/* Assign remaining allocated dynamic memory to pointers.
796785
* y (v) | a (m) | mu (p) | e1 (p) | r2 (v) | u (v) | v (p)*/
797786
u = e2 + MLKEM_N;
798787
v = u + MLKEM_N * k;
799788

800789
/* Perform encapsulation maths.
801790
* Steps 18-19, 21: calculate u and v */
802-
mlkem_encapsulate(key->pub, u, v, a, y, e1, e2, mu, k);
803-
#else
791+
ret = mlkem_encapsulate(key->pub, u, v, a, y, e1, e2, mu, k);
792+
}
793+
#else /* WOLFSSL_MLKEM_ENCAPSULATE_SMALL_MEM */
794+
if (ret == 0) {
795+
/* Assign allocated dynamic memory to pointers.
796+
* y (v) | a (v) | u (v) */
797+
a = y + MLKEM_N * k;
798+
804799
/* Initialize the PRF for use in the noise generation. */
805800
mlkem_prf_init(&key->prf);
806801
/* Generate noise using PRF.
@@ -819,41 +814,39 @@ static int mlkemkey_encapsulate(MlKemKey* key, const byte* m, byte* r, byte* c)
819814
ret = mlkem_encapsulate_seeds(key->pub, &key->prf, u, a, y, k, m,
820815
key->pubSeed, r);
821816
}
817+
#endif /* WOLFSSL_MLKEM_ENCAPSULATE_SMALL_MEM */
818+
822819
if (ret == 0) {
823-
#endif
824-
{
825-
byte* c1 = c;
826-
byte* c2 = c + compVecSz;
827-
828-
#if defined(WOLFSSL_KYBER512) || defined(WOLFSSL_WC_ML_KEM_512)
829-
if (k == WC_ML_KEM_512_K) {
830-
/* Step 22: c_1 <- ByteEncode_d_u(Compress_d_u(u)) */
831-
mlkem_vec_compress_10(c1, u, k);
832-
/* Step 23: c_2 <- ByteEncode_d_v(Compress_d_v(v)) */
833-
mlkem_compress_4(c2, v);
834-
/* Step 24: return c <- (c_1||c_2) */
835-
}
836-
#endif
837-
#if defined(WOLFSSL_KYBER768) || defined(WOLFSSL_WC_ML_KEM_768)
838-
if (k == WC_ML_KEM_768_K) {
839-
/* Step 22: c_1 <- ByteEncode_d_u(Compress_d_u(u)) */
840-
mlkem_vec_compress_10(c1, u, k);
841-
/* Step 23: c_2 <- ByteEncode_d_v(Compress_d_v(v)) */
842-
mlkem_compress_4(c2, v);
843-
/* Step 24: return c <- (c_1||c_2) */
844-
}
845-
#endif
846-
#if defined(WOLFSSL_KYBER1024) || defined(WOLFSSL_WC_ML_KEM_1024)
847-
if (k == WC_ML_KEM_1024_K) {
848-
/* Step 22: c_1 <- ByteEncode_d_u(Compress_d_u(u)) */
849-
mlkem_vec_compress_11(c1, u);
850-
/* Step 23: c_2 <- ByteEncode_d_v(Compress_d_v(v)) */
851-
mlkem_compress_5(c2, v);
852-
/* Step 24: return c <- (c_1||c_2) */
853-
}
854-
#endif
820+
byte* c1 = c;
821+
byte* c2 = c + compVecSz;
855822

823+
#if defined(WOLFSSL_KYBER512) || defined(WOLFSSL_WC_ML_KEM_512)
824+
if (k == WC_ML_KEM_512_K) {
825+
/* Step 22: c_1 <- ByteEncode_d_u(Compress_d_u(u)) */
826+
mlkem_vec_compress_10(c1, u, k);
827+
/* Step 23: c_2 <- ByteEncode_d_v(Compress_d_v(v)) */
828+
mlkem_compress_4(c2, v);
829+
/* Step 24: return c <- (c_1||c_2) */
856830
}
831+
#endif
832+
#if defined(WOLFSSL_KYBER768) || defined(WOLFSSL_WC_ML_KEM_768)
833+
if (k == WC_ML_KEM_768_K) {
834+
/* Step 22: c_1 <- ByteEncode_d_u(Compress_d_u(u)) */
835+
mlkem_vec_compress_10(c1, u, k);
836+
/* Step 23: c_2 <- ByteEncode_d_v(Compress_d_v(v)) */
837+
mlkem_compress_4(c2, v);
838+
/* Step 24: return c <- (c_1||c_2) */
839+
}
840+
#endif
841+
#if defined(WOLFSSL_KYBER1024) || defined(WOLFSSL_WC_ML_KEM_1024)
842+
if (k == WC_ML_KEM_1024_K) {
843+
/* Step 22: c_1 <- ByteEncode_d_u(Compress_d_u(u)) */
844+
mlkem_vec_compress_11(c1, u);
845+
/* Step 23: c_2 <- ByteEncode_d_v(Compress_d_v(v)) */
846+
mlkem_compress_5(c2, v);
847+
/* Step 24: return c <- (c_1||c_2) */
848+
}
849+
#endif
857850
}
858851

859852
#ifndef WOLFSSL_NO_MALLOC

0 commit comments

Comments
 (0)