diff --git a/blake2b.h b/blake2b.h index 1b2656745d..1a43e92d1e 100644 --- a/blake2b.h +++ b/blake2b.h @@ -30,8 +30,8 @@ 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, size_t personal_len); int blake2b_InitKey(blake2b_state *S, size_t outlen, const void *key, size_t keylen); +int blake2b_InitPersonal(blake2b_state *S, size_t outlen, const void *personal, size_t personal_len); int blake2b_Update(blake2b_state *S, const void *pin, size_t inlen); int blake2b_Final(blake2b_state *S, void *out, size_t outlen); diff --git a/blake2s.c b/blake2s.c index 636479b9b9..57435e7a15 100644 --- a/blake2s.c +++ b/blake2s.c @@ -126,6 +126,29 @@ int blake2s_Init( blake2s_state *S, size_t outlen ) return blake2s_init_param( S, P ); } +int blake2s_InitPersonal( blake2s_state *S, size_t outlen, const void *personal, size_t personal_len) +{ + blake2s_param P[1]; + + if ( ( !outlen ) || ( outlen > BLAKE2S_OUTBYTES ) ) return -1; + if ( ( !personal ) || ( personal_len != BLAKE2S_PERSONALBYTES ) ) 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 ); + store16( &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, BLAKE2S_PERSONALBYTES ); + return blake2s_init_param( S, P ); +} + + int blake2s_InitKey( blake2s_state *S, size_t outlen, const void *key, size_t keylen ) { blake2s_param P[1]; diff --git a/blake2s.h b/blake2s.h index dd34bf1949..57991bc913 100644 --- a/blake2s.h +++ b/blake2s.h @@ -31,6 +31,7 @@ typedef struct __blake2s_state int blake2s_Init(blake2s_state *S, size_t outlen); int blake2s_InitKey(blake2s_state *S, size_t outlen, const void *key, size_t keylen); +int blake2s_InitPersonal(blake2s_state *S, size_t outlen, const void *personal, size_t personal_len); int blake2s_Update(blake2s_state *S, const void *pin, size_t inlen); int blake2s_Final(blake2s_state *S, void *out, size_t outlen);