From 1397c0f8327f7f2b7fdace1f222138ec7e6f308d Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 12 Mar 2011 20:31:56 +1100 Subject: [PATCH] Create custom "loop count" system to determine how many times to hash a password when encrypting based on the datestamp. This data will be stored as a 2 byte entry in the header in the future (b1 and b2). --- lrzip.c | 31 +++++++++++++++++++++++++++++++ lrzip_private.h | 5 ++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lrzip.c b/lrzip.c index f6f4300..a07b986 100644 --- a/lrzip.c +++ b/lrzip.c @@ -35,6 +35,7 @@ #include #endif #include +#include #include "md5.h" #include "rzip.h" @@ -44,6 +45,36 @@ #define MAGIC_LEN (39) +/* Determine how many times to hash the password when encrypting, based on + * the date such that we increase the number of loops according to Moore's + * law relative to when the data is encrypted. It is then stored as a two + * byte value in the header */ +#define MOORE 1.835 // world constant [TIMES per YEAR] +#define ARBITRARY 1000000 // number of sha2 calls per one second in 2011 +#define T_ZERO 1293840000 // seconds since epoch in 2011 + +#define SECONDS_IN_A_YEAR (365*86400) +#define MOORE_TIMES_PER_SECOND pow (MOORE, 1.0 / SECONDS_IN_A_YEAR) +#define ARBITRARY_AT_EPOCH (ARBITRARY * pow (MOORE_TIMES_PER_SECOND, -T_ZERO)) + +static i64 nloops(i64 seconds, uchar *b1, uchar *b2) +{ + i64 nloops_encoded, nloops; + int nbits; + + nloops = ARBITRARY_AT_EPOCH * pow(MOORE_TIMES_PER_SECOND, seconds); + nbits = log (nloops) / M_LN2; + *b1 = nbits - 7; + *b2 = nloops >> *b1; + nloops_encoded = (i64)*b2 << (i64)*b1; + return nloops_encoded; +} + +static i64 enc_loops(uchar b1, uchar b2) +{ + return (i64)b2 << (i64)b1; +} + static char *make_magic(rzip_control *control, int fd_in) { struct timeval tv; diff --git a/lrzip_private.h b/lrzip_private.h index a9c10cb..8f98f02 100644 --- a/lrzip_private.h +++ b/lrzip_private.h @@ -181,7 +181,10 @@ struct rzip_control { i64 st_size; long page_size; int fd_out; - int encrypt; + char encrypt; + i64 encloops; + uchar loop_byte1; + uchar loop_byte2; i64 secs; i64 usecs; unsigned char eof;