Fixes and improvements to the new Crypto callback code for AES and Hashing.

This commit is contained in:
David Garske
2019-01-09 17:39:05 -08:00
parent ba0d488807
commit ebc9533bc7
7 changed files with 34 additions and 31 deletions
+5
View File
@@ -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) {
+10 -9
View File
@@ -59,8 +59,9 @@ static CryptoDev* wc_CryptoDev_FindDevice(int devId)
void wc_CryptoDev_Init(void)
{
int i;
for (i=0; i<MAX_CRYPTO_DEVICES; i++)
for (i=0; i<MAX_CRYPTO_DEVICES; i++) {
gCryptoDev[i].devId = INVALID_DEVID;
}
}
int wc_CryptoDev_RegisterDevice(int devId, CryptoDevCallbackFunc cb, void* ctx)
@@ -347,10 +348,10 @@ int wc_CryptoDev_AesCbcEncrypt(Aes* aes, byte* out,
cryptoInfo.algo_type = WC_ALGO_TYPE_CIPHER;
cryptoInfo.cipher.type = WC_CIPHER_AES_CBC;
cryptoInfo.cipher.enc = 1;
cryptoInfo.cipher.aescbc_enc.aes = aes;
cryptoInfo.cipher.aescbc_enc.out = out;
cryptoInfo.cipher.aescbc_enc.in = in;
cryptoInfo.cipher.aescbc_enc.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);
}
@@ -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);
}
+12 -12
View File
@@ -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 */
+2 -1
View File
@@ -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];
+1 -7
View File
@@ -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;
+2 -1
View File
@@ -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) && \
+2 -1
View File
@@ -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;