diff options
author | Frank Denis <github@pureftpd.org> | 2016-04-06 02:32:36 +0300 |
---|---|---|
committer | Frank Denis <github@pureftpd.org> | 2016-04-06 02:40:45 +0300 |
commit | bcc99c1b6a4888fe0c289995879144b489f0dff8 (patch) | |
tree | 5286d18f652c27dff5261ebad4698dd255e49806 /ref/blake2b-ref.c | |
parent | 168fbb78f53f684384ec1fa71e509475e96cd1ea (diff) |
blake2*_final() should return an error if called twice
Diffstat (limited to 'ref/blake2b-ref.c')
-rw-r--r-- | ref/blake2b-ref.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/ref/blake2b-ref.c b/ref/blake2b-ref.c index dd728bc..0e36ee2 100644 --- a/ref/blake2b-ref.c +++ b/ref/blake2b-ref.c @@ -58,6 +58,11 @@ static inline int blake2b_clear_lastnode( blake2b_state *S ) } /* Some helper functions, not necessarily useful */ +static inline int blake2b_is_lastblock( const blake2b_state *S ) +{ + return S->f[0] != 0; +} + static inline int blake2b_set_lastblock( blake2b_state *S ) { if( S->last_node ) blake2b_set_lastnode( S ); @@ -317,6 +322,9 @@ int blake2b_final( blake2b_state *S, uint8_t *out, uint8_t outlen ) if( out == NULL || outlen == 0 || outlen > BLAKE2B_OUTBYTES ) return -1; + if( blake2b_is_lastblock( S ) ) + return -1; + if( S->buflen > BLAKE2B_BLOCKBYTES ) { blake2b_increment_counter( S, BLAKE2B_BLOCKBYTES ); |