# HG changeset patch # User Olaf Wintermann # Date 1575470938 -3600 # Node ID ce253cfb91277883ad99ba82d14b541861241cae # Parent b1f7d83f6e6916e22822fafc5e763d781e5fe298 fix aes encrypter stream (cng) diff -r b1f7d83f6e69 -r ce253cfb9127 libidav/crypto.c --- a/libidav/crypto.c Wed Dec 04 15:18:15 2019 +0100 +++ b/libidav/crypto.c Wed Dec 04 15:48:58 2019 +0100 @@ -1205,7 +1205,11 @@ } size_t remaining = len % 16; - len -= remaining; + len -= remaining; + + if(len > 256) { + len -= 16; // optimization for avoiding tmp buffer usage + } size_t inalloc = len; ULONG inlen = 0; @@ -1234,7 +1238,12 @@ char *out = malloc(outalloc); // encrypt - if(BCryptEncrypt(enc->ctx.hKey, in, inlen, NULL, enc->ctx.pbIV, 16, out, outalloc, &outlen, BCRYPT_BLOCK_PADDING)) { + int flags = 0; + if(inlen % 16 != 0) { + flags = BCRYPT_BLOCK_PADDING; + enc->end = 1; + } + if(BCryptEncrypt(enc->ctx.hKey, in, inlen, NULL, enc->ctx.pbIV, 16, out, outalloc, &outlen, flags)) { fprintf(stderr, "Error: BCryptEncrypt failed\n"); }