Skip to content

Add crypto callbacks for LMS and XMSS#10380

Open
padelsbach wants to merge 2 commits intowolfSSL:masterfrom
padelsbach:lms-xmss
Open

Add crypto callbacks for LMS and XMSS#10380
padelsbach wants to merge 2 commits intowolfSSL:masterfrom
padelsbach:lms-xmss

Conversation

@padelsbach
Copy link
Copy Markdown
Contributor

@padelsbach padelsbach commented May 1, 2026

Description

Add struct fields and callbacks (MakeKey, Sign, Verify and SigsLeft) into existing LMS and XMSS code. Add wc_LmsKey_InitId and _InitLabel for PKCS11 compat. Added unit tests.

Testing

New unit tests

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

Copy link
Copy Markdown

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #10380

Scan targets checked: wolfcrypt-bugs, wolfcrypt-src

Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Findings are non-blocking.

Comment thread wolfcrypt/src/wc_xmss.c Outdated
switch (key->params->hash) {
#ifdef WC_XMSS_SHA256
case WC_HASH_TYPE_SHA256:
ret = wc_Hash(WC_HASH_TYPE_SHA256, msg, msgSz, hash, needSz);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 [Medium] wc_XmssKey_HashMsg breaks for XMSS-SHA2_*_192 (SHA-256 truncated) · Logic errors

For XMSS-SHA2_*_192 variants params->n is 24 while params->hash is WC_HASH_TYPE_SHA256. wc_Hash rejects hash_len < 32 with BUFFER_E, so the helper always fails for the 192-bit profiles. The LMS counterpart hashes into a 32-byte stack buffer and copies needSz bytes; the XMSS path skips that step.

Fix: Hash into a WC_SHA256_DIGEST_SIZE stack buffer and XMEMCPY(hash, full, needSz), mirroring the LMS_SHA256_192 path.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@padelsbach padelsbach force-pushed the lms-xmss branch 3 times, most recently from 49f1cc2 to 6673edd Compare May 4, 2026 17:47
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

MemBrowse Memory Report

No memory changes detected for:

@padelsbach
Copy link
Copy Markdown
Contributor Author

jenkins retest this please

Copy link
Copy Markdown
Contributor

@Frauschi Frauschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of minor things, mainly as the WiP patch I sent you was in a very rough state tbh (sorry for that).

Comment thread doc/LMS_XMSS_CryptoCb.md Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove this file. I only added it to the patch I originally sent you as a reference and easy starting point.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

struct {
/* Raw message. Backends following the PKCS#11 v3.2
* CKM_HSS / CKM_XMSS convention of operating on a
* pre-computed digest can call wc_LmsKey_HashMsg /
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, but I'm unsure if we want to have a specific PKCS#11 reference here.

WOLFSSL_LOCAL int wc_CryptoCb_PqcStatefulSigKeyGen(int type, void* key,
WC_RNG* rng);
/* The raw message is forwarded to the callback. Backends that follow the
* PKCS#11 v3.2 CKM_HSS / CKM_XMSS convention (digest input) can call
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above regarding the mention of PKCS#11 V3.2

Comment thread wolfcrypt/src/wc_lms.c Outdated
* small for the digest.
* @return NOT_COMPILED_IN when the param set's hash family is disabled.
*/
int wc_LmsKey_HashMsg(const LmsKey* key, const byte* msg, word32 msgSz,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move this method further down in the file to where the other public API methods are located? At the top of the file, only static internal functions are placed otherwise.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread wolfcrypt/src/wc_lms.c Outdated
if (*hashSz < needSz)
return BAD_FUNC_ARG;

switch (key->params->lmsType & 0xF000) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use LMS_HASH_MASK instead of the magic 0xF000 literal.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread wolfcrypt/src/wc_xmss.c Outdated
WOLFSSL_MSG("error: XmssKey context is not set");
ret = BAD_FUNC_ARG;
}
/* Callback context is opaque; NULL is allowed. */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Comment thread wolfcrypt/src/wc_xmss.c Outdated
WC_PQC_STATEFUL_SIG_TYPE_XMSS, key, &sigsLeft);
if (cbRet == 0) {
/* Clamp to int range; callers treat 0 as "exhausted". */
return (sigsLeft > (word32)0x7FFFFFFF)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to LMS, we only return 1 or 0 here, not the actual amount of signatures left.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread wolfcrypt/src/wc_xmss.c
if ((key == NULL) || (sig == NULL) || (m == NULL)) {
ret = BAD_FUNC_ARG;
}
if ((ret == 0) && (mLen <= 0)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to LMS, should we allow mLen == 0 for verify? Not prohibited by the spec.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allowed len of 0

Comment thread wolfcrypt/src/wc_lms.c Outdated
WOLFSSL_MSG("error: LmsKey context is not set");
ret = BAD_FUNC_ARG;
}
/* Callback context is opaque to wolfCrypt and may legitimately be NULL
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment is unnecessary I think.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

const byte* msg, int msgSz);
/* Compute the digest of a message with the hash function dictated by the
* XMSS parameter set. Useful for crypto-callback / HSM backends that follow
* the PKCS#11 v3.2 CKM_XMSS / CKM_XMSSMT convention of taking a
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I would remove/weaken the PKCS#11 reference here and be more general.

@Frauschi Frauschi assigned padelsbach and unassigned wolfSSL-Bot May 5, 2026
@padelsbach
Copy link
Copy Markdown
Contributor Author

jenkins retest this please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants