Cryptocb hooks rsapss ed448 cmac - #10886
Conversation
|
retest this please |
|
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #10886
Scan targets checked: wolfcrypt-bugs, wolfcrypt-port-bugs, wolfcrypt-rs-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-src
Findings: 4
4 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Findings are non-blocking.
0108bd2 to
10370ac
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #10886
Scan targets checked: wolfcrypt-bugs, wolfcrypt-port-bugs, wolfcrypt-rs-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-src
Findings: 3
3 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Findings are non-blocking.
10370ac to
513619f
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #10886
Scan targets checked: wolfcrypt-bugs, wolfcrypt-port-bugs, wolfcrypt-rs-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-src
Findings: 2
2 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Findings are non-blocking.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #10886
Scan targets checked: wolfcrypt-bugs, wolfcrypt-port-bugs, wolfcrypt-rs-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-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.
b20a6df to
dc84530
Compare
|
jenkins retest this please |
dc84530 to
54ed373
Compare
54ed373 to
c8482b1
Compare
c8482b1 to
8d3993d
Compare
dgarske
left a comment
There was a problem hiding this comment.
Please resolve merge conflicts. Thanks
8d3993d to
8db30e3
Compare
There was a problem hiding this comment.
Recommend we do this check for crypto callback too right? Maybe move it up higher? Also bring in the brace to same line if under 80 chars.
| if (key->devId != INVALID_DEVID) | ||
| #endif | ||
| { | ||
| ret = wc_CryptoCb_Ed448Verify(sig, sigLen, msg, msgLen, res, key, type, |
There was a problem hiding this comment.
Set *res = 0; before, just in case.
| #endif | ||
|
|
||
| /* sanity check on arguments */ | ||
| if ((in == NULL) || (out == NULL) || (outLen == NULL) || (key == NULL) || |
There was a problem hiding this comment.
Recommendation: Relocate the WOLFSSL_CHECK_MEM_ZERO registration block to after the crypto-callback hook (mirroring wc_ed25519_sign_msg_ex), or alternatively goto a common exit label instead of returning directly. Add a --enable-cryptocb + WOLFSSL_CHECK_MEM_ZERO build to the validation matrix for this PR.
| * so report no inline output rather than a misleading pointer. */ | ||
| if (out != NULL) | ||
| *out = NULL; | ||
| ret = (res != 0) ? (int)inLen : SIG_VERIFY_E; |
There was a problem hiding this comment.
wc_RsaPSS_VerifyCheck device path returns a different length and leaves out untouched, with no way for the caller to tell.
The software path returns the value of wc_RsaPSS_Verify_ex(), which ultimately comes from RsaUnPad_PSS (rsa.c:2024): return saltLen + hLen; — 64 for SHA-256 with a 32-byte salt — and it fills the caller's out buffer with that recovered PSS block. The new crypto-callback path returns (int)inLen — 256 for a 2048-bit key — and never writes out at all.
Recommendation: Do not return inLen as if it were the recovered-PSS-block length. Either have the device report the actual output length and fill out, or define an unambiguous "device verified, no recovered data" signal. Whichever is chosen, document it in doc/dox_comments/header_files/rsa.h for wc_RsaPSS_VerifyCheck as well as wc_RsaPSS_VerifyCheckInline, and add a test that asserts the device return value equals the software return value (or the documented sentinel).
| ExpectIntEQ(wc_RsaSetRNG(key, &rng), 0); | ||
|
|
||
| /* PSS sign runs in software (device declines). */ | ||
| ExpectIntGT(sigLen = (word32)wc_RsaPSS_Sign(digest, |
There was a problem hiding this comment.
Buffer overflow in new RSA-PSS test when wc_RsaPSS_Sign fails: word32 sigLen holds a cast negative error code
Recommendation: Capture the signature length in a signed int and only widen to word32 after confirming it is positive, and additionally gate the plain-if inline sub-test on EXPECT_SUCCESS() so it does not run after a failure.
| *out = NULL; | ||
| ret = (res != 0) ? (int)inLen : SIG_VERIFY_E; | ||
| } | ||
| return ret; |
There was a problem hiding this comment.
Recommendation: Explicitly map any positive device return to SIG_VERIFY_E (fail closed), and document in cryptocb.h that a WC_PK_TYPE_RSA_PSS_VERIFY handler must return exactly 0 (with *res set) or a negative error.
| if (cmac->devId != INVALID_DEVID) | ||
| #endif | ||
| { | ||
| (void)wc_CryptoCb_Free(cmac->devId, WC_ALGO_TYPE_CMAC, (int)cmac->type, |
There was a problem hiding this comment.
Reset cmac->devId = INVALID_DEVID after the ForceZero so a repeat wc_CmacFree() is inert
There was a problem hiding this comment.
Writing devId back after the ForceZero breaks WOLFSSL_CHECK_MEM_ZERO, which requires the freed struct to be all zero. On the repeat-free concern: with nothing registered at devId 0 the dispatch finds no device and is a no-op, and if something is registered there it receives a fully zeroed context with a NULL devCtx and nothing to release. wc_AesFree and wc_Sha256Free behave the same way, so I left CMAC consistent with them.
| WOLFSSL_MSG_EX("CryptoDevCb: Pk Type %d\n", info->pk.type); | ||
| #endif | ||
|
|
||
| #if defined(WC_RSA_PSS) && defined(WOLF_CRYPTO_CB_RSA_PAD) |
There was a problem hiding this comment.
Add the same WOLF_CRYPTO_CB_ONLY_RSA escape as the sibling branches, or add && !defined(WOLF_CRYPTO_CB_ONLY_RSA) to the block guard.
Add WOLF_CRYPTO_CB dispatch hooks so a device can service: * Ed448 sign and verify, mirroring the existing Ed25519 hooks. * CMAC context free on wc_CmacFree (WOLF_CRYPTO_CB_FREE), letting a device release offload state. * RSA-PSS verify with the digest (WOLF_CRYPTO_CB_RSA_PAD) so the device does the full signature and padding check. On that path *out is set to NULL with a positive return, documented in rsa.h. Includes testwolfcrypt and API unit test coverage for each hook.
The PSS hook can hand back the recovered block through out/outSz/outLen. A device that reports only a verdict leaves outLen at 0; wolfSSL then zeroes the buffer and returns saltLen + hLen, and rejects a buffer smaller than that with RSA_BUFFER_E. A reported length is clamped to the buffer size, and any positive handler return maps to SIG_VERIFY_E. Move the Ed448 sign WOLFSSL_CHECK_MEM_ZERO registration below the crypto callback hook so the device path no longer returns past it, and guard the RSA-PSS test callback against WOLF_CRYPTO_CB_ONLY_RSA. Adds tests for the recovered-data, over-claimed-length and undersized buffer paths, and an os-check config that builds the hooks under WOLFSSL_CHECK_MEM_ZERO.
da24c28 to
375febc
Compare
|
Jenkins retest this please |
Adds WOLF_CRYPTO_CB crypto callback hooks so a device can service three more operations:
Ed448 sign and verify, mirroring the existing Ed25519 hooks.
CMAC context free on wc_CmacFree (WOLF_CRYPTO_CB_FREE), letting a device release offload state.
RSA-PSS verify with the digest (WOLF_CRYPTO_CB_RSA_PAD) so the device performs the full signature and padding check.
Includes testwolfcrypt and API unit test coverage for each hook.