if(!oneshot)
return false;
- size_t reqlen = ((inlen + 8) / cipher->blklen) * cipher->blklen;
+ size_t reqlen = ((inlen + cipher->blklen) / cipher->blklen) * cipher->blklen;
+
+ if(*outlen < reqlen) {
+ logger(LOG_ERR, "Error while encrypting: not enough room for padding");
+ return false;
+ }
+
uint8_t padbyte = reqlen - inlen;
inlen = reqlen - cipher->blklen;
}
*outlen = origlen;
- }
+ } else
+ *outlen = inlen;
return true;
}