Consolidate cbc padding into a macro.

This commit is contained in:
Con Kolivas 2011-03-16 10:17:48 +11:00
parent ddcc45ebf0
commit bedea4dbec

View file

@ -58,6 +58,8 @@
#define STREAM_BUFSIZE (1024 * 1024 * 10)
#define CBC_PAD(LEN) ((LEN % CBC_LEN) ? (CBC_LEN - (LEN % CBC_LEN)) : 0)
static struct compress_thread{
uchar *s_buf; /* Uncompressed buffer -> Compressed buffer */
uchar c_type; /* Compression type */
@ -1174,8 +1176,7 @@ retry:
/* We must pad the block length to a mutliple of CBC_LEN to be
* able to encrypt. We pad it with random data */
if (cti->c_len % CBC_LEN)
encrypt_pad = CBC_LEN - (cti->c_len % CBC_LEN);
encrypt_pad = CBC_PAD(cti->c_len);
padded_len = cti->c_len + encrypt_pad;
if (encrypt_pad)
get_rand(cti->s_buf + cti->c_len, encrypt_pad);
@ -1298,7 +1299,7 @@ static void clear_buffer(rzip_control *control, struct stream_info *sinfo, int s
/* The stream buffer has been given to the thread, allocate a
* new one. Allocate slightly more in case we need padding for
* encryption */
sinfo->s[streamno].buf = malloc(sinfo->bufsize + CBC_LEN);
sinfo->s[streamno].buf = malloc(sinfo->bufsize + CBC_PAD(sinfo->bufsize));
if (unlikely(!sinfo->s[streamno].buf))
fatal("Unable to malloc buffer of size %lld in flush_buffer\n", sinfo->bufsize);
sinfo->s[streamno].buflen = 0;
@ -1423,15 +1424,15 @@ fill_another:
fsync(control->fd_out);
s_buf = malloc(c_len + CBC_LEN);
s_buf = malloc(c_len + CBC_PAD(c_len));
if (unlikely(c_len && !s_buf))
fatal("Unable to malloc buffer of size %lld in fill_buffer\n", c_len);
sinfo->ram_alloced += c_len;
/* If the data was encrypted, we need to read the padded data
* at the end and then discard it once it's decrypted */
if (ENCRYPT && c_len % CBC_LEN)
padded_len = c_len + CBC_LEN - (c_len % CBC_LEN);
if (ENCRYPT)
padded_len = c_len + CBC_PAD(c_len);
else
padded_len = c_len;