return value on AES CCM encrypt

This commit is contained in:
Jacob Barthelmeh 2015-10-02 11:40:47 -06:00
parent 08771518a7
commit 10276944d3
5 changed files with 21 additions and 8 deletions

View File

@ -5895,13 +5895,15 @@ static INLINE int Encrypt(WOLFSSL* ssl, byte* out, const byte* input, word16 sz)
ssl->keys.aead_enc_imp_IV, AEAD_IMP_IV_SZ);
XMEMCPY(nonce + AEAD_IMP_IV_SZ,
ssl->keys.aead_exp_IV, AEAD_EXP_IV_SZ);
wc_AesCcmEncrypt(ssl->encrypt.aes,
ret = wc_AesCcmEncrypt(ssl->encrypt.aes,
out + AEAD_EXP_IV_SZ, input + AEAD_EXP_IV_SZ,
sz - AEAD_EXP_IV_SZ - ssl->specs.aead_mac_size,
nonce, AEAD_NONCE_SZ,
out + sz - ssl->specs.aead_mac_size,
ssl->specs.aead_mac_size,
additional, AEAD_AUTH_DATA_SZ);
if (ret != 0)
return ret;
AeadIncrementExpIV(ssl);
ForceZero(nonce, AEAD_NONCE_SZ);
}

View File

@ -134,13 +134,19 @@ void wc_AesCcmSetKey(Aes* aes, const byte* key, word32 keySz)
}
void wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
int wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
const byte* nonce, word32 nonceSz,
byte* authTag, word32 authTagSz,
const byte* authIn, word32 authInSz)
{
/* sanity check on arugments */
if (aes == NULL || out == NULL || in == NULL || nonce == NULL
|| authTag == NULL || nonceSz < 7 || nonceSz > 13)
return BAD_FUNC_ARG;
AesCcmEncrypt(aes, out, in, inSz, nonce, nonceSz, authTag, authTagSz,
authIn, authInSz);
return 0;
}
@ -3556,7 +3562,8 @@ static INLINE void AesCcmCtrInc(byte* B, word32 lenSz)
}
void wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
/* return 0 on success */
int wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
const byte* nonce, word32 nonceSz,
byte* authTag, word32 authTagSz,
const byte* authIn, word32 authInSz)
@ -3575,7 +3582,7 @@ void wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
/* sanity check on arugments */
if (aes == NULL || out == NULL || in == NULL || nonce == NULL
|| authTag == NULL || nonceSz < 7 || nonceSz > 13)
return;
return BAD_FUNC_ARG;
#ifdef FREESCALE_MMCAU
key = (byte*)aes->key;
@ -3640,6 +3647,8 @@ void wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
ForceZero(A, AES_BLOCK_SIZE);
ForceZero(B, AES_BLOCK_SIZE);
return 0;
}

View File

@ -522,12 +522,12 @@ WOLFSSL_API void wc_AesCcmSetKey(Aes* aes, const byte* key, word32 keySz)
AesAuthSetKey(aes, key, keySz) ;
}
WOLFSSL_API void wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
WOLFSSL_API int wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
const byte* nonce, word32 nonceSz,
byte* authTag, word32 authTagSz,
const byte* authIn, word32 authInSz)
{
AesAuthEncrypt(aes, out, in, inSz, nonce, nonceSz, authTag, authTagSz,
return AesAuthEncrypt(aes, out, in, inSz, nonce, nonceSz, authTag, authTagSz,
authIn, authInSz, AES_CFG_MODE_CCM) ;
}

View File

@ -2955,8 +2955,10 @@ int aesccm_test(void)
wc_AesCcmSetKey(&enc, k, sizeof(k));
/* AES-CCM encrypt and decrypt both use AES encrypt internally */
wc_AesCcmEncrypt(&enc, c2, p, sizeof(c2), iv, sizeof(iv),
result = wc_AesCcmEncrypt(&enc, c2, p, sizeof(c2), iv, sizeof(iv),
t2, sizeof(t2), a, sizeof(a));
if (result != 0)
return -106;
if (memcmp(c, c2, sizeof(c2)))
return -107;
if (memcmp(t, t2, sizeof(t2)))

View File

@ -166,7 +166,7 @@ WOLFSSL_API int wc_AesCbcDecrypt(Aes* aes, byte* out,
#endif /* HAVE_AESGCM */
#ifdef HAVE_AESCCM
WOLFSSL_API void wc_AesCcmSetKey(Aes* aes, const byte* key, word32 keySz);
WOLFSSL_API void wc_AesCcmEncrypt(Aes* aes, byte* out,
WOLFSSL_API int wc_AesCcmEncrypt(Aes* aes, byte* out,
const byte* in, word32 inSz,
const byte* nonce, word32 nonceSz,
byte* authTag, word32 authTagSz,