Skip to content

Commit 80a63a3

Browse files
authored
Merge pull request #7924 from anhu/pqm4_purge
Get rid of pqm4 in favour our own Kyber/MLDSA implementation
2 parents 945f976 + 844d0ec commit 80a63a3

11 files changed

Lines changed: 70 additions & 105 deletions

File tree

IDE/STM32Cube/default_conf.ftl

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -334,15 +334,6 @@ extern ${variable.value} ${variable.name};
334334
#define NO_SESSION_CACHE
335335
#endif
336336

337-
/* Post Quantum
338-
* Note: PQM4 is compatible with STM32. The project can be found at:
339-
* https://github.com/mupq/pqm4
340-
*/
341-
#if defined(WOLF_CONF_PQM4) && WOLF_CONF_PQM4 == 1
342-
#define HAVE_PQM4
343-
#endif
344-
345-
346337
/* ------------------------------------------------------------------------- */
347338
/* Crypto */
348339
/* ------------------------------------------------------------------------- */
@@ -534,6 +525,33 @@ extern ${variable.value} ${variable.name};
534525
#define NO_MD5
535526
#endif
536527

528+
/* ------------------------------------------------------------------------- */
529+
/* Post-Quantum Crypto */
530+
/* ------------------------------------------------------------------------- */
531+
/* NOTE: this is after the hashing section to override the potential SHA3 undef
532+
* above. */
533+
#if defined(WOLF_CONF_KYBER) && WOLF_CONF_KYBER == 1
534+
#undef WOLFSSL_EXPERIMENTAL_SETTINGS
535+
#define WOLFSSL_EXPERIMENTAL_SETTINGS
536+
537+
#undef WOLFSSL_HAVE_KYBER
538+
#define WOLFSSL_HAVE_KYBER
539+
540+
#undef WOLFSSL_WC_KYBER
541+
#define WOLFSSL_WC_KYBER
542+
543+
#undef WOLFSSL_NO_SHAKE128
544+
#undef WOLFSSL_SHAKE128
545+
#define WOLFSSL_SHAKE128
546+
547+
#undef WOLFSSL_NO_SHAKE256
548+
#undef WOLFSSL_SHAKE256
549+
#define WOLFSSL_SHAKE256
550+
551+
#undef WOLFSSL_SHA3
552+
#define WOLFSSL_SHA3
553+
#endif /* WOLF_CONF_KYBER */
554+
537555
/* ------------------------------------------------------------------------- */
538556
/* Crypto Acceleration */
539557
/* ------------------------------------------------------------------------- */

IDE/STM32Cube/wolfssl_example.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,7 @@ static int tls13_uart_client(void)
17501750

17511751
wolfSSL_SetIOReadCtx(ssl, tbuf);
17521752

1753-
#ifdef HAVE_PQC
1753+
#ifdef WOLFSSL_HAVE_KYBER
17541754
if (wolfSSL_UseKeyShare(ssl, WOLFSSL_KYBER_LEVEL1) != WOLFSSL_SUCCESS) {
17551755
printf("wolfSSL_UseKeyShare Error!!");
17561756
}

