diff --git a/src/tls13.c b/src/tls13.c index d16a5761f..82f3bce84 100644 --- a/src/tls13.c +++ b/src/tls13.c @@ -8896,7 +8896,7 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl) ret = wc_dilithium_sign_msg(args->sigData, args->sigDataSz, args->verify + HASH_SIG_SIZE + VERIFY_HEADER, (word32*)&sig->length, - (dilithium_key*)ssl->hsKey); + (dilithium_key*)ssl->hsKey, ssl->rng); args->length = (word16)sig->length; } #endif diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index 49803d6d9..e3b98fef4 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -11909,7 +11909,7 @@ void bench_dilithiumKeySign(byte level) x = DILITHIUM_LEVEL5_SIG_SIZE; } - ret = wc_dilithium_sign_msg(msg, sizeof(msg), sig, &x, &key); + ret = wc_dilithium_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG); if (ret != 0) { printf("wc_dilithium_sign_msg failed\n"); } diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 6147dea8c..cbbc962be 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -28906,7 +28906,7 @@ static int MakeSignature(CertSignCtx* certSignCtx, const byte* buf, word32 sz, if (!rsaKey && !eccKey && !ed25519Key && !ed448Key && !falconKey && dilithiumKey) { word32 outSz = sigSz; - ret = wc_dilithium_sign_msg(buf, sz, sig, &outSz, dilithiumKey); + ret = wc_dilithium_sign_msg(buf, sz, sig, &outSz, dilithiumKey, rng); if (ret == 0) ret = outSz; } diff --git a/wolfcrypt/src/dilithium.c b/wolfcrypt/src/dilithium.c index d50b6db37..f03e8b6f4 100644 --- a/wolfcrypt/src/dilithium.c +++ b/wolfcrypt/src/dilithium.c @@ -59,7 +59,7 @@ */ int wc_dilithium_sign_msg(const byte* in, word32 inLen, byte* out, word32 *outLen, - dilithium_key* key) + dilithium_key* key, WC_RNG* rng) { int ret = 0; #ifdef HAVE_LIBOQS @@ -107,6 +107,10 @@ int wc_dilithium_sign_msg(const byte* in, word32 inLen, localOutLen = *outLen; } + if (ret == 0) { + ret = wolfSSL_liboqsRngMutexLock(rng); + } + if ((ret == 0) && (OQS_SIG_sign(oqssig, out, &localOutLen, in, inLen, key->k) == OQS_ERROR)) { @@ -117,6 +121,8 @@ int wc_dilithium_sign_msg(const byte* in, word32 inLen, *outLen = (word32)localOutLen; } + wolfSSL_liboqsRngMutexUnlock(); + if (oqssig != NULL) { OQS_SIG_free(oqssig); } diff --git a/wolfssl/wolfcrypt/dilithium.h b/wolfssl/wolfcrypt/dilithium.h index 896976c5f..896d06ac6 100644 --- a/wolfssl/wolfcrypt/dilithium.h +++ b/wolfssl/wolfcrypt/dilithium.h @@ -35,6 +35,7 @@ #ifdef HAVE_LIBOQS #include +#include #endif #ifdef __cplusplus @@ -84,7 +85,7 @@ struct dilithium_key { WOLFSSL_API int wc_dilithium_sign_msg(const byte* in, word32 inLen, byte* out, word32 *outLen, - dilithium_key* key); + dilithium_key* key, WC_RNG* rng); WOLFSSL_API int wc_dilithium_verify_msg(const byte* sig, word32 sigLen, const byte* msg, word32 msgLen, int* res, dilithium_key* key);