diff --git a/.gitignore b/.gitignore index 9d22eb4..23ee58b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.o *.so +dispasstest diff --git a/Makefile b/Makefile index 9a75ffc..021cef7 100644 --- a/Makefile +++ b/Makefile @@ -2,3 +2,6 @@ CFLAGS = -lcrypto -fPIC libdispass.so: dispass.o $(CC) $(CFLAGS) -shared -o libdispass.so $^ + +dispasstest: libdispass.so dispasstest.o + $(CC) -o dispasstest -L. -ldispass dispasstest.o diff --git a/README.org b/README.org index 25100e1..b5d3a37 100644 --- a/README.org +++ b/README.org @@ -3,9 +3,9 @@ A simple test executable (should be converted to library) of [[https://babab.nl][Benjamin Althues]]' DisPass algorithms. -To run: +To run a test: -: make && ./dispasstest +: make dispasstest && LD_LIBRARY_PATH=. ./dispasstest It should output 4 lines with the hashed passphrases copied from the DisPass algorithms' doctests. diff --git a/dispass.c b/dispass.c index 3024845..4f0c88a 100644 --- a/dispass.c +++ b/dispass.c @@ -4,10 +4,12 @@ #include #include +#include "dispass.h" + #define MIN(A, B) ((A) < (B) ? (A) : (B)) #define MAXLEN (SHA512_DIGEST_LENGTH * 2) -char * +static char * base64encode(const void *data, int len) { /* Copied from http://stackoverflow.com/a/16511093/459915 */ BIO *b64_bio, *mem_bio; @@ -34,7 +36,7 @@ base64encode(const void *data, int len) return ret; } -void +static void sha512_to_string(unsigned char *data, char *buff) { int i; @@ -46,7 +48,7 @@ sha512_to_string(unsigned char *data, char *buff) } } -void +static void rmchar(char rm, char **s) { int i, j = 0; @@ -114,25 +116,3 @@ dispass2(char *label, char *password, int len, long long unsigned seqno) return b64; } - -int main(int argc, char *argv[]) -{ - char *test1, *test2, *test3, *test4; - - test1 = dispass1("test", "qqqqqqqq", 30, 0); - test2 = dispass1("test2", "qqqqqqqq", 50, 0); - test3 = dispass2("test", "qqqqqqqq", 30, 1); - test4 = dispass2("test2", "qqqqqqqq", 50, 10); - - printf("%s\n", test1); - printf("%s\n", test2); - printf("%s\n", test3); - printf("%s\n", test4); - - free(test1); - free(test2); - free(test3); - free(test4); - - return 0; -} diff --git a/dispass.h b/dispass.h new file mode 100644 index 0000000..bb94358 --- /dev/null +++ b/dispass.h @@ -0,0 +1,7 @@ +#ifndef DISPASS_H +#define DISPASS_H + +char *dispass1(char *label, char *password, int len, long long unsigned seqno); +char *dispass2(char *label, char *password, int len, long long unsigned seqno); + +#endif /* DISPASS_H */ diff --git a/dispasstest.c b/dispasstest.c new file mode 100644 index 0000000..abf9750 --- /dev/null +++ b/dispasstest.c @@ -0,0 +1,26 @@ +#include +#include + +#include "dispass.h" + +int main(int argc, char *argv[]) +{ + char *test1, *test2, *test3, *test4; + + test1 = dispass1("test", "qqqqqqqq", 30, 0); + test2 = dispass1("test2", "qqqqqqqq", 50, 0); + test3 = dispass2("test", "qqqqqqqq", 30, 1); + test4 = dispass2("test2", "qqqqqqqq", 50, 10); + + printf("%s\n", test1); + printf("%s\n", test2); + printf("%s\n", test3); + printf("%s\n", test4); + + free(test1); + free(test2); + free(test3); + free(test4); + + return 0; +}