From 6a903eff8d33717f1efead0d0c84abf8ff555fc4 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 15 Mar 2011 13:14:27 +1100 Subject: [PATCH] Convert the usecs field to a dedicated salt one which has 6 random bytes and 2 encoded loops bytes. --- lrzip.c | 10 +++++++--- lrzip_private.h | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lrzip.c b/lrzip.c index d99ed44..25566e4 100644 --- a/lrzip.c +++ b/lrzip.c @@ -112,9 +112,13 @@ static char *make_magic(rzip_control *control) if (unlikely(gettimeofday(&tv, NULL))) fatal("Failed to gettimeofday in write_magic\n"); control->secs = tv.tv_sec; - control->usecs = tv.tv_usec; + /* The first 6 bytes of the salt is random data. The last 2 bytes + * encode how many times to hash the password */ + get_rand(control->salt, 6); + control->encloops = nloops(control->secs, control->salt + 6, control->salt + 7); + memcpy(&magic[23], &control->secs, 8); - memcpy(&magic[31], &control->usecs, 8); + memcpy(&magic[31], &control->salt, 8); return magic; } @@ -187,7 +191,7 @@ static void get_magicver06(rzip_control *control, char *magic) if (magic[22] == 1) control->encrypt = 1; memcpy(&control->secs, &magic[23], 8); - memcpy(&control->usecs, &magic[31], 8); + memcpy(&control->salt, &magic[31], 8); print_maxverbose("Seconds %lld\n", control->secs); } diff --git a/lrzip_private.h b/lrzip_private.h index 1380adf..4a8e72a 100644 --- a/lrzip_private.h +++ b/lrzip_private.h @@ -196,7 +196,7 @@ struct rzip_control { uchar loop_byte1; uchar loop_byte2; i64 secs; - i64 usecs; + uchar salt[8]; unsigned char eof; unsigned char magic_written; md5_ctx ctx;