Skip to content

Commit 85c40b1

Browse files
committed
liboqs: add RNG support for falcon
Added a RNG argument to the wc_falcon_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 ec86a86 commit 85c40b1

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
@@ -8887,7 +8887,7 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl)
88878887
ret = wc_falcon_sign_msg(args->sigData, args->sigDataSz,
88888888
args->verify + HASH_SIG_SIZE +
88898889
VERIFY_HEADER, (word32*)&sig->length,
8890-
(falcon_key*)ssl->hsKey);
8890+
(falcon_key*)ssl->hsKey, ssl->rng);
88918891
args->length = (word16)sig->length;
88928892
}
88938893
#endif

wolfcrypt/benchmark/benchmark.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11788,7 +11788,7 @@ void bench_falconKeySign(byte level)
1178811788
x = FALCON_LEVEL5_SIG_SIZE;
1178911789
}
1179011790

11791-
ret = wc_falcon_sign_msg(msg, sizeof(msg), sig, &x, &key);
11791+
ret = wc_falcon_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
1179211792
if (ret != 0) {
1179311793
printf("wc_falcon_sign_msg failed\n");
1179411794
}

wolfcrypt/src/asn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28897,7 +28897,7 @@ static int MakeSignature(CertSignCtx* certSignCtx, const byte* buf, word32 sz,
2889728897
#if defined(HAVE_FALCON)
2889828898
if (!rsaKey && !eccKey && !ed25519Key && !ed448Key && falconKey) {
2889928899
word32 outSz = sigSz;
28900-
ret = wc_falcon_sign_msg(buf, sz, sig, &outSz, falconKey);
28900+
ret = wc_falcon_sign_msg(buf, sz, sig, &outSz, falconKey, rng);
2890128901
if (ret == 0)
2890228902
ret = outSz;
2890328903
}

wolfcrypt/src/falcon.c

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

104+
if (ret == 0) {
105+
ret = wolfSSL_liboqsRngMutexLock(rng);
106+
}
107+
104108
if ((ret == 0) &&
105109
(OQS_SIG_sign(oqssig, out, &localOutLen, in, inLen, key->k)
106110
== OQS_ERROR)) {
@@ -111,6 +115,8 @@ int wc_falcon_sign_msg(const byte* in, word32 inLen,
111115
*outLen = (word32)localOutLen;
112116
}
113117

118+
wolfSSL_liboqsRngMutexUnlock();
119+
114120
if (oqssig != NULL) {
115121
OQS_SIG_free(oqssig);
116122
}

wolfssl/wolfcrypt/falcon.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
@@ -79,7 +80,7 @@ struct falcon_key {
7980

8081
WOLFSSL_API
8182
int wc_falcon_sign_msg(const byte* in, word32 inLen, byte* out, word32 *outLen,
82-
falcon_key* key);
83+
falcon_key* key, WC_RNG* rng);
8384
WOLFSSL_API
8485
int wc_falcon_verify_msg(const byte* sig, word32 sigLen, const byte* msg,
8586
word32 msgLen, int* res, falcon_key* key);

0 commit comments

Comments
 (0)