tests/chardata.@OBJEXT@: tests/chardata.c tests/chardata.h
tests/minicheck.@OBJEXT@: tests/minicheck.c tests/minicheck.h
tests/memcheck.@OBJEXT@: tests/memcheck.c tests/memcheck.h
-tests/runtests.@OBJEXT@: tests/runtests.c tests/chardata.h tests/memcheck.h
+tests/runtests.@OBJEXT@: tests/runtests.c tests/chardata.h tests/memcheck.h lib/siphash.h
tests/runtests@EXEEXT@: tests/runtests.@OBJEXT@ tests/chardata.@OBJEXT@ tests/minicheck.@OBJEXT@ tests/memcheck.@OBJEXT@ $(LIBRARY)
$(LINK_EXE) tests/runtests.@OBJEXT@ tests/chardata.@OBJEXT@ tests/minicheck.@OBJEXT@ tests/memcheck.@OBJEXT@ $(LIBRARY)
tests/runtestspp.@OBJEXT@: tests/runtestspp.cpp tests/runtests.c tests/chardata.h tests/memcheck.h
#include "internal.h" /* for UNUSED_P only */
#include "minicheck.h"
#include "memcheck.h"
+#include "siphash.h"
#ifdef XML_LARGE_SIZE
#define XML_FMT_INT_MOD "ll"
}
END_TEST
+START_TEST(test_siphash_self)
+{
+ if (! sip24_valid())
+ fail("SipHash self-test failed");
+}
+END_TEST
+
+START_TEST(test_siphash_spec)
+{
+ /* https://131002.net/siphash/siphash.pdf (page 19, "Test values") */
+ const char message[] = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09"
+ "\x0a\x0b\x0c\x0d\x0e";
+ const size_t len = sizeof(message) - 1;
+ const uint64_t expected = 0xa129ca6149be45e5U;
+ struct siphash state;
+ struct sipkey key;
+ (void)sip_tobin;
+
+ sip_tokey(&key,
+ "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09"
+ "\x0a\x0b\x0c\x0d\x0e\x0f");
+ sip24_init(&state, &key);
+
+ /* Cover spread across calls */
+ sip24_update(&state, message, 4);
+ sip24_update(&state, message + 4, len - 4);
+
+ /* Cover null length */
+ sip24_update(&state, message, 0);
+
+ if (sip24_final(&state) != expected)
+ fail("sip24_final failed spec test\n");
+
+ /* Cover wrapper */
+ if (siphash24(message, len, &key) != expected)
+ fail("siphash24 failed spec test\n");
+}
+END_TEST
+
START_TEST(test_bom_utf8)
{
/* This test is really just making sure we don't core on a UTF-8 BOM. */
tcase_add_checked_fixture(tc_basic, basic_setup, basic_teardown);
tcase_add_test(tc_basic, test_nul_byte);
tcase_add_test(tc_basic, test_u0000_char);
+ tcase_add_test(tc_basic, test_siphash_self);
+ tcase_add_test(tc_basic, test_siphash_spec);
tcase_add_test(tc_basic, test_bom_utf8);
tcase_add_test(tc_basic, test_bom_utf16_be);
tcase_add_test(tc_basic, test_bom_utf16_le);