Skip to content

Commit fafc333

Browse files
committed
LMS: add API to get Key ID from raw private key
Always last 16 bytes of private key.
1 parent 83e1cfc commit fafc333

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

wolfcrypt/src/ext_lms.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,4 +1049,12 @@ int wc_LmsKey_Verify(LmsKey * key, const byte * sig, word32 sigSz,
10491049
return 0;
10501050
}
10511051

1052+
const byte * wc_LmsKey_GetKidFromPrivRaw(const byte * priv, word32 privSz)
1053+
{
1054+
if ((priv == NULL) || (privSz < 16)) {
1055+
return NULL;
1056+
}
1057+
return priv - 16;
1058+
}
1059+
10521060
#endif /* WOLFSSL_HAVE_LMS && HAVE_LIBLMS */

wolfcrypt/src/wc_lms.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,4 +1264,28 @@ int wc_LmsKey_Verify(LmsKey* key, const byte* sig, word32 sigSz,
12641264
return ret;
12651265
}
12661266

1267+
/* Get the Key ID from the raw private key data.
1268+
*
1269+
* PRIV = Q | PARAMS | SEED | I
1270+
* where I is the Key ID.
1271+
*
1272+
* @param [in] priv Private key data.
1273+
* @param [in] privSz Size of private key data.
1274+
* @param Pointer to 16 byte Key ID in the private key.
1275+
* @return NULL on failure.
1276+
*/
1277+
const byte * wc_LmsKey_GetKidFromPrivRaw(const byte * priv, word32 privSz)
1278+
{
1279+
word32 seedSz = privSz - LMS_Q_LEN + HSS_PRIV_KEY_PARAM_SET_LEN - LMS_I_LEN;
1280+
1281+
if (priv == NULL) {
1282+
return NULL;
1283+
}
1284+
if ((seedSz != WC_SHA256_192_DIGEST_SIZE) &&
1285+
(seedSz != WC_SHA256_DIGEST_SIZE)) {
1286+
return NULL;
1287+
}
1288+
return priv - LMS_I_LEN;
1289+
}
1290+
12671291
#endif /* WOLFSSL_HAVE_LMS && WOLFSSL_WC_LMS */

wolfssl/wolfcrypt/lms.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ WOLFSSL_API int wc_LmsKey_Verify(LmsKey * key, const byte * sig, word32 sigSz,
186186
const byte * msg, int msgSz);
187187
WOLFSSL_API const char * wc_LmsKey_ParmToStr(enum wc_LmsParm lmsParm);
188188
WOLFSSL_API const char * wc_LmsKey_RcToStr(enum wc_LmsRc lmsRc);
189+
190+
WOLFSSL_API const byte * wc_LmsKey_GetKidFromPrivRaw(const byte * priv,
191+
word32 privSz);
189192
#ifdef __cplusplus
190193
} /* extern "C" */
191194
#endif

0 commit comments

Comments
 (0)