Skip to content

Commit 99f25c6

Browse files
authored
Merge pull request #8494 from Laboratory-for-Safe-and-Secure-Systems/various
Various fixes and improvements
2 parents 92ed003 + 75d6307 commit 99f25c6

13 files changed

Lines changed: 166 additions & 71 deletions

File tree

CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,16 @@ else()
655655
endif()
656656
endif()
657657

658+
# LMS
659+
add_option(WOLFSSL_LMS
660+
"Enable the wolfSSL LMS implementation (default: disabled)"
661+
"no" "yes;no")
662+
663+
# XMSS
664+
add_option(WOLFSSL_XMSS
665+
"Enable the wolfSSL XMSS implementation (default: disabled)"
666+
"no" "yes;no")
667+
658668
# TODO: - Lean PSK
659669
# - Lean TLS
660670
# - Low resource
@@ -668,8 +678,6 @@ endif()
668678
# - Atomic user record layer
669679
# - Public key callbacks
670680
# - Microchip/Atmel CryptoAuthLib
671-
# - XMSS
672-
# - LMS
673681
# - dual-certs
674682

675683
# AES-CBC

cmake/functions.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ function(generate_build_flags)
208208
set(BUILD_EXT_KYBER "yes" PARENT_SCOPE)
209209
set(BUILD_OQS_HELPER "yes" PARENT_SCOPE)
210210
endif()
211+
if(WOLFSSL_LMS OR WOLFSSL_USER_SETTINGS)
212+
set(BUILD_WC_LMS "yes" PARENT_SCOPE)
213+
endif()
214+
if(WOLFSSL_XMSS OR WOLFSSL_USER_SETTINGS)
215+
set(BUILD_WC_XMSS "yes" PARENT_SCOPE)
216+
endif()
211217
if(WOLFSSL_ARIA OR WOLFSSL_USER_SETTINGS)
212218
message(STATUS "ARIA functions.cmake found WOLFSSL_ARIA")
213219
# we cannot actually build, as we only have pre-compiled bin
@@ -818,6 +824,16 @@ function(generate_lib_src_list LIB_SOURCES)
818824
list(APPEND LIB_SOURCES wolfcrypt/src/ext_kyber.c)
819825
endif()
820826

827+
if(BUILD_WC_LMS)
828+
list(APPEND LIB_SOURCES wolfcrypt/src/wc_lms.c)
829+
list(APPEND LIB_SOURCES wolfcrypt/src/wc_lms_impl.c)
830+
endif()
831+
832+
if(BUILD_WC_XMSS)
833+
list(APPEND LIB_SOURCES wolfcrypt/src/wc_xmss.c)
834+
list(APPEND LIB_SOURCES wolfcrypt/src/wc_xmss_impl.c)
835+
endif()
836+
821837
if(BUILD_LIBZ)
822838
list(APPEND LIB_SOURCES wolfcrypt/src/compress.c)
823839
endif()

cmake/options.h.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,14 @@ extern "C" {
382382
#cmakedefine HAVE_ECC_KOBLITZ
383383
#undef HAVE_ECC_CDH
384384
#cmakedefine HAVE_ECC_CDH
385+
#undef WOLFSSL_HAVE_LMS
386+
#cmakedefine WOLFSSL_HAVE_LMS
387+
#undef WOLFSSL_WC_LMS
388+
#cmakedefine WOLFSSL_WC_LMS
389+
#undef WOLFSSL_HAVE_XMSS
390+
#cmakedefine WOLFSSL_HAVE_XMSS
391+
#undef WOLFSSL_WC_XMSS
392+
#cmakedefine WOLFSSL_WC_XMSS
385393

386394
#ifdef __cplusplus
387395
}

src/internal.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8906,6 +8906,10 @@ void FreeHandshakeResources(WOLFSSL* ssl)
89068906
FreeKey(ssl, DYNAMIC_TYPE_FALCON, (void**)&ssl->peerFalconKey);
89078907
ssl->peerFalconKeyPresent = 0;
89088908
#endif /* HAVE_FALCON */
8909+
#if defined(HAVE_DILITHIUM)
8910+
FreeKey(ssl, DYNAMIC_TYPE_DILITHIUM, (void**)&ssl->peerDilithiumKey);
8911+
ssl->peerDilithiumKeyPresent = 0;
8912+
#endif /* HAVE_DILITHIUM */
89098913
}
89108914

