ref: a18d2b03fb0df1458c447d488816b51b1164c006
parent: 7d657211ab04ff404e050e12aa01db43a3773e66
author: JP Aumasson <jeanphilippe.aumasson@gmail.com>
date: Wed Oct 14 19:03:14 EDT 2015
consistent checks
--- a/ref/blake2b-ref.c
+++ b/ref/blake2b-ref.c
@@ -341,11 +341,15 @@
blake2b_state S[1];
/* Verify parameters */
- if ( NULL == in ) return -1;
+ if ( NULL == in && inlen > 0 ) return -1;
if ( NULL == out ) return -1;
- if( NULL == key ) keylen = 0;
+ if( NULL == key && keylen > 0 ) return -1;
+
+ if( !outlen || outlen > BLAKE2B_OUTBYTES ) return -1;
+
+ if( keylen > BLAKE2B_KEYBYTES ) return -1;
if( keylen > 0 )
{
--- a/ref/blake2bp-ref.c
+++ b/ref/blake2bp-ref.c
@@ -190,11 +190,15 @@
blake2b_state FS[1];
/* Verify parameters */
- if ( NULL == in ) return -1;
+ if ( NULL == in && inlen > 0 ) return -1;
if ( NULL == out ) return -1;
- if ( NULL == key ) keylen = 0;
+ if( NULL == key && keylen > 0 ) return -1;
+
+ if( !outlen || outlen > BLAKE2B_OUTBYTES ) return -1;
+
+ if( keylen > BLAKE2B_KEYBYTES ) return -1;
for( size_t i = 0; i < PARALLELISM_DEGREE; ++i )
if( blake2bp_init_leaf( S[i], outlen, keylen, i ) < 0 ) return -1;
--- a/ref/blake2s-ref.c
+++ b/ref/blake2s-ref.c
@@ -329,11 +329,15 @@
blake2s_state S[1];
/* Verify parameters */
- if ( NULL == in ) return -1;
+ if ( NULL == in && inlen > 0 ) return -1;
if ( NULL == out ) return -1;
- if ( NULL == key ) keylen = 0; /* Fail here instead if keylen != 0 and key == NULL? */
+ if ( NULL == key && keylen > 0) return -1;
+
+ if( !outlen || outlen > BLAKE2S_OUTBYTES ) return -1;
+
+ if( keylen > BLAKE2S_KEYBYTES ) return -1;
if( keylen > 0 )
{
--- a/ref/blake2sp-ref.c
+++ b/ref/blake2sp-ref.c
@@ -188,11 +188,15 @@
blake2s_state FS[1];
/* Verify parameters */
- if ( NULL == in ) return -1;
+ :if ( NULL == in && inlen > 0 ) return -1;
if ( NULL == out ) return -1;
- if ( NULL == key ) keylen = 0;
+ if ( NULL == key && keylen > 0) return -1;
+
+ if( !outlen || outlen > BLAKE2S_OUTBYTES ) return -1;
+
+ if( keylen > BLAKE2S_KEYBYTES ) return -1;
for( size_t i = 0; i < PARALLELISM_DEGREE; ++i )
if( blake2sp_init_leaf( S[i], outlen, keylen, i ) < 0 ) return -1;
--- a/sse/blake2b.c
+++ b/sse/blake2b.c
@@ -375,11 +375,15 @@
blake2b_state S[1];
/* Verify parameters */
- if ( NULL == in ) return -1;
+ if ( NULL == in && inlen > 0 ) return -1;
if ( NULL == out ) return -1;
- if( NULL == key ) keylen = 0;
+ if( NULL == key && keylen > 0 ) return -1;
+
+ if( !outlen || outlen > BLAKE2B_OUTBYTES ) return -1;
+
+ if( keylen > BLAKE2B_KEYBYTES ) return -1;
if( keylen )
{
--- a/sse/blake2bp.c
+++ b/sse/blake2bp.c
@@ -191,11 +191,15 @@
blake2b_state FS[1];
/* Verify parameters */
- if ( NULL == in ) return -1;
+ if ( NULL == in && inlen > 0 ) return -1;
if ( NULL == out ) return -1;
- if ( NULL == key ) keylen = 0;
+ if( NULL == key && keylen > 0 ) return -1;
+
+ if( !outlen || outlen > BLAKE2B_OUTBYTES ) return -1;
+
+ if( keylen > BLAKE2B_KEYBYTES ) return -1;
for( size_t i = 0; i < PARALLELISM_DEGREE; ++i )
if( blake2bp_init_leaf( S[i], outlen, keylen, i ) < 0 ) return -1;
--- a/sse/blake2s.c
+++ b/sse/blake2s.c
@@ -357,11 +357,15 @@
blake2s_state S[1];
/* Verify parameters */
- if ( NULL == in ) return -1;
+ if ( NULL == in && inlen > 0 ) return -1;
if ( NULL == out ) return -1;
- if ( NULL == key ) keylen = 0; /* Fail here instead if keylen != 0 and key == NULL? */
+ if ( NULL == key && keylen > 0) return -1;
+
+ if( !outlen || outlen > BLAKE2S_OUTBYTES ) return -1;
+
+ if( keylen > BLAKE2S_KEYBYTES ) return -1;
if( keylen > 0 )
{
--- a/sse/blake2sp.c
+++ b/sse/blake2sp.c
@@ -188,11 +188,15 @@
blake2s_state FS[1];
/* Verify parameters */
- if ( NULL == in ) return -1;
+ if ( NULL == in && inlen > 0 ) return -1;
if ( NULL == out ) return -1;
- if ( NULL == key ) keylen = 0;
+ if ( NULL == key && keylen > 0) return -1;
+
+ if( !outlen || outlen > BLAKE2S_OUTBYTES ) return -1;
+
+ if( keylen > BLAKE2S_KEYBYTES ) return -1;
for( size_t i = 0; i < PARALLELISM_DEGREE; ++i )
if( blake2sp_init_leaf( S[i], outlen, keylen, i ) < 0 ) return -1;
--
⑨