summaryrefslogtreecommitdiff
path: root/src/test/test-siphash24.c
diff options
context:
space:
mode:
authorMartin Pitt <martin.pitt@ubuntu.com>2015-11-16 16:24:56 +0100
committerMartin Pitt <martin.pitt@ubuntu.com>2015-11-16 16:24:56 +0100
commit69b98e71b4e5a915d59ea814386cf1c8e2a0e297 (patch)
treeb52de0d0538b8edb2a53ed2e370f8613abdd19ae /src/test/test-siphash24.c
parentf5ed8d4a51b7f168eba9114a7cf4c2a3132cafff (diff)
siphash42: add tests with unaligned input pointers
Add test case for calling siphash24 with unaligned input pointers, as we commonly get with calling it on the result on basename() or similar. This provides a test for PR #1916, rescued from the superseded PR #1911. Thanks to Steve Langasek for the test!
Diffstat (limited to 'src/test/test-siphash24.c')
-rw-r--r--src/test/test-siphash24.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/src/test/test-siphash24.c b/src/test/test-siphash24.c
index e5a989cdad..0200e146ad 100644
--- a/src/test/test-siphash24.c
+++ b/src/test/test-siphash24.c
@@ -24,17 +24,12 @@
#define ITERATIONS 10000000ULL
-/* see https://131002.net/siphash/siphash.pdf, Appendix A */
-int main(int argc, char *argv[]) {
+static int do_test(const uint8_t *in, size_t len, const uint8_t *key) {
struct siphash state = {};
- const uint8_t in[15] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e };
- const uint8_t key[16] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
uint64_t out = 0;
unsigned i, j;
- siphash24(&out, in, sizeof(in), key);
+ siphash24(&out, in, len, key);
assert_se(out == htole64(0xa129ca6149be45e5));
/* verify the internal state as given in the above paper */
@@ -43,7 +38,7 @@ int main(int argc, char *argv[]) {
assert_se(state.v1 == 0x6b617f6d656e6665);
assert_se(state.v2 == 0x6b7f62616d677361);
assert_se(state.v3 == 0x7b6b696e727e6c7b);
- siphash24_compress(in, sizeof(in), &state);
+ siphash24_compress(in, len, &state);
assert_se(state.v0 == 0x4a017198de0a59e0);
assert_se(state.v1 == 0x0d52f6f62a4f59a4);
assert_se(state.v2 == 0x634cb3577b01fd3d);
@@ -57,14 +52,34 @@ int main(int argc, char *argv[]) {
/* verify that decomposing the input in three chunks gives the
same result */
- for (i = 0; i < sizeof(in); i++) {
- for (j = i; j < sizeof(in); j++) {
+ for (i = 0; i < len; i++) {
+ for (j = i; j < len; j++) {
siphash24_init(&state, key);
siphash24_compress(in, i, &state);
siphash24_compress(&in[i], j - i, &state);
- siphash24_compress(&in[j], sizeof(in) - j, &state);
+ siphash24_compress(&in[j], len - j, &state);
siphash24_finalize(&out, &state);
assert_se(out == htole64(0xa129ca6149be45e5));
}
}
+ return 0;
+}
+
+/* see https://131002.net/siphash/siphash.pdf, Appendix A */
+int main(int argc, char *argv[]) {
+ const uint8_t in[15] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e };
+ const uint8_t key[16] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
+ uint8_t in_buf[20];
+
+ /* Test with same input but different alignments. */
+ memcpy(in_buf, in, sizeof(in));
+ do_test(in_buf, sizeof(in), key);
+ memcpy(in_buf + 1, in, sizeof(in));
+ do_test(in_buf + 1, sizeof(in), key);
+ memcpy(in_buf + 2, in, sizeof(in));
+ do_test(in_buf + 2, sizeof(in), key);
+ memcpy(in_buf + 4, in, sizeof(in));
+ do_test(in_buf + 4, sizeof(in), key);
}