Skip to content

Commit ec86a86

Browse files
committed
liboqs: add RNG support for dilithium
Added a RNG argument to the wc_dilithium_sign_msg method to properly generate necessary random data using the desired WolfSSL RNG object. Signed-off-by: Tobias Frauenschläger <t.frauenschlaeger@me.com>
1 parent 755c385 commit ec86a86

5 files changed

Lines changed: 12 additions & 5 deletions

File tree

src/tls13.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8896,7 +8896,7 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl)
88968896
ret = wc_dilithium_sign_msg(args->sigData, args->sigDataSz,
88978897
args->verify + HASH_SIG_SIZE +
88988898
VERIFY_HEADER, (word32*)&sig->length,
8899-
(dilithium_key*)ssl->hsKey);
8899+
(dilithium_key*)ssl->hsKey, ssl->rng);
89008900
args->length = (word16)sig->length;
89018901
}
89028902
#endif

wolfcrypt/benchmark/benchmark.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11909,7 +11909,7 @@ void bench_dilithiumKeySign(byte level)
1190911909
x = DILITHIUM_LEVEL5_SIG_SIZE;
1191011910
}
1191111911

11912-
ret = wc_dilithium_sign_msg(msg, sizeof(msg), sig, &x, &key);
11912+
ret = wc_dilithium_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
1191311913
if (ret != 0) {
1191411914
printf("wc_dilithium_sign_msg failed\n");
1191511915
}

wolfcrypt/src/asn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28906,7 +28906,7 @@ static int MakeSignature(CertSignCtx* certSignCtx, const byte* buf, word32 sz,
2890628906
if (!rsaKey && !eccKey && !ed25519Key && !ed448Key && !falconKey &&
2890728907
dilithiumKey) {
2890828908
word32 outSz = sigSz;
28909-
ret = wc_dilithium_sign_msg(buf, sz, sig, &outSz, dilithiumKey);
28909+
ret = wc_dilithium_sign_msg(buf, sz, sig, &outSz, dilithiumKey, rng);
2891028910
if (ret == 0)
2891128911
ret = outSz;
2891228912
}

wolfcrypt/src/dilithium.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
*/
6060
int wc_dilithium_sign_msg(const byte* in, word32 inLen,
6161
byte* out, word32 *outLen,
62-
dilithium_key* key)
62+
dilithium_key* key, WC_RNG* rng)
6363
{
6464
int ret = 0;
6565
#ifdef HAVE_LIBOQS
@@ -107,6 +107,10 @@ int wc_dilithium_sign_msg(const byte* in, word32 inLen,
107107
localOutLen = *outLen;
108108
}
109109

110+
if (ret == 0) {
111+
ret = wolfSSL_liboqsRngMutexLock(rng);
112+
}
113+
110114
if ((ret == 0) &&
111115
(OQS_SIG_sign(oqssig, out, &localOutLen, in, inLen, key->k)
112116
== OQS_ERROR)) {
@@ -117,6 +121,8 @@ int wc_dilithium_sign_msg(const byte* in, word32 inLen,
117121
*outLen = (word32)localOutLen;
118122
}
119123

124+
wolfSSL_liboqsRngMutexUnlock();
125+
120126
if (oqssig != NULL) {
121127
OQS_SIG_free(oqssig);
122128
}

wolfssl/wolfcrypt/dilithium.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
#ifdef HAVE_LIBOQS
3737
#include <oqs/oqs.h>
38+
#include <wolfssl/wolfcrypt/port/liboqs/liboqs.h>
3839
#endif
3940

4041
#ifdef __cplusplus
@@ -84,7 +85,7 @@ struct dilithium_key {
8485

8586
WOLFSSL_API
8687
int wc_dilithium_sign_msg(const byte* in, word32 inLen, byte* out, word32 *outLen,
87-
dilithium_key* key);
88+
dilithium_key* key, WC_RNG* rng);
8889
WOLFSSL_API
8990
int wc_dilithium_verify_msg(const byte* sig, word32 sigLen, const byte* msg,
9091
word32 msgLen, int* res, dilithium_key* key);

0 commit comments

Comments
 (0)