Merge pull request #8623 from SparkiDev/lms_kid_from_privraw

LMS: add API to get Key ID from raw private key
This commit is contained in:
Daniel Pouzzner
2025-04-17 00:49:08 -05:00
committed by GitHub
3 changed files with 35 additions and 0 deletions

View File

@ -1043,4 +1043,12 @@ int wc_LmsKey_Verify(LmsKey * key, const byte * sig, word32 sigSz,
return 0;
}
const byte * wc_LmsKey_GetKidFromPrivRaw(const byte * priv, word32 privSz)
{
if ((priv == NULL) || (privSz < 16)) {
return NULL;
}
return priv - 16;
}
#endif /* WOLFSSL_HAVE_LMS && HAVE_LIBLMS */

View File

@ -1258,4 +1258,28 @@ int wc_LmsKey_Verify(LmsKey* key, const byte* sig, word32 sigSz,
return ret;
}
/* Get the Key ID from the raw private key data.
*
* PRIV = Q | PARAMS | SEED | I
* where I is the Key ID.
*
* @param [in] priv Private key data.
* @param [in] privSz Size of private key data.
* @param Pointer to 16 byte Key ID in the private key.
* @return NULL on failure.
*/
const byte * wc_LmsKey_GetKidFromPrivRaw(const byte * priv, word32 privSz)
{
word32 seedSz = privSz - LMS_Q_LEN + HSS_PRIV_KEY_PARAM_SET_LEN - LMS_I_LEN;
if (priv == NULL) {
return NULL;
}
if ((seedSz != WC_SHA256_192_DIGEST_SIZE) &&
(seedSz != WC_SHA256_DIGEST_SIZE)) {
return NULL;
}
return priv - LMS_I_LEN;
}
#endif /* WOLFSSL_HAVE_LMS && WOLFSSL_WC_LMS */

View File

@ -186,6 +186,9 @@ WOLFSSL_API int wc_LmsKey_Verify(LmsKey * key, const byte * sig, word32 sigSz,
const byte * msg, int msgSz);
WOLFSSL_API const char * wc_LmsKey_ParmToStr(enum wc_LmsParm lmsParm);
WOLFSSL_API const char * wc_LmsKey_RcToStr(enum wc_LmsRc lmsRc);
WOLFSSL_API const byte * wc_LmsKey_GetKidFromPrivRaw(const byte * priv,
word32 privSz);
#ifdef __cplusplus
} /* extern "C" */
#endif