1232 ULONG outalloc = inlen + 16; |
1236 ULONG outalloc = inlen + 16; |
1233 ULONG outlen = 0; |
1237 ULONG outlen = 0; |
1234 char *out = malloc(outalloc); |
1238 char *out = malloc(outalloc); |
1235 |
1239 |
1236 // encrypt |
1240 // encrypt |
1237 if(BCryptEncrypt(enc->ctx.hKey, in, inlen, NULL, enc->ctx.pbIV, 16, out, outalloc, &outlen, BCRYPT_BLOCK_PADDING)) { |
1241 int flags = 0; |
|
1242 if(inlen % 16 != 0) { |
|
1243 flags = BCRYPT_BLOCK_PADDING; |
|
1244 enc->end = 1; |
|
1245 } |
|
1246 if(BCryptEncrypt(enc->ctx.hKey, in, inlen, NULL, enc->ctx.pbIV, 16, out, outalloc, &outlen, flags)) { |
1238 fprintf(stderr, "Error: BCryptEncrypt failed\n"); |
1247 fprintf(stderr, "Error: BCryptEncrypt failed\n"); |
1239 } |
1248 } |
1240 |
1249 |
1241 // check if the output fits in buf, if not, save the remaining bytes in tmp |
1250 // check if the output fits in buf, if not, save the remaining bytes in tmp |
1242 if(outlen > len) { |
1251 if(outlen > len) { |