Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/cryptocb-only.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name: cryptocb-only Tests

# START OF COMMON SECTION
Expand Down Expand Up @@ -203,8 +203,8 @@
"comment": "Same coverage as the \"all\" entry above, but driven by ./configure --enable-cryptocb=only instead of a hand-written CPPFLAGS list. This is the regression test for the configure option: it must emit exactly the WOLF_CRYPTO_CB_ONLY_* set that \"all\" passes by hand, for the algorithms enabled here. The \"all\" entry deliberately stays on explicit CPPFLAGS so a bug in the configure logic cannot silently weaken both. Note the base already passes --enable-cryptocb; this entry's flags are appended after the base, so --enable-cryptocb=only wins.",
"configure": ["--enable-lms", "--enable-xmss", "--enable-cryptocb=only"]},
{"name": "keygen-sw-fallback", "minutes": 4.0,
"comment": "WOLF_CRYPTO_CB_KEYGEN_SW_FALLBACK: an id or label key whose registered device declines key generation is generated in software again instead of failing with NO_VALID_DEVID. test_wc_ecc_make_key_id_dev checks that fallback here; every other entry builds the default, which refuses. No ONLY_* strip, so software key generation is available.",
"configure": ["CPPFLAGS=-DWOLF_CRYPTO_CB_KEYGEN_SW_FALLBACK"]},
"comment": "WOLF_CRYPTO_CB_KEYGEN_SW_FALLBACK: an id or label key whose registered device declines key generation is generated in software again instead of failing with NO_VALID_DEVID. test_wc_ecc_make_key_id_dev checks that fallback here, and the LMS/XMSS reload tests and test_wc_Pkcs11_Lms (hence --enable-pkcs11) that a named key then reloads from its read callback; every other entry builds the default, which refuses. No ONLY_* strip, so software key generation is available.",
"configure": ["--enable-lms", "--enable-xmss", "--enable-pkcs11", "CPPFLAGS=-DWOLF_CRYPTO_CB_KEYGEN_SW_FALLBACK"]},
{"name": "setkey", "minutes": 4.0,
"comment": "--enable-cryptocbutils enables all cryptocb utilities (COPY/FREE/SETKEY/EXPORT_KEY/KEYSTORE); WOLF_CRYPTO_CB_SETKEY is what lets test_wc_CryptoCb_TLS_CBC_HMAC run -- a TLS 1.2 CBC MtE handshake whose record HMAC is computed by a key-owning callback, the only config exercising the TLS_hmac update/final routing. No ONLY_* strip, so the device's software HMAC keeps its providers.",
"configure": ["--enable-cryptocbutils"]}
Expand Down
1 change: 1 addition & 0 deletions .wolfssl_known_macro_extras
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ NO_PKCS11_ECC
NO_PKCS11_ECDH
NO_PKCS11_EC_KEYGEN
NO_PKCS11_HMAC
NO_PKCS11_LMS
NO_PKCS11_MLDSA
NO_PKCS11_MLKEM
NO_PKCS11_RNG
Expand Down
9 changes: 6 additions & 3 deletions doc/dox_comments/header_files/wc_lms.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,12 @@ int wc_LmsKey_MakeKey(LmsKey* key, WC_RNG* rng);
the private key bytes; the parameter set is metadata the
application owns).

With WOLF_CRYPTO_CB, a key on a devId with no read callback is
taken to be device-backed and Reload is a no-op. With a read
callback the software reload runs as usual.
With WOLF_CRYPTO_CB, a key on a devId is taken to be device-backed
and Reload is a no-op when it has no read callback or has a device
context. A key with an id or label is a no-op too, always with
WOLF_CRYPTO_CB_ONLY_LMS, and otherwise when a device is registered for
its devId and WOLF_CRYPTO_CB_KEYGEN_SW_FALLBACK is not defined.
Otherwise the software reload runs as usual.

