summaryrefslogtreecommitdiffstats
path: root/crypto/siphash
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2018-11-11 12:23:26 +0100
committerRichard Levitte <levitte@openssl.org>2018-11-12 07:15:55 +0100
commit425036130dfb3cfbef5937772f7526ce60133264 (patch)
tree17ee9c186aa40a33822e716498248a2be1b31ed8 /crypto/siphash
parent59fbc8ef9a9c0700fd2b107fea390470ff17ada4 (diff)
Fix SipHash init order.
Setting the SipHash hash size and setting its key is done with two independent functions... and yet, the internals depend on both. Unfortunately, the function to change the size wasn't adapted for the possibility that the key was set first, with a different hash size. This changes the hash setting function to fix the internal values (which is easy, fortunately) according to the hash size. evpmac.txt value for digestsize:8 is also corrected. Reviewed-by: Paul Dale <paul.dale@oracle.com> (Merged from https://github.com/openssl/openssl/pull/7613)
Diffstat (limited to 'crypto/siphash')
-rw-r--r--crypto/siphash/siphash.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/crypto/siphash/siphash.c b/crypto/siphash/siphash.c
index ff84a29f82..be74a38d93 100644
--- a/crypto/siphash/siphash.c
+++ b/crypto/siphash/siphash.c
@@ -94,7 +94,19 @@ int SipHash_set_hash_size(SIPHASH *ctx, size_t hash_size)
&& hash_size != SIPHASH_MAX_DIGEST_SIZE)
return 0;
- ctx->hash_size = hash_size;
+ /*
+ * It's possible that the key was set first. If the hash size changes,
+ * we need to adjust v1 (see SipHash_Init().
+ */
+
+ /* Start by adjusting the stored size, to make things easier */
+ ctx->hash_size = siphash_adjust_hash_size(ctx->hash_size);
+
+ /* Now, adjust ctx->v1 if the old and the new size differ */
+ if ((size_t)ctx->hash_size != hash_size) {
+ ctx->v1 ^= 0xee;
+ ctx->hash_size = hash_size;
+ }
return 1;
}