diff --git a/Makefile.in b/Makefile.in index c768e9a..cd6e92d 100644 --- a/Makefile.in +++ b/Makefile.in @@ -51,6 +51,7 @@ binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) PROGRAMS = $(bin_PROGRAMS) am_scrypt_OBJECTS = scrypt-main.$(OBJEXT) \ scrypt-readpass.$(OBJEXT) scrypt-warn.$(OBJEXT) \ + scrypt-hashtopass.$(OBJEXT) \ scrypt-genpass.$(OBJEXT) \ scrypt-sha256.$(OBJEXT) \ scrypt-crypto_scrypt-@SCRYPTVER@.$(OBJEXT) @@ -175,6 +176,7 @@ AUTOMAKE_OPTIONS = foreign dist_man_MANS = $(scrypt_man_MANS) scrypt_SOURCES = main.c \ lib/util/readpass.c \ + lib/util/hashtopass.c \ lib/util/warn.c \ lib/genpass/genpass.c \ lib/crypto/sha256.c \ @@ -274,6 +276,7 @@ distclean-compile: @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@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/scrypt-hashtopass.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/scrypt-genpass.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/scrypt-sha256.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/scrypt-warn.Po@am__quote@ @@ -319,6 +322,21 @@ scrypt-readpass.obj: lib/util/readpass.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='lib/util/readpass.c' object='scrypt-readpass.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(scrypt_CFLAGS) $(CFLAGS) -c -o scrypt-readpass.obj `if test -f 'lib/util/readpass.c'; then $(CYGPATH_W) 'lib/util/readpass.c'; else $(CYGPATH_W) '$(srcdir)/lib/util/readpass.c'; fi` +scrypt-readpass.o: lib/util/readpass.c + +scrypt-hashtopass.o: lib/util/hashtopass.c +@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(scrypt_CFLAGS) $(CFLAGS) -MT scrypt-hashtopass.o -MD -MP -MF $(DEPDIR)/scrypt-hashtopass.Tpo -c -o scrypt-hashtopass.o `test -f 'lib/util/hashtopass.c' || echo '$(srcdir)/'`lib/util/hashtopass.c +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/scrypt-hashtopass.Tpo $(DEPDIR)/scrypt-hashtopass.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='lib/util/hashtopass.c' object='scrypt-hashtopass.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(scrypt_CFLAGS) $(CFLAGS) -c -o scrypt-hashtopass.o `test -f 'lib/util/hashtopass.c' || echo '$(srcdir)/'`lib/util/hashtopass.c + +scrypt-hashtopass.obj: lib/util/hashtopass.c +@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(scrypt_CFLAGS) $(CFLAGS) -MT scrypt-hashtopass.obj -MD -MP -MF $(DEPDIR)/scrypt-hashtopass.Tpo -c -o scrypt-hashtopass.obj `if test -f 'lib/util/hashtopass.c'; then $(CYGPATH_W) 'lib/util/hashtopass.c'; else $(CYGPATH_W) '$(srcdir)/lib/util/hashtopass.c'; fi` +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/scrypt-hashtopass.Tpo $(DEPDIR)/scrypt-hashtopass.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='lib/util/hashtopass.c' object='scrypt-hashtopass.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(scrypt_CFLAGS) $(CFLAGS) -c -o scrypt-hashtopass.obj `if test -f 'lib/util/hashtopass.c'; then $(CYGPATH_W) 'lib/util/hashtopass.c'; else $(CYGPATH_W) '$(srcdir)/lib/util/hashtopass.c'; fi` scrypt-warn.o: lib/util/warn.c @am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(scrypt_CFLAGS) $(CFLAGS) -MT scrypt-warn.o -MD -MP -MF $(DEPDIR)/scrypt-warn.Tpo -c -o scrypt-warn.o `test -f 'lib/util/warn.c' || echo '$(srcdir)/'`lib/util/warn.c diff --git a/lib/util/hashtopass.c b/lib/util/hashtopass.c new file mode 100644 index 0000000..08695ea --- /dev/null +++ b/lib/util/hashtopass.c @@ -0,0 +1,18 @@ +#include "hashtopass.h" + +void hashtopass(char* p, size_t len, uint8_t* key) +{ + char* lowers = "abcdefghijklmnopqrstuvwxyz"; + char* uppers = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + char* numerals = "0123456789"; + 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)]; + p[len] = '\0'; +} \ No newline at end of file diff --git a/lib/util/hashtopass.h b/lib/util/hashtopass.h new file mode 100644 index 0000000..13f6391 --- /dev/null +++ b/lib/util/hashtopass.h @@ -0,0 +1,12 @@ +#include "scrypt_platform.h" + +#include +#include +#include +#include +#include +#include + +#include "warn.h" + +void hashtopass(char* p, size_t len, uint8_t* key); \ No newline at end of file diff --git a/main.c b/main.c index bc244aa..1f48175 100644 --- a/main.c +++ b/main.c @@ -41,7 +41,7 @@ usage(void) { fprintf(stderr, - "usage: scrypt-genpass [-m MAXMEM] [-o MAXOPS] [-k KEYFILE] [-p PASS] \n"); + "usage: scrypt-genpass [-l LEN] [-m MAXMEM] [-o MAXOPS] [-k KEYFILE] [-p PASS] \n"); fprintf(stderr, " scrypt-genpass -t\n"); exit(1); @@ -75,6 +75,7 @@ main(int argc, char *argv[]) FILE * outfile = stdout; int dec = 0; size_t passwdlen = 0; + size_t outputlength = 12; uint32_t maxmem = 1000; uint32_t megaops = 32; char ch; @@ -90,11 +91,13 @@ main(int argc, char *argv[]) usage(); /* Parse arguments. */ - while ((ch = getopt(argc, argv, "htk:m:o:p:")) != -1) { + while ((ch = getopt(argc, argv, "htk:l:m:o:p:")) != -1) { switch (ch) { case 'k': keyfile = strdup(optarg); break; + case 'l': + outputlength = atoi(optarg); case 'm': maxmem = atoi(optarg); break; @@ -177,6 +180,15 @@ main(int argc, char *argv[]) bintohex(buf, 64, dk); printf("Pass hex: %s\n", buf); + if ((outputlength < 3)||(outputlength > 64)) { + warn("Unable to generate password for output length %lu", outputlength); + exit(1); + } + + char output[outputlength + 1]; + hashtopass(output, outputlength, dk); + printf("Generated password: %s\n", output); + /* If we failed, print the right error message and exit. */ if (rc != 0) { switch (rc) { diff --git a/test/test.bash b/test/test.bash index 61ea317..e504b1c 100755 --- a/test/test.bash +++ b/test/test.bash @@ -7,5 +7,8 @@ $PROG -t > $RESULTS 2>&1 $PROG -h >> $RESULTS 2>&1 $PROG -p b a >> $RESULTS 2>&1 $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 diff $RESULTS test/test_results.reference diff --git a/test/test_results.reference b/test/test_results.reference index e1561a3..c3dfc7a 100644 --- a/test/test_results.reference +++ b/test/test_results.reference @@ -1,9 +1,23 @@ All internal tests pass -usage: scrypt-genpass [-m MAXMEM] [-o MAXOPS] [-k KEYFILE] [-p PASS] +usage: scrypt-genpass [-l LEN] [-m MAXMEM] [-o MAXOPS] [-k KEYFILE] [-p PASS] scrypt-genpass -t Master hex: 3e23e8160039594a33894f6564e1b1348bbd7a0088d42c4acb73eeaed59c009d Site hex: ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb Pass hex: 0160b45a147d0a0f5b6976a7ab698554a41c06c5f77cc9d77b06304265d1646fdc8e3119474748778ab3b68a39d0a67b3a92b41a8ddb45d4bb6ebec20a5f4a57 +Generated password: b6YCubkpDR4R Master hex: bef57ec7f53a6d40beb640a780a639c83bc29ac8a9816f1fc6c5c6dcd93c4721 Site hex: 50ae61e841fac4e8f9e40baf2ad36ec868922ea48368c18f9535e47db56dd7fb Pass hex: a46a99d8d0ed2388d48cc3ddd33efe0b635790176c4f84387c0b02b589d2db9703db2fa3d41d5ee1d670ba0ddd1cfd1520a0d1a7394db5ff5eaa8b290aa80ebd +Generated password: i6XEwZJmAqjJ +scrypt-genpass: Unable to generate password for output length 2: Undefined error: 0 +Master hex: ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb +Site hex: ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb +Pass hex: 4394a3d67ecf5faa9ee733225147a7b58be00c497d990ad0ff4a5c63c608f843160924503886964e275867c1885cf73e072ebbed617088ae8f864d672e656097 +scrypt-genpass: Unable to generate password for output length 65: Undefined error: 0 +Master hex: ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb +Site hex: ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb +Pass hex: fcd149fda370967694b85b3e29edba64c68a0fe3b679770aec240b3cf460222c9d259f8b38064c1f07628dc2050a205cf52d498b300aa3851a9d0de5d0a27aa8 +Master hex: ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb +Site hex: ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb +Pass hex: fcd149fda370967694b85b3e29edba64c68a0fe3b679770aec240b3cf460222c9d259f8b38064c1f07628dc2050a205cf52d498b300aa3851a9d0de5d0a27aa8 +Generated password: s9VfNYA4y8DaPZaMmopP675kYKl86IISHLJp4goFhKrifkGE7TlpWkNjAHnRwM8S