return ctx->hash_size;
}
+static size_t siphash_adjust_hash_size(size_t hash_size)
+{
+ if (hash_size == 0)
+ hash_size = SIPHASH_MAX_DIGEST_SIZE;
+ return hash_size;
+}
+
+int SipHash_set_hash_size(SIPHASH *ctx, size_t hash_size)
+{
+ hash_size = siphash_adjust_hash_size(hash_size);
+ if (hash_size != SIPHASH_MIN_DIGEST_SIZE
+ && hash_size != SIPHASH_MAX_DIGEST_SIZE)
+ return 0;
+
+ ctx->hash_size = hash_size;
+ return 1;
+}
+
/* hash_size = crounds = drounds = 0 means SipHash24 with 16-byte output */
-int SipHash_Init(SIPHASH *ctx, const unsigned char *k, int hash_size, int crounds, int drounds)
+int SipHash_Init(SIPHASH *ctx, const unsigned char *k, int crounds, int drounds)
{
uint64_t k0 = U8TO64_LE(k);
uint64_t k1 = U8TO64_LE(k + 8);
- if (hash_size == 0)
- hash_size = SIPHASH_MAX_DIGEST_SIZE;
- else if (hash_size != SIPHASH_MIN_DIGEST_SIZE &&
- hash_size != SIPHASH_MAX_DIGEST_SIZE)
- return 0;
+ /* If the hash size wasn't set, i.e. is zero */
+ ctx->hash_size = siphash_adjust_hash_size(ctx->hash_size);
if (drounds == 0)
drounds = SIPHASH_D_ROUNDS;
ctx->crounds = crounds;
ctx->drounds = drounds;
- ctx->hash_size = hash_size;
ctx->len = 0;
ctx->total_inlen = 0;