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.
This commit is contained in:
Tom Willemse 2013-11-17 01:08:10 +01:00
parent 19129006d3
commit 6aa289c124
6 changed files with 44 additions and 27 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
*.o
*.so
dispasstest

View file

@ -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

View file

@ -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.

View file

@ -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;
}

7
dispass.h Normal file
View file

@ -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 */

26
dispasstest.c Normal file
View file

@ -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;
}