diff options
author | JP Aumasson <jeanphilippe.aumasson@gmail.com> | 2015-10-15 00:03:14 +0300 |
---|---|---|
committer | JP Aumasson <jeanphilippe.aumasson@gmail.com> | 2015-10-15 00:03:14 +0300 |
commit | a18d2b03fb0df1458c447d488816b51b1164c006 (patch) | |
tree | aa030f2a137db4c51ccc83f0aa0b2aeb606a2eb9 | |
parent | 7d657211ab04ff404e050e12aa01db43a3773e66 (diff) |
consistent checks
-rw-r--r-- | ref/blake2b-ref.c | 8 | ||||
-rw-r--r-- | ref/blake2bp-ref.c | 8 | ||||
-rw-r--r-- | ref/blake2s-ref.c | 8 | ||||
-rw-r--r-- | ref/blake2sp-ref.c | 8 | ||||
-rw-r--r-- | sse/blake2b.c | 8 | ||||
-rw-r--r-- | sse/blake2bp.c | 8 | ||||
-rw-r--r-- | sse/blake2s.c | 8 | ||||
-rw-r--r-- | sse/blake2sp.c | 8 |
8 files changed, 48 insertions, 16 deletions
diff --git a/ref/blake2b-ref.c b/ref/blake2b-ref.c index f962671..f9e852a 100644 --- a/ref/blake2b-ref.c +++ b/ref/blake2b-ref.c @@ -341,11 +341,15 @@ int blake2b( uint8_t *out, const void *in, const void *key, const uint8_t outlen 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 ) { diff --git a/ref/blake2bp-ref.c b/ref/blake2bp-ref.c index 16542ef..d265549 100644 --- a/ref/blake2bp-ref.c +++ b/ref/blake2bp-ref.c @@ -190,11 +190,15 @@ int blake2bp( uint8_t *out, const void *in, const void *key, uint8_t outlen, uin 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; diff --git a/ref/blake2s-ref.c b/ref/blake2s-ref.c index 9678e79..0746ac5 100644 --- a/ref/blake2s-ref.c +++ b/ref/blake2s-ref.c @@ -329,11 +329,15 @@ int blake2s( uint8_t *out, const void *in, const void *key, const uint8_t outlen 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 ) { diff --git a/ref/blake2sp-ref.c b/ref/blake2sp-ref.c index 0e30e49..4397618 100644 --- a/ref/blake2sp-ref.c +++ b/ref/blake2sp-ref.c @@ -188,11 +188,15 @@ int blake2sp( uint8_t *out, const void *in, const void *key, uint8_t outlen, uin 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; diff --git a/sse/blake2b.c b/sse/blake2b.c index 634f0ae..906b10e 100644 --- a/sse/blake2b.c +++ b/sse/blake2b.c @@ -375,11 +375,15 @@ int blake2b( uint8_t *out, const void *in, const void *key, const uint8_t outlen 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 ) { diff --git a/sse/blake2bp.c b/sse/blake2bp.c index d93784c..5734515 100644 --- a/sse/blake2bp.c +++ b/sse/blake2bp.c @@ -191,11 +191,15 @@ int blake2bp( uint8_t *out, const void *in, const void *key, uint8_t outlen, uin 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; diff --git a/sse/blake2s.c b/sse/blake2s.c index 1731b7d..acb0f5a 100644 --- a/sse/blake2s.c +++ b/sse/blake2s.c @@ -357,11 +357,15 @@ int blake2s( uint8_t *out, const void *in, const void *key, const uint8_t outlen 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 ) { diff --git a/sse/blake2sp.c b/sse/blake2sp.c index 954670f..4e5f3cb 100644 --- a/sse/blake2sp.c +++ b/sse/blake2sp.c @@ -188,11 +188,15 @@ int blake2sp( uint8_t *out, const void *in, const void *key, uint8_t outlen, uin 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; |