From 97bfdd7eadd8786cdefe21614b750fc6e8c97ec2 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 25 Nov 2020 12:42:46 -0500 Subject: [PATCH] Tune defaults --- doc/mkchallenge.scd | 7 +------ src/checkproof.c | 5 +++-- src/mkchallenge.c | 25 +++++-------------------- src/mkproof.c | 8 ++++---- 4 files changed, 13 insertions(+), 32 deletions(-) diff --git a/doc/mkchallenge.scd b/doc/mkchallenge.scd index 78cc354..bc643b8 100644 --- a/doc/mkchallenge.scd +++ b/doc/mkchallenge.scd @@ -6,15 +6,10 @@ mkchallenge(1) # SYNOPSIS -*mkchallenge* [-d _difficulty_] +*mkchallenge* # DESCRIPTION *mkchallenge* generates a proof-of-work challenge and prints it to stdout. To solve the challenge, see *mkproof*(1). To check the solution, see *checkproof*(1). - -# OPTIONS - -*-d* _difficulty_ - Sets the challenge difficulty. The default is 4. diff --git a/src/checkproof.c b/src/checkproof.c index 1ad15f7..e9da205 100644 --- a/src/checkproof.c +++ b/src/checkproof.c @@ -74,8 +74,9 @@ main(int argc, char *argv[]) r = argon2id_ctx(&context); die(r != 0, "argon2id failed\n"); - for (int i = 0; i < digits / 2; ++i) { - if (hash[i] != 0) { + for (int i = 0; i < digits; ++i) { + unsigned char n = hash[i / 2] & (i % 2 ? 0x0F : 0xF0); + if (n != 0) { printf("proof: failed\n"); return 1; } diff --git a/src/mkchallenge.c b/src/mkchallenge.c index 720d361..411e77d 100644 --- a/src/mkchallenge.c +++ b/src/mkchallenge.c @@ -6,35 +6,21 @@ #include "util.h" #define ALGORITHM "argon2id" -#define ITERATIONS 5 +#define ITERATIONS 10 #define MEMORY 12 +#define DIGITS 5 static void usage(char *argv_0) { - fprintf(stderr, "Usage: %s [-d difficulty]\n", argv_0); exit(1); } int main(int argc, char *argv[]) { - int digits = 4; - - 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) { + if (argc != 1) { + fprintf(stderr, "Usage: %s\n", argv[0]); usage(argv[0]); } @@ -44,8 +30,7 @@ main(int argc, char *argv[]) char seedhex[33]; enchex(seed, sizeof(seed), seedhex, sizeof(seedhex)); - printf("%s:%d:%d:%d:%s\n", ALGORITHM, - ITERATIONS, MEMORY, digits * 2, seedhex); + ITERATIONS, MEMORY, DIGITS, seedhex); return 0; } diff --git a/src/mkproof.c b/src/mkproof.c index e83f6e6..ce55a0f 100644 --- a/src/mkproof.c +++ b/src/mkproof.c @@ -70,7 +70,7 @@ main(int argc, char *argv[]) if (isatty(STDERR_FILENO)) { // TODO: Provide a better estimate based on the difficulty 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; @@ -87,8 +87,9 @@ main(int argc, char *argv[]) die(r != 0, "argon2id failed\n"); valid = 1; - for (int i = 0; i < digits / 2; ++i) { - if (hash[i] != 0) { + for (int i = 0; i < digits; ++i) { + unsigned char n = hash[i / 2] & (i % 2 ? 0x0F : 0xF0); + if (n != 0) { valid = 0; break; } @@ -102,6 +103,5 @@ main(int argc, char *argv[]) char proof[33]; enchex(password, sizeof(password), proof, sizeof(proof)); printf("%s\n", proof); - return 0; }