Skip to content

Add delegated signing seam#59

Draft
aidangarske wants to merge 1 commit into
wolfSSL:mainfrom
aidangarske:tfm-integration
Draft

Add delegated signing seam#59
aidangarske wants to merge 1 commit into
wolfSSL:mainfrom
aidangarske:tfm-integration

Conversation

@aidangarske

@aidangarske aidangarske commented Jul 17, 2026

Copy link
Copy Markdown
Member

Adds WOLFCOSE_ENABLE_EXT_SIGN, letting a caller supply a signature callback so the private key never enters wolfCOSE. Needed for TF-M, where the attestation key stays in the crypto partition and signing goes over psa_sign_hash. Useful for any HSM backed key.

Wired into both wc_CoseSign1_Sign and wc_CoseSign_Sign. With a callback set, rng may be NULL.

Off by default. src/wolfcose.o is byte identical when disabled (verified with cmp), +792 B when enabled.

Testing: full suite passes with the feature on and off. Verified end to end in TF-M v2.3.0 on QEMU mps2-an521, where the tf-m-tests regression suite passes 200/0, matching stock t_cose, and real t_cose verifies the wolfCOSE produced token. Paired OSP patch adds the TF-M side.

  • Skoll still needs run.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds an opt-in “delegated/external signing” seam so callers can provide a signature callback (e.g., TF-M / PSA / HSM-backed keys) and keep private key material outside of wolfCOSE, integrating this into COSE_Sign1 and COSE_Sign.

Changes:

  • Introduces WOLFCOSE_ENABLE_EXT_SIGNWOLFCOSE_EXT_SIGN build-time gate and public WOLFCOSE_SIGN_CB callback type.
  • Adds wc_CoseKey_SetExtSigner() and plumbs the callback-driven signing path into wc_CoseSign1_Sign() and wc_CoseSign_Sign().
  • Extends failure-injection points to cover external signer failures.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/force_failure.h Adds a failure-injection enum for external signer callbacks.
src/wolfcose.c Implements delegated signing, callback invocation, and integrates it into Sign1/Sign signing flows.
src/wolfcose_internal.h Declares internal wolfCose_ExtSign() helper under the feature gate.
include/wolfcose/wolfcose.h Adds public callback typedef, extends WOLFCOSE_KEY (feature-gated), and exports wc_CoseKey_SetExtSigner().
include/wolfcose/settings.h Adds the opt-in configuration macro and a build-time sanity check for signing enablement.

Comment thread src/wolfcose.c
Comment on lines +3607 to +3615
/* ECDSA is fixed-width r||s (RFC 9053 Section 2.1); a short or long
* signature here would produce a malformed COSE message. */
if ((ret == WOLFCOSE_SUCCESS) && (key->kty == WOLFCOSE_KTY_EC2)) {
ret = wolfCose_CrvKeySize(key->crv, &coordSz);

if ((ret == WOLFCOSE_SUCCESS) && (*sigLen != (2u * coordSz))) {
ret = WOLFCOSE_E_CRYPTO;
}
}
Comment thread src/wolfcose.c
Comment on lines +4656 to +4665
#if defined(WOLFCOSE_EXT_SIGN)
if ((ret == WOLFCOSE_SUCCESS) && (signer->key->signCb != NULL)) {
size_t extSigLen = 0;

/* Signature goes after the Sig_structure in scratch; sigBuf is
* reserved for the local-signing branches. */
if (scratchSz <= sigStructLen) {
ret = WOLFCOSE_E_BUFFER_TOO_SMALL;
}
if (ret == WOLFCOSE_SUCCESS) {
Comment thread src/wolfcose.c
Comment on lines +3536 to +3546
switch (alg) {
case WOLFCOSE_ALG_EDDSA:
case WOLFCOSE_ALG_ML_DSA_44:
case WOLFCOSE_ALG_ML_DSA_65:
case WOLFCOSE_ALG_ML_DSA_87:
preHashes = 0;
break;
default:
preHashes = 1;
break;
}
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.

2 participants