89118915
#ifdef HAVE_ECC

src/ssl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18569,11 +18569,11 @@ const WOLFSSL_ObjectInfo wolfssl_object_info[] = {
1856918569
"Dilithium Level 5", "Dilithium Level 5"},
1857018570
#endif /* WOLFSSL_DILITHIUM_FIPS204_DRAFT */
1857118571
{ CTC_ML_DSA_LEVEL2, ML_DSA_LEVEL2k, oidKeyType,
18572-
"ML_DSA Level 2", "ML_DSA Level 2"},
18572+
"ML-DSA 44", "ML-DSA 44"},
1857318573
{ CTC_ML_DSA_LEVEL3, ML_DSA_LEVEL3k, oidKeyType,
18574-
"ML_DSA Level 3", "ML_DSA Level 3"},
18574+
"ML-DSA 65", "ML-DSA 65"},
1857518575
{ CTC_ML_DSA_LEVEL5, ML_DSA_LEVEL5k, oidKeyType,
18576-
"ML_DSA Level 5", "ML_DSA Level 5"},
18576+
"ML-DSA 87", "ML-DSA 87"},
1857718577
#endif /* HAVE_DILITHIUM */
1857818578

1857918579
/* oidCurveType */

src/tls13.c

Lines changed: 34 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7181,7 +7181,7 @@ int DoTls13ClientHello(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
71817181
ERROR_OUT(MATCH_SUITE_ERROR, exit_dch);
71827182
}
71837183

7184-
#ifdef HAVE_SESSION_TICKET
7184+
#if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
71857185
if (ssl->options.resuming) {
71867186
ssl->options.resuming = 0;
71877187
ssl->arrays->psk_keySz = 0;
@@ -9145,41 +9145,12 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl)
91459145
#endif
91469146
#if defined(HAVE_FALCON)
91479147
else if (ssl->hsType == DYNAMIC_TYPE_FALCON) {
9148-
falcon_key* fkey = (falcon_key*)ssl->hsKey;
9149-
byte level = 0;
9150-
if (wc_falcon_get_level(fkey, &level) != 0) {
9151-
ERROR_OUT(ALGO_ID_E, exit_scv);
9152-
}
9153-
if (level == 1) {
9154-
args->sigAlgo = falcon_level1_sa_algo;
9155-
}
9156-
else if (level == 5) {
9157-
args->sigAlgo = falcon_level5_sa_algo;
9158-
}
9159-
else {
9160-
ERROR_OUT(ALGO_ID_E, exit_scv);
9161-
}
9148+
args->sigAlgo = ssl->buffers.keyType;
91629149
}
91639150
#endif /* HAVE_FALCON */
91649151
#if defined(HAVE_DILITHIUM)
91659152
else if (ssl->hsType == DYNAMIC_TYPE_DILITHIUM) {
9166-
dilithium_key* fkey = (dilithium_key*)ssl->hsKey;
9167-
byte level = 0;
9168-
if (wc_dilithium_get_level(fkey, &level) != 0) {
9169-
ERROR_OUT(ALGO_ID_E, exit_scv);
9170-
}
9171-
if (level == 2) {
9172-
args->sigAlgo = dilithium_level2_sa_algo;
9173-
}
9174-
else if (level == 3) {
9175-
args->sigAlgo = dilithium_level3_sa_algo;
9176-
}
9177-
else if (level == 5) {
9178-
args->sigAlgo = dilithium_level5_sa_algo;
9179-
}
9180-
else {
9181-
ERROR_OUT(ALGO_ID_E, exit_scv);
9182-
}
9153+
args->sigAlgo = ssl->buffers.keyType;
91839154
}
91849155
#endif /* HAVE_DILITHIUM */
91859156
else {
@@ -9463,9 +9434,11 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl)
94639434
#endif /* HAVE_FALCON */
94649435
#if defined(HAVE_DILITHIUM) && !defined(WOLFSSL_DILITHIUM_NO_SIGN)
94659436
if (ssl->hsType == DYNAMIC_TYPE_DILITHIUM) {
9466-
ret = wc_dilithium_sign_msg(args->sigData, args->sigDataSz,
9467-
sigOut, &args->sigLen,
9468-
(dilithium_key*)ssl->hsKey, ssl->rng);
9437+
ret = wc_dilithium_sign_ctx_msg(NULL, 0, args->sigData,
9438+
args->sigDataSz, sigOut,
9439+
&args->sigLen,
9440+
(dilithium_key*)ssl->hsKey,
9441+
ssl->rng);
94699442
args->length = (word16)args->sigLen;
94709443
}
94719444
#endif /* HAVE_DILITHIUM */
@@ -9557,11 +9530,9 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl)
95579530
#endif /* HAVE_FALCON */
95589531
#if defined(HAVE_DILITHIUM) && !defined(WOLFSSL_DILITHIUM_NO_SIGN)
95599532
if (ssl->hsAltType == DYNAMIC_TYPE_DILITHIUM) {
9560-
ret = wc_dilithium_sign_msg(args->altSigData,
9561-
args->altSigDataSz, sigOut,
9562-
&args->altSigLen,
9563-
(dilithium_key*)ssl->hsAltKey,
9564-
ssl->rng);
9533+
ret = wc_dilithium_sign_ctx_msg(NULL, 0, args->altSigData,
9534+
args->altSigDataSz, sigOut, &args->altSigLen,
9535+
(dilithium_key*)ssl->hsAltKey, ssl->rng);
95659536
}
95669537
#endif /* HAVE_DILITHIUM */
95679538

