Wed, 05 Sep 2018 07:02:04 +0200
aes encrypter: fixes case where EVP_EncryptFinal_ex was not called at the stream end
libidav/crypto.c | file | annotate | diff | comparison | revisions |
--- a/libidav/crypto.c Sat Aug 25 15:12:38 2018 +0200 +++ b/libidav/crypto.c Wed Sep 05 07:02:04 2018 +0200 @@ -197,18 +197,22 @@ int outlen = 0; size_t ivl = enc->ivlen; if(in_len != 0) { - outlen = len + 16; + outlen = len + 32; out = malloc(outlen + ivl); if(enc->iv) { memcpy(out, enc->iv, ivl); } EVP_EncryptUpdate(enc->ctx, out + ivl, &outlen, in, in_len); - free(in); + if(in_len != len) { + int newoutlen = 16; + EVP_EncryptFinal_ex(enc->ctx, out + ivl + outlen, &newoutlen); + outlen += newoutlen; + enc->end = 1; + } } else { out = malloc(16); EVP_EncryptFinal_ex(enc->ctx, out, &outlen); enc->end = 1; - free(in); } enc->tmp = (char*)out; enc->tmplen = outlen + ivl; @@ -220,6 +224,8 @@ enc->ivlen = 0; } + free(in); + return aes_read(buf, s, n, enc); }