mirror of
https://github.com/cathugger/mkp224o.git
synced 2025-02-02 22:07:05 -03:00
Add checkpointing support for passphrases
This commit is contained in:
parent
ff3873965f
commit
2a4afad91a
5 changed files with 67 additions and 2 deletions
19
main.c
19
main.c
|
@ -112,6 +112,7 @@ static void printhelp(FILE *out,const char *progname)
|
||||||
#ifdef PASSPHRASE
|
#ifdef PASSPHRASE
|
||||||
"\t-p passphrase - use passphrase to initialize the random seed with\n"
|
"\t-p passphrase - use passphrase to initialize the random seed with\n"
|
||||||
"\t-P - same as -p, but takes passphrase from PASSPHRASE environment variable\n"
|
"\t-P - same as -p, but takes passphrase from PASSPHRASE environment variable\n"
|
||||||
|
"\t-c filename - load/save checkpoint of progress to specified file (requires passphrase)\n"
|
||||||
#endif
|
#endif
|
||||||
,progname,progname);
|
,progname,progname);
|
||||||
fflush(out);
|
fflush(out);
|
||||||
|
@ -393,6 +394,12 @@ int main(int argc,char **argv)
|
||||||
setpassphrase(pass);
|
setpassphrase(pass);
|
||||||
deterministic = 1;
|
deterministic = 1;
|
||||||
}
|
}
|
||||||
|
else if (*arg == 'c') {
|
||||||
|
if (argc--)
|
||||||
|
checkpointfile = *argv++;
|
||||||
|
else
|
||||||
|
e_additional();
|
||||||
|
}
|
||||||
#endif // PASSPHRASE
|
#endif // PASSPHRASE
|
||||||
else {
|
else {
|
||||||
fprintf(stderr,"unrecognised argument: -%c\n",*arg);
|
fprintf(stderr,"unrecognised argument: -%c\n",*arg);
|
||||||
|
@ -465,6 +472,18 @@ int main(int argc,char **argv)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (checkpointfile) {
|
||||||
|
// Read current checkpoint position if file exists
|
||||||
|
FILE *checkout = fopen(checkpointfile, "r");
|
||||||
|
if (checkout) {
|
||||||
|
if(fread(checkpoint, 1, SEED_LEN, checkout) != SEED_LEN) {
|
||||||
|
fprintf(stderr,"failed to read checkpoint file\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
fclose(checkout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
filters_prepare();
|
filters_prepare();
|
||||||
|
|
||||||
filters_print();
|
filters_print();
|
||||||
|
|
2
worker.c
2
worker.c
|
@ -63,6 +63,8 @@ void worker_init(void)
|
||||||
|
|
||||||
pthread_mutex_t determseed_mutex;
|
pthread_mutex_t determseed_mutex;
|
||||||
u8 determseed[SEED_LEN];
|
u8 determseed[SEED_LEN];
|
||||||
|
u8 checkpoint[SEED_LEN];
|
||||||
|
const char *checkpointfile = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
2
worker.h
2
worker.h
|
@ -33,6 +33,8 @@ VEC_STRUCT(statsvec,struct statstruct);
|
||||||
#ifdef PASSPHRASE
|
#ifdef PASSPHRASE
|
||||||
extern pthread_mutex_t determseed_mutex;
|
extern pthread_mutex_t determseed_mutex;
|
||||||
extern u8 determseed[SEED_LEN];
|
extern u8 determseed[SEED_LEN];
|
||||||
|
extern u8 checkpoint[SEED_LEN];
|
||||||
|
extern const char *checkpointfile;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern void worker_init(void);
|
extern void worker_init(void);
|
||||||
|
|
|
@ -36,18 +36,39 @@ void *worker_batch_pass(void *task)
|
||||||
|
|
||||||
sname = makesname();
|
sname = makesname();
|
||||||
|
|
||||||
|
// load checkpoint
|
||||||
|
pthread_mutex_lock(&determseed_mutex);
|
||||||
|
for (int i = 0; i < SEED_LEN; i++)
|
||||||
|
determseed[i] += checkpoint[i];
|
||||||
|
pthread_mutex_unlock(&determseed_mutex);
|
||||||
|
|
||||||
initseed:
|
initseed:
|
||||||
#ifdef STATISTICS
|
#ifdef STATISTICS
|
||||||
++st->numrestart.v;
|
++st->numrestart.v;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pthread_mutex_lock(&determseed_mutex);
|
pthread_mutex_lock(&determseed_mutex);
|
||||||
for (int i = 0; i < SEED_LEN; i++)
|
for (int i = 0; i < SEED_LEN; i++) {
|
||||||
|
++checkpoint[i];
|
||||||
if (++determseed[i])
|
if (++determseed[i])
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
memcpy(seed, determseed, SEED_LEN);
|
memcpy(seed, determseed, SEED_LEN);
|
||||||
pthread_mutex_unlock(&determseed_mutex);
|
pthread_mutex_unlock(&determseed_mutex);
|
||||||
|
|
||||||
|
if (checkpointfile) {
|
||||||
|
FILE *checkout = fopen(checkpointfile, "w");
|
||||||
|
if (!checkout) {
|
||||||
|
fprintf(stderr,"cannot open checkpoint file for writing\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if(fwrite(checkpoint, 1, SEED_LEN, checkout) != SEED_LEN) {
|
||||||
|
fprintf(stderr,"cannot write to checkpoint file\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
fclose(checkout);
|
||||||
|
}
|
||||||
|
|
||||||
ed25519_seckey_expand(sk,seed);
|
ed25519_seckey_expand(sk,seed);
|
||||||
|
|
||||||
ge_scalarmult_base(&ge_public,sk);
|
ge_scalarmult_base(&ge_public,sk);
|
||||||
|
|
|
@ -33,18 +33,39 @@ void *worker_fast_pass(void *task)
|
||||||
|
|
||||||
sname = makesname();
|
sname = makesname();
|
||||||
|
|
||||||
|
// load checkpoint
|
||||||
|
pthread_mutex_lock(&determseed_mutex);
|
||||||
|
for (int i = 0; i < SEED_LEN; i++)
|
||||||
|
determseed[i] += checkpoint[i];
|
||||||
|
pthread_mutex_unlock(&determseed_mutex);
|
||||||
|
|
||||||
initseed:
|
initseed:
|
||||||
#ifdef STATISTICS
|
#ifdef STATISTICS
|
||||||
++st->numrestart.v;
|
++st->numrestart.v;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pthread_mutex_lock(&determseed_mutex);
|
pthread_mutex_lock(&determseed_mutex);
|
||||||
for (int i = 0; i < SEED_LEN; i++)
|
for (int i = 0; i < SEED_LEN; i++) {
|
||||||
|
++checkpoint[i];
|
||||||
if (++determseed[i])
|
if (++determseed[i])
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
memcpy(seed, determseed, SEED_LEN);
|
memcpy(seed, determseed, SEED_LEN);
|
||||||
pthread_mutex_unlock(&determseed_mutex);
|
pthread_mutex_unlock(&determseed_mutex);
|
||||||
|
|
||||||
|
if (checkpointfile) {
|
||||||
|
FILE *checkout = fopen(checkpointfile, "w");
|
||||||
|
if (!checkout) {
|
||||||
|
fprintf(stderr,"cannot open checkpoint file for writing\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if(fwrite(checkpoint, 1, SEED_LEN, checkout) != SEED_LEN) {
|
||||||
|
fprintf(stderr,"cannot write to checkpoint file\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
fclose(checkout);
|
||||||
|
}
|
||||||
|
|
||||||
ed25519_seckey_expand(sk,seed);
|
ed25519_seckey_expand(sk,seed);
|
||||||
|
|
||||||
ge_scalarmult_base(&ge_public,sk);
|
ge_scalarmult_base(&ge_public,sk);
|
||||||
|
|
Loading…
Add table
Reference in a new issue