diff --git a/Makefile.in b/Makefile.in index cd6e92d..2e6d680 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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@ diff --git a/lib/util/hashtopass.c b/lib/util/hashtopass.c index 08695ea..be75326 100644 --- a/lib/util/hashtopass.c +++ b/lib/util/hashtopass.c @@ -1,18 +1,30 @@ #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) { - char* lowers = "abcdefghijklmnopqrstuvwxyz"; - char* uppers = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + int i; char* numerals = "0123456789"; - char* allchars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - p[0] = lowers[key[0] % 26]; - p[1] = numerals[key[1] % 10]; - p[2] = uppers[key[2] % 26]; + if (numbers_only) { + + for (i = 0; i < len; i++) + p[i] = numerals[key[i] % 10]; + + } else { + + char* lowers = "abcdefghijklmnopqrstuvwxyz"; + char* uppers = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + char* allchars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + + p[0] = lowers[key[0] % 26]; + p[1] = numerals[key[1] % 10]; + p[2] = uppers[key[2] % 26]; + + size_t i; + for (i = 3; i < len; i++) + p[i] = allchars[key[i] % (26 + 26 + 10)]; + } - size_t i; - for (i = 3; i < len; i++) - p[i] = allchars[key[i] % (26 + 26 + 10)]; p[len] = '\0'; + } \ No newline at end of file diff --git a/lib/util/hashtopass.h b/lib/util/hashtopass.h index 13f6391..45e1d55 100644 --- a/lib/util/hashtopass.h +++ b/lib/util/hashtopass.h @@ -9,4 +9,4 @@ #include "warn.h" -void hashtopass(char* p, size_t len, uint8_t* key); \ No newline at end of file +void hashtopass(int numbers_only, char* p, size_t len, uint8_t* key); \ No newline at end of file diff --git a/main.c b/main.c index 364c792..fa14988 100644 --- a/main.c +++ b/main.c @@ -41,7 +41,7 @@ usage(void) { fprintf(stderr, - "usage: scrypt-genpass [-l LEN] [-m MAXMEM] [-o MAXOPS] [-k KEYFILE] [-p PASS] \n"); + "usage: scrypt-genpass [-l LEN] [-m MAXMEM] [-n] [-o MAXOPS] [-k KEYFILE] [-p PASS] \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); diff --git a/test/test.bash b/test/test.bash index e504b1c..3fea04e 100755 --- a/test/test.bash +++ b/test/test.bash @@ -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 diff --git a/test/test_results.reference b/test/test_results.reference index bf3f98a..dfe80a7 100644 --- a/test/test_results.reference +++ b/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] +usage: scrypt-genpass [-l LEN] [-m MAXMEM] [-n] [-o MAXOPS] [-k KEYFILE] [-p PASS] 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