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.
This commit is contained in:
2021-11-15 01:18:39 +01:00
parent 0a7046d45c
commit e81544ff5f
2 changed files with 32 additions and 2 deletions

View File

@ -21,13 +21,18 @@
/* /*
* The default pattern used for password generation * 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) * List of special characters (order is important)
*/ */
#define PASSGENY_SPECIAL " +-./=_" #define PASSGENY_SPECIAL " +-./=_"
/*
* base64 characters
*/
#define PASSGENY_BASE64 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
/* /*
* Argon2 parameters * Argon2 parameters
*/ */
@ -235,6 +240,21 @@ bool passgeny_generate(
passgeny_gen_str(cword, clen + 1, "0123456789abcdef", &bh); 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 else
{ {
printf("Error parsing pattern at: %s\n", ppat); printf("Error parsing pattern at: %s\n", ppat);

View File

@ -10,11 +10,14 @@ from . import bhash, phogen
# #
# WARNING: Changing any of the parameters below will affect password generation # 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 # List of special characters
PASSGENY_SPECIAL = " +-./=_" PASSGENY_SPECIAL = " +-./=_"
# List of base64 characters
PASSGENY_BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
# Default SALT to use; this cannot be random since passgeny must # Default SALT to use; this cannot be random since passgeny must
# generate predictable passwords # generate predictable passwords
PASSGENY_SALT_DEFAULT = b"Passgeny v1" PASSGENY_SALT_DEFAULT = b"Passgeny v1"
@ -93,6 +96,12 @@ class Passgeny:
x += "{:x}".format(bh.modulo(16)) x += "{:x}".format(bh.modulo(16))
return x 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): def gen_capitalize(match):
nonlocal flags nonlocal flags
@ -104,6 +113,7 @@ class Passgeny:
[ '([0-9]*)s', gen_special ], [ '([0-9]*)s', gen_special ],
[ '([0-9]+)d', gen_decimal ], [ '([0-9]+)d', gen_decimal ],
[ '([0-9]+)x', gen_hexstr ], [ '([0-9]+)x', gen_hexstr ],
[ '([0-9]+)b', gen_base64 ],
[ '\^', gen_capitalize ], [ '\^', gen_capitalize ],
] ]