|
25 | 25 | #include <wolfssl/wolfcrypt/logging.h> |
26 | 26 | #include <wolfssl/wolfcrypt/cryptocb.h> |
27 | 27 |
|
| 28 | +#if 0 |
28 | 29 | #define CERT_FILE "../certs/client-cert.der" |
29 | 30 | #define KEY_FILE "../certs/client-key.der" |
30 | 31 | #define KEYPUB_FILE "../certs/client-keyPub.der" |
| 32 | +#else |
| 33 | +#define CERT_FILE "../certs/client-ecc-cert.der" |
| 34 | +#define KEY_FILE "../certs/ecc-client-key.der" |
| 35 | +#define KEYPUB_FILE "../certs/ecc-client-keyPub.der" |
| 36 | +#endif |
| 37 | + |
31 | 38 | #define encodedFileNoAttrs "signedData_cryptocb_noattrs.der" |
32 | 39 | #define encodedFileAttrs "signedData_cryptocb_attrs.der" |
33 | 40 |
|
@@ -372,16 +379,13 @@ static int myCryptoCb(int devIdArg, wc_CryptoInfo* info, void* ctx) |
372 | 379 | return ret; |
373 | 380 | } |
374 | 381 | ret = wc_RsaPrivateKeyDecode(der, &idx, &rsaPriv, derSz); |
375 | | - if (ret != 0) { |
376 | | - wc_FreeRsaKey(&rsaPriv); |
377 | | - return ret; |
| 382 | + if (ret == 0) { |
| 383 | + /* perform software based RSA private op */ |
| 384 | + ret = wc_RsaFunction( |
| 385 | + info->pk.rsa.in, info->pk.rsa.inLen, |
| 386 | + info->pk.rsa.out, info->pk.rsa.outLen, |
| 387 | + info->pk.rsa.type, &rsaPriv, info->pk.rsa.rng); |
378 | 388 | } |
379 | | - |
380 | | - /* perform software based RSA private op */ |
381 | | - ret = wc_RsaFunction( |
382 | | - info->pk.rsa.in, info->pk.rsa.inLen, |
383 | | - info->pk.rsa.out, info->pk.rsa.outLen, |
384 | | - info->pk.rsa.type, &rsaPriv, info->pk.rsa.rng); |
385 | 389 | wc_FreeRsaKey(&rsaPriv); |
386 | 390 | if (der != NULL) |
387 | 391 | free(der); |
@@ -413,16 +417,31 @@ static int myCryptoCb(int devIdArg, wc_CryptoInfo* info, void* ctx) |
413 | 417 | info->pk.eckg.key->devId = devIdArg; |
414 | 418 | } |
415 | 419 | else if (info->pk.type == WC_PK_TYPE_ECDSA_SIGN) { |
416 | | - /* set devId to invalid, so software is used */ |
417 | | - info->pk.eccsign.key->devId = INVALID_DEVID; |
418 | | - |
419 | | - ret = wc_ecc_sign_hash( |
420 | | - info->pk.eccsign.in, info->pk.eccsign.inlen, |
421 | | - info->pk.eccsign.out, info->pk.eccsign.outlen, |
422 | | - info->pk.eccsign.rng, info->pk.eccsign.key); |
| 420 | + ecc_key eccPriv; |
| 421 | + byte* der = NULL; |
| 422 | + size_t derSz = 0; |
| 423 | + word32 idx = 0; |
| 424 | + |
| 425 | + ret = load_file(myCtx->keyFilePriv, &der, &derSz); |
| 426 | + if (ret != 0) { |
| 427 | + printf("Error %d loading %s\n", ret, myCtx->keyFilePriv); |
| 428 | + return ret; |
| 429 | + } |
423 | 430 |
|
424 | | - /* reset devId */ |
425 | | - info->pk.eccsign.key->devId = devIdArg; |
| 431 | + ret = wc_ecc_init_ex(&eccPriv, NULL, INVALID_DEVID); |
| 432 | + if (ret != 0) { |
| 433 | + return ret; |
| 434 | + } |
| 435 | + ret = wc_EccPrivateKeyDecode(der, &idx, &eccPriv, derSz); |
| 436 | + if (ret == 0) { |
| 437 | + ret = wc_ecc_sign_hash( |
| 438 | + info->pk.eccsign.in, info->pk.eccsign.inlen, |
| 439 | + info->pk.eccsign.out, info->pk.eccsign.outlen, |
| 440 | + info->pk.eccsign.rng, &eccPriv); |
| 441 | + } |
| 442 | + wc_ecc_free(&eccPriv); |
| 443 | + if (der != NULL) |
| 444 | + free(der); |
426 | 445 | } |
427 | 446 | else if (info->pk.type == WC_PK_TYPE_ECDSA_VERIFY) { |
428 | 447 | /* set devId to invalid, so software is used */ |
|
0 commit comments