Add ECC support to PKCS7 crypto callback example.
parent
6a34cb5d0c
commit
a944dfb8ef
|
@ -25,9 +25,16 @@
|
||||||
#include <wolfssl/wolfcrypt/logging.h>
|
#include <wolfssl/wolfcrypt/logging.h>
|
||||||
#include <wolfssl/wolfcrypt/cryptocb.h>
|
#include <wolfssl/wolfcrypt/cryptocb.h>
|
||||||
|
|
||||||
|
#if 0
|
||||||
#define CERT_FILE "../certs/client-cert.der"
|
#define CERT_FILE "../certs/client-cert.der"
|
||||||
#define KEY_FILE "../certs/client-key.der"
|
#define KEY_FILE "../certs/client-key.der"
|
||||||
#define KEYPUB_FILE "../certs/client-keyPub.der"
|
#define KEYPUB_FILE "../certs/client-keyPub.der"
|
||||||
|
#else
|
||||||
|
#define CERT_FILE "../certs/client-ecc-cert.der"
|
||||||
|
#define KEY_FILE "../certs/ecc-client-key.der"
|
||||||
|
#define KEYPUB_FILE "../certs/ecc-client-keyPub.der"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define encodedFileNoAttrs "signedData_cryptocb_noattrs.der"
|
#define encodedFileNoAttrs "signedData_cryptocb_noattrs.der"
|
||||||
#define encodedFileAttrs "signedData_cryptocb_attrs.der"
|
#define encodedFileAttrs "signedData_cryptocb_attrs.der"
|
||||||
|
|
||||||
|
@ -372,16 +379,13 @@ static int myCryptoCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
ret = wc_RsaPrivateKeyDecode(der, &idx, &rsaPriv, derSz);
|
ret = wc_RsaPrivateKeyDecode(der, &idx, &rsaPriv, derSz);
|
||||||
if (ret != 0) {
|
if (ret == 0) {
|
||||||
wc_FreeRsaKey(&rsaPriv);
|
/* perform software based RSA private op */
|
||||||
return ret;
|
ret = wc_RsaFunction(
|
||||||
|
info->pk.rsa.in, info->pk.rsa.inLen,
|
||||||
|
info->pk.rsa.out, info->pk.rsa.outLen,
|
||||||
|
info->pk.rsa.type, &rsaPriv, info->pk.rsa.rng);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* perform software based RSA private op */
|
|
||||||
ret = wc_RsaFunction(
|
|
||||||
info->pk.rsa.in, info->pk.rsa.inLen,
|
|
||||||
info->pk.rsa.out, info->pk.rsa.outLen,
|
|
||||||
info->pk.rsa.type, &rsaPriv, info->pk.rsa.rng);
|
|
||||||
wc_FreeRsaKey(&rsaPriv);
|
wc_FreeRsaKey(&rsaPriv);
|
||||||
if (der != NULL)
|
if (der != NULL)
|
||||||
free(der);
|
free(der);
|
||||||
|
@ -413,16 +417,31 @@ static int myCryptoCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
|
||||||
info->pk.eckg.key->devId = devIdArg;
|
info->pk.eckg.key->devId = devIdArg;
|
||||||
}
|
}
|
||||||
else if (info->pk.type == WC_PK_TYPE_ECDSA_SIGN) {
|
else if (info->pk.type == WC_PK_TYPE_ECDSA_SIGN) {
|
||||||
/* set devId to invalid, so software is used */
|
ecc_key eccPriv;
|
||||||
info->pk.eccsign.key->devId = INVALID_DEVID;
|
byte* der = NULL;
|
||||||
|
size_t derSz = 0;
|
||||||
|
word32 idx = 0;
|
||||||
|
|
||||||
ret = wc_ecc_sign_hash(
|
ret = load_file(myCtx->keyFilePriv, &der, &derSz);
|
||||||
info->pk.eccsign.in, info->pk.eccsign.inlen,
|
if (ret != 0) {
|
||||||
info->pk.eccsign.out, info->pk.eccsign.outlen,
|
printf("Error %d loading %s\n", ret, myCtx->keyFilePriv);
|
||||||
info->pk.eccsign.rng, info->pk.eccsign.key);
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/* reset devId */
|
ret = wc_ecc_init_ex(&eccPriv, NULL, INVALID_DEVID);
|
||||||
info->pk.eccsign.key->devId = devIdArg;
|
if (ret != 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
ret = wc_EccPrivateKeyDecode(der, &idx, &eccPriv, derSz);
|
||||||
|
if (ret == 0) {
|
||||||
|
ret = wc_ecc_sign_hash(
|
||||||
|
info->pk.eccsign.in, info->pk.eccsign.inlen,
|
||||||
|
info->pk.eccsign.out, info->pk.eccsign.outlen,
|
||||||
|
info->pk.eccsign.rng, &eccPriv);
|
||||||
|
}
|
||||||
|
wc_ecc_free(&eccPriv);
|
||||||
|
if (der != NULL)
|
||||||
|
free(der);
|
||||||
}
|
}
|
||||||
else if (info->pk.type == WC_PK_TYPE_ECDSA_VERIFY) {
|
else if (info->pk.type == WC_PK_TYPE_ECDSA_VERIFY) {
|
||||||
/* set devId to invalid, so software is used */
|
/* set devId to invalid, so software is used */
|
||||||
|
|
Loading…
Reference in New Issue