Skip to content

Commit 0780fd9

Browse files
committed
liboqs: add RNG support for sphincs
Added a RNG argument to the wc_sphincs_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 85c40b1 commit 0780fd9

4 files changed

Lines changed: 11 additions & 4 deletions

File tree

wolfcrypt/benchmark/benchmark.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12055,7 +12055,7 @@ void bench_sphincsKeySign(byte level, byte optim)
1205512055
x = SPHINCS_SMALL_LEVEL5_SIG_SIZE;
1205612056
}
1205712057

12058-
ret = wc_sphincs_sign_msg(msg, sizeof(msg), sig, &x, &key);
12058+
ret = wc_sphincs_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
1205912059
if (ret != 0) {
1206012060
printf("wc_sphincs_sign_msg failed\n");
1206112061
}

wolfcrypt/src/asn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28915,7 +28915,7 @@ static int MakeSignature(CertSignCtx* certSignCtx, const byte* buf, word32 sz,
2891528915
if (!rsaKey && !eccKey && !ed25519Key && !ed448Key && !falconKey &&
2891628916
!dilithiumKey && sphincsKey) {
2891728917
word32 outSz = sigSz;
28918-
ret = wc_sphincs_sign_msg(buf, sz, sig, &outSz, sphincsKey);
28918+
ret = wc_sphincs_sign_msg(buf, sz, sig, &outSz, sphincsKey, rng);
2891928919
if (ret == 0)
2892028920
ret = outSz;
2892128921
}

wolfcrypt/src/sphincs.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
* 0 otherwise.
5959
*/
6060
int wc_sphincs_sign_msg(const byte* in, word32 inLen, byte* out, word32 *outLen,
61-
sphincs_key* key)
61+
sphincs_key* key, WC_RNG* rng)
6262
{
6363
int ret = 0;
6464
#ifdef HAVE_LIBOQS
@@ -135,6 +135,10 @@ int wc_sphincs_sign_msg(const byte* in, word32 inLen, byte* out, word32 *outLen,
135135
localOutLen = *outLen;
136136
}
137137

138+
if (ret == 0) {
139+
ret = wolfSSL_liboqsRngMutexLock(rng);
140+
}
141+
138142
if ((ret == 0) &&
139143
(OQS_SIG_sign(oqssig, out, &localOutLen, in, inLen, key->k)
140144
== OQS_ERROR)) {
@@ -145,6 +149,8 @@ int wc_sphincs_sign_msg(const byte* in, word32 inLen, byte* out, word32 *outLen,
145149
*outLen = (word32)localOutLen;
146150
}
147151

152+
wolfSSL_liboqsRngMutexUnlock();
153+
148154
if (oqssig != NULL) {
149155
OQS_SIG_free(oqssig);
150156
}

wolfssl/wolfcrypt/sphincs.h

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

4242
#ifdef HAVE_LIBOQS
4343
#include <oqs/oqs.h>
44+
#include <wolfssl/wolfcrypt/port/liboqs/liboqs.h>
4445
#endif
4546

4647
#ifdef __cplusplus
@@ -99,7 +100,7 @@ struct sphincs_key {
99100

100101
WOLFSSL_API
101102
int wc_sphincs_sign_msg(const byte* in, word32 inLen, byte* out, word32 *outLen,
102-
sphincs_key* key);
103+
sphincs_key* key, WC_RNG* rng);
103104
WOLFSSL_API
104105
int wc_sphincs_verify_msg(const byte* sig, word32 sigLen, const byte* msg,
105106
word32 msgLen, int* res, sphincs_key* key);

0 commit comments

Comments
 (0)