create test for crypto
authorEugene Crosser <crosser@average.org>
Wed, 30 Oct 2013 20:46:36 +0000 (00:46 +0400)
committerEugene Crosser <crosser@average.org>
Wed, 30 Oct 2013 20:46:36 +0000 (00:46 +0400)
Makefile.am
configure.ac
test_crypto.c [new file with mode: 0644]

index 23711acba19c056e87359fe0cff182c67457245f..c2b8529fc244d26038e1d64d3c6391101ec545a0 100644 (file)
@@ -15,9 +15,10 @@ lib_LTLIBRARIES = pam_pcsc_cr.la
 pam_pcsc_cr_la_LDFLAGS = -module -avoid-version
 pam_pcsc_cr_la_LIBADD = libpcsc_cr.la
 
 pam_pcsc_cr_la_LDFLAGS = -module -avoid-version
 pam_pcsc_cr_la_LIBADD = libpcsc_cr.la
 
-check_PROGRAMS = test_cr
+check_PROGRAMS = test_crypto test_cr
+test_crypto_LDADD = libpcsc_cr.la
 test_cr_LDADD = libpcsc_cr.la
 
 EXTRA_DIST = autogen.sh
 
 test_cr_LDADD = libpcsc_cr.la
 
 EXTRA_DIST = autogen.sh
 
-TESTS = test_cr
+TESTS = test_crypto test_cr
index 1e6cdfa850fa1b24e5bb95e6f1ccaa0c5b78df4f..4a9453d3126a62d7d791a95250141dbb4155a532 100644 (file)
@@ -9,7 +9,7 @@ AC_LANG_C
 AC_PROG_CC
 
 if test "X$CC" = "Xgcc"; then
 AC_PROG_CC
 
 if test "X$CC" = "Xgcc"; then
-  CFLAGS="$CFLAGS -Wall -g"
+  CFLAGS="$CFLAGS -Wall"
 fi
 
 AC_PROG_MAKE_SET
 fi
 
 AC_PROG_MAKE_SET
diff --git a/test_crypto.c b/test_crypto.c
new file mode 100644 (file)
index 0000000..695c4fe
--- /dev/null
@@ -0,0 +1,45 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include "crypto.h"
+
+unsigned char pt[48] = "the quick brown fox jumps over a lazy dog";
+unsigned char key[16] = {
+0x0f,0x65,0xd1,0x3a,0xfe,0xcb,0xc4,0xb9,0x52,0xb1,0x60,0xcf,0xe8,0x55,0x6a,0xdd
+};
+
+static void usage(const char const *cmd)
+{
+       fprintf(stderr, "usage: %s\n", cmd);
+}
+
+#define printh(p,x) printh_f(p, x, sizeof(x))
+void printh_f(char *p, unsigned char *x, size_t l)
+{
+       int i;
+       printf("%s:", p);
+       for (i=0; i<l; i++) printf(" %02x", x[i]);
+       printf("\n");
+}
+
+int main(int argc, char *argv[])
+{
+       unsigned long err;
+       unsigned char ct1[48], re1[48];
+       unsigned char sha1[20], sha2[20];
+       unsigned char hmac1[20], hmac2[20];
+
+       printf("source: %s\n", pt);
+       printh("source", pt);
+       printh("key", key);
+       if (select_crypto_if(0)) return 1;
+       if (err = encrypt(key, sizeof(key), pt, ct1, sizeof(pt)))
+               printf("encrypt error: %s\n", crypto_errstr(err));
+       printh("ct1", ct1);
+       if (err = decrypt(key, sizeof(key), ct1, re1, sizeof(re1)))
+               printf("decrypt error: %s\n", crypto_errstr(err));
+       printh("re1", re1);
+       if (select_crypto_if(1)) return 1;
+       return 0;
+}