Skip to content

Commit 90f30fd

Browse files
authored
Merge pull request #8623 from SparkiDev/lms_kid_from_privraw
LMS: add API to get Key ID from raw private key
2 parents 4906974 + fafc333 commit 90f30fd

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
@@ -1043,4 +1043,12 @@ int wc_LmsKey_Verify(LmsKey * key, const byte * sig, word32 sigSz,
10431043
return 0;
10441044
}
10451045

1046+
const byte * wc_LmsKey_GetKidFromPrivRaw(const byte * priv, word32 privSz)
1047+
{
1048+
if ((priv == NULL) || (privSz < 16)) {
1049+
return NULL;
1050+
}
1051+
return priv - 16;
1052+
}
1053+
10461054
#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
@@ -1258,4 +1258,28 @@ int wc_LmsKey_Verify(LmsKey* key, const byte* sig, word32 sigSz,
12581258
return ret;
12591259
}
12601260

1261+
/* Get the Key ID from the raw private key data.
1262+
*
1263+
* PRIV = Q | PARAMS | SEED | I
1264+
* where I is the Key ID.
1265+
*
1266+
* @param [in] priv Private key data.
1267+
* @param [in] privSz Size of private key data.
1268+
* @param Pointer to 16 byte Key ID in the private key.
1269+
* @return NULL on failure.
1270+
*/
1271+
const byte * wc_LmsKey_GetKidFromPrivRaw(const byte * priv, word32 privSz)
1272+
{
1273+
word32 seedSz = privSz - LMS_Q_LEN + HSS_PRIV_KEY_PARAM_SET_LEN - LMS_I_LEN;
1274+
1275+
if (priv == NULL) {
1276+
return NULL;
1277+
}
1278+
if ((seedSz != WC_SHA256_192_DIGEST_SIZE) &&
1279+
(seedSz != WC_SHA256_DIGEST_SIZE)) {
1280+
return NULL;
1281+
}
1282+
return priv - LMS_I_LEN;
1283+
}
1284+
12611285
#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)