mirror of
https://git.sr.ht/~sircmpwn/mkproof
synced 2024-05-06 00:26:20 +02:00
Add -j option to specify number of processes
This commit is contained in:
parent
aea879847a
commit
2efaf30d3a
|
@ -71,21 +71,43 @@ run_mkproof(argon2_context context, int digits)
|
|||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: %s <challenge>\n", argv[0]);
|
||||
#ifdef _SC_NPROCESSORS_ONLN
|
||||
long nprocs = sysconf(_SC_NPROCESSORS_ONLN) - 1;
|
||||
#else
|
||||
long nprocs = 2;
|
||||
#endif
|
||||
|
||||
char *endptr;
|
||||
int c;
|
||||
while ((c = getopt(argc, argv, "j:")) != -1) {
|
||||
switch (c) {
|
||||
case 'j':
|
||||
nprocs = strtol(optarg, &endptr, 10);
|
||||
die(*endptr, "error parsing nprocs");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((argc - optind) != 1) {
|
||||
fprintf(stderr, "Usage: %s [-j nprocs] <challenge>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (nprocs <= 0 || nprocs > MAX_PIDS) {
|
||||
fprintf(stderr, "please specify nprocs value between 1 and "
|
||||
"%d\n", MAX_PIDS);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int iters, memory, digits;
|
||||
unsigned char salt[16];
|
||||
|
||||
char *challenge = argv[1];
|
||||
char *challenge = argv[optind];
|
||||
char *algo = strtok(challenge, ":");
|
||||
if (strcmp(algo, "argon2id") != 0) {
|
||||
fprintf(stderr, "Error: unknown challenge type %s\n", algo);
|
||||
return 1;
|
||||
}
|
||||
char *endptr;
|
||||
|
||||
char *iterstr = strtok(NULL, ":");
|
||||
iters = strtoul(iterstr, &endptr, 10);
|
||||
|
@ -110,12 +132,6 @@ main(int argc, char *argv[])
|
|||
fprintf(stderr, "This may take anywhere from several minutes to a few hours on slow computers.\n");
|
||||
}
|
||||
|
||||
#ifdef _SC_NPROCESSORS_ONLN
|
||||
long nprocs = sysconf(_SC_NPROCESSORS_ONLN) - 1;
|
||||
#else
|
||||
long nprocs = 2;
|
||||
#endif
|
||||
|
||||
pid_t pids[MAX_PIDS];
|
||||
assert(nprocs <= MAX_PIDS);
|
||||
|
||||
|
|
Loading…
Reference in New Issue