examples/configs/user_settings_stm32.h

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ extern "C" {
119119
/*---------- WOLF_CONF_TEST -----------*/
120120
#define WOLF_CONF_TEST 1
121121

122-
/*---------- WOLF_CONF_PQM4 -----------*/
123-
#define WOLF_CONF_PQM4 0
122+
/*---------- WOLF_CONF_KYBER -----------*/
123+
#define WOLF_CONF_kYBER 0
124124

125125
/* ------------------------------------------------------------------------- */
126126
/* Hardware platform */
@@ -373,14 +373,6 @@ extern "C" {
373373
#define NO_SESSION_CACHE
374374
#endif
375375

376-
/* Post Quantum
377-
* Note: PQM4 is compatible with STM32. The project can be found at:
378-
* https://github.com/mupq/pqm4
379-
*/
380-
#if defined(WOLF_CONF_PQM4) && WOLF_CONF_PQM4 == 1
381-
#define HAVE_PQM4
382-
#endif
383-
384376
/* ------------------------------------------------------------------------- */
385377
/* Crypto */
386378
/* ------------------------------------------------------------------------- */
@@ -576,6 +568,35 @@ extern "C" {
576568
#define NO_MD5
577569
#endif
578570

571+
/* ------------------------------------------------------------------------- */
572+
/* Post-Quantum Crypto */
573+
/* ------------------------------------------------------------------------- */
574+
575+
/*
576+
* NOTE: this is after the hashing section to override the potential SHA3 undef
577+
* above. */
578+
#if defined(WOLF_CONF_KYBER) && WOLF_CONF_KYBER == 1
579+
#undef WOLFSSL_EXPERIMENTAL_SETTINGS
580+
#define WOLFSSL_EXPERIMENTAL_SETTINGS
581+
582+
#undef WOLFSSL_HAVE_KYBER
583+
#define WOLFSSL_HAVE_KYBER
584+
585+
#undef WOLFSSL_WC_KYBER
586+
#define WOLFSSL_WC_KYBER
587+
588+
#undef WOLFSSL_NO_SHAKE128
589+
#undef WOLFSSL_SHAKE128
590+
#define WOLFSSL_SHAKE128
591+
592+
#undef WOLFSSL_NO_SHAKE256
593+
#undef WOLFSSL_SHAKE256
594+
#define WOLFSSL_SHAKE256
595+
596+
#undef WOLFSSL_SHA3
597+
#define WOLFSSL_SHA3
598+
#endif /* WOLF_CONF_KYBER */
599+
579600
/* ------------------------------------------------------------------------- */
580601
/* Benchmark / Test */
581602
/* ------------------------------------------------------------------------- */

src/ssl.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14439,9 +14439,6 @@ const char* wolfSSL_get_curve_name(WOLFSSL* ssl)
1443914439
return "P384_KYBER_LEVEL3";
1444014440
case WOLFSSL_P521_KYBER_LEVEL5:
1444114441
return "P521_KYBER_LEVEL5";
14442-
#elif defined(HAVE_PQM4)
14443-
case WOLFSSL_KYBER_LEVEL1:
14444-
return "KYBER_LEVEL1";
1444514442
#elif defined(WOLFSSL_WC_KYBER)
1444614443
#ifdef WOLFSSL_KYBER512
1444714444
case WOLFSSL_KYBER_LEVEL1:

src/tls.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
#include <wolfssl/wolfcrypt/kyber.h>
5353
#ifdef WOLFSSL_WC_KYBER
5454
#include <wolfssl/wolfcrypt/wc_kyber.h>
55-
#elif defined(HAVE_LIBOQS) || defined(HAVE_PQM4)
55+
#elif defined(HAVE_LIBOQS)
5656
#include <wolfssl/wolfcrypt/ext_kyber.h>
5757
#endif
5858
#endif
@@ -9458,9 +9458,6 @@ static int TLSX_KeyShare_IsSupported(int namedGroup)
94589458
}
94599459
break;
94609460
}
9461-
#elif defined(HAVE_PQM4)
9462-
case WOLFSSL_KYBER_LEVEL1:
9463-
break;
94649461
#endif
94659462
#endif
94669463
default:
@@ -9529,8 +9526,6 @@ static const word16 preferredGroup[] = {
95299526
WOLFSSL_P256_KYBER_LEVEL1,
95309527
WOLFSSL_P384_KYBER_LEVEL3,
95319528
WOLFSSL_P521_KYBER_LEVEL5,
9532-
#elif defined(HAVE_PQM4)
9533-
WOLFSSL_KYBER_LEVEL1,
95349529
#endif
95359530
WOLFSSL_NAMED_GROUP_INVALID
95369531
};
@@ -13171,8 +13166,6 @@ static int TLSX_PopulateSupportedGroups(WOLFSSL* ssl, TLSX** extensions)
1317113166
if (ret == WOLFSSL_SUCCESS)
1317213167
ret = TLSX_UseSupportedCurve(extensions, WOLFSSL_P521_KYBER_LEVEL5,
1317313168
ssl->heap);
13174-
#elif defined(HAVE_PQM4)
13175-
ret = TLSX_UseSupportedCurve(extensions, WOLFSSL_KYBER_LEVEL1, ssl->heap);
1317613169
#endif /* HAVE_LIBOQS */
1317713170
#endif /* WOLFSSL_HAVE_KYBER */
1317813171

wolfcrypt/benchmark/benchmark.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@
172172
#ifdef WOLFSSL_WC_KYBER
173173
#include <wolfssl/wolfcrypt/wc_kyber.h>
174174
#endif
175-
#if defined(HAVE_LIBOQS) || defined(HAVE_PQM4)
175+
#if defined(HAVE_LIBOQS)
176176
#include <wolfssl/wolfcrypt/ext_kyber.h>
177177
#endif
178178
#endif

wolfcrypt/src/ext_kyber.c

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,6 @@ int wc_KyberKey_PrivateKeySize(KyberKey* key, word32* len)
168168
}
169169
}
170170
#endif /* HAVE_LIBOQS */
171-
#ifdef HAVE_PQM4
172-
(void)key;
173-
if (ret == 0) {
174-
*len = PQM4_PRIVATE_KEY_LENGTH;
175-
}
176-
#endif /* HAVE_PQM4 */
177171

