From 202d972a6c26b62ed2ae710ec93b4f97a7174575 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 15 Mar 2011 15:04:58 +1100 Subject: [PATCH] Add encryption -e option and flag encryption with a control flag, removing encrypt field. --- liblrzip.h | 1 + lrzip.c | 9 ++++++--- lrzip_private.h | 2 +- main.c | 10 ++++++++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/liblrzip.h b/liblrzip.h index 08d88fb..d817af0 100644 --- a/liblrzip.h +++ b/liblrzip.h @@ -48,6 +48,7 @@ #define LZO_TEST (control->flags & FLAG_THRESHOLD) #define TMP_OUTBUF (control->flags & FLAG_TMP_OUTBUF) #define TMP_INBUF (control->flags & FLAG_TMP_INBUF) +#define ENCRYPT (control->flags & FLAG_ENCRYPT) #define print_output(format, args...) do {\ fprintf(control->msgout, format, ##args); \ diff --git a/lrzip.c b/lrzip.c index e451565..770dfcd 100644 --- a/lrzip.c +++ b/lrzip.c @@ -74,7 +74,7 @@ static char *make_magic(rzip_control *control) * crc is still stored for compatibility with 0.5 versions. */ magic[21] = 1; - if (control->encrypt) + if (ENCRYPT) magic[22] = 1; memcpy(&magic[23], &control->salt, 16); @@ -153,12 +153,13 @@ static i64 enc_loops(uchar b1, uchar b2) static void get_magicver06(rzip_control *control, char *magic) { if (magic[22] == 1) - control->encrypt = 1; + control->flags |= FLAG_ENCRYPT; memcpy(control->salt, &magic[23], 16); memcpy(&control->secs, control->salt, 5); print_maxverbose("Storage time in seconds %lld\n", control->secs); control->encloops = enc_loops(control->salt[5], control->salt[6]); - print_maxverbose("Encryption hash loops %lld\n", control->encloops); + if (ENCRYPT) + print_maxverbose("Encryption hash loops %lld\n", control->encloops); } void read_magic(rzip_control *control, int fd_in, i64 *expected_size) @@ -791,6 +792,8 @@ next_chunk: print_output("%s:\nlrzip version: %d.%d file\n", infilecopy, control->major_version, control->minor_version); + if (ENCRYPT) + print_output("Encrypted\n"); print_output("Compression: "); if (ctype == CTYPE_NONE) print_output("rzip alone\n"); diff --git a/lrzip_private.h b/lrzip_private.h index 0c6e724..f2f856e 100644 --- a/lrzip_private.h +++ b/lrzip_private.h @@ -122,6 +122,7 @@ typedef struct md5_ctx md5_ctx; #define FLAG_THRESHOLD (1 << 20) #define FLAG_TMP_OUTBUF (1 << 21) #define FLAG_TMP_INBUF (1 << 22) +#define FLAG_ENCRYPT (1 << 23) #define NO_MD5 (!(HASH_CHECK) && !(HAS_MD5)) @@ -191,7 +192,6 @@ struct rzip_control { int fd_in; int fd_out; int fd_hist; - char encrypt; i64 encloops; uchar loop_byte1; uchar loop_byte2; diff --git a/main.c b/main.c index 50e5e98..d79fc77 100644 --- a/main.c +++ b/main.c @@ -77,6 +77,7 @@ #define LZO_TEST (control.flags & FLAG_THRESHOLD) #define TMP_OUTBUF (control.flags & FLAG_TMP_OUTBUF) #define TMP_INBUF (control.flags & FLAG_TMP_INBUF) +#define ENCRYPT (control.flags & FLAG_ENCRYPT) #define print_output(format, args...) do {\ fprintf(control.msgout, format, ##args); \ @@ -166,6 +167,7 @@ static void usage(void) print_output("General options:\n"); print_output(" -c check integrity of file written on decompression\n"); print_output(" -d decompress\n"); + print_output(" -e password protected encryption on compression\n"); print_output(" -h|-? show help\n"); print_output(" -H display md5 hash integrity information\n"); print_output(" -i show compressed file information\n"); @@ -268,7 +270,8 @@ static void show_summary(void) print_verbose("Using Unlimited Window size\n"); } print_maxverbose("Storage time in seconds %lld\n", control.secs); - print_maxverbose("Encryption hash loops %lld\n", control.encloops); + if (ENCRYPT) + print_maxverbose("Encryption hash loops %lld\n", control.encloops); } } @@ -515,7 +518,7 @@ int main(int argc, char *argv[]) else if (!strstr(eptr,"NOCONFIG")) read_config(&control); - while ((c = getopt(argc, argv, "L:h?dS:tVvDfqo:w:nlbUO:TN:p:gziHck")) != -1) { + while ((c = getopt(argc, argv, "bcdDefghHiklL:nN:o:O:p:qS:tTUvVw:z?")) != -1) { switch (c) { case 'b': if (control.flags & FLAG_NOT_LZMA) @@ -532,6 +535,9 @@ int main(int argc, char *argv[]) case 'D': control.flags &= ~FLAG_KEEP_FILES; break; + case 'e': + control.flags |= FLAG_ENCRYPT; + break; case 'f': control.flags |= FLAG_FORCE_REPLACE; break;