Skip to content

Commit 40b583f

Browse files
committed
Wconversion fixes for LMS
1 parent 6a3eb6f commit 40b583f

4 files changed

Lines changed: 154 additions & 127 deletions

File tree

wolfcrypt/src/sha256.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,9 +1881,9 @@ static WC_INLINE int Transform_Sha256_Len(wc_Sha256* sha256, const byte* data,
18811881
}
18821882

18831883
if (SHA256_UPDATE_REV_BYTES(&sha256->ctx)) {
1884-
ByteReverseWords(sha256->buffer, (word32*)data,
1884+
ByteReverseWords(sha256->buffer, (const word32*)data,
18851885
WC_SHA256_BLOCK_SIZE);
1886-
data = (unsigned char*)sha256->buffer;
1886+
data = (const unsigned char*)sha256->buffer;
18871887
}
18881888
ret = XTRANSFORM(sha256, data);
18891889

wolfcrypt/src/wc_lms.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ void wc_LmsKey_Free(LmsKey* key)
824824
#ifndef WOLFSSL_LMS_VERIFY_ONLY
825825
if (key->priv_data != NULL) {
826826
const LmsParams* params = key->params;
827-
int priv_data_len = LMS_PRIV_DATA_LEN(params->levels,
827+
word32 priv_data_len = LMS_PRIV_DATA_LEN(params->levels,
828828
params->height, params->p, params->rootLevels,
829829
params->cacheBits, params->hash_len);
830830

@@ -958,7 +958,7 @@ int wc_LmsKey_SetContext(LmsKey* key, void* context)
958958
int wc_LmsKey_MakeKey(LmsKey* key, WC_RNG* rng)
959959
{
960960
int ret = 0;
961-
int priv_data_len = 0;
961+
word32 priv_data_len = 0;
962962

963963
/* Validate parameters. */
964964
if ((key == NULL) || (rng == NULL)) {
@@ -1066,7 +1066,7 @@ int wc_LmsKey_MakeKey(LmsKey* key, WC_RNG* rng)
10661066
int wc_LmsKey_Reload(LmsKey* key)
10671067
{
10681068
int ret = 0;
1069-
int priv_data_len = 0;
1069+
word32 priv_data_len = 0;
10701070

10711071
/* Validate parameter. */
10721072
if (key == NULL) {
@@ -1260,7 +1260,7 @@ int wc_LmsKey_Sign(LmsKey* key, byte* sig, word32* sigSz, const byte* msg,
12601260
if (ret == 0) {
12611261
/* Sign message. */
12621262
ret = wc_hss_sign(state, key->priv_raw, &key->priv,
1263-
key->priv_data, msg, msgSz, sig);
1263+
key->priv_data, msg, (word32)msgSz, sig);
12641264
wc_lmskey_state_free(state);
12651265
}
12661266
ForceZero(state, sizeof(LmsState));
@@ -1276,7 +1276,7 @@ int wc_LmsKey_Sign(LmsKey* key, byte* sig, word32* sigSz, const byte* msg,
12761276
/* Write private key to storage. */
12771277
#ifdef WOLFSSL_WC_LMS_SERIALIZE_STATE
12781278
const LmsParams* params = key->params;
1279-
int priv_data_len = LMS_PRIV_DATA_LEN(params->levels, params->height,
1279+
word32 priv_data_len = LMS_PRIV_DATA_LEN(params->levels, params->height,
12801280
params->p, params->rootLevels, params->cacheBits,
12811281
params->hash_len) + HSS_PRIVATE_KEY_LEN(key->params->hash_len);
12821282

@@ -1492,6 +1492,7 @@ int wc_LmsKey_GetSigLen(const LmsKey* key, word32* len)
14921492
* @param [in] msgSz Length of the message in bytes.
14931493
* @return 0 on success.
14941494
* @return BAD_FUNC_ARG when a key, sig or msg is NULL.
1495+
* @return BAD_FUNC_ARG when msgSz is negative.
14951496
* @return SIG_VERIFY_E when signature did not verify message.
14961497
* @return BAD_STATE_E when wrong state for operation.
14971498
* @return BUFFER_E when sigSz is invalid for parameters.
@@ -1505,6 +1506,9 @@ int wc_LmsKey_Verify(LmsKey* key, const byte* sig, word32 sigSz,
15051506
if ((key == NULL) || (sig == NULL) || (msg == NULL)) {
15061507
ret = BAD_FUNC_ARG;
15071508
}
1509+
if ((ret == 0) && (msgSz < 0)) {
1510+
ret = BAD_FUNC_ARG;
1511+
}
15081512
/* Check state. */
15091513
if ((ret == 0) && (key->state != WC_LMS_STATE_OK) &&
15101514
(key->state != WC_LMS_STATE_VERIFYONLY)) {
@@ -1530,7 +1534,8 @@ int wc_LmsKey_Verify(LmsKey* key, const byte* sig, word32 sigSz,
15301534
ret = wc_lmskey_state_init(state, key->params);
15311535
if (ret == 0) {
15321536
/* Verify signature of message with public key. */
1533-
ret = wc_hss_verify(state, key->pub, msg, msgSz, sig, sigSz);
1537+
ret = wc_hss_verify(state, key->pub, msg, (word32)msgSz, sig,
1538+
sigSz);
15341539
wc_lmskey_state_free(state);
15351540
}
15361541
ForceZero(state, sizeof(LmsState));

0 commit comments

Comments
 (0)