Fix to keep existing behavior where AAD is optional for wc_ChaCha20Poly1305_Encrypt and wc_ChaCha20Poly1305_Decrypt.

This commit is contained in:
David Garske
2020-01-07 18:58:26 -08:00
parent 56e57f3216
commit bc1cb4ead8
2 changed files with 6 additions and 3 deletions

View File

@ -176,7 +176,7 @@ int wc_ChaCha20Poly1305_UpdateAad(ChaChaPoly_Aead* aead,
{
int ret = 0;
if (aead == NULL || inAAD == NULL) {
if (aead == NULL || (inAAD == NULL && inAADLen > 0)) {
return BAD_FUNC_ARG;
}
if (aead->state != CHACHA20_POLY1305_STATE_READY &&
@ -184,7 +184,7 @@ int wc_ChaCha20Poly1305_UpdateAad(ChaChaPoly_Aead* aead,
return BAD_STATE_E;
}
if (inAADLen > 0) {
if (inAAD && inAADLen > 0) {
ret = wc_Poly1305Update(&aead->poly, inAAD, inAADLen);
if (ret == 0) {
aead->aadLen += inAADLen;
@ -218,7 +218,7 @@ int wc_ChaCha20Poly1305_UpdateData(ChaChaPoly_Aead* aead,
/* advance state */
aead->state = CHACHA20_POLY1305_STATE_DATA;
/* Perform ChaCha20 encrypt or decrypt inline and Poly1305 auth calc */
/* Perform ChaCha20 encrypt/decrypt and Poly1305 auth calc */
if (ret == 0) {
if (aead->isEncrypt) {
ret = wc_Chacha_Process(&aead->chacha, outData, inData, dataLen);

View File

@ -770,6 +770,9 @@ int wc_Poly1305_Pad(Poly1305* ctx, word32 lenToPad)
if (ctx == NULL) {
return BAD_FUNC_ARG;
}
if (lenToPad == 0) {
return 0; /* nothing needs to be done */
}
XMEMSET(padding, 0, sizeof(padding));