WOLF_CRYPTO_CB_ONLY_LMS removes the software reload, so the read
callback is never called and only the device-backed no-op
Expand Down
9 changes: 6 additions & 3 deletions doc/dox_comments/header_files/wc_xmss.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,12 @@ int wc_XmssKey_MakeKey(XmssKey* key, WC_RNG* rng);
The same parameter set selected at key-generation time must be
reapplied with wc_XmssKey_SetParamStr() before calling Reload.

With WOLF_CRYPTO_CB, a key on a devId with no read callback is
taken to be device-backed and Reload is a no-op. With a read
callback the software reload runs as usual, which needs the write
With WOLF_CRYPTO_CB, a key on a devId is taken to be device-backed
and Reload is a no-op when it has no read callback or has a device
context. A key with an id or label is a no-op too, always with
WOLF_CRYPTO_CB_ONLY_XMSS, and otherwise when a device is registered for
its devId and WOLF_CRYPTO_CB_KEYGEN_SW_FALLBACK is not defined.
Otherwise the software reload runs as usual, which needs the write
callback set too.

WOLF_CRYPTO_CB_ONLY_XMSS removes the software reload, so the read
Expand Down
69 changes: 68 additions & 1 deletion tests/api/test_lms_xmss.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ static int test_lms_xmss_verify_cryptocb(int devIdArg, wc_CryptoInfo* info,
/*
* Test reloading an LMS key on a devId that keeps its state in software, the
* case of a devId set only to route other algorithms to an accelerator. The
* second half covers the device-backed arm, where no read callback is set.
* second half covers the device-backed arm, where no read callback is set,
* and a named key with its device registered and unregistered.
*
* Without the fix: Reload does no work, priv_data is left NULL and the
* following sign dereferences it.
Expand Down Expand Up @@ -500,6 +501,39 @@ int test_wc_LmsKey_reload_devid(void)
ExpectNull(hsmKey.priv_data);
ExpectIntEQ(wc_LmsKey_GetKid(&hsmKey, &kid, &kidSz),
WC_NO_ERR_TRACE(BAD_STATE_E));
#ifdef WOLF_PRIVATE_KEY_ID
/* A named key with a read callback stays on the device under the keygen id
* check, and otherwise reloads from the read callback and signs. */
wc_LmsKey_Free(&hsmKey);
XMEMSET(&hsmKey, 0, sizeof(hsmKey));
ExpectIntEQ(wc_LmsKey_InitId(&hsmKey, (const unsigned char*)"lms", 3, NULL,
TEST_LMS_XMSS_CRYPTOCB_DEVID), 0);
ExpectIntEQ(test_lms_set_params(&hsmKey), 0);
ExpectIntEQ(wc_LmsKey_SetWriteCb(&hsmKey, test_lms_write_key), 0);
ExpectIntEQ(wc_LmsKey_SetReadCb(&hsmKey, test_lms_read_key), 0);
ExpectIntEQ(wc_LmsKey_SetContext(&hsmKey, (void*)LMS_TEST_PRIV_KEY_FILE),
0);
ExpectIntEQ(wc_LmsKey_Reload(&hsmKey), 0);
#ifdef WC_CRYPTOCB_KEYGEN_ID_CHECK
ExpectNull(hsmKey.priv_data);
/* With no device registered for its devId it reloads in software. */
wc_LmsKey_Free(&hsmKey);
XMEMSET(&hsmKey, 0, sizeof(hsmKey));
wc_CryptoCb_UnRegisterDevice(TEST_LMS_XMSS_CRYPTOCB_DEVID);
ExpectIntEQ(wc_LmsKey_InitId(&hsmKey, (const unsigned char*)"lms", 3, NULL,
TEST_LMS_XMSS_CRYPTOCB_DEVID), 0);
ExpectIntEQ(test_lms_set_params(&hsmKey), 0);
ExpectIntEQ(wc_LmsKey_SetWriteCb(&hsmKey, test_lms_write_key), 0);
ExpectIntEQ(wc_LmsKey_SetReadCb(&hsmKey, test_lms_read_key), 0);
ExpectIntEQ(wc_LmsKey_SetContext(&hsmKey, (void*)LMS_TEST_PRIV_KEY_FILE),
0);
ExpectIntEQ(wc_LmsKey_Reload(&hsmKey), 0);
#endif
ExpectNotNull(hsmKey.priv_data);
sigSz = sizeof(sig);
ExpectIntEQ(wc_LmsKey_Sign(&hsmKey, sig, &sigSz, msg, sizeof(msg)), 0);
ExpectIntEQ(wc_LmsKey_Verify(&vkey, sig, sigSz, msg, sizeof(msg)), 0);
#endif

wc_LmsKey_Free(&hsmKey);
wc_LmsKey_Free(&vkey);
Expand Down Expand Up @@ -1099,6 +1133,39 @@ int test_wc_XmssKey_reload_devid(void)
ExpectIntEQ(wc_XmssKey_SetParamStr(&hsmKey, "XMSS-SHA2_10_256"), 0);
ExpectIntEQ(wc_XmssKey_Reload(&hsmKey), 0);
ExpectNull(hsmKey.sk);
#ifdef WOLF_PRIVATE_KEY_ID
/* A named key with a read callback stays on the device under the keygen id
* check, and otherwise reloads from the read callback and signs. */
wc_XmssKey_Free(&hsmKey);
XMEMSET(&hsmKey, 0, sizeof(hsmKey));
ExpectIntEQ(wc_XmssKey_InitId(&hsmKey, (const unsigned char*)"xmss", 4,
NULL, TEST_LMS_XMSS_CRYPTOCB_DEVID), 0);
ExpectIntEQ(wc_XmssKey_SetParamStr(&hsmKey, "XMSS-SHA2_10_256"), 0);
ExpectIntEQ(wc_XmssKey_SetWriteCb(&hsmKey, xmss_devid_write_key), 0);
ExpectIntEQ(wc_XmssKey_SetReadCb(&hsmKey, xmss_devid_read_key), 0);
ExpectIntEQ(wc_XmssKey_SetContext(&hsmKey,
(void*)XMSS_DEVID_TEST_PRIV_KEY_FILE), 0);
ExpectIntEQ(wc_XmssKey_Reload(&hsmKey), 0);
#ifdef WC_CRYPTOCB_KEYGEN_ID_CHECK
ExpectNull(hsmKey.sk);
/* With no device registered for its devId it reloads in software. */
wc_XmssKey_Free(&hsmKey);
XMEMSET(&hsmKey, 0, sizeof(hsmKey));
wc_CryptoCb_UnRegisterDevice(TEST_LMS_XMSS_CRYPTOCB_DEVID);
ExpectIntEQ(wc_XmssKey_InitId(&hsmKey, (const unsigned char*)"xmss", 4,
NULL, TEST_LMS_XMSS_CRYPTOCB_DEVID), 0);
ExpectIntEQ(wc_XmssKey_SetParamStr(&hsmKey, "XMSS-SHA2_10_256"), 0);
ExpectIntEQ(wc_XmssKey_SetWriteCb(&hsmKey, xmss_devid_write_key), 0);
ExpectIntEQ(wc_XmssKey_SetReadCb(&hsmKey, xmss_devid_read_key), 0);
ExpectIntEQ(wc_XmssKey_SetContext(&hsmKey,
(void*)XMSS_DEVID_TEST_PRIV_KEY_FILE), 0);
ExpectIntEQ(wc_XmssKey_Reload(&hsmKey), 0);
#endif
ExpectNotNull(hsmKey.sk);
sigSz = sizeof(sig);
ExpectIntEQ(wc_XmssKey_Sign(&hsmKey, sig, &sigSz, msg, sizeof(msg)), 0);
ExpectIntEQ(wc_XmssKey_Verify(&vkey, sig, sigSz, msg, sizeof(msg)), 0);
#endif

wc_XmssKey_Free(&hsmKey);
wc_XmssKey_Free(&vkey);
Expand Down
Loading
Loading