-
Notifications
You must be signed in to change notification settings - Fork 39
Un-nest Ed25519 cryptocb cases from HAVE_CURVE25519 #493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -361,6 +361,94 @@ static int _whTest_CryptoEd25519ServerKey(whClientContext* ctx) | |||||||||||||||||
| return ret; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| /* Signs and verifies through the wolfCrypt API on a key whose private material | ||||||||||||||||||
| * lives only in the server, so the crypto callback must handle the operation. | ||||||||||||||||||
| * A software fallback has no private scalar and returns BAD_FUNC_ARG. */ | ||||||||||||||||||
| static int _whTest_CryptoEd25519CryptoCbHsmKey(whClientContext* ctx) | ||||||||||||||||||
| { | ||||||||||||||||||
| int devId = WH_CLIENT_DEVID(ctx); | ||||||||||||||||||
| int ret = 0; | ||||||||||||||||||
| WC_RNG rng[1]; | ||||||||||||||||||
| ed25519_key key[1] = {0}; | ||||||||||||||||||
| ed25519_key pubKey[1] = {0}; | ||||||||||||||||||
| whKeyId signKeyId = WH_KEYID_ERASED; | ||||||||||||||||||
| whKeyId verifyKeyId = WH_KEYID_ERASED; | ||||||||||||||||||
| byte msg[] = "Ed25519 cryptocb dispatch message"; | ||||||||||||||||||
| byte sig[ED25519_SIG_SIZE]; | ||||||||||||||||||
| word32 sigSz = sizeof(sig); | ||||||||||||||||||
| int verified = 0; | ||||||||||||||||||
| uint8_t label[] = "Ed25519 CryptoCb Key"; | ||||||||||||||||||
|
|
||||||||||||||||||
| ret = wc_InitRng_ex(rng, NULL, devId); | ||||||||||||||||||
| if (ret != 0) { | ||||||||||||||||||
| WH_ERROR_PRINT("Failed to wc_InitRng_ex %d\n", ret); | ||||||||||||||||||
| return ret; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| ret = wc_ed25519_init_ex(key, NULL, devId); | ||||||||||||||||||
| if (ret != 0) { | ||||||||||||||||||
| WH_ERROR_PRINT("Failed to initialize Ed25519 key: %d\n", ret); | ||||||||||||||||||
| (void)wc_FreeRng(rng); | ||||||||||||||||||
| return ret; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| ret = wc_ed25519_init_ex(pubKey, NULL, devId); | ||||||||||||||||||
| if (ret != 0) { | ||||||||||||||||||
| WH_ERROR_PRINT("Failed to initialize Ed25519 public key: %d\n", ret); | ||||||||||||||||||
| wc_ed25519_free(key); | ||||||||||||||||||
| (void)wc_FreeRng(rng); | ||||||||||||||||||
| return ret; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| ret = wc_ed25519_make_key(rng, ED25519_KEY_SIZE, key); | ||||||||||||||||||
| if (ret != 0) { | ||||||||||||||||||
| WH_ERROR_PRINT("Failed to generate Ed25519 key: %d\n", ret); | ||||||||||||||||||
| } | ||||||||||||||||||
| else { | ||||||||||||||||||
| ret = whTest_Ed25519ImportToServer(ctx, devId, key, pubKey, label, | ||||||||||||||||||
| sizeof(label), &signKeyId, | ||||||||||||||||||
| &verifyKeyId); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| if (ret == 0) { | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 [Medium] New regression test's dispatch path is ambient rather than pinned, and the only CI row that runs it is DMA=1 The defect fixed in this PR lives in Suggestion:
Suggested change
|
||||||||||||||||||
| sigSz = sizeof(sig); | ||||||||||||||||||
| ret = wc_ed25519_sign_msg(msg, (word32)sizeof(msg), sig, &sigSz, key); | ||||||||||||||||||
| if (ret != 0) { | ||||||||||||||||||
| WH_ERROR_PRINT("wc_ed25519_sign_msg on server key failed: %d\n", | ||||||||||||||||||
| ret); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| if (ret == 0) { | ||||||||||||||||||
| ret = wc_ed25519_verify_msg(sig, sigSz, msg, (word32)sizeof(msg), | ||||||||||||||||||
| &verified, pubKey); | ||||||||||||||||||
| if (ret != 0) { | ||||||||||||||||||
| WH_ERROR_PRINT("wc_ed25519_verify_msg on server key failed: %d\n", | ||||||||||||||||||
| ret); | ||||||||||||||||||
| } | ||||||||||||||||||
| else if (verified != 1) { | ||||||||||||||||||
| WH_ERROR_PRINT("Server key Ed25519 signature did not verify\n"); | ||||||||||||||||||
| ret = -1; | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| if (!WH_KEYID_ISERASED(signKeyId)) { | ||||||||||||||||||
| (void)wh_Client_KeyEvict(ctx, signKeyId); | ||||||||||||||||||
| } | ||||||||||||||||||
| if (!WH_KEYID_ISERASED(verifyKeyId)) { | ||||||||||||||||||
| (void)wh_Client_KeyEvict(ctx, verifyKeyId); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| if (ret == 0) { | ||||||||||||||||||
| WH_TEST_PRINT("Ed25519 CRYPTOCB DEVID=0x%X SUCCESS\n", devId); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| wc_ed25519_free(pubKey); | ||||||||||||||||||
| wc_ed25519_free(key); | ||||||||||||||||||
| (void)wc_FreeRng(rng); | ||||||||||||||||||
| return ret; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| #ifdef WOLFHSM_CFG_DMA | ||||||||||||||||||
| static int _whTest_CryptoEd25519Dma(whClientContext* ctx) | ||||||||||||||||||
| { | ||||||||||||||||||
|
|
@@ -731,6 +819,7 @@ int whTest_Crypto_Ed25519(whClientContext* ctx) | |||||||||||||||||
| { | ||||||||||||||||||
| WH_TEST_RETURN_ON_FAIL(_whTest_CryptoEd25519Inline(ctx)); | ||||||||||||||||||
| WH_TEST_RETURN_ON_FAIL(_whTest_CryptoEd25519ServerKey(ctx)); | ||||||||||||||||||
| WH_TEST_RETURN_ON_FAIL(_whTest_CryptoEd25519CryptoCbHsmKey(ctx)); | ||||||||||||||||||
| #ifdef WOLFHSM_CFG_DMA | ||||||||||||||||||
| WH_TEST_RETURN_ON_FAIL(_whTest_CryptoEd25519Dma(ctx)); | ||||||||||||||||||
| #endif | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔵 [Low] WC_PK_TYPE_ED25519_KEYGEN dispatch remains uncovered by the new regression test
💡 SUGGEST
The PR un-nests three dispatch cases —
WC_PK_TYPE_ED25519_KEYGEN,_SIGNand_VERIFY— but the new test only pins two of them. The sign case is covered because the key is reduced to a bare keyId (software fallback hitsif (!key->privKeySet) return BAD_FUNC_ARG;in wolfSSLed25519.c:559), and verify likewise (pubKeySet == 0after re-init). The keygen case is not:wc_ed25519_make_key(rng, ED25519_KEY_SIZE, key)at line 403 runs against a freshly initialised key with local material available, so whenWC_PK_TYPE_ED25519_KEYGENis compiled out the callback returnsCRYPTOCB_UNAVAILABLE, wolfCrypt generates the key in software, and every subsequent step of the test still succeeds. This is exactly the failure mode described in the PR body — silent software fallback with no diagnostic — surviving for one of the three cases the fix touches.Recommendation: Add a keygen assertion that can only pass through the callback — e.g. generate into a key whose
devCtxalready carries a keyId viawh_Client_Ed25519MakeCacheKey/wh_Client_Ed25519MakeExportKeysemantics, or assert the resulting key is a server handle rather than one holding local private material — so a re-nestedWC_PK_TYPE_ED25519_KEYGENguard is caught too.