summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2017-10-05 14:13:02 +0100
committerRoy Marples <roy@marples.name>2017-10-05 14:13:02 +0100
commit5cb0490cb9273864dcd5eeb36e31148dcc37a72d (patch)
tree353f90f33c92f37bdcfde828367737a18af63c74 /tests
parent18539557d779fbd72a887eb5eca484f5dedaecf5 (diff)
downloaddhcpcd-5cb0490cb9273864dcd5eeb36e31148dcc37a72d.tar.xz
Detect hmac(3) in libc or the library containing MD5.
If not found, a compat function is provided, taken from NetBSD.
Diffstat (limited to 'tests')
-rw-r--r--tests/crypt/Makefile14
-rw-r--r--tests/crypt/test_hmac_md5.c48
2 files changed, 31 insertions, 31 deletions
diff --git a/tests/crypt/Makefile b/tests/crypt/Makefile
index ab668f21..acdcc3f1 100644
--- a/tests/crypt/Makefile
+++ b/tests/crypt/Makefile
@@ -3,7 +3,7 @@ include ${TOP}/iconfig.mk
PROG= run-test
SRCS= run-test.c
-SRCS+= test_hmac_md5.c ${TOP}/src/crypt/hmac_md5.c
+SRCS+= test_hmac_md5.c
CFLAGS?= -O2
CSTD?= c99
@@ -11,9 +11,9 @@ CFLAGS+= -std=${CSTD}
CPPFLAGS+= -I${TOP} -I${TOP}/src
-T_COMPAT_SRCS= ${COMPAT_SRCS:compat/%=${TOP}/compat/%}
-T_MD5_SRC= ${MD5_SRC:compat/%=${TOP}/compat/%}
-OBJS+= ${SRCS:.c=.o} ${T_COMPAT_SRCS:.c=.o} ${T_MD5_SRC:.c=.o}
+CRYPT_SRCS= ${HMAC_SRC} ${MD5_SRC}
+PCRYPT_SRCS= ${CRYPT_SRCS:compat/%=${TOP}/compat/%}
+OBJS+= ${SRCS:.c=.o} ${PCRYPT_SRCS:.c=.o}
.c.o:
${CC} ${CFLAGS} ${CPPFLAGS} -c $< -o $@
@@ -26,10 +26,8 @@ clean:
distclean: clean
rm -f .depend
-.depend: ${SRCS} ${T_COMPAT_SRCS} ${T_MD5_SRC}
- ${CC} ${CPPFLAGS} -MM ${SRCS} ${T_COMPAT_SRCS} ${T_MD5_SRC} > .depend
-
-depend: .depend
+.depend: ${SRCS} ${PCRYPT_SRCS}
+ ${CC} ${CPPFLAGS} -MM ${SRCS} ${PCRYPT_SRCS}
${PROG}: ${DEPEND} ${OBJS}
${CC} ${LDFLAGS} -o $@ ${OBJS} ${LDADD}
diff --git a/tests/crypt/test_hmac_md5.c b/tests/crypt/test_hmac_md5.c
index 07d5de04..5ce35cbb 100644
--- a/tests/crypt/test_hmac_md5.c
+++ b/tests/crypt/test_hmac_md5.c
@@ -30,10 +30,12 @@
#include <stdlib.h>
#include <string.h>
-#include "crypt/crypt.h"
+#include "config.h"
#include "test.h"
-/* RFC2202 MD5 implementation */
+#ifdef HAVE_HMAC_H
+#include <hmac.h>
+#endif
static void
print_hmac(FILE *stream, const uint8_t *hmac)
@@ -66,14 +68,14 @@ hmac_md5_test1(void)
0x92, 0x94, 0x72, 0x7a, 0x36, 0x38, 0xbb, 0x1c,
0x13, 0xf4, 0x8e, 0xf8, 0x15, 0x8b, 0xfc, 0x9d,
};
- uint8_t hmac[16];
+ uint8_t digest[16];
int i;
printf ("HMAC MD5 Test 1:\t\t");
for (i = 0; i < 16; i++)
key[i] = 0x0b;
- hmac_md5(text, 8, key, 16, hmac);
- test_hmac(hmac, expect);
+ hmac("md5", key, 16, text, 8, digest, sizeof(digest));
+ test_hmac(digest, expect);
}
static void
@@ -85,11 +87,11 @@ hmac_md5_test2(void)
0x75, 0x0c, 0x78, 0x3e, 0x6a, 0xb0, 0xb5, 0x03,
0xea, 0xa8, 0x6e, 0x31, 0x0a, 0x5d, 0xb7, 0x38,
};
- uint8_t hmac[16];
+ uint8_t digest[16];
printf("HMAC MD5 Test 2:\t\t");
- hmac_md5(text, 28, key, 4, hmac);
- test_hmac(hmac, expect);
+ hmac("md5", key, 4, text, 28, digest, sizeof(digest));
+ test_hmac(digest, expect);
}
static void
@@ -99,7 +101,7 @@ hmac_md5_test3(void)
0x56, 0xbe, 0x34, 0x52, 0x1d, 0x14, 0x4c, 0x88,
0xdb, 0xb8, 0xc7, 0x33, 0xf0, 0xe8, 0xb3, 0xf6,
};
- uint8_t hmac[16];
+ uint8_t digest[16];
uint8_t text[50];
uint8_t key[16];
int i;
@@ -109,8 +111,8 @@ hmac_md5_test3(void)
text[i] = 0xdd;
for (i = 0; i < 16; i++)
key[i] = 0xaa;
- hmac_md5(text, 50, key, 16, hmac);
- test_hmac(hmac, expect);
+ hmac("md5", key, 16, text, 50, digest, sizeof(digest));
+ test_hmac(digest, expect);
}
static void
@@ -120,7 +122,7 @@ hmac_md5_test4(void)
0x69, 0x7e, 0xaf, 0x0a, 0xca, 0x3a, 0x3a, 0xea,
0x3a, 0x75, 0x16, 0x47, 0x46, 0xff, 0xaa, 0x79,
};
- uint8_t hmac[16];
+ uint8_t digest[16];
uint8_t text[50];
uint8_t key[25];
uint8_t i;
@@ -130,8 +132,8 @@ hmac_md5_test4(void)
text[i] = 0xcd;
for (i = 0; i < 25; i++)
key[i] = (uint8_t)(i + 1);
- hmac_md5(text, 50, key, 25, hmac);
- test_hmac(hmac, expect);
+ hmac("md5", key, 25, text, 50, digest, sizeof(digest));
+ test_hmac(digest, expect);
}
static void
@@ -142,15 +144,15 @@ hmac_md5_test5(void)
0x56, 0x46, 0x1e, 0xf2, 0x34, 0x2e, 0xdc, 0x00,
0xf9, 0xba, 0xb9, 0x95, 0x69, 0x0e, 0xfd, 0x4c,
};
- uint8_t hmac[16];
+ uint8_t digest[16];
uint8_t key[16];
int i;
printf ("HMAC MD5 Test 5:\t\t");
for (i = 0; i < 16; i++)
key[i] = 0x0c;
- hmac_md5(text, 20, key, 16, hmac);
- test_hmac(hmac, expect);
+ hmac("md5", key, 16, text, 20, digest, sizeof(digest));
+ test_hmac(digest, expect);
}
static void
@@ -161,15 +163,15 @@ hmac_md5_test6(void)
0x6b, 0x1a, 0xb7, 0xfe, 0x4b, 0xd7, 0xbf, 0x8f,
0x0b, 0x62, 0xe6, 0xce, 0x61, 0xb9, 0xd0, 0xcd,
};
- uint8_t hmac[16];
+ uint8_t digest[16];
uint8_t key[80];
int i;
printf ("HMAC MD5 Test 6:\t\t");
for (i = 0; i < 80; i++)
key[i] = 0xaa;
- hmac_md5(text, 54, key, 80, hmac);
- test_hmac(hmac, expect);
+ hmac("md5", key, 80, text, 54, digest, sizeof(digest));
+ test_hmac(digest, expect);
}
static void
@@ -180,15 +182,15 @@ hmac_md5_test7(void)
0x6f, 0x63, 0x0f, 0xad, 0x67, 0xcd, 0xa0, 0xee,
0x1f, 0xb1, 0xf5, 0x62, 0xdb, 0x3a, 0xa5, 0x3e,
};
- uint8_t hmac[16];
+ uint8_t digest[16];
uint8_t key[80];
int i;
printf ("HMAC MD5 Test 7:\t\t");
for (i = 0; i < 80; i++)
key[i] = 0xaa;
- hmac_md5(text, 73, key, 80, hmac);
- test_hmac(hmac, expect);
+ hmac("md5", key, 80, text, 73, digest, sizeof(digest));
+ test_hmac(digest, expect);
}
int test_hmac_md5(void)