aes encrypter: fixes case where EVP_EncryptFinal_ex was not called at the stream end

Wed, 05 Sep 2018 07:02:04 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 05 Sep 2018 07:02:04 +0200
changeset 459
2c112cbaa08e
parent 458
295eaa04fc41
child 460
22522ff52a62

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);
 }
 

mercurial