Add -n flag for outputting numbers only (for PINs, etc.)
This commit is contained in:
parent
f9f61afa4c
commit
d93ca58d76
6 changed files with 39 additions and 15 deletions
|
@ -273,6 +273,9 @@ mostlyclean-compile:
|
|||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
check:
|
||||
./test/test.bash
|
||||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/scrypt-crypto_scrypt-@SCRYPTVER@.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/scrypt-main.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/scrypt-readpass.Po@am__quote@
|
||||
|
|
|
@ -1,10 +1,19 @@
|
|||
#include "hashtopass.h"
|
||||
|
||||
void hashtopass(char* p, size_t len, uint8_t* key)
|
||||
void hashtopass(int numbers_only, char* p, size_t len, uint8_t* key)
|
||||
{
|
||||
int i;
|
||||
char* numerals = "0123456789";
|
||||
|
||||
if (numbers_only) {
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
p[i] = numerals[key[i] % 10];
|
||||
|
||||
} else {
|
||||
|
||||
char* lowers = "abcdefghijklmnopqrstuvwxyz";
|
||||
char* uppers = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
char* numerals = "0123456789";
|
||||
char* allchars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
|
||||
p[0] = lowers[key[0] % 26];
|
||||
|
@ -14,5 +23,8 @@ void hashtopass(char* p, size_t len, uint8_t* key)
|
|||
size_t i;
|
||||
for (i = 3; i < len; i++)
|
||||
p[i] = allchars[key[i] % (26 + 26 + 10)];
|
||||
}
|
||||
|
||||
p[len] = '\0';
|
||||
|
||||
}
|
|
@ -9,4 +9,4 @@
|
|||
|
||||
#include "warn.h"
|
||||
|
||||
void hashtopass(char* p, size_t len, uint8_t* key);
|
||||
void hashtopass(int numbers_only, char* p, size_t len, uint8_t* key);
|
10
main.c
10
main.c
|
@ -41,7 +41,7 @@ usage(void)
|
|||
{
|
||||
|
||||
fprintf(stderr,
|
||||
"usage: scrypt-genpass [-l LEN] [-m MAXMEM] [-o MAXOPS] [-k KEYFILE] [-p PASS] <site>\n");
|
||||
"usage: scrypt-genpass [-l LEN] [-m MAXMEM] [-n] [-o MAXOPS] [-k KEYFILE] [-p PASS] <site>\n");
|
||||
fprintf(stderr,
|
||||
" scrypt-genpass -t\n");
|
||||
exit(1);
|
||||
|
@ -81,6 +81,7 @@ main(int argc, char *argv[])
|
|||
char ch;
|
||||
char * keyfile = NULL;
|
||||
uint8_t* passwd = NULL;
|
||||
int numbers_only = 0;
|
||||
int rc;
|
||||
|
||||
#ifdef NEED_WARN_PROGNAME
|
||||
|
@ -91,7 +92,7 @@ main(int argc, char *argv[])
|
|||
usage();
|
||||
|
||||
/* Parse arguments. */
|
||||
while ((ch = getopt(argc, argv, "htk:l:m:o:p:")) != -1) {
|
||||
while ((ch = getopt(argc, argv, "htk:l:m:no:p:")) != -1) {
|
||||
switch (ch) {
|
||||
case 'k':
|
||||
keyfile = strdup(optarg);
|
||||
|
@ -101,6 +102,9 @@ main(int argc, char *argv[])
|
|||
case 'm':
|
||||
maxmem = atoi(optarg);
|
||||
break;
|
||||
case 'n':
|
||||
numbers_only++;
|
||||
break;
|
||||
case 'o':
|
||||
megaops = atoi(optarg);
|
||||
break;
|
||||
|
@ -188,7 +192,7 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
char output[outputlength + 1];
|
||||
hashtopass(output, outputlength, dk);
|
||||
hashtopass(numbers_only, output, outputlength, dk);
|
||||
printf("Generated password: %s\n", output);
|
||||
memset(output, 0, outputlength + 1);
|
||||
|
||||
|
|
|
@ -10,5 +10,6 @@ $PROG -k test/keyfile1.dat -p abc ghi >> $RESULTS 2>&1
|
|||
$PROG -l 2 -p a a >> $RESULTS 2>&1
|
||||
$PROG -l 65 -p a a >> $RESULTS 2>&1
|
||||
$PROG -l 64 -p a a >> $RESULTS 2>&1
|
||||
$PROG -l 4 -p "Speak, friend, and enter." "The Doors of Durin" >> $RESULTS 2>&1
|
||||
|
||||
diff $RESULTS test/test_results.reference
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
All internal tests pass
|
||||
usage: scrypt-genpass [-l LEN] [-m MAXMEM] [-o MAXOPS] [-k KEYFILE] [-p PASS] <site>
|
||||
usage: scrypt-genpass [-l LEN] [-m MAXMEM] [-n] [-o MAXOPS] [-k KEYFILE] [-p PASS] <site>
|
||||
scrypt-genpass -t
|
||||
Master hex: 3e23e8160039594a33894f6564e1b1348bbd7a0088d42c4acb73eeaed59c009d
|
||||
Site hex: ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb
|
||||
|
@ -21,3 +21,7 @@ Master hex: ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb
|
|||
Site hex: ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb
|
||||
Pass hex: fcd149fda370967694b85b3e29edba64c68a0fe3b679770aec240b3cf460222c9d259f8b38064c1f07628dc2050a205cf52d498b300aa3851a9d0de5d0a27aa8
|
||||
Generated password: s9VfNYA4y8DaPZaMmopP675kYKl86IISHLJp4goFhKrifkGE7TlpWkNjAHnRwM8S
|
||||
Master hex: 319c8c993599782ea06a815ece43de8920a4d36e03ab85855b4bab96311b9ba6
|
||||
Site hex: 9dec4c078ad50db0b21292d0c72bb0fc20326ea766ed358340c6b22f79615e88
|
||||
Pass hex: 5c63721e7af2f61b3b7537fb66fc52c6c17f0fb0e83959b75cd6ba1ec415f0e42984d1379e4af6dd534de9cc431a4b3cedb97ce80a2f7f0a6bd85a3951685a97
|
||||
Generated password: o9KE
|
||||
|
|
Reference in a new issue