From a4c1d028654284beeb80ce2f4cbd15221ac2a397 Mon Sep 17 00:00:00 2001 From: Karel Bilek Date: Thu, 14 Jun 2018 04:08:33 +0200 Subject: [PATCH] blake2b: Add init with personal key Necessary for zcash hashing --- blake2b.c | 20 ++++++++++++++++++++ blake2b.h | 1 + 2 files changed, 21 insertions(+) diff --git a/blake2b.c b/blake2b.c index 15df011904..26a2f9e082 100644 --- a/blake2b.c +++ b/blake2b.c @@ -131,6 +131,26 @@ int blake2b_Init( blake2b_state *S, size_t outlen ) return blake2b_init_param( S, P ); } +int blake2b_InitPersonal( blake2b_state *S, size_t outlen, const void *personal ) +{ + blake2b_param P[1]; + + if ( ( !outlen ) || ( outlen > BLAKE2B_OUTBYTES ) ) return -1; + + P->digest_length = (uint8_t)outlen; + P->key_length = 0; + P->fanout = 1; + P->depth = 1; + store32( &P->leaf_length, 0 ); + store32( &P->node_offset, 0 ); + store32( &P->xof_length, 0 ); + P->node_depth = 0; + P->inner_length = 0; + memset( P->reserved, 0, sizeof( P->reserved ) ); + memset( P->salt, 0, sizeof( P->salt ) ); + memcpy( P->personal, personal, BLAKE2B_PERSONALBYTES ); + return blake2b_init_param( S, P ); +} int blake2b_InitKey( blake2b_state *S, size_t outlen, const void *key, size_t keylen ) { diff --git a/blake2b.h b/blake2b.h index 772a5cfe44..1c067ee166 100644 --- a/blake2b.h +++ b/blake2b.h @@ -30,6 +30,7 @@ typedef struct __blake2b_state #define BLAKE2B_KEY_LENGTH BLAKE2B_KEYBYTES int blake2b_Init(blake2b_state *S, size_t outlen); +int blake2b_InitPersonal(blake2b_state *S, size_t outlen, const void *personal); int blake2b_InitKey(blake2b_state *S, size_t outlen, const void *key, size_t keylen); int blake2b_Update(blake2b_state *S, const void *pin, size_t inlen); int blake2b_Final(blake2b_state *S, void *out, size_t outlen);