@@ -10546,6 +10517,10 @@ static int DoTls13CertificateVerify(WOLFSSL* ssl, byte* input,
1054610517
(void**)&ssl->peerFalconKey);
1054710518
ssl->peerFalconKeyPresent = 0;
1054810519
}
10520+
else if ((ret >= 0) && (res == 0)) {
10521+
WOLFSSL_MSG("Falcon signature verification failed");
10522+
ret = SIG_VERIFY_E;
10523+
}
1054910524
}
1055010525
#endif /* HAVE_FALCON */
1055110526
#if defined(HAVE_DILITHIUM) && !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
@@ -10555,9 +10530,9 @@ static int DoTls13CertificateVerify(WOLFSSL* ssl, byte* input,
1055510530
(ssl->peerDilithiumKeyPresent)) {
1055610531
int res = 0;
1055710532
WOLFSSL_MSG("Doing Dilithium peer cert verify");
10558-
ret = wc_dilithium_verify_msg(sig, args->sigSz,
10559-
args->sigData, args->sigDataSz,
10560-
&res, ssl->peerDilithiumKey);
10533+
ret = wc_dilithium_verify_ctx_msg(sig, args->sigSz, NULL, 0,
10534+
args->sigData, args->sigDataSz,
10535+
&res, ssl->peerDilithiumKey);
1056110536

1056210537
if ((ret >= 0) && (res == 1)) {
1056310538
/* CLIENT/SERVER: data verified with public key from
@@ -10568,6 +10543,10 @@ static int DoTls13CertificateVerify(WOLFSSL* ssl, byte* input,
1056810543
(void**)&ssl->peerDilithiumKey);
1056910544
ssl->peerDilithiumKeyPresent = 0;
1057010545
}
10546+
else if ((ret >= 0) && (res == 0)) {
10547+
WOLFSSL_MSG("Dilithium signature verification failed");
10548+
ret = SIG_VERIFY_E;
10549+
}
1057110550
}
1057210551
#endif /* HAVE_DILITHIUM */
1057310552

@@ -10648,6 +10627,10 @@ static int DoTls13CertificateVerify(WOLFSSL* ssl, byte* input,
1064810627
(void**)&ssl->peerFalconKey);
1064910628
ssl->peerFalconKeyPresent = 0;
1065010629
}
10630+
else if ((ret >= 0) && (res == 0)) {
10631+
WOLFSSL_MSG("Falcon signature verification failed");
10632+
ret = SIG_VERIFY_E;
10633+
}
1065110634
}
1065210635
#endif /* HAVE_FALCON */
1065310636
#if defined(HAVE_DILITHIUM) && !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
@@ -10657,9 +10640,10 @@ static int DoTls13CertificateVerify(WOLFSSL* ssl, byte* input,
1065710640
(ssl->peerDilithiumKeyPresent)) {
1065810641
int res = 0;
1065910642
WOLFSSL_MSG("Doing Dilithium peer cert alt verify");
10660-
ret = wc_dilithium_verify_msg(sig, args->altSignatureSz,
10661-
args->altSigData, args->altSigDataSz,
10662-
&res, ssl->peerDilithiumKey);
10643+
ret = wc_dilithium_verify_ctx_msg(sig, args->altSignatureSz,
10644+
NULL, 0, args->altSigData,
10645+
args->altSigDataSz, &res,
10646+
ssl->peerDilithiumKey);
1066310647

1066410648
if ((ret >= 0) && (res == 1)) {
1066510649
/* CLIENT/SERVER: data verified with public key from
@@ -10670,6 +10654,10 @@ static int DoTls13CertificateVerify(WOLFSSL* ssl, byte* input,
1067010654
(void**)&ssl->peerDilithiumKey);
1067110655
ssl->peerDilithiumKeyPresent = 0;
1067210656
}
10657+
else if ((ret >= 0) && (res == 0)) {
10658+
WOLFSSL_MSG("Dilithium signature verification failed");
10659+
ret = SIG_VERIFY_E;
10660+
}
1067310661
}
1067410662
#endif /* HAVE_DILITHIUM */
1067510663

wolfcrypt/src/asn.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17282,6 +17282,10 @@ int ConfirmSignature(SignatureCtx* sigCtx,
1728217282
level = WC_ML_DSA_87_DRAFT;
1728317283
}
1728417284
#endif
17285+
else {
17286+
WOLFSSL_MSG("Invalid Dilithium key OID");
17287+
goto exit_cs;
17288+
}
1728517289
sigCtx->verify = 0;
1728617290
sigCtx->key.dilithium = (dilithium_key*)XMALLOC(
1728717291
sizeof(dilithium_key), sigCtx->heap,

wolfcrypt/src/cryptocb.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,8 @@ int wc_CryptoCb_MakePqcSignatureKey(WC_RNG* rng, int type, int keySize,
10431043
}
10441044

10451045
int wc_CryptoCb_PqcSign(const byte* in, word32 inlen, byte* out, word32 *outlen,
1046-
WC_RNG* rng, int type, void* key)
1046+
const byte* context, byte contextLen, word32 preHashType, WC_RNG* rng,
1047+
int type, void* key)
10471048
{
10481049
int ret = WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE);
10491050
int devId = INVALID_DEVID;
@@ -1068,6 +1069,9 @@ int wc_CryptoCb_PqcSign(const byte* in, word32 inlen, byte* out, word32 *outlen,
10681069
cryptoInfo.pk.pqc_sign.inlen = inlen;
10691070
cryptoInfo.pk.pqc_sign.out = out;
10701071
cryptoInfo.pk.pqc_sign.outlen = outlen;
1072+
cryptoInfo.pk.pqc_sign.context = context;
1073+
cryptoInfo.pk.pqc_sign.contextLen = contextLen;
1074+
cryptoInfo.pk.pqc_sign.preHashType = preHashType;
10711075
cryptoInfo.pk.pqc_sign.rng = rng;
10721076
cryptoInfo.pk.pqc_sign.key = key;
10731077
cryptoInfo.pk.pqc_sign.type = type;
@@ -1079,7 +1083,8 @@ int wc_CryptoCb_PqcSign(const byte* in, word32 inlen, byte* out, word32 *outlen,
10791083
}
10801084

10811085
int wc_CryptoCb_PqcVerify(const byte* sig, word32 siglen, const byte* msg,
1082-
word32 msglen, int* res, int type, void* key)
1086+
word32 msglen, const byte* context, byte contextLen, word32 preHashType,
1087+
int* res, int type, void* key)
10831088
{
10841089
int ret = WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE);
10851090
int devId = INVALID_DEVID;
@@ -1104,6 +1109,9 @@ int wc_CryptoCb_PqcVerify(const byte* sig, word32 siglen, const byte* msg,
11041109
cryptoInfo.pk.pqc_verify.siglen = siglen;
11051110
cryptoInfo.pk.pqc_verify.msg = msg;
11061111
cryptoInfo.pk.pqc_verify.msglen = msglen;
1112+
cryptoInfo.pk.pqc_verify.context = context;
1113+
cryptoInfo.pk.pqc_verify.contextLen = contextLen;
1114+
cryptoInfo.pk.pqc_verify.preHashType = preHashType;
11071115
cryptoInfo.pk.pqc_verify.res = res;
11081116
cryptoInfo.pk.pqc_verify.key = key;
11091117
cryptoInfo.pk.pqc_verify.type = type;

0 commit comments

Comments
 (0)