178172
return ret;
179173
}
@@ -216,12 +210,6 @@ int wc_KyberKey_PublicKeySize(KyberKey* key, word32* len)
216210
}
217211
}
218212
#endif /* HAVE_LIBOQS */
219-
#ifdef HAVE_PQM4
220-
(void)key;
221-
if (ret == 0) {
222-
*len = PQM4_PUBLIC_KEY_LENGTH;
223-
}
224-
#endif /* HAVE_PQM4 */
225213

226214
return ret;
227215
}
@@ -264,12 +252,6 @@ int wc_KyberKey_CipherTextSize(KyberKey* key, word32* len)
264252
}
265253
}
266254
#endif /* HAVE_LIBOQS */
267-
#ifdef HAVE_PQM4
268-
(void)key;
269-
if (ret == 0) {
270-
*len = PQM4_CIPHERTEXT_LENGTH;
271-
}
272-
#endif /* HAVE_PQM4 */
273255

274256
return ret;
275257
}
@@ -301,7 +283,7 @@ int wc_KyberKey_SharedSecretSize(KyberKey* key, word32* len)
301283
/**
302284
* Make a Kyber key object using a random number generator.
303285
*
304-
* NOTE: rng is ignored. OQS and PQM4 don't use our RNG.
286+
* NOTE: rng is ignored. OQS doesn't use our RNG.
305287
*
306288
* @param [in, out] key Kyber key ovject.
307289
* @param [in] rng Random number generator.
@@ -362,14 +344,6 @@ int wc_KyberKey_MakeKey(KyberKey* key, WC_RNG* rng)
362344
wolfSSL_liboqsRngMutexUnlock();
363345
OQS_KEM_free(kem);
364346
#endif /* HAVE_LIBOQS */
365-
#ifdef HAVE_PQM4
366-
if (ret == 0) {
367-
if (crypto_kem_keypair(key->pub, key->priv) != 0) {
368-
WOLFSSL_MSG("PQM4 keygen failure");
369-
ret = BAD_FUNC_ARG;
370-
}
371-
}
372-
#endif /* HAVE_PQM4 */
373347

