mirror of
https://github.com/ckolivas/lrzip.git
synced 2025-12-06 07:12:00 +01:00
Get the seconds, salt and encryption loop data before compressing.
Store seconds in only 5 bytes which is enough for 400 years, leaving more room for random data.
This commit is contained in:
parent
6a903eff8d
commit
65f901a83c
|
|
@ -18,8 +18,9 @@ Magic data:
|
||||||
16->20 LZMA Properties Encoded (lc,lp,pb,fb, and dictionary size)
|
16->20 LZMA Properties Encoded (lc,lp,pb,fb, and dictionary size)
|
||||||
21 Flag that md5sum hash is stored at the end of the archive
|
21 Flag that md5sum hash is stored at the end of the archive
|
||||||
22 Flag that the data is encrypted
|
22 Flag that the data is encrypted
|
||||||
23->30 Time in seconds (first 8 bits of salt)
|
23->27 Time in seconds (first 5 bytes of salt)
|
||||||
31->38 Time in useconds (last 8 bits of salt)
|
28->29 Encoded number of hash loops (bytes 6-7 of salt)
|
||||||
|
30->38 Random data (last 9 bytes of salt)
|
||||||
|
|
||||||
Rzip chunk data:
|
Rzip chunk data:
|
||||||
0 Data offsets byte width
|
0 Data offsets byte width
|
||||||
|
|
|
||||||
58
lrzip.c
58
lrzip.c
|
|
@ -35,7 +35,6 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#endif
|
#endif
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#include "md5.h"
|
#include "md5.h"
|
||||||
#include "rzip.h"
|
#include "rzip.h"
|
||||||
|
|
@ -46,39 +45,8 @@
|
||||||
|
|
||||||
#define MAGIC_LEN (39)
|
#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)
|
static char *make_magic(rzip_control *control)
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
|
||||||
char *magic;
|
char *magic;
|
||||||
|
|
||||||
magic = calloc(MAGIC_LEN, 1);
|
magic = calloc(MAGIC_LEN, 1);
|
||||||
|
|
@ -109,16 +77,7 @@ static char *make_magic(rzip_control *control)
|
||||||
if (control->encrypt)
|
if (control->encrypt)
|
||||||
magic[22] = 1;
|
magic[22] = 1;
|
||||||
|
|
||||||
if (unlikely(gettimeofday(&tv, NULL)))
|
memcpy(&magic[23], &control->salt, 16);
|
||||||
fatal("Failed to gettimeofday in write_magic\n");
|
|
||||||
control->secs = tv.tv_sec;
|
|
||||||
/* 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->salt, 8);
|
|
||||||
|
|
||||||
return magic;
|
return magic;
|
||||||
}
|
}
|
||||||
|
|
@ -186,13 +145,20 @@ static void get_magicver05(rzip_control *control, char *magic)
|
||||||
control->flags |= FLAG_MD5;
|
control->flags |= FLAG_MD5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static i64 enc_loops(uchar b1, uchar b2)
|
||||||
|
{
|
||||||
|
return (i64)b2 << (i64)b1;
|
||||||
|
}
|
||||||
|
|
||||||
static void get_magicver06(rzip_control *control, char *magic)
|
static void get_magicver06(rzip_control *control, char *magic)
|
||||||
{
|
{
|
||||||
if (magic[22] == 1)
|
if (magic[22] == 1)
|
||||||
control->encrypt = 1;
|
control->encrypt = 1;
|
||||||
memcpy(&control->secs, &magic[23], 8);
|
memcpy(control->salt, &magic[23], 16);
|
||||||
memcpy(&control->salt, &magic[31], 8);
|
memcpy(&control->secs, control->salt, 5);
|
||||||
print_maxverbose("Seconds %lld\n", control->secs);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
void read_magic(rzip_control *control, int fd_in, i64 *expected_size)
|
void read_magic(rzip_control *control, int fd_in, i64 *expected_size)
|
||||||
|
|
@ -824,8 +790,6 @@ next_chunk:
|
||||||
cratio = (long double)expected_size / (long double)infile_size;
|
cratio = (long double)expected_size / (long double)infile_size;
|
||||||
|
|
||||||
print_output("%s:\nlrzip version: %d.%d file\n", infilecopy, control->major_version, control->minor_version);
|
print_output("%s:\nlrzip version: %d.%d file\n", infilecopy, control->major_version, control->minor_version);
|
||||||
if (control->secs)
|
|
||||||
print_maxverbose("Storage time seconds: %lld\n", control->secs);
|
|
||||||
|
|
||||||
print_output("Compression: ");
|
print_output("Compression: ");
|
||||||
if (ctype == CTYPE_NONE)
|
if (ctype == CTYPE_NONE)
|
||||||
|
|
|
||||||
|
|
@ -196,7 +196,7 @@ struct rzip_control {
|
||||||
uchar loop_byte1;
|
uchar loop_byte1;
|
||||||
uchar loop_byte2;
|
uchar loop_byte2;
|
||||||
i64 secs;
|
i64 secs;
|
||||||
uchar salt[8];
|
uchar salt[16];
|
||||||
unsigned char eof;
|
unsigned char eof;
|
||||||
unsigned char magic_written;
|
unsigned char magic_written;
|
||||||
md5_ctx ctx;
|
md5_ctx ctx;
|
||||||
|
|
|
||||||
41
main.c
41
main.c
|
|
@ -35,7 +35,7 @@
|
||||||
#ifdef HAVE_SYS_RESOURCE_H
|
#ifdef HAVE_SYS_RESOURCE_H
|
||||||
# include <sys/resource.h>
|
# include <sys/resource.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include "rzip.h"
|
#include "rzip.h"
|
||||||
#include "lrzip.h"
|
#include "lrzip.h"
|
||||||
|
|
@ -267,6 +267,8 @@ static void show_summary(void)
|
||||||
if (UNLIMITED)
|
if (UNLIMITED)
|
||||||
print_verbose("Using Unlimited Window size\n");
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -425,9 +427,34 @@ static void read_config( struct rzip_control *control )
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct timeval start_time, end_time;
|
struct timeval start_time, end_time, tv;
|
||||||
struct sigaction handler;
|
struct sigaction handler;
|
||||||
double seconds,total_time; // for timers
|
double seconds,total_time; // for timers
|
||||||
int c, i;
|
int c, i;
|
||||||
|
|
@ -454,6 +481,16 @@ int main(int argc, char *argv[])
|
||||||
control.page_size = PAGE_SIZE;
|
control.page_size = PAGE_SIZE;
|
||||||
control.nice_val = 19;
|
control.nice_val = 19;
|
||||||
|
|
||||||
|
/* The first 5 bytes of the salt is the time in seconds.
|
||||||
|
* The next 2 bytes encode how many times to hash the password.
|
||||||
|
* The last 9 bytes are random data, making 16 bytes of salt */
|
||||||
|
if (unlikely(gettimeofday(&tv, NULL)))
|
||||||
|
fatal("Failed to gettimeofday in main\n");
|
||||||
|
control.secs = tv.tv_sec;
|
||||||
|
memcpy(control.salt, &control.secs, 5);
|
||||||
|
control.encloops = nloops(control.secs, control.salt + 5, control.salt + 6);
|
||||||
|
get_rand(control.salt + 7, 9);
|
||||||
|
|
||||||
/* generate crc table */
|
/* generate crc table */
|
||||||
CrcGenerateTable();
|
CrcGenerateTable();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue