From 79f24e04e329051b3c52638093fde94c7ade739a Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sun, 20 Jan 2013 15:25:22 -0800 Subject: [PATCH] One more test --- configure.ac | 1 + test/Makefile.am | 14 +++++++++----- test/auth.c | 22 ++++++++++++++++++++++ test/auth.out | 4 ++++ test/cmptest.h | 40 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 test/auth.c create mode 100644 test/auth.out create mode 100644 test/cmptest.h diff --git a/configure.ac b/configure.ac index 79e8077b..81f7d9c0 100644 --- a/configure.ac +++ b/configure.ac @@ -14,6 +14,7 @@ AC_SUBST(ISODATE) LX_CFLAGS=${CFLAGS-NONE} AC_PROG_CC_C99 +AM_PROG_CC_C_O AC_USE_SYSTEM_EXTENSIONS CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2" diff --git a/test/Makefile.am b/test/Makefile.am index 4141182b..34492d11 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,10 +1,11 @@ AM_CPPFLAGS = \ - -I. \ - -I$(top_srcdir)/src/libsodium/include + -I$(top_srcdir)/src/libsodium/include \ + -I$(top_srcdir)/src/libsodium/include/sodium TESTS_TARGETS = \ - test-randombytes + test-randombytes \ + auth check_PROGRAMS = $(TESTS_TARGETS) @@ -12,7 +13,10 @@ TESTS = $(TESTS_TARGETS) TESTS_LDADD = $(top_srcdir)/src/libsodium/libsodium.la -test_randombytes_SOURCES = test-randombytes.c -test_randombytes_LDADD = $(TESTS_LDADD) +test_randombytes_SOURCES = test-randombytes.c +test_randombytes_LDADD = $(TESTS_LDADD) + +auth_SOURCES = auth.c cmptest.h +auth_LDADD = $(TESTS_LDADD) verify: check diff --git a/test/auth.c b/test/auth.c new file mode 100644 index 00000000..80442ff5 --- /dev/null +++ b/test/auth.c @@ -0,0 +1,22 @@ +#include +#include "crypto_auth_hmacsha512256.h" + +#define TEST_NAME "auth" +#include "cmptest.h" + +/* "Test Case 2" from RFC 4231 */ +unsigned char key[32] = "Jefe"; +unsigned char c[28] = "what do ya want for nothing?"; + +unsigned char a[32]; + +main() +{ + int i; + crypto_auth_hmacsha512256(a,c,sizeof c,key); + for (i = 0;i < 32;++i) { + printf(",0x%02x",(unsigned int) a[i]); + if (i % 8 == 7) printf("\n"); + } + return 0; +} diff --git a/test/auth.out b/test/auth.out new file mode 100644 index 00000000..35e5909d --- /dev/null +++ b/test/auth.out @@ -0,0 +1,4 @@ +,0x16,0x4b,0x7a,0x7b,0xfc,0xf8,0x19,0xe2 +,0xe3,0x95,0xfb,0xe7,0x3b,0x56,0xe0,0xa3 +,0x87,0xbd,0x64,0x22,0x2e,0x83,0x1f,0xd6 +,0x10,0x27,0x0c,0xd7,0xea,0x25,0x05,0x54 diff --git a/test/cmptest.h b/test/cmptest.h new file mode 100644 index 00000000..177572a4 --- /dev/null +++ b/test/cmptest.h @@ -0,0 +1,40 @@ + +#ifndef __CMPTEST_H__ +#define __CMPTEST_H__ + +#include + +#define TEST_NAME_RES TEST_NAME ".res" +#define TEST_NAME_OUT TEST_NAME ".out" + +FILE *fp_res; +int xmain(void); + +int main(void) +{ + FILE *fp_out; + int c; + + if ((fp_res = fopen(TEST_NAME_RES, "w+")) == NULL) { + perror("fopen(" TEST_NAME_RES ")"); + return 99; + } + xmain(); + rewind(fp_res); + if ((fp_out = fopen(TEST_NAME_OUT, "r")) == NULL) { + perror("fopen(" TEST_NAME_OUT ")"); + return 99; + } + do { + if ((c = fgetc(fp_res)) != fgetc(fp_out)) { + return 99; + } + } while (c != EOF); + + return 0; +} + +#define printf(...) fprintf(fp_res, __VA_ARGS__) +#define main xmain + +#endif