mirror of
https://git.sr.ht/~sircmpwn/mkproof
synced 2024-05-13 07:26:04 +02:00
Tune defaults
This commit is contained in:
parent
66d4788762
commit
97bfdd7ead
|
@ -6,15 +6,10 @@ mkchallenge(1)
|
||||||
|
|
||||||
# SYNOPSIS
|
# SYNOPSIS
|
||||||
|
|
||||||
*mkchallenge* [-d _difficulty_]
|
*mkchallenge*
|
||||||
|
|
||||||
# DESCRIPTION
|
# DESCRIPTION
|
||||||
|
|
||||||
*mkchallenge* generates a proof-of-work challenge and prints it to stdout. To
|
*mkchallenge* generates a proof-of-work challenge and prints it to stdout. To
|
||||||
solve the challenge, see *mkproof*(1). To check the solution, see
|
solve the challenge, see *mkproof*(1). To check the solution, see
|
||||||
*checkproof*(1).
|
*checkproof*(1).
|
||||||
|
|
||||||
# OPTIONS
|
|
||||||
|
|
||||||
*-d* _difficulty_
|
|
||||||
Sets the challenge difficulty. The default is 4.
|
|
||||||
|
|
|
@ -74,8 +74,9 @@ main(int argc, char *argv[])
|
||||||
r = argon2id_ctx(&context);
|
r = argon2id_ctx(&context);
|
||||||
die(r != 0, "argon2id failed\n");
|
die(r != 0, "argon2id failed\n");
|
||||||
|
|
||||||
for (int i = 0; i < digits / 2; ++i) {
|
for (int i = 0; i < digits; ++i) {
|
||||||
if (hash[i] != 0) {
|
unsigned char n = hash[i / 2] & (i % 2 ? 0x0F : 0xF0);
|
||||||
|
if (n != 0) {
|
||||||
printf("proof: failed\n");
|
printf("proof: failed\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,35 +6,21 @@
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#define ALGORITHM "argon2id"
|
#define ALGORITHM "argon2id"
|
||||||
#define ITERATIONS 5
|
#define ITERATIONS 10
|
||||||
#define MEMORY 12
|
#define MEMORY 12
|
||||||
|
#define DIGITS 5
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage(char *argv_0)
|
usage(char *argv_0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: %s [-d difficulty]\n", argv_0);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int digits = 4;
|
if (argc != 1) {
|
||||||
|
fprintf(stderr, "Usage: %s\n", argv[0]);
|
||||||
int c;
|
|
||||||
char *endptr;
|
|
||||||
while ((c = getopt(argc, argv, "d:")) != -1) {
|
|
||||||
switch (c) {
|
|
||||||
case 'd':
|
|
||||||
digits = strtoul(optarg, &endptr, 10);
|
|
||||||
if (*endptr) {
|
|
||||||
usage(argv[0]);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (optind < argc) {
|
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,8 +30,7 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
char seedhex[33];
|
char seedhex[33];
|
||||||
enchex(seed, sizeof(seed), seedhex, sizeof(seedhex));
|
enchex(seed, sizeof(seed), seedhex, sizeof(seedhex));
|
||||||
|
|
||||||
printf("%s:%d:%d:%d:%s\n", ALGORITHM,
|
printf("%s:%d:%d:%d:%s\n", ALGORITHM,
|
||||||
ITERATIONS, MEMORY, digits * 2, seedhex);
|
ITERATIONS, MEMORY, DIGITS, seedhex);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ main(int argc, char *argv[])
|
||||||
if (isatty(STDERR_FILENO)) {
|
if (isatty(STDERR_FILENO)) {
|
||||||
// TODO: Provide a better estimate based on the difficulty
|
// TODO: Provide a better estimate based on the difficulty
|
||||||
fprintf(stderr, "Generating a proof of work.\n");
|
fprintf(stderr, "Generating a proof of work.\n");
|
||||||
fprintf(stderr, "This may take anywhere from tens of seconds to a few hours on slow computers.\n");
|
fprintf(stderr, "This may take anywhere from several minutes to a few hours on slow computers.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long nattempts = 0;
|
unsigned long nattempts = 0;
|
||||||
|
@ -87,8 +87,9 @@ main(int argc, char *argv[])
|
||||||
die(r != 0, "argon2id failed\n");
|
die(r != 0, "argon2id failed\n");
|
||||||
|
|
||||||
valid = 1;
|
valid = 1;
|
||||||
for (int i = 0; i < digits / 2; ++i) {
|
for (int i = 0; i < digits; ++i) {
|
||||||
if (hash[i] != 0) {
|
unsigned char n = hash[i / 2] & (i % 2 ? 0x0F : 0xF0);
|
||||||
|
if (n != 0) {
|
||||||
valid = 0;
|
valid = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -102,6 +103,5 @@ main(int argc, char *argv[])
|
||||||
char proof[33];
|
char proof[33];
|
||||||
enchex(password, sizeof(password), proof, sizeof(proof));
|
enchex(password, sizeof(password), proof, sizeof(proof));
|
||||||
printf("%s\n", proof);
|
printf("%s\n", proof);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue