Added crypto callback support for AES CCM.

This commit is contained in:
David Garske
2021-11-02 09:53:55 -07:00
parent 7e01af0121
commit 82c106be80
4 changed files with 145 additions and 1 deletions
+20
View File
@@ -9938,6 +9938,16 @@ int wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
return BAD_FUNC_ARG;
}
#ifdef WOLF_CRYPTO_CB
if (aes->devId != INVALID_DEVID) {
int ret = wc_CryptoCb_AesCcmEncrypt(aes, out, in, inSz, nonce, nonceSz,
authTag, authTagSz, authIn, authInSz);
if (ret != CRYPTOCB_UNAVAILABLE)
return ret;
/* fall-through when unavailable */
}
#endif
XMEMSET(A, 0, sizeof(A));
XMEMCPY(B+1, nonce, nonceSz);
lenSz = AES_BLOCK_SIZE - 1 - (byte)nonceSz;
@@ -10040,6 +10050,16 @@ int wc_AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
return BAD_FUNC_ARG;
}
#ifdef WOLF_CRYPTO_CB
if (aes->devId != INVALID_DEVID) {
int ret = wc_CryptoCb_AesCcmDecrypt(aes, out, in, inSz, nonce, nonceSz,
authTag, authTagSz, authIn, authInSz);
if (ret != CRYPTOCB_UNAVAILABLE)
return ret;
/* fall-through when unavailable */
}
#endif
o = out;
oSz = inSz;
XMEMSET(A, 0, sizeof A);
+84
View File
@@ -578,6 +578,90 @@ int wc_CryptoCb_AesGcmDecrypt(Aes* aes, byte* out,
}
#endif /* HAVE_AESGCM */
#ifdef HAVE_AESCCM
int wc_CryptoCb_AesCcmEncrypt(Aes* aes, byte* out,
const byte* in, word32 sz,
const byte* nonce, word32 nonceSz,
byte* authTag, word32 authTagSz,
const byte* authIn, word32 authInSz)
{
int ret = CRYPTOCB_UNAVAILABLE;
CryptoCb* dev;
/* locate registered callback */
if (aes) {
dev = wc_CryptoCb_FindDevice(aes->devId);
}
else {
/* locate first callback and try using it */
dev = wc_CryptoCb_FindDeviceByIndex(0);
}
if (dev && dev->cb) {
wc_CryptoInfo cryptoInfo;
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
cryptoInfo.algo_type = WC_ALGO_TYPE_CIPHER;
cryptoInfo.cipher.type = WC_CIPHER_AES_CCM;
cryptoInfo.cipher.enc = 1;
cryptoInfo.cipher.aesccm_enc.aes = aes;
cryptoInfo.cipher.aesccm_enc.out = out;
cryptoInfo.cipher.aesccm_enc.in = in;
cryptoInfo.cipher.aesccm_enc.sz = sz;
cryptoInfo.cipher.aesccm_enc.nonce = nonce;
cryptoInfo.cipher.aesccm_enc.nonceSz = nonceSz;
cryptoInfo.cipher.aesccm_enc.authTag = authTag;
cryptoInfo.cipher.aesccm_enc.authTagSz = authTagSz;
cryptoInfo.cipher.aesccm_enc.authIn = authIn;
cryptoInfo.cipher.aesccm_enc.authInSz = authInSz;
ret = dev->cb(dev->devId, &cryptoInfo, dev->ctx);
}
return wc_CryptoCb_TranslateErrorCode(ret);
}
int wc_CryptoCb_AesCcmDecrypt(Aes* aes, byte* out,
const byte* in, word32 sz,
const byte* nonce, word32 nonceSz,
const byte* authTag, word32 authTagSz,
const byte* authIn, word32 authInSz)
{
int ret = CRYPTOCB_UNAVAILABLE;
CryptoCb* dev;
/* locate registered callback */
if (aes) {
dev = wc_CryptoCb_FindDevice(aes->devId);
}
else {
/* locate first callback and try using it */
dev = wc_CryptoCb_FindDeviceByIndex(0);
}
if (dev && dev->cb) {
wc_CryptoInfo cryptoInfo;
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
cryptoInfo.algo_type = WC_ALGO_TYPE_CIPHER;
cryptoInfo.cipher.type = WC_CIPHER_AES_CCM;
cryptoInfo.cipher.enc = 0;
cryptoInfo.cipher.aesccm_dec.aes = aes;
cryptoInfo.cipher.aesccm_dec.out = out;
cryptoInfo.cipher.aesccm_dec.in = in;
cryptoInfo.cipher.aesccm_dec.sz = sz;
cryptoInfo.cipher.aesccm_enc.nonce = nonce;
cryptoInfo.cipher.aesccm_enc.nonceSz = nonceSz;
cryptoInfo.cipher.aesccm_dec.authTag = authTag;
cryptoInfo.cipher.aesccm_dec.authTagSz = authTagSz;
cryptoInfo.cipher.aesccm_dec.authIn = authIn;
cryptoInfo.cipher.aesccm_dec.authInSz = authInSz;
ret = dev->cb(dev->devId, &cryptoInfo, dev->ctx);
}
return wc_CryptoCb_TranslateErrorCode(ret);
}
#endif /* HAVE_AESCCM */
#ifdef HAVE_AES_CBC
int wc_CryptoCb_AesCbcEncrypt(Aes* aes, byte* out,
const byte* in, word32 sz)