-
Notifications
You must be signed in to change notification settings - Fork 920
Add PKCS7 ECC raw sign callback support #9656
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: master
Are you sure you want to change the base?
Changes from 2 commits
dcf9439
f2f959f
8e2e6d1
37f4c13
352c362
2eae560
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 |
|---|---|---|
|
|
@@ -451,6 +451,46 @@ static int rsaSignRawDigestCb(PKCS7* pkcs7, byte* digest, word32 digestSz, | |
| } | ||
| #endif | ||
|
|
||
| #if defined(HAVE_PKCS7) && defined(HAVE_PKCS7_ECC_RAW_SIGN_CALLBACK) && \ | ||
| defined(HAVE_ECC) && !defined(NO_SHA256) | ||
| /* ECC sign raw digest callback */ | ||
| static int eccSignRawDigestCb(PKCS7* pkcs7, byte* digest, word32 digestSz, | ||
| byte* out, word32 outSz, byte* privateKey, | ||
| word32 privateKeySz, int devid, int hashOID) | ||
| { | ||
| int ret; | ||
| word32 idx = 0; | ||
| word32 sigSz = outSz; | ||
| ecc_key ecc; | ||
|
|
||
| if (pkcs7 == NULL || digest == NULL || out == NULL) { | ||
| return -1; | ||
| } | ||
|
|
||
| (void)hashOID; | ||
|
|
||
| /* set up ECC key */ | ||
| ret = wc_ecc_init_ex(&ecc, pkcs7->heap, devid); | ||
| if (ret != 0) { | ||
| return ret; | ||
| } | ||
|
|
||
| ret = wc_EccPrivateKeyDecode(privateKey, &idx, &ecc, privateKeySz); | ||
|
|
||
| /* sign digest */ | ||
| if (ret == 0) { | ||
| ret = wc_ecc_sign_hash(digest, digestSz, out, &sigSz, pkcs7->rng, &ecc); | ||
| if (ret == 0) { | ||
| ret = (int)sigSz; | ||
| } | ||
| } | ||
|
|
||
| wc_ecc_free(&ecc); | ||
|
|
||
| return ret; | ||
| } | ||
| #endif | ||
|
|
||
| #if defined(HAVE_PKCS7) && defined(ASN_BER_TO_DER) | ||
| typedef struct encodeSignedDataStream { | ||
| byte out[FOURK_BUF*3]; | ||
|
|
@@ -769,6 +809,30 @@ int test_wc_PKCS7_EncodeSignedData(void) | |
| ExpectIntGT(wc_PKCS7_EncodeSignedData(pkcs7, output, outputSz), 0); | ||
| #endif | ||
|
|
||
| #if defined(HAVE_PKCS7) && defined(HAVE_PKCS7_ECC_RAW_SIGN_CALLBACK) && \ | ||
| defined(HAVE_ECC) && defined(NO_RSA) && !defined(NO_SHA256) | ||
| /* test ECC sign raw digest callback, if using ECC and compiled in. | ||
| * Example callback assumes SHA-256, so only run test if compiled in. */ | ||
| wc_PKCS7_Free(pkcs7); | ||
| pkcs7 = NULL; | ||
| ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId)); | ||
| ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0); | ||
|
|
||
| if (pkcs7 != NULL) { | ||
| pkcs7->content = data; | ||
| pkcs7->contentSz = (word32)sizeof(data); | ||
| pkcs7->privateKey = key; | ||
|
||
| pkcs7->privateKeySz = (word32)keySz; | ||
| pkcs7->encryptOID = ECDSAk; | ||
| pkcs7->hashOID = SHA256h; | ||
| pkcs7->rng = &rng; | ||
| } | ||
|
|
||
| ExpectIntEQ(wc_PKCS7_SetEccSignRawDigestCb(pkcs7, eccSignRawDigestCb), 0); | ||
|
|
||
| ExpectIntGT(wc_PKCS7_EncodeSignedData(pkcs7, output, outputSz), 0); | ||
| #endif | ||
|
|
||
| wc_PKCS7_Free(pkcs7); | ||
| DoExpectIntEQ(wc_FreeRng(&rng), 0); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.