summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-10-04 00:24:23 +0200
committerTom Gundersen <teg@jklm.no>2015-10-05 17:33:58 +0200
commit1283d704172cb3852c717fe8cfaebe7a56d0aebf (patch)
tree64e004ed79c652314addf860159dd89a3f7a8063
parent7c57f504c935a34362d36f514a409f4cbd23a349 (diff)
downloadsystemd-1283d704172cb3852c717fe8cfaebe7a56d0aebf.tar.gz
systemd-1283d704172cb3852c717fe8cfaebe7a56d0aebf.tar.bz2
systemd-1283d704172cb3852c717fe8cfaebe7a56d0aebf.zip
test: siphash24 - verify internal state and composability
Verify the state of the hash-function according to the reference paper, also verify that we can decompose the input and hash the chunks one by one and still get the same result.
-rw-r--r--src/test/test-siphash24.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/test/test-siphash24.c b/src/test/test-siphash24.c
index ec9f64686f..65eb2b6f35 100644
--- a/src/test/test-siphash24.c
+++ b/src/test/test-siphash24.c
@@ -26,15 +26,17 @@
/* see https://131002.net/siphash/siphash.pdf, Appendix A */
int main(int argc, char *argv[]) {
+ 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 k;
+ unsigned i, j, k;
usec_t ts;
siphash24((uint8_t *)&out, in, sizeof(in), key);
+ assert_se(out == 0xa129ca6149be45e5);
assert_se(out == 0xa129ca6149be45e5ULL);
@@ -44,4 +46,33 @@ int main(int argc, char *argv[]) {
ts = now(CLOCK_MONOTONIC) - ts;
log_info("%llu iterations per second", (ITERATIONS * USEC_PER_SEC) / ts);
+
+ /* verify the internal state as given in the above paper */
+ siphash_init(&state, key);
+ assert_se(state.v0 == 0x7469686173716475);
+ assert_se(state.v1 == 0x6b617f6d656e6665);
+ assert_se(state.v2 == 0x6b7f62616d677361);
+ assert_se(state.v3 == 0x7b6b696e727e6c7b);
+ siphash24_compress(in, sizeof(in), &state);
+ assert_se(state.v0 == 0x4a017198de0a59e0);
+ assert_se(state.v1 == 0x0d52f6f62a4f59a4);
+ assert_se(state.v2 == 0x634cb3577b01fd3d);
+ assert_se(state.v3 == 0xa5224d6f55c7d9c8);
+ assert_se(siphash24_finalize(&state) == 0xa129ca6149be45e5);
+ assert_se(state.v0 == 0xf6bcd53893fecff1);
+ assert_se(state.v1 == 0x54b9964c7ea0d937);
+ assert_se(state.v2 == 0x1b38329c099bb55a);
+ assert_se(state.v3 == 0x1814bb89ad7be679);
+
+ /* 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++) {
+ siphash_init(&state, key);
+ siphash24_compress(in, i, &state);
+ siphash24_compress(&in[i], j - i, &state);
+ siphash24_compress(&in[j], sizeof(in) - j, &state);
+ assert_se(siphash24_finalize(&state) == 0xa129ca6149be45e5);
+ }
+ }
}