diff --git a/wolfcrypt/src/aes.c b/wolfcrypt/src/aes.c index 145078b1bd..b2053c8318 100644 --- a/wolfcrypt/src/aes.c +++ b/wolfcrypt/src/aes.c @@ -2210,6 +2210,11 @@ static void wc_AesDecrypt(Aes* aes, const byte* inBlock, byte* outBlock) XMEMCPY(aes->asyncIv, iv, AES_BLOCK_SIZE); } #endif /* WOLFSSL_ASYNC_CRYPT */ + #ifdef WOLF_CRYPTO_DEV + if (aes->devId != INVALID_DEVID) { + XMEMCPY(aes->devKey, userKey, keylen); + } + #endif #ifdef WOLFSSL_AESNI if (checkAESNI == 0) { diff --git a/wolfcrypt/src/cryptodev.c b/wolfcrypt/src/cryptodev.c index af3e3b38ca..2edaf74daf 100644 --- a/wolfcrypt/src/cryptodev.c +++ b/wolfcrypt/src/cryptodev.c @@ -59,8 +59,9 @@ static CryptoDev* wc_CryptoDev_FindDevice(int devId) void wc_CryptoDev_Init(void) { int i; - for (i=0; icb(aes->devId, &cryptoInfo, dev->ctx); } @@ -374,10 +375,10 @@ int wc_CryptoDev_AesCbcDecrypt(Aes* aes, byte* out, cryptoInfo.algo_type = WC_ALGO_TYPE_CIPHER; cryptoInfo.cipher.type = WC_CIPHER_AES_CBC; cryptoInfo.cipher.enc = 0; - cryptoInfo.cipher.aescbc_dec.aes = aes; - cryptoInfo.cipher.aescbc_dec.out = out; - cryptoInfo.cipher.aescbc_dec.in = in; - cryptoInfo.cipher.aescbc_dec.sz = sz; + cryptoInfo.cipher.aescbc.aes = aes; + cryptoInfo.cipher.aescbc.out = out; + cryptoInfo.cipher.aescbc.in = in; + cryptoInfo.cipher.aescbc.sz = sz; ret = dev->cb(aes->devId, &cryptoInfo, dev->ctx); } diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 91d75f5b32..6f1274b541 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -22977,29 +22977,29 @@ static int myCryptoDevCb(int devIdArg, wc_CryptoInfo* info, void* ctx) if (info->cipher.type == WC_CIPHER_AES_CBC) { if (info->cipher.enc) { /* set devId to invalid, so software is used */ - info->cipher.aescbc_enc.aes->devId = INVALID_DEVID; + info->cipher.aescbc.aes->devId = INVALID_DEVID; ret = wc_AesCbcEncrypt( - info->cipher.aescbc_enc.aes, - info->cipher.aescbc_enc.out, - info->cipher.aescbc_enc.in, - info->cipher.aescbc_enc.sz); + info->cipher.aescbc.aes, + info->cipher.aescbc.out, + info->cipher.aescbc.in, + info->cipher.aescbc.sz); /* reset devId */ - info->cipher.aescbc_enc.aes->devId = devIdArg; + info->cipher.aescbc.aes->devId = devIdArg; } else { /* set devId to invalid, so software is used */ - info->cipher.aescbc_dec.aes->devId = INVALID_DEVID; + info->cipher.aescbc.aes->devId = INVALID_DEVID; ret = wc_AesCbcDecrypt( - info->cipher.aescbc_dec.aes, - info->cipher.aescbc_dec.out, - info->cipher.aescbc_dec.in, - info->cipher.aescbc_dec.sz); + info->cipher.aescbc.aes, + info->cipher.aescbc.out, + info->cipher.aescbc.in, + info->cipher.aescbc.sz); /* reset devId */ - info->cipher.aescbc_dec.aes->devId = devIdArg; + info->cipher.aescbc.aes->devId = devIdArg; } } #endif /* HAVE_AES_CBC */ diff --git a/wolfssl/wolfcrypt/aes.h b/wolfssl/wolfcrypt/aes.h index 2c42c493ce..b2119feb6b 100644 --- a/wolfssl/wolfcrypt/aes.h +++ b/wolfssl/wolfcrypt/aes.h @@ -151,7 +151,8 @@ typedef struct Aes { byte use_aesni; #endif /* WOLFSSL_AESNI */ #ifdef WOLF_CRYPTO_DEV - int devId; + int devId; + word32 devKey[AES_MAX_KEY_SIZE/WOLFSSL_BIT_SIZE/sizeof(word32)]; /* raw key */ #endif #ifdef HAVE_PKCS11 byte id[AES_MAX_ID_LEN]; diff --git a/wolfssl/wolfcrypt/cryptodev.h b/wolfssl/wolfcrypt/cryptodev.h index 993b1cf8a5..d27161d616 100644 --- a/wolfssl/wolfcrypt/cryptodev.h +++ b/wolfssl/wolfcrypt/cryptodev.h @@ -142,13 +142,7 @@ typedef struct wc_CryptoInfo { byte* out; const byte* in; word32 sz; - } aescbc_enc; - struct { - Aes* aes; - byte* out; - const byte* in; - word32 sz; - } aescbc_dec; + } aescbc; #endif /* HAVE_AES_CBC */ }; } cipher; diff --git a/wolfssl/wolfcrypt/sha.h b/wolfssl/wolfcrypt/sha.h index 13b7f635cc..63ecff29c2 100644 --- a/wolfssl/wolfcrypt/sha.h +++ b/wolfssl/wolfcrypt/sha.h @@ -124,7 +124,8 @@ typedef struct wc_Sha { WC_ASYNC_DEV asyncDev; #endif /* WOLFSSL_ASYNC_CRYPT */ #ifdef WOLF_CRYPTO_DEV - int devId; + int devId; + void* devCtx; /* generic crypto callback context */ #endif #endif #if defined(WOLFSSL_ESP32WROOM32_CRYPT) && \ diff --git a/wolfssl/wolfcrypt/sha256.h b/wolfssl/wolfcrypt/sha256.h index 4fed79d64c..1d91d4ae38 100644 --- a/wolfssl/wolfcrypt/sha256.h +++ b/wolfssl/wolfcrypt/sha256.h @@ -159,7 +159,8 @@ typedef struct wc_Sha256 { WC_ESP32SHA ctx; #endif #ifdef WOLF_CRYPTO_DEV - int devId; + int devId; + void* devCtx; /* generic crypto callback context */ #endif #endif } wc_Sha256;