Skip to content

Commit 46b1a03

Browse files
committed
XMSS/XMSSMT hooks support: fix g++ warnings, and small cleanup for review.
1 parent 60fea5e commit 46b1a03

4 files changed

Lines changed: 30 additions & 20 deletions

File tree

wolfcrypt/benchmark/benchmark.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8100,7 +8100,8 @@ void bench_lms(void)
81008100

81018101
#if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
81028102

8103-
static int xmss_write_key_mem(const byte * priv, word32 privSz, void *context)
8103+
static enum wc_XmssRc xmss_write_key_mem(const byte * priv, word32 privSz,
8104+
void *context)
81048105
{
81058106
/* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
81068107
* BE USED FOR TESTING PURPOSES! Production applications should
@@ -8109,7 +8110,8 @@ static int xmss_write_key_mem(const byte * priv, word32 privSz, void *context)
81098110
return WC_XMSS_RC_SAVED_TO_NV_MEMORY;
81108111
}
81118112

8112-
static int xmss_read_key_mem(byte * priv, word32 privSz, void *context)
8113+
static enum wc_XmssRc xmss_read_key_mem(byte * priv, word32 privSz,
8114+
void *context)
81138115
{
81148116
/* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
81158117
* BE USED FOR TESTING PURPOSES! */
@@ -8179,14 +8181,14 @@ static void bench_xmss_sign_verify(const char * params)
81798181
}
81808182

81818183
/* Allocate secret keys.*/
8182-
sk = XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
8184+
sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
81838185
if (sk == NULL) {
81848186
fprintf(stderr, "error: allocate xmss sk failed\n");
81858187
goto exit_xmss_sign_verify;
81868188
}
81878189

81888190
/* Allocate signature array. */
8189-
sig = XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
8191+
sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
81908192
if (sig == NULL) {
81918193
fprintf(stderr, "error: allocate xmss sig failed\n");
81928194
goto exit_xmss_sign_verify;
@@ -8300,11 +8302,6 @@ static void bench_xmss_sign_verify(const char * params)
83008302
freeKey = 0;
83018303
}
83028304

8303-
if (sig != NULL) {
8304-
XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
8305-
sig = NULL;
8306-
}
8307-
83088305
return;
83098306
}
83108307

wolfcrypt/src/ext_xmss.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static int rng_cb(void * output, size_t length)
5757
return 0;
5858
}
5959

60-
ret = wc_RNG_GenerateBlock(xmssRng, output, (word32) length);
60+
ret = wc_RNG_GenerateBlock(xmssRng, (byte *)output, (word32)length);
6161

6262
if (ret) {
6363
WOLFSSL_MSG("error: XMSS rng_cb failed");
@@ -415,7 +415,8 @@ static int wc_XmssKey_AllocSk(XmssKey* key)
415415
return -1;
416416
}
417417

418-
key->sk = XMALLOC(key->sk_len, NULL, DYNAMIC_TYPE_TMP_BUFFER);
418+
key->sk = (unsigned char *)XMALLOC(key->sk_len, NULL,
419+
DYNAMIC_TYPE_TMP_BUFFER);
419420

420421
if (key->sk == NULL) {
421422
WOLFSSL_MSG("error: malloc XMSS key->sk failed");
@@ -731,6 +732,16 @@ int wc_XmssKey_Sign(XmssKey* key, byte * sig, word32 * sigLen, const byte * msg,
731732
return -1;
732733
}
733734

735+
if (key->write_private_key == NULL || key->read_private_key == NULL) {
736+
WOLFSSL_MSG("error: XmssKey write/read callbacks are not set");
737+
return -1;
738+
}
739+
740+
if (key->context == NULL) {
741+
WOLFSSL_MSG("error: XmssKey context is not set");
742+
return -1;
743+
}
744+
734745
/* Finally, sign and update the secret key. */
735746
wc_XmssKey_SignUpdate(key, sig, sigLen, msg, msgLen);
736747

wolfcrypt/test/test.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35122,7 +35122,8 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t kyber_test(void)
3512235122
#endif /* WOLFSSL_HAVE_KYBER */
3512335123

3512435124
#if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
35125-
static int xmss_write_key_mem(const byte * priv, word32 privSz, void *context)
35125+
static enum wc_XmssRc xmss_write_key_mem(const byte * priv, word32 privSz,
35126+
void *context)
3512635127
{
3512735128
/* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
3512835129
* BE USED FOR TESTING PURPOSES! Production applications should
@@ -35131,7 +35132,8 @@ static int xmss_write_key_mem(const byte * priv, word32 privSz, void *context)
3513135132
return WC_XMSS_RC_SAVED_TO_NV_MEMORY;
3513235133
}
3513335134

35134-
static int xmss_read_key_mem(byte * priv, word32 privSz, void *context)
35135+
static enum wc_XmssRc xmss_read_key_mem(byte * priv, word32 privSz,
35136+
void *context)
3513535137
{
3513635138
/* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
3513735139
* BE USED FOR TESTING PURPOSES! */
@@ -35191,7 +35193,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test(void)
3519135193
if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
3519235194

3519335195
/* Allocate signature array. */
35194-
sig = XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
35196+
sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
3519535197
if (sig == NULL) { return WC_TEST_RET_ENC_ERRNO; }
3519635198

3519735199
bufSz = sigSz;
@@ -35204,10 +35206,10 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test(void)
3520435206
#endif
3520535207

3520635208
/* Allocate current and old secret keys.*/
35207-
sk = XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
35209+
sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
3520835210
if (sk == NULL) { return WC_TEST_RET_ENC_ERRNO; }
3520935211

35210-
old_sk = XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
35212+
old_sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
3521135213
if (old_sk == NULL) { return WC_TEST_RET_ENC_ERRNO; }
3521235214

3521335215
XMEMSET(sk, 0, skSz);

wolfssl/wolfcrypt/xmss.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@
9191

9292
typedef struct XmssKey XmssKey;
9393

94-
/* Private key write and read callbacks. */
95-
typedef int (*write_private_key_cb)(const byte * priv, word32 privSz, void *context);
96-
typedef int (*read_private_key_cb)(byte * priv, word32 privSz, void *context);
97-
9894
/* Return codes returned by private key callbacks. */
9995
enum wc_XmssRc {
10096
WC_XMSS_RC_NONE,
@@ -116,6 +112,10 @@ enum wc_XmssState {
116112
WC_XMSS_STATE_NOSIGS /* Signatures exhausted. */
117113
};
118114

115+
/* Private key write and read callbacks. */
116+
typedef enum wc_XmssRc (*write_private_key_cb)(const byte * priv, word32 privSz, void *context);
117+
typedef enum wc_XmssRc (*read_private_key_cb)(byte * priv, word32 privSz, void *context);
118+
119119
#ifdef __cplusplus
120120
extern "C" {
121121
#endif

0 commit comments

Comments
 (0)