From e81544ff5faa8cf6c81a9648a76bb78ee16cf5ca Mon Sep 17 00:00:00 2001 From: Mitja HORVAT Date: Mon, 15 Nov 2021 01:18:39 +0100 Subject: [PATCH] c,python: Add the 'b' pattern for base64 encoded strings Change the default pattern to use a short base64 string at the end. This increses the used bits to generate a password from 65 to 73. --- c/passgeny/src/passgeny.c | 22 +++++++++++++++++++++- python/passgeny/passgeny.py | 12 +++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/c/passgeny/src/passgeny.c b/c/passgeny/src/passgeny.c index 0ed238a..271a8d3 100644 --- a/c/passgeny/src/passgeny.c +++ b/c/passgeny/src/passgeny.c @@ -21,13 +21,18 @@ /* * The default pattern used for password generation */ -#define PASSGENY_DEFAULT_PATTERN "^6p^6p^6ps2p100d" +#define PASSGENY_DEFAULT_PATTERN "^6p^6p^6ps3bd" /* * List of special characters (order is important) */ #define PASSGENY_SPECIAL " +-./=_" +/* + * base64 characters + */ +#define PASSGENY_BASE64 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" + /* * Argon2 parameters */ @@ -235,6 +240,21 @@ bool passgeny_generate( passgeny_gen_str(cword, clen + 1, "0123456789abcdef", &bh); } + else if (passgeny_patmatch(&ppat, "([0-9]*)b", popt, sizeof(popt))) + { + size_t clen = atoi(popt); + if (clen >= sizeof(cword)) + { + fprintf(stderr, "Invalid base64 string length: %zd\n", clen); + return false; + } + else if (clen == 0) + { + clen = 1; + } + + passgeny_gen_str(cword, clen + 1, PASSGENY_BASE64, &bh); + } else { printf("Error parsing pattern at: %s\n", ppat); diff --git a/python/passgeny/passgeny.py b/python/passgeny/passgeny.py index c15fcf7..d9d5e64 100644 --- a/python/passgeny/passgeny.py +++ b/python/passgeny/passgeny.py @@ -10,11 +10,14 @@ from . import bhash, phogen # # WARNING: Changing any of the parameters below will affect password generation # -PASSGENY_DEFAULT_PATTERN = "^6p^6p^6ps2p100d" +PASSGENY_DEFAULT_PATTERN = "^6p^6p^6ps3b10d" # List of special characters PASSGENY_SPECIAL = " +-./=_" +# List of base64 characters +PASSGENY_BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" + # Default SALT to use; this cannot be random since passgeny must # generate predictable passwords PASSGENY_SALT_DEFAULT = b"Passgeny v1" @@ -93,6 +96,12 @@ class Passgeny: x += "{:x}".format(bh.modulo(16)) return x + def gen_base64(match): + blen = 1 if match[1] == "" else int(match[1]) + b = "" + for l in range(blen): + b += PASSGENY_BASE64[bh.modulo(len(PASSGENY_BASE64))] + return b def gen_capitalize(match): nonlocal flags @@ -104,6 +113,7 @@ class Passgeny: [ '([0-9]*)s', gen_special ], [ '([0-9]+)d', gen_decimal ], [ '([0-9]+)x', gen_hexstr ], + [ '([0-9]+)b', gen_base64 ], [ '\^', gen_capitalize ], ]