123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- #ifdef HAVE_CONFIG_H
- #include <config.h>
- #endif
- #ifndef WOLFSSL_USER_SETTINGS
- #include <wolfssl/options.h>
- #endif
- #include <wolfssl/ssl.h>
- #include <wolfssl/wolfio.h>
- #include <wolfssl/wolfcrypt/error-crypt.h>
- #include "examples/async/async_tls.h"
- #ifdef WOLF_CRYPTO_CB
- #ifndef TEST_PEND_COUNT
- #define TEST_PEND_COUNT 2
- #endif
- int AsyncTlsCryptoCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
- {
- int ret = WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE);
- AsyncTlsCryptoCbCtx* myCtx = (AsyncTlsCryptoCbCtx*)ctx;
- if (info == NULL)
- return BAD_FUNC_ARG;
- #ifdef DEBUG_CRYPTOCB
- wc_CryptoCb_InfoString(info);
- #endif
- if (info->algo_type == WC_ALGO_TYPE_PK) {
- #ifdef WOLFSSL_ASYNC_CRYPT
-
- if (info->pk.type == WC_PK_TYPE_RSA ||
- info->pk.type == WC_PK_TYPE_EC_KEYGEN ||
- info->pk.type == WC_PK_TYPE_ECDSA_SIGN ||
- info->pk.type == WC_PK_TYPE_ECDSA_VERIFY ||
- info->pk.type == WC_PK_TYPE_ECDH)
- {
- if (myCtx->pendingCount++ < TEST_PEND_COUNT) return WC_PENDING_E;
- myCtx->pendingCount = 0;
- }
- #endif
- #ifndef NO_RSA
- if (info->pk.type == WC_PK_TYPE_RSA) {
-
- info->pk.rsa.key->devId = INVALID_DEVID;
- switch (info->pk.rsa.type) {
- case RSA_PUBLIC_ENCRYPT:
- case RSA_PUBLIC_DECRYPT:
-
- ret = wc_RsaFunction(
- info->pk.rsa.in, info->pk.rsa.inLen,
- info->pk.rsa.out, info->pk.rsa.outLen,
- info->pk.rsa.type, info->pk.rsa.key, info->pk.rsa.rng);
- break;
- case RSA_PRIVATE_ENCRYPT:
- case RSA_PRIVATE_DECRYPT:
-
- ret = wc_RsaFunction(
- info->pk.rsa.in, info->pk.rsa.inLen,
- info->pk.rsa.out, info->pk.rsa.outLen,
- info->pk.rsa.type, info->pk.rsa.key, info->pk.rsa.rng);
- break;
- }
-
- info->pk.rsa.key->devId = devIdArg;
- }
- #endif
- #ifdef HAVE_ECC
- if (info->pk.type == WC_PK_TYPE_EC_KEYGEN) {
-
- info->pk.eckg.key->devId = INVALID_DEVID;
- ret = wc_ecc_make_key_ex(info->pk.eckg.rng, info->pk.eckg.size,
- info->pk.eckg.key, info->pk.eckg.curveId);
-
- info->pk.eckg.key->devId = devIdArg;
- }
- else if (info->pk.type == WC_PK_TYPE_ECDSA_SIGN) {
-
- info->pk.eccsign.key->devId = INVALID_DEVID;
- 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, info->pk.eccsign.key);
-
- info->pk.eccsign.key->devId = devIdArg;
- }
- else if (info->pk.type == WC_PK_TYPE_ECDSA_VERIFY) {
-
- info->pk.eccverify.key->devId = INVALID_DEVID;
- ret = wc_ecc_verify_hash(
- info->pk.eccverify.sig, info->pk.eccverify.siglen,
- info->pk.eccverify.hash, info->pk.eccverify.hashlen,
- info->pk.eccverify.res, info->pk.eccverify.key);
-
- info->pk.eccverify.key->devId = devIdArg;
- }
- else if (info->pk.type == WC_PK_TYPE_ECDH) {
-
- info->pk.ecdh.private_key->devId = INVALID_DEVID;
- ret = wc_ecc_shared_secret(
- info->pk.ecdh.private_key, info->pk.ecdh.public_key,
- info->pk.ecdh.out, info->pk.ecdh.outlen);
-
- info->pk.ecdh.private_key->devId = devIdArg;
- }
- #endif
- }
- (void)devIdArg;
- (void)myCtx;
- return ret;
- }
- #endif
- #ifdef HAVE_PK_CALLBACKS
- #endif
|