374348
if (ret != 0) {
375349
ForceZero(key, sizeof(*key));
@@ -394,7 +368,7 @@ int wc_KyberKey_MakeKeyWithRandom(KyberKey* key, const unsigned char* rand,
394368
{
395369
(void)rand;
396370
(void)len;
397-
/* OQS and PQM4 don't support external randomness. */
371+
/* OQS doesn't support external randomness. */
398372
return wc_KyberKey_MakeKey(key, NULL);
399373
}
400374

@@ -471,14 +445,6 @@ int wc_KyberKey_Encapsulate(KyberKey* key, unsigned char* ct, unsigned char* ss,
471445
wolfSSL_liboqsRngMutexUnlock();
472446
OQS_KEM_free(kem);
473447
#endif /* HAVE_LIBOQS */
474-
#ifdef HAVE_PQM4
475-
if (ret == 0) {
476-
if (crypto_kem_enc(ct, ss, key->pub) != 0) {
477-
WOLFSSL_MSG("PQM4 Encapsulation failure.");
478-
ret = BAD_FUNC_ARG;
479-
}
480-
}
481-
#endif /* HAVE_PQM4 */
482448

483449
return ret;
484450
}
@@ -501,7 +467,7 @@ int wc_KyberKey_EncapsulateWithRandom(KyberKey* key, unsigned char* ct,
501467
{
502468
(void)rand;
503469
(void)len;
504-
/* OQS and PQM4 don't support external randomness. */
470+
/* OQS doesn't support external randomness. */
505471
return wc_KyberKey_Encapsulate(key, ct, ss, NULL);
506472
}
507473

@@ -577,14 +543,6 @@ int wc_KyberKey_Decapsulate(KyberKey* key, unsigned char* ss,
577543

578544
OQS_KEM_free(kem);
579545
#endif /* HAVE_LIBOQS */
580-
#ifdef HAVE_PQM4
581-
if (ret == 0) {
582-
if (crypto_kem_dec(ss, ct, key->priv) != 0) {
583-
WOLFSSL_MSG("PQM4 Decapsulation failure.");
584-
ret = BAD_FUNC_ARG;
585-
}
586-
}
587-
#endif /* HAVE_PQM4 */
588546

589547
return ret;
590548

wolfcrypt/test/test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ const byte const_byte_array[] = "A+Gd\0\0\0";
314314
#ifdef WOLFSSL_WC_KYBER
315315
#include <wolfssl/wolfcrypt/wc_kyber.h>
316316
#endif
317-
#if defined(HAVE_LIBOQS) || defined(HAVE_PQM4)
317+
#if defined(HAVE_LIBOQS)
318318
#include <wolfssl/wolfcrypt/ext_kyber.h>
319319
#endif
320320
#endif
@@ -37758,7 +37758,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed448_test(void)
3775837758
#endif /* HAVE_ED448 */
3775937759

3776037760
#ifdef WOLFSSL_HAVE_KYBER
37761-
#ifdef WOLFSSL_WC_KYBER /* OQS and PQM4 do not support KATs */
37761+
#ifdef WOLFSSL_WC_KYBER /* OQS does not support KATs */
3776237762
#ifdef WOLFSSL_KYBER512
3776337763
static wc_test_ret_t kyber512_kat(void)
3776437764
{

wolfssl/wolfcrypt/cryptocb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
#include <wolfssl/wolfcrypt/kyber.h>
7676
#ifdef WOLFSSL_WC_KYBER
7777
#include <wolfssl/wolfcrypt/wc_kyber.h>
78-
#elif defined(HAVE_LIBOQS) || defined(HAVE_PQM4)
78+
#elif defined(HAVE_LIBOQS)
7979
#include <wolfssl/wolfcrypt/ext_kyber.h>
8080
#endif
8181
#endif

wolfssl/wolfcrypt/ext_kyber.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
#ifdef WOLFSSL_HAVE_KYBER
3030
#include <wolfssl/wolfcrypt/kyber.h>
3131

32-
#if !defined(HAVE_LIBOQS) && !defined(HAVE_PQM4)
33-
#error "This code requires liboqs or pqm4"
32+
#if !defined(HAVE_LIBOQS)
33+
#error "This code requires liboqs"
3434
#endif
3535

3636
#if defined(WOLFSSL_WC_KYBER)
@@ -41,15 +41,6 @@
4141
#include <oqs/kem.h>
4242
#define EXT_KYBER_MAX_PRIV_SZ OQS_KEM_kyber_1024_length_secret_key
4343
#define EXT_KYBER_MAX_PUB_SZ OQS_KEM_kyber_1024_length_public_key
44-
#elif defined(HAVE_PQM4)
45-
#include "api_kyber.h"
46-
#define PQM4_PUBLIC_KEY_LENGTH CRYPTO_PUBLICKEYBYTES
47-
#define PQM4_PRIVATE_KEY_LENGTH CRYPTO_SECRETKEYBYTES
48-
#define PQM4_SHARED_SECRET_LENGTH CRYPTO_BYTES
49-
#define PQM4_CIPHERTEXT_LENGTH CRYPTO_CIPHERTEXTBYTES
50-
51-
#define EXT_KYBER_MAX_PRIV_SZ PQM4_PRIVATE_KEY_LENGTH
52-
#define EXT_KYBER_MAX_PUB_SZ PQM4_PUBLIC_KEY_LENGTH
5344
#endif
5445

5546
struct KyberKey {

0 commit comments

Comments
 (0)