aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Willemse2013-11-17 01:08:10 +0100
committerTom Willemse2013-11-17 01:13:08 +0100
commit6aa289c124bd823ee352fa5bda5c9d7c792c7bf5 (patch)
treede4fccaaa3504f15bde9988ddab236c4bcab9687
parent19129006d3e6507b7192d16fe10a29f3374b9df1 (diff)
downloadlibdispass-6aa289c124bd823ee352fa5bda5c9d7c792c7bf5.tar.gz
libdispass-6aa289c124bd823ee352fa5bda5c9d7c792c7bf5.zip
Remove main from libdispass, add test executable
- Add ~dispasstest~ which is used to test the DisPass algorithms. - Remove =main= from libdispass since shared libraries shouldn't have main functions - Add ~dispass.h~ which defines and exports the DisPass algorithms. - Make some functions in ~dispass.c~ static to make clear they're not exported anywhere.
-rw-r--r--.gitignore1
-rw-r--r--Makefile3
-rw-r--r--README.org4
-rw-r--r--dispass.c30
-rw-r--r--dispass.h7
-rw-r--r--dispasstest.c26
6 files changed, 44 insertions, 27 deletions
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 <openssl/pem.h>
#include <limits.h>
+#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 <stdio.h>
+#include <stdlib.h>
+
+#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;
+}