Skip to content

Commit 0e27b3e

Browse files
authored
Merge pull request #8613 from SparkiDev/lms_iana
LMS: change identifiers to match standard
2 parents 3ff4e5e + 83e1cfc commit 0e27b3e

2 files changed

Lines changed: 21 additions & 21 deletions

File tree

wolfcrypt/src/wc_lms_impl.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,10 +1339,10 @@ static void wc_lmots_public_key_encode(const LmsParams* params,
13391339
const byte* priv_i = priv + LMS_Q_LEN + params->hash_len;
13401340

13411341
/* u32str(type) || ... || T(1) */
1342-
c32toa(params->lmsType, pub);
1342+
c32toa(params->lmsType & LMS_H_W_MASK, pub);
13431343
pub += 4;
13441344
/* u32str(type) || u32str(otstype) || ... || T(1) */
1345-
c32toa(params->lmOtsType, pub);
1345+
c32toa(params->lmOtsType & LMS_H_W_MASK, pub);
13461346
pub += 4;
13471347
/* u32str(type) || u32str(otstype) || I || T(1) */
13481348
XMEMCPY(pub, priv_i, LMS_I_LEN);
@@ -1365,14 +1365,14 @@ static int wc_lmots_public_key_check(const LmsParams* params, const byte* pub)
13651365
ato32(pub, &type);
13661366
pub += 4;
13671367
/* Compare with parameters. */
1368-
if (type != params->lmsType) {
1368+
if (type != (params->lmsType & LMS_H_W_MASK)) {
13691369
ret = PUBLIC_KEY_E;
13701370
}
13711371
if (ret == 0) {
13721372
/* Get node hash and Winternitz width type. */
13731373
ato32(pub, &type);
13741374
/* Compare with parameters. */
1375-
if (type != params->lmOtsType) {
1375+
if (type != (params->lmOtsType & LMS_H_W_MASK)) {
13761376
ret = PUBLIC_KEY_E;
13771377
}
13781378
}
@@ -2250,7 +2250,7 @@ static int wc_lms_sign(LmsState* state, const byte* priv, const byte* msg,
22502250
s += LMS_Q_LEN;
22512251

22522252
/* ots_signature = sig = u32str(type) || ... */
2253-
c32toa(state->params->lmOtsType, s);
2253+
c32toa(state->params->lmOtsType & LMS_H_W_MASK, s);
22542254
s += LMS_TYPE_LEN;
22552255
/* Sign this level.
22562256
* S = u32str(q) || ots_signature || ... */
@@ -2259,7 +2259,7 @@ static int wc_lms_sign(LmsState* state, const byte* priv, const byte* msg,
22592259
/* Skip over ots_signature. */
22602260
s += params->hash_len + params->p * params->hash_len;
22612261
/* S = u32str(q) || ots_signature || u32str(type) || ... */
2262-
c32toa(params->lmsType, s);
2262+
c32toa(params->lmsType & LMS_H_W_MASK, s);
22632263
}
22642264

22652265
return ret;
@@ -2280,13 +2280,13 @@ static void wc_lms_sig_copy(const LmsParams* params, const byte* y,
22802280
XMEMCPY(sig, priv, LMS_Q_LEN);
22812281
sig += LMS_Q_LEN;
22822282
/* S = u32str(q) || ... */
2283-
c32toa(params->lmOtsType, sig);
2283+
c32toa(params->lmOtsType & LMS_H_W_MASK, sig);
22842284
sig += LMS_TYPE_LEN;
22852285
/* S = u32str(q) || ots_signature || ... */
22862286
XMEMCPY(sig, y, params->hash_len + params->p * params->hash_len);
22872287
sig += params->hash_len + params->p * params->hash_len;
22882288
/* S = u32str(q) || ots_signature || u32str(type) || ... */
2289-
c32toa(params->lmsType, sig);
2289+
c32toa(params->lmsType & LMS_H_W_MASK, sig);
22902290
}
22912291
#endif /* !WOLFSSL_WC_LMS_SMALL && !WOLFSSL_LMS_NO_SIG_CACHE */
22922292
#endif /* !WOLFSSL_LMS_VERIFY_ONLY */

wolfssl/wolfcrypt/wc_lms.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,13 @@
303303
#endif
304304

305305
/* Indicates using SHA-256 for hashing. */
306-
#define LMS_SHA256 0x00
306+
#define LMS_SHA256 0x0000
307307
/* Indicates using SHA-256/192 for hashing. */
308-
#define LMS_SHA256_192 0x10
308+
#define LMS_SHA256_192 0x1000
309309
/* Mask to get hashing algorithm from type. */
310-
#define LMS_HASH_MASK 0xf0
310+
#define LMS_HASH_MASK 0xf000
311311
/* Mask to get height or Winternitz width from type. */
312-
#define LMS_H_W_MASK 0x0f
312+
#define LMS_H_W_MASK 0x0fff
313313

314314
/* LMS Parameters. */
315315
/* SHA-256 hash, 32-bytes of hash used, tree height of 5. */
@@ -333,24 +333,24 @@
333333
#define LMOTS_SHA256_N32_W8 0x04
334334

335335
/* SHA-256 hash, 32-bytes of hash used, tree height of 5. */
336-
#define LMS_SHA256_M24_H5 (0x05 | LMS_SHA256_192)
336+
#define LMS_SHA256_M24_H5 (0x0a | LMS_SHA256_192)
337337
/* SHA-256 hash, 32-bytes of hash used, tree height of 10. */
338-
#define LMS_SHA256_M24_H10 (0x06 | LMS_SHA256_192)
338+
#define LMS_SHA256_M24_H10 (0x0b | LMS_SHA256_192)
339339
/* SHA-256 hash, 32-bytes of hash used, tree height of 15. */
340-
#define LMS_SHA256_M24_H15 (0x07 | LMS_SHA256_192)
340+
#define LMS_SHA256_M24_H15 (0x0c | LMS_SHA256_192)
341341
/* SHA-256 hash, 32-bytes of hash used, tree height of 20. */
342-
#define LMS_SHA256_M24_H20 (0x08 | LMS_SHA256_192)
342+
#define LMS_SHA256_M24_H20 (0x0d | LMS_SHA256_192)
343343
/* SHA-256 hash, 32-bytes of hash used, tree height of 25. */
344-
#define LMS_SHA256_M24_H25 (0x09 | LMS_SHA256_192)
344+
#define LMS_SHA256_M24_H25 (0x0e | LMS_SHA256_192)
345345

346346
/* SHA-256 hash, 32-bytes of hash used, Winternitz width of 1 bit. */
347-
#define LMOTS_SHA256_N24_W1 (0x01 | LMS_SHA256_192)
347+
#define LMOTS_SHA256_N24_W1 (0x05 | LMS_SHA256_192)
348348
/* SHA-256 hash, 32-bytes of hash used, Winternitz width of 2 bits. */
349-
#define LMOTS_SHA256_N24_W2 (0x02 | LMS_SHA256_192)
349+
#define LMOTS_SHA256_N24_W2 (0x06 | LMS_SHA256_192)
350350
/* SHA-256 hash, 32-bytes of hash used, Winternitz width of 4 bits. */
351-
#define LMOTS_SHA256_N24_W4 (0x03 | LMS_SHA256_192)
351+
#define LMOTS_SHA256_N24_W4 (0x07 | LMS_SHA256_192)
352352
/* SHA-256 hash, 32-bytes of hash used, Winternitz width of 8 bits. */
353-
#define LMOTS_SHA256_N24_W8 (0x04 | LMS_SHA256_192)
353+
#define LMOTS_SHA256_N24_W8 (0x08 | LMS_SHA256_192)
354354

355355
typedef struct LmsParams {
356356
/* Number of tree levels. */

0 commit comments

Comments
 (0)