mirror of
https://github.com/ckolivas/lrzip.git
synced 2025-12-06 07:12:00 +01:00
Consolidate cbc padding into a macro.
This commit is contained in:
parent
ddcc45ebf0
commit
bedea4dbec
13
stream.c
13
stream.c
|
|
@ -58,6 +58,8 @@
|
||||||
|
|
||||||
#define STREAM_BUFSIZE (1024 * 1024 * 10)
|
#define STREAM_BUFSIZE (1024 * 1024 * 10)
|
||||||
|
|
||||||
|
#define CBC_PAD(LEN) ((LEN % CBC_LEN) ? (CBC_LEN - (LEN % CBC_LEN)) : 0)
|
||||||
|
|
||||||
static struct compress_thread{
|
static struct compress_thread{
|
||||||
uchar *s_buf; /* Uncompressed buffer -> Compressed buffer */
|
uchar *s_buf; /* Uncompressed buffer -> Compressed buffer */
|
||||||
uchar c_type; /* Compression type */
|
uchar c_type; /* Compression type */
|
||||||
|
|
@ -1174,8 +1176,7 @@ retry:
|
||||||
|
|
||||||
/* We must pad the block length to a mutliple of CBC_LEN to be
|
/* We must pad the block length to a mutliple of CBC_LEN to be
|
||||||
* able to encrypt. We pad it with random data */
|
* able to encrypt. We pad it with random data */
|
||||||
if (cti->c_len % CBC_LEN)
|
encrypt_pad = CBC_PAD(cti->c_len);
|
||||||
encrypt_pad = CBC_LEN - (cti->c_len % CBC_LEN);
|
|
||||||
padded_len = cti->c_len + encrypt_pad;
|
padded_len = cti->c_len + encrypt_pad;
|
||||||
if (encrypt_pad)
|
if (encrypt_pad)
|
||||||
get_rand(cti->s_buf + cti->c_len, 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
|
/* The stream buffer has been given to the thread, allocate a
|
||||||
* new one. Allocate slightly more in case we need padding for
|
* new one. Allocate slightly more in case we need padding for
|
||||||
* encryption */
|
* 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))
|
if (unlikely(!sinfo->s[streamno].buf))
|
||||||
fatal("Unable to malloc buffer of size %lld in flush_buffer\n", sinfo->bufsize);
|
fatal("Unable to malloc buffer of size %lld in flush_buffer\n", sinfo->bufsize);
|
||||||
sinfo->s[streamno].buflen = 0;
|
sinfo->s[streamno].buflen = 0;
|
||||||
|
|
@ -1423,15 +1424,15 @@ fill_another:
|
||||||
|
|
||||||
fsync(control->fd_out);
|
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))
|
if (unlikely(c_len && !s_buf))
|
||||||
fatal("Unable to malloc buffer of size %lld in fill_buffer\n", c_len);
|
fatal("Unable to malloc buffer of size %lld in fill_buffer\n", c_len);
|
||||||
sinfo->ram_alloced += c_len;
|
sinfo->ram_alloced += c_len;
|
||||||
|
|
||||||
/* If the data was encrypted, we need to read the padded data
|
/* If the data was encrypted, we need to read the padded data
|
||||||
* at the end and then discard it once it's decrypted */
|
* at the end and then discard it once it's decrypted */
|
||||||
if (ENCRYPT && c_len % CBC_LEN)
|
if (ENCRYPT)
|
||||||
padded_len = c_len + CBC_LEN - (c_len % CBC_LEN);
|
padded_len = c_len + CBC_PAD(c_len);
|
||||||
else
|
else
|
||||||
padded_len = c_len;
|
padded_len = c_len;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue