Use separate lrz_encrypt and lrz_decrypt wrappers to lrz_crypt.

This commit is contained in:
Con Kolivas 2011-03-19 14:04:22 +11:00
parent 0b1db75a44
commit ff5a5ed054
5 changed files with 20 additions and 7 deletions

View file

@ -377,7 +377,7 @@ i64 runzip_fd(rzip_control *control, int fd_in, int fd_out, int fd_hist, i64 exp
if (unlikely(read_1g(control, fd_in, md5_stored, MD5_DIGEST_SIZE) != MD5_DIGEST_SIZE))
fatal("Failed to read md5 data in runzip_fd\n");
if (ENCRYPT)
lrz_crypt(control, md5_stored, MD5_DIGEST_SIZE, control->pass_hash, 0);
lrz_decrypt(control, md5_stored, MD5_DIGEST_SIZE, control->pass_hash);
for (i = 0; i < MD5_DIGEST_SIZE; i++)
if (md5_stored[i] != md5_resblock[i]) {
print_output("MD5 CHECK FAILED.\nStored:");

2
rzip.c
View file

@ -985,7 +985,7 @@ retry:
}
/* When encrypting data, we encrypt the MD5 value as well */
if (ENCRYPT)
lrz_crypt(control, md5_resblock, MD5_DIGEST_SIZE, control->pass_hash, 1);
lrz_encrypt(control, md5_resblock, MD5_DIGEST_SIZE, control->pass_hash);
if (unlikely(write_1g(control, md5_resblock, MD5_DIGEST_SIZE) != MD5_DIGEST_SIZE))
fatal("Failed to write md5 in rzip_fd\n");

View file

@ -1195,7 +1195,7 @@ retry:
get_rand(cti->salt, 8);
memcpy(cti->salt + 8, &cti->c_len, 8);
memcpy(cti->salt + 16, &cti->s_len, 8);
lrz_crypt(control, cti->s_buf, padded_len, cti->salt, 1);
lrz_encrypt(control, cti->s_buf, padded_len, cti->salt);
}
/* If compression fails for whatever reason multithreaded, then wait
@ -1465,7 +1465,7 @@ fill_another:
return -1;
if (ENCRYPT)
lrz_crypt(control, s_buf, padded_len, salt, 0);
lrz_decrypt(control, s_buf, padded_len, salt);
ucthread[s->uthread_no].s_buf = s_buf;
ucthread[s->uthread_no].c_len = c_len;

16
util.c
View file

@ -55,6 +55,8 @@
#include "sha4.h"
#include "aes.h"
#define LRZ_DECRYPT (0)
#define LRZ_ENCRYPT (1)
static const char *infile = NULL;
static char delete_infile = 0;
@ -164,7 +166,7 @@ static void xor128 (void *pa, const void *pb)
a [1] ^= b [1];
}
void lrz_crypt(rzip_control *control, uchar *buf, i64 len, uchar *salt, int encrypt)
static void lrz_crypt(rzip_control *control, uchar *buf, i64 len, uchar *salt, int encrypt)
{
/* Encryption requires CBC_LEN blocks so we can use ciphertext
* stealing to not have to pad the block */
@ -190,7 +192,7 @@ void lrz_crypt(rzip_control *control, uchar *buf, i64 len, uchar *salt, int encr
M = len % CBC_LEN;
N = len - M;
if (encrypt) {
if (encrypt == LRZ_ENCRYPT) {
print_maxverbose("Encrypting data \n");
if (unlikely(aes_setkey_enc(&aes_ctx, key, 128)))
failure("Failed to aes_setkey_enc in lrz_crypt\n");
@ -234,6 +236,16 @@ void lrz_crypt(rzip_control *control, uchar *buf, i64 len, uchar *salt, int encr
munlock(key, HASH_LEN + BLOCKSALT_LEN);
}
inline void lrz_encrypt(rzip_control *control, uchar *buf, i64 len, uchar *salt)
{
lrz_crypt(control, buf, len, salt, LRZ_ENCRYPT);
}
inline void lrz_decrypt(rzip_control *control, uchar *buf, i64 len, uchar *salt)
{
lrz_crypt(control, buf, len, salt, LRZ_DECRYPT);
}
void lrz_keygen(rzip_control *control, const uchar *passphrase)
{
int i, j;

3
util.h
View file

@ -29,7 +29,8 @@ void fatal(const char *format, ...);
void failure(const char *format, ...);
void round_to_page(i64 *size);
void get_rand(uchar *buf, int len);
void lrz_crypt(rzip_control *control, uchar *buf, i64 len, uchar *salt, int encrypt);
inline void lrz_encrypt(rzip_control *control, uchar *buf, i64 len, uchar *salt);
inline void lrz_decrypt(rzip_control *control, uchar *buf, i64 len, uchar *salt);
void lrz_keygen(rzip_control *control, const uchar *passphrase);
#endif