shithub: blake2

Download patch

ref: a90684ab3fe788b2ca45076cf9b38335de289f58
parent: d4418edab4b9e7595973f876f82d9fecf54b9d19
author: Samuel Neves <sneves@dei.uc.pt>
date: Wed Nov 9 15:37:09 EST 2016

Address bug with small blake2*p output sizes (see #36)

--- a/ref/blake2bp-ref.c
+++ b/ref/blake2bp-ref.c
@@ -1,14 +1,14 @@
 /*
    BLAKE2 reference source code package - reference C implementations
-  
+
    Copyright 2012, Samuel Neves <sneves@dei.uc.pt>.  You may use this under the
    terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
    your option.  The terms of these licenses can be found at:
-  
+
    - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
    - OpenSSL license   : https://www.openssl.org/source/license.html
    - Apache 2.0        : http://www.apache.org/licenses/LICENSE-2.0
-  
+
    More information about the BLAKE2 hash function can be found at
    https://blake2.net.
 */
@@ -27,6 +27,20 @@
 
 #define PARALLELISM_DEGREE 4
 
+/*
+  blake2b_init_param defaults to setting the expecting output length
+  from the digest_length parameter block field.
+
+  In some cases, however, we do not want this, as the output length
+  of these instances is given by inner_length instead.
+*/
+static int blake2bp_init_leaf_param( blake2b_state *S, const blake2b_param *P )
+{
+  int err = blake2b_init_param(S, P);
+  S->outlen = P->inner_length;
+  return err;
+}
+
 static int blake2bp_init_leaf( blake2b_state *S, size_t outlen, size_t keylen, uint64_t offset )
 {
   blake2b_param P[1];
@@ -42,7 +56,7 @@
   memset( P->reserved, 0, sizeof( P->reserved ) );
   memset( P->salt, 0, sizeof( P->salt ) );
   memset( P->personal, 0, sizeof( P->personal ) );
-  return blake2b_init_param( S, P );
+  return blake2bp_init_leaf_param( S, P );
 }
 
 static int blake2bp_init_root( blake2b_state *S, size_t outlen, size_t keylen )
--- a/ref/blake2sp-ref.c
+++ b/ref/blake2sp-ref.c
@@ -1,14 +1,14 @@
 /*
    BLAKE2 reference source code package - reference C implementations
-  
+
    Copyright 2012, Samuel Neves <sneves@dei.uc.pt>.  You may use this under the
    terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
    your option.  The terms of these licenses can be found at:
-  
+
    - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
    - OpenSSL license   : https://www.openssl.org/source/license.html
    - Apache 2.0        : http://www.apache.org/licenses/LICENSE-2.0
-  
+
    More information about the BLAKE2 hash function can be found at
    https://blake2.net.
 */
@@ -26,6 +26,20 @@
 
 #define PARALLELISM_DEGREE 8
 
+/*
+  blake2sp_init_param defaults to setting the expecting output length
+  from the digest_length parameter block field.
+
+  In some cases, however, we do not want this, as the output length
+  of these instances is given by inner_length instead.
+*/
+static int blake2sp_init_leaf_param( blake2s_state *S, const blake2s_param *P )
+{
+  int err = blake2s_init_param(S, P);
+  S->outlen = P->inner_length;
+  return err;
+}
+
 static int blake2sp_init_leaf( blake2s_state *S, size_t outlen, size_t keylen, uint64_t offset )
 {
   blake2s_param P[1];
@@ -40,7 +54,7 @@
   P->inner_length = BLAKE2S_OUTBYTES;
   memset( P->salt, 0, sizeof( P->salt ) );
   memset( P->personal, 0, sizeof( P->personal ) );
-  return blake2s_init_param( S, P );
+  return blake2sp_init_leaf_param( S, P );
 }
 
 static int blake2sp_init_root( blake2s_state *S, size_t outlen, size_t keylen )
--- a/sse/blake2b.c
+++ b/sse/blake2b.c
@@ -1,14 +1,14 @@
 /*
    BLAKE2 reference source code package - optimized C implementations
-  
+
    Copyright 2012, Samuel Neves <sneves@dei.uc.pt>.  You may use this under the
    terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
    your option.  The terms of these licenses can be found at:
-  
+
    - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
    - OpenSSL license   : https://www.openssl.org/source/license.html
    - Apache 2.0        : http://www.apache.org/licenses/LICENSE-2.0
-  
+
    More information about the BLAKE2 hash function can be found at
    https://blake2.net.
 */
--- a/sse/blake2bp.c
+++ b/sse/blake2bp.c
@@ -1,14 +1,14 @@
 /*
    BLAKE2 reference source code package - optimized C implementations
-  
+
    Copyright 2012, Samuel Neves <sneves@dei.uc.pt>.  You may use this under the
    terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
    your option.  The terms of these licenses can be found at:
-  
+
    - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
    - OpenSSL license   : https://www.openssl.org/source/license.html
    - Apache 2.0        : http://www.apache.org/licenses/LICENSE-2.0
-  
+
    More information about the BLAKE2 hash function can be found at
    https://blake2.net.
 */
@@ -27,6 +27,20 @@
 
 #define PARALLELISM_DEGREE 4
 
+/*
+  blake2b_init_param defaults to setting the expecting output length
+  from the digest_length parameter block field.
+
+  In some cases, however, we do not want this, as the output length
+  of these instances is given by inner_length instead.
+*/
+static int blake2bp_init_leaf_param( blake2b_state *S, const blake2b_param *P )
+{
+  int err = blake2b_init_param(S, P);
+  S->outlen = P->inner_length;
+  return err;
+}
+
 static int blake2bp_init_leaf( blake2b_state *S, size_t outlen, size_t keylen, uint64_t offset )
 {
   blake2b_param P[1];
@@ -42,7 +56,7 @@
   memset( P->reserved, 0, sizeof( P->reserved ) );
   memset( P->salt, 0, sizeof( P->salt ) );
   memset( P->personal, 0, sizeof( P->personal ) );
-  return blake2b_init_param( S, P );
+  return blake2bp_init_leaf_param( S, P );
 }
 
 static int blake2bp_init_root( blake2b_state *S, size_t outlen, size_t keylen )
--- a/sse/blake2sp.c
+++ b/sse/blake2sp.c
@@ -1,14 +1,14 @@
 /*
    BLAKE2 reference source code package - optimized C implementations
-  
+
    Copyright 2012, Samuel Neves <sneves@dei.uc.pt>.  You may use this under the
    terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
    your option.  The terms of these licenses can be found at:
-  
+
    - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
    - OpenSSL license   : https://www.openssl.org/source/license.html
    - Apache 2.0        : http://www.apache.org/licenses/LICENSE-2.0
-  
+
    More information about the BLAKE2 hash function can be found at
    https://blake2.net.
 */
@@ -26,6 +26,20 @@
 
 #define PARALLELISM_DEGREE 8
 
+/*
+  blake2sp_init_param defaults to setting the expecting output length
+  from the digest_length parameter block field.
+
+  In some cases, however, we do not want this, as the output length
+  of these instances is given by inner_length instead.
+*/
+static int blake2sp_init_leaf_param( blake2s_state *S, const blake2s_param *P )
+{
+  int err = blake2s_init_param(S, P);
+  S->outlen = P->inner_length;
+  return err;
+}
+
 static int blake2sp_init_leaf( blake2s_state *S, size_t outlen, size_t keylen, uint64_t offset )
 {
   blake2s_param P[1];
@@ -40,7 +54,7 @@
   P->inner_length = BLAKE2S_OUTBYTES;
   memset( P->salt, 0, sizeof( P->salt ) );
   memset( P->personal, 0, sizeof( P->personal ) );
-  return blake2s_init_param( S, P );
+  return blake2sp_init_leaf_param( S, P );
 }
 
 static int blake2sp_init_root( blake2s_state *S, size_t outlen, size_t keylen )
--