diff options
author | Richard Levitte <levitte@openssl.org> | 2018-09-06 22:52:38 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2018-09-09 01:47:56 +0200 |
commit | d74f23d2dbf2de0f374bff004c135242cfb65174 (patch) | |
tree | 766fdbfde67286e37c872b562e4887203399a483 /test/siphash_internal_test.c | |
parent | 2725232132207ee30fd16e596885e3b0bd810fc4 (diff) |
SipHash: add separate setter for the hash size
This was originally part of SipHash_Init. However, there are cases
where there isn't any key material to initialize from when setting the
hash size, and we do allow doing so with a EVP_PKEY control. The
solution is to provide a separate hash_size setter and to use it in
the corresponding EVP_PKEY_METHOD.
Fixes #7143
Reviewed-by: Tim Hudson <tjh@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/7145)
Diffstat (limited to 'test/siphash_internal_test.c')
-rw-r--r-- | test/siphash_internal_test.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/test/siphash_internal_test.c b/test/siphash_internal_test.c index 573c15d254..dfdce48d13 100644 --- a/test/siphash_internal_test.c +++ b/test/siphash_internal_test.c @@ -196,7 +196,8 @@ static int test_siphash(int idx) for (i = 0; i < inlen; i++) in[i] = (unsigned char)i; - if (!TEST_true(SipHash_Init(&siphash, key, expectedlen, 0, 0))) + if (!TEST_true(SipHash_set_hash_size(&siphash, expectedlen)) + || !TEST_true(SipHash_Init(&siphash, key, 0, 0))) return 0; SipHash_Update(&siphash, in, inlen); if (!TEST_true(SipHash_Final(&siphash, out, expectedlen)) @@ -204,7 +205,8 @@ static int test_siphash(int idx) return 0; if (inlen > 16) { - if (!TEST_true(SipHash_Init(&siphash, key, expectedlen, 0, 0))) + if (!TEST_true(SipHash_set_hash_size(&siphash, expectedlen)) + || !TEST_true(SipHash_Init(&siphash, key, 0, 0))) return 0; SipHash_Update(&siphash, in, 1); SipHash_Update(&siphash, in+1, inlen-1); @@ -220,7 +222,8 @@ static int test_siphash(int idx) if (inlen > 32) { size_t half = inlen / 2; - if (!TEST_true(SipHash_Init(&siphash, key, expectedlen, 0, 0))) + if (!TEST_true(SipHash_set_hash_size(&siphash, expectedlen)) + || !TEST_true(SipHash_Init(&siphash, key, 0, 0))) return 0; SipHash_Update(&siphash, in, half); SipHash_Update(&siphash, in+half, inlen-half); @@ -233,7 +236,8 @@ static int test_siphash(int idx) } for (half = 16; half < inlen; half += 16) { - if (!TEST_true(SipHash_Init(&siphash, key, expectedlen, 0, 0))) + if (!TEST_true(SipHash_set_hash_size(&siphash, expectedlen)) + || !TEST_true(SipHash_Init(&siphash, key, 0, 0))) return 0; SipHash_Update(&siphash, in, half); SipHash_Update(&siphash, in+half, inlen-half); @@ -258,19 +262,22 @@ static int test_siphash_basic(void) unsigned char output[SIPHASH_MAX_DIGEST_SIZE]; /* Use invalid hash size */ - return TEST_int_eq(SipHash_Init(&siphash, key, 4, 0, 0), 0) + return TEST_int_eq(SipHash_set_hash_size(&siphash, 4), 0) /* Use hash size = 8 */ - && TEST_true(SipHash_Init(&siphash, key, 8, 0, 0)) + && TEST_true(SipHash_set_hash_size(&siphash, 8)) + && TEST_true(SipHash_Init(&siphash, key, 0, 0)) && TEST_true(SipHash_Final(&siphash, output, 8)) && TEST_int_eq(SipHash_Final(&siphash, output, 16), 0) /* Use hash size = 16 */ - && TEST_true(SipHash_Init(&siphash, key, 16, 0, 0)) + && TEST_true(SipHash_set_hash_size(&siphash, 16)) + && TEST_true(SipHash_Init(&siphash, key, 0, 0)) && TEST_int_eq(SipHash_Final(&siphash, output, 8), 0) && TEST_true(SipHash_Final(&siphash, output, 16)) /* Use hash size = 0 (default = 16) */ - && TEST_true(SipHash_Init(&siphash, key, 0, 0, 0)) + && TEST_true(SipHash_set_hash_size(&siphash, 0)) + && TEST_true(SipHash_Init(&siphash, key, 0, 0)) && TEST_int_eq(SipHash_Final(&siphash, output, 8), 0) && TEST_true(SipHash_Final(&siphash, output, 16)); } |