Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/BLAKE2/BLAKE2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Neves <sneves@dei.uc.pt>2016-06-11 13:11:20 +0300
committerSamuel Neves <sneves@dei.uc.pt>2016-06-11 13:11:20 +0300
commit86f24fed1052bbfa9f0739743678b66305ba3907 (patch)
tree5bfa8ed59fb1d40937e998d5090520ab39bb2662
parent259e61dedee5383eac1a90db6ef88f9ccdcf6002 (diff)
api cleanup, sse edition
-rw-r--r--ref/blake2.h8
-rw-r--r--ref/blake2b-ref.c90
-rw-r--r--ref/blake2s-ref.c90
-rw-r--r--ref/makefile2
-rw-r--r--sse/blake2.h70
-rw-r--r--sse/blake2b.c168
-rw-r--r--sse/blake2bp.c33
-rw-r--r--sse/blake2s.c150
-rw-r--r--sse/blake2sp.c35
-rw-r--r--sse/genkat-json.c4
10 files changed, 184 insertions, 466 deletions
diff --git a/ref/blake2.h b/ref/blake2.h
index 50194b0..2e1838c 100644
--- a/ref/blake2.h
+++ b/ref/blake2.h
@@ -52,7 +52,7 @@ extern "C" {
uint32_t t[2];
uint32_t f[2];
uint8_t buf[BLAKE2S_BLOCKBYTES];
- uint32_t buflen;
+ size_t buflen;
uint8_t last_node;
} blake2s_state;
@@ -62,7 +62,7 @@ extern "C" {
uint64_t t[2];
uint64_t f[2];
uint8_t buf[BLAKE2B_BLOCKBYTES];
- uint32_t buflen;
+ size_t buflen;
uint8_t last_node;
} blake2b_state;
@@ -71,7 +71,7 @@ extern "C" {
blake2s_state S[8][1];
blake2s_state R[1];
uint8_t buf[8 * BLAKE2S_BLOCKBYTES];
- uint32_t buflen;
+ size_t buflen;
} blake2sp_state;
typedef struct blake2bp_state__
@@ -79,7 +79,7 @@ extern "C" {
blake2b_state S[4][1];
blake2b_state R[1];
uint8_t buf[4 * BLAKE2B_BLOCKBYTES];
- uint32_t buflen;
+ size_t buflen;
} blake2bp_state;
diff --git a/ref/blake2b-ref.c b/ref/blake2b-ref.c
index 9e02d4a..1ed4a5a 100644
--- a/ref/blake2b-ref.c
+++ b/ref/blake2b-ref.c
@@ -45,16 +45,14 @@ static const uint8_t blake2b_sigma[12][16] =
};
-static int blake2b_set_lastnode( blake2b_state *S )
+static void blake2b_set_lastnode( blake2b_state *S )
{
- S->f[1] = -1;
- return 0;
+ S->f[1] = (uint64_t)-1;
}
-static int blake2b_clear_lastnode( blake2b_state *S )
+static void blake2b_clear_lastnode( blake2b_state *S )
{
S->f[1] = 0;
- return 0;
}
/* Some helper functions, not necessarily useful */
@@ -63,94 +61,32 @@ static int blake2b_is_lastblock( const blake2b_state *S )
return S->f[0] != 0;
}
-static int blake2b_set_lastblock( blake2b_state *S )
+static void blake2b_set_lastblock( blake2b_state *S )
{
if( S->last_node ) blake2b_set_lastnode( S );
- S->f[0] = -1;
- return 0;
+ S->f[0] = (uint64_t)-1;
}
-static int blake2b_clear_lastblock( blake2b_state *S )
+static void blake2b_clear_lastblock( blake2b_state *S )
{
if( S->last_node ) blake2b_clear_lastnode( S );
S->f[0] = 0;
- return 0;
}
-static int blake2b_increment_counter( blake2b_state *S, const uint64_t inc )
+static void blake2b_increment_counter( blake2b_state *S, const uint64_t inc )
{
S->t[0] += inc;
S->t[1] += ( S->t[0] < inc );
- return 0;
}
-
-
-/* Parameter-related functions */
-static int blake2b_param_set_digest_length( blake2b_param *P, const uint8_t digest_length )
+static void blake2b_init0( blake2b_state *S )
{
- P->digest_length = digest_length;
- return 0;
-}
-
-static int blake2b_param_set_fanout( blake2b_param *P, const uint8_t fanout )
-{
- P->fanout = fanout;
- return 0;
-}
-
-static int blake2b_param_set_max_depth( blake2b_param *P, const uint8_t depth )
-{
- P->depth = depth;
- return 0;
-}
-
-static int blake2b_param_set_leaf_length( blake2b_param *P, const uint32_t leaf_length )
-{
- store32( &P->leaf_length, leaf_length );
- return 0;
-}
-
-static int blake2b_param_set_node_offset( blake2b_param *P, const uint64_t node_offset )
-{
- store64( &P->node_offset, node_offset );
- return 0;
-}
-
-static int blake2b_param_set_node_depth( blake2b_param *P, const uint8_t node_depth )
-{
- P->node_depth = node_depth;
- return 0;
-}
-
-static int blake2b_param_set_inner_length( blake2b_param *P, const uint8_t inner_length )
-{
- P->inner_length = inner_length;
- return 0;
-}
-
-static int blake2b_param_set_salt( blake2b_param *P, const uint8_t salt[BLAKE2B_SALTBYTES] )
-{
- memcpy( P->salt, salt, BLAKE2B_SALTBYTES );
- return 0;
-}
-
-static int blake2b_param_set_personal( blake2b_param *P, const uint8_t personal[BLAKE2B_PERSONALBYTES] )
-{
- memcpy( P->personal, personal, BLAKE2B_PERSONALBYTES );
- return 0;
-}
-
-static int blake2b_init0( blake2b_state *S )
-{
- int i;
+ size_t i;
memset( S, 0, sizeof( blake2b_state ) );
for( i = 0; i < 8; ++i ) S->h[i] = blake2b_IV[i];
-
- return 0;
}
/* init xors IV with input parameter block */
@@ -176,7 +112,7 @@ int blake2b_init( blake2b_state *S, size_t outlen )
if ( ( !outlen ) || ( outlen > BLAKE2B_OUTBYTES ) ) return -1;
- P->digest_length = outlen;
+ P->digest_length = (uint8_t)outlen;
P->key_length = 0;
P->fanout = 1;
P->depth = 1;
@@ -251,7 +187,7 @@ static void blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOC
{
uint64_t m[16];
uint64_t v[16];
- int i;
+ size_t i;
for( i = 0; i < 16; ++i ) {
m[i] = load64( block + i * sizeof( m[i] ) );
@@ -313,7 +249,7 @@ int blake2b_update( blake2b_state *S, const void *pin, size_t inlen )
}
}
memcpy( S->buf + S->buflen, in, inlen );
- S->buflen += (uint32_t)inlen;
+ S->buflen += inlen;
}
return 0;
}
@@ -321,7 +257,7 @@ int blake2b_update( blake2b_state *S, const void *pin, size_t inlen )
int blake2b_final( blake2b_state *S, void *out, size_t outlen )
{
uint8_t buffer[BLAKE2B_OUTBYTES] = {0};
- int i;
+ size_t i;
if( out == NULL || outlen == 0 || outlen > BLAKE2B_OUTBYTES )
return -1;
diff --git a/ref/blake2s-ref.c b/ref/blake2s-ref.c
index 190208d..d4efe7e 100644
--- a/ref/blake2s-ref.c
+++ b/ref/blake2s-ref.c
@@ -40,16 +40,14 @@ static const uint8_t blake2s_sigma[10][16] =
{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 } ,
};
-static int blake2s_set_lastnode( blake2s_state *S )
+static void blake2s_set_lastnode( blake2s_state *S )
{
- S->f[1] = -1;
- return 0;
+ S->f[1] = (uint32_t)-1;
}
-static int blake2s_clear_lastnode( blake2s_state *S )
+static void blake2s_clear_lastnode( blake2s_state *S )
{
S->f[1] = 0;
- return 0;
}
/* Some helper functions, not necessarily useful */
@@ -58,105 +56,45 @@ static int blake2s_is_lastblock( const blake2s_state *S )
return S->f[0] != 0;
}
-static int blake2s_set_lastblock( blake2s_state *S )
+static void blake2s_set_lastblock( blake2s_state *S )
{
if( S->last_node ) blake2s_set_lastnode( S );
- S->f[0] = -1;
- return 0;
+ S->f[0] = (uint32_t)-1;
}
-static int blake2s_clear_lastblock( blake2s_state *S )
+static void blake2s_clear_lastblock( blake2s_state *S )
{
if( S->last_node ) blake2s_clear_lastnode( S );
S->f[0] = 0;
- return 0;
}
-static int blake2s_increment_counter( blake2s_state *S, const uint32_t inc )
+static void blake2s_increment_counter( blake2s_state *S, const uint32_t inc )
{
S->t[0] += inc;
S->t[1] += ( S->t[0] < inc );
- return 0;
-}
-
-/* Parameter-related functions */
-static int blake2s_param_set_digest_length( blake2s_param *P, const uint8_t digest_length )
-{
- P->digest_length = digest_length;
- return 0;
-}
-
-static int blake2s_param_set_fanout( blake2s_param *P, const uint8_t fanout )
-{
- P->fanout = fanout;
- return 0;
-}
-
-static int blake2s_param_set_max_depth( blake2s_param *P, const uint8_t depth )
-{
- P->depth = depth;
- return 0;
-}
-
-static int blake2s_param_set_leaf_length( blake2s_param *P, const uint32_t leaf_length )
-{
- store32( &P->leaf_length, leaf_length );
- return 0;
-}
-
-static int blake2s_param_set_node_offset( blake2s_param *P, const uint64_t node_offset )
-{
- store48( P->node_offset, node_offset );
- return 0;
-}
-
-static int blake2s_param_set_node_depth( blake2s_param *P, const uint8_t node_depth )
-{
- P->node_depth = node_depth;
- return 0;
}
-static int blake2s_param_set_inner_length( blake2s_param *P, const uint8_t inner_length )
+static void blake2s_init0( blake2s_state *S )
{
- P->inner_length = inner_length;
- return 0;
-}
-
-static int blake2s_param_set_salt( blake2s_param *P, const uint8_t salt[BLAKE2S_SALTBYTES] )
-{
- memcpy( P->salt, salt, BLAKE2S_SALTBYTES );
- return 0;
-}
-
-static int blake2s_param_set_personal( blake2s_param *P, const uint8_t personal[BLAKE2S_PERSONALBYTES] )
-{
- memcpy( P->personal, personal, BLAKE2S_PERSONALBYTES );
- return 0;
-}
-
-static int blake2s_init0( blake2s_state *S )
-{
- int i;
+ size_t i;
memset( S, 0, sizeof( blake2s_state ) );
for( i = 0; i < 8; ++i ) S->h[i] = blake2s_IV[i];
-
- return 0;
}
/* init2 xors IV with input parameter block */
int blake2s_init_param( blake2s_state *S, const blake2s_param *P )
{
+ const unsigned char *p = ( const unsigned char * )( P );
size_t i;
- const uint32_t *p = ( const uint32_t * )( P );
blake2s_init0( S );
/* IV XOR ParamBlock */
for( i = 0; i < 8; ++i )
- S->h[i] ^= load32( &p[i] );
+ S->h[i] ^= load32( &p[i * 4] );
return 0;
}
@@ -170,7 +108,7 @@ int blake2s_init( blake2s_state *S, size_t outlen )
/* Move interval verification here? */
if ( ( !outlen ) || ( outlen > BLAKE2S_OUTBYTES ) ) return -1;
- P->digest_length = outlen;
+ P->digest_length = (uint8_t)outlen;
P->key_length = 0;
P->fanout = 1;
P->depth = 1;
@@ -304,7 +242,7 @@ int blake2s_update( blake2s_state *S, const void *pin, size_t inlen )
}
}
memcpy( S->buf + S->buflen, in, inlen );
- S->buflen += (uint32_t)inlen;
+ S->buflen += inlen;
}
return 0;
}
@@ -312,7 +250,7 @@ int blake2s_update( blake2s_state *S, const void *pin, size_t inlen )
int blake2s_final( blake2s_state *S, void *out, size_t outlen )
{
uint8_t buffer[BLAKE2S_OUTBYTES] = {0};
- int i;
+ size_t i;
if( out == NULL || outlen == 0 || outlen > BLAKE2S_OUTBYTES )
return -1;
diff --git a/ref/makefile b/ref/makefile
index 0772bd6..7815544 100644
--- a/ref/makefile
+++ b/ref/makefile
@@ -1,5 +1,5 @@
CC=gcc
-CFLAGS=-O2 -Wall -I../testvectors
+CFLAGS=-O2 -I../testvectors
all: blake2s blake2b blake2sp blake2bp check
diff --git a/sse/blake2.h b/sse/blake2.h
index 6e5b967..2e1838c 100644
--- a/sse/blake2.h
+++ b/sse/blake2.h
@@ -46,44 +46,44 @@ extern "C" {
BLAKE2B_PERSONALBYTES = 16
};
- typedef struct __blake2s_state
+ typedef struct blake2s_state__
{
uint32_t h[8];
uint32_t t[2];
uint32_t f[2];
- uint8_t buf[2 * BLAKE2S_BLOCKBYTES];
+ uint8_t buf[BLAKE2S_BLOCKBYTES];
size_t buflen;
uint8_t last_node;
} blake2s_state;
- typedef struct __blake2b_state
+ typedef struct blake2b_state__
{
uint64_t h[8];
uint64_t t[2];
uint64_t f[2];
- uint8_t buf[2 * BLAKE2B_BLOCKBYTES];
+ uint8_t buf[BLAKE2B_BLOCKBYTES];
size_t buflen;
uint8_t last_node;
} blake2b_state;
- typedef struct __blake2sp_state
+ typedef struct blake2sp_state__
{
blake2s_state S[8][1];
blake2s_state R[1];
- uint8_t buf[8 * BLAKE2S_BLOCKBYTES];
- size_t buflen;
+ uint8_t buf[8 * BLAKE2S_BLOCKBYTES];
+ size_t buflen;
} blake2sp_state;
- typedef struct __blake2bp_state
+ typedef struct blake2bp_state__
{
blake2b_state S[4][1];
blake2b_state R[1];
- uint8_t buf[4 * BLAKE2B_BLOCKBYTES];
- size_t buflen;
+ uint8_t buf[4 * BLAKE2B_BLOCKBYTES];
+ size_t buflen;
} blake2bp_state;
- BLAKE2_PACKED(struct __blake2s_param
+ BLAKE2_PACKED(struct blake2s_param__
{
uint8_t digest_length; /* 1 */
uint8_t key_length; /* 2 */
@@ -98,9 +98,9 @@ extern "C" {
uint8_t personal[BLAKE2S_PERSONALBYTES]; /* 32 */
});
- typedef struct __blake2s_param blake2s_param;
+ typedef struct blake2s_param__ blake2s_param;
- BLAKE2_PACKED(struct __blake2b_param
+ BLAKE2_PACKED(struct blake2b_param__
{
uint8_t digest_length; /* 1 */
uint8_t key_length; /* 2 */
@@ -115,7 +115,7 @@ extern "C" {
uint8_t personal[BLAKE2B_PERSONALBYTES]; /* 64 */
});
- typedef struct __blake2b_param blake2b_param;
+ typedef struct blake2b_param__ blake2b_param;
/* Padded structs result in a compile-time error */
enum {
@@ -124,37 +124,37 @@ extern "C" {
};
/* Streaming API */
- int blake2s_init( blake2s_state *S, const uint8_t outlen );
- int blake2s_init_key( blake2s_state *S, const uint8_t outlen, const void *key, const uint8_t keylen );
+ int blake2s_init( blake2s_state *S, size_t outlen );
+ int blake2s_init_key( blake2s_state *S, size_t outlen, const void *key, size_t keylen );
int blake2s_init_param( blake2s_state *S, const blake2s_param *P );
- int blake2s_update( blake2s_state *S, const uint8_t *in, uint64_t inlen );
- int blake2s_final( blake2s_state *S, uint8_t *out, uint8_t outlen );
+ int blake2s_update( blake2s_state *S, const void *in, size_t inlen );
+ int blake2s_final( blake2s_state *S, void *out, size_t outlen );
- int blake2b_init( blake2b_state *S, const uint8_t outlen );
- int blake2b_init_key( blake2b_state *S, const uint8_t outlen, const void *key, const uint8_t keylen );
+ int blake2b_init( blake2b_state *S, size_t outlen );
+ int blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t keylen );
int blake2b_init_param( blake2b_state *S, const blake2b_param *P );
- int blake2b_update( blake2b_state *S, const uint8_t *in, uint64_t inlen );
- int blake2b_final( blake2b_state *S, uint8_t *out, uint8_t outlen );
+ int blake2b_update( blake2b_state *S, const void *in, size_t inlen );
+ int blake2b_final( blake2b_state *S, void *out, size_t outlen );
- int blake2sp_init( blake2sp_state *S, const uint8_t outlen );
- int blake2sp_init_key( blake2sp_state *S, const uint8_t outlen, const void *key, const uint8_t keylen );
- int blake2sp_update( blake2sp_state *S, const uint8_t *in, uint64_t inlen );
- int blake2sp_final( blake2sp_state *S, uint8_t *out, uint8_t outlen );
+ int blake2sp_init( blake2sp_state *S, size_t outlen );
+ int blake2sp_init_key( blake2sp_state *S, size_t outlen, const void *key, size_t keylen );
+ int blake2sp_update( blake2sp_state *S, const void *in, size_t inlen );
+ int blake2sp_final( blake2sp_state *S, void *out, size_t outlen );
- int blake2bp_init( blake2bp_state *S, const uint8_t outlen );
- int blake2bp_init_key( blake2bp_state *S, const uint8_t outlen, const void *key, const uint8_t keylen );
- int blake2bp_update( blake2bp_state *S, const uint8_t *in, uint64_t inlen );
- int blake2bp_final( blake2bp_state *S, uint8_t *out, uint8_t outlen );
+ int blake2bp_init( blake2bp_state *S, size_t outlen );
+ int blake2bp_init_key( blake2bp_state *S, size_t outlen, const void *key, size_t keylen );
+ int blake2bp_update( blake2bp_state *S, const void *in, size_t inlen );
+ int blake2bp_final( blake2bp_state *S, void *out, size_t outlen );
/* Simple API */
- int blake2s( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen );
- int blake2b( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen );
+ int blake2s( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
+ int blake2b( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
- int blake2sp( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen );
- int blake2bp( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen );
+ int blake2sp( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
+ int blake2bp( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
/* This is simply an alias for blake2b */
- int blake2( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen );
+ int blake2( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
#if defined(__cplusplus)
}
diff --git a/sse/blake2b.c b/sse/blake2b.c
index 6c5ec7a..a855262 100644
--- a/sse/blake2b.c
+++ b/sse/blake2b.c
@@ -66,17 +66,15 @@ static const uint8_t blake2b_sigma[12][16] =
};
-/* Some helper functions, not necessarily useful */
-static int blake2b_set_lastnode( blake2b_state *S )
+/* Some helper functions */
+static void blake2b_set_lastnode( blake2b_state *S )
{
- S->f[1] = -1;
- return 0;
+ S->f[1] = (uint64_t)-1;
}
-static int blake2b_clear_lastnode( blake2b_state *S )
+static void blake2b_clear_lastnode( blake2b_state *S )
{
S->f[1] = 0;
- return 0;
}
static int blake2b_is_lastblock( const blake2b_state *S )
@@ -84,112 +82,43 @@ static int blake2b_is_lastblock( const blake2b_state *S )
return S->f[0] != 0;
}
-static int blake2b_set_lastblock( blake2b_state *S )
+static void blake2b_set_lastblock( blake2b_state *S )
{
if( S->last_node ) blake2b_set_lastnode( S );
- S->f[0] = -1;
- return 0;
+ S->f[0] = (uint64_t)-1;
}
-static int blake2b_clear_lastblock( blake2b_state *S )
+static void blake2b_clear_lastblock( blake2b_state *S )
{
if( S->last_node ) blake2b_clear_lastnode( S );
S->f[0] = 0;
- return 0;
}
-static int blake2b_increment_counter( blake2b_state *S, const uint64_t inc )
+static void blake2b_increment_counter( blake2b_state *S, const uint64_t inc )
{
-#if defined(__x86_64__)
- /* ADD/ADC chain */
- __uint128_t t = ( ( __uint128_t )S->t[1] << 64 ) | S->t[0];
- t += inc;
- S->t[0] = ( uint64_t )( t >> 0 );
- S->t[1] = ( uint64_t )( t >> 64 );
-#else
S->t[0] += inc;
S->t[1] += ( S->t[0] < inc );
-#endif
- return 0;
}
-
-/* Parameter-related functions */
-static int blake2b_param_set_digest_length( blake2b_param *P, const uint8_t digest_length )
+static void blake2b_init0( blake2b_state *S )
{
- P->digest_length = digest_length;
- return 0;
-}
-
-static int blake2b_param_set_fanout( blake2b_param *P, const uint8_t fanout )
-{
- P->fanout = fanout;
- return 0;
-}
-
-static int blake2b_param_set_max_depth( blake2b_param *P, const uint8_t depth )
-{
- P->depth = depth;
- return 0;
-}
-
-static int blake2b_param_set_leaf_length( blake2b_param *P, const uint32_t leaf_length )
-{
- P->leaf_length = leaf_length;
- return 0;
-}
-
-static int blake2b_param_set_node_offset( blake2b_param *P, const uint64_t node_offset )
-{
- P->node_offset = node_offset;
- return 0;
-}
-
-static int blake2b_param_set_node_depth( blake2b_param *P, const uint8_t node_depth )
-{
- P->node_depth = node_depth;
- return 0;
-}
-
-static int blake2b_param_set_inner_length( blake2b_param *P, const uint8_t inner_length )
-{
- P->inner_length = inner_length;
- return 0;
-}
-
-static int blake2b_param_set_salt( blake2b_param *P, const uint8_t salt[BLAKE2B_SALTBYTES] )
-{
- memcpy( P->salt, salt, BLAKE2B_SALTBYTES );
- return 0;
-}
-
-static int blake2b_param_set_personal( blake2b_param *P, const uint8_t personal[BLAKE2B_PERSONALBYTES] )
-{
- memcpy( P->personal, personal, BLAKE2B_PERSONALBYTES );
- return 0;
-}
-
-static int blake2b_init0( blake2b_state *S )
-{
- int i;
+ size_t i;
memset( S, 0, sizeof( blake2b_state ) );
for( i = 0; i < 8; ++i ) S->h[i] = blake2b_IV[i];
-
- return 0;
}
/* init xors IV with input parameter block */
int blake2b_init_param( blake2b_state *S, const blake2b_param *P )
{
- int i;
+ size_t i;
/*blake2b_init0( S ); */
- const uint8_t * v = ( const uint8_t * )( blake2b_IV );
- const uint8_t * p = ( const uint8_t * )( P );
- uint8_t * h = ( uint8_t * )( S->h );
+ const unsigned char * v = ( const unsigned char * )( blake2b_IV );
+ const unsigned char * p = ( const unsigned char * )( P );
+ unsigned char * h = ( unsigned char * )( S->h );
/* IV XOR ParamBlock */
memset( S, 0, sizeof( blake2b_state ) );
@@ -200,11 +129,11 @@ int blake2b_init_param( blake2b_state *S, const blake2b_param *P )
/* Some sort of default parameter block initialization, for sequential blake2b */
-int blake2b_init( blake2b_state *S, const uint8_t outlen )
+int blake2b_init( blake2b_state *S, size_t outlen )
{
const blake2b_param P =
{
- outlen,
+ (uint8_t)outlen,
0,
1,
1,
@@ -222,12 +151,12 @@ int blake2b_init( blake2b_state *S, const uint8_t outlen )
return blake2b_init_param( S, &P );
}
-int blake2b_init_key( blake2b_state *S, const uint8_t outlen, const void *key, const uint8_t keylen )
+int blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t keylen )
{
const blake2b_param P =
{
- outlen,
- keylen,
+ (uint8_t)outlen,
+ (uint8_t)keylen,
1,
1,
0,
@@ -256,7 +185,7 @@ int blake2b_init_key( blake2b_state *S, const uint8_t outlen, const void *key, c
return 0;
}
-static int blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] )
+static void blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] )
{
__m128i row1l, row1h;
__m128i row2l, row2h;
@@ -323,42 +252,38 @@ static int blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCK
row2h = _mm_xor_si128( row4h, row2h );
STOREU( &S->h[4], _mm_xor_si128( LOADU( &S->h[4] ), row2l ) );
STOREU( &S->h[6], _mm_xor_si128( LOADU( &S->h[6] ), row2h ) );
- return 0;
}
-int blake2b_update( blake2b_state *S, const uint8_t *in, uint64_t inlen )
+int blake2b_update( blake2b_state *S, const void *pin, size_t inlen )
{
- while( inlen > 0 )
+ const unsigned char * in = (const unsigned char *)pin;
+ if( inlen > 0 )
{
size_t left = S->buflen;
- size_t fill = 2 * BLAKE2B_BLOCKBYTES - left;
-
+ size_t fill = BLAKE2B_BLOCKBYTES - left;
if( inlen > fill )
{
+ S->buflen = 0;
memcpy( S->buf + left, in, fill ); /* Fill buffer */
- S->buflen += fill;
blake2b_increment_counter( S, BLAKE2B_BLOCKBYTES );
blake2b_compress( S, S->buf ); /* Compress */
- memcpy( S->buf, S->buf + BLAKE2B_BLOCKBYTES, BLAKE2B_BLOCKBYTES ); /* Shift buffer left */
- S->buflen -= BLAKE2B_BLOCKBYTES;
- in += fill;
- inlen -= fill;
- }
- else /* inlen <= fill */
- {
- memcpy( S->buf + left, in, inlen );
- S->buflen += inlen; /* Be lazy, do not compress */
- in += inlen;
- inlen -= inlen;
+ in += fill; inlen -= fill;
+ while(inlen > BLAKE2B_BLOCKBYTES) {
+ blake2b_increment_counter(S, BLAKE2B_BLOCKBYTES);
+ blake2b_compress( S, in );
+ in += BLAKE2B_BLOCKBYTES;
+ inlen -= BLAKE2B_BLOCKBYTES;
+ }
}
+ memcpy( S->buf + S->buflen, in, inlen );
+ S->buflen += inlen;
}
-
return 0;
}
-int blake2b_final( blake2b_state *S, uint8_t *out, uint8_t outlen )
+int blake2b_final( blake2b_state *S, void *out, size_t outlen )
{
if( outlen > BLAKE2B_OUTBYTES )
return -1;
@@ -366,24 +291,17 @@ int blake2b_final( blake2b_state *S, uint8_t *out, uint8_t outlen )
if( blake2b_is_lastblock( S ) )
return -1;
- if( S->buflen > BLAKE2B_BLOCKBYTES )
- {
- blake2b_increment_counter( S, BLAKE2B_BLOCKBYTES );
- blake2b_compress( S, S->buf );
- S->buflen -= BLAKE2B_BLOCKBYTES;
- memcpy( S->buf, S->buf + BLAKE2B_BLOCKBYTES, S->buflen );
- }
-
blake2b_increment_counter( S, S->buflen );
blake2b_set_lastblock( S );
- memset( S->buf + S->buflen, 0, 2 * BLAKE2B_BLOCKBYTES - S->buflen ); /* Padding */
+ memset( S->buf + S->buflen, 0, BLAKE2B_BLOCKBYTES - S->buflen ); /* Padding */
blake2b_compress( S, S->buf );
+
memcpy( out, &S->h[0], outlen );
return 0;
}
-int blake2b( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen )
+int blake2b( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen )
{
blake2b_state S[1];
@@ -412,21 +330,21 @@ int blake2b( uint8_t *out, const void *in, const void *key, const uint8_t outlen
return 0;
}
-int blake2( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ) {
- return blake2b(out, in, key, outlen, inlen, keylen);
+int blake2( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ) {
+ return blake2b(out, outlen, in, inlen, key, keylen);
}
#if defined(SUPERCOP)
int crypto_hash( unsigned char *out, unsigned char *in, unsigned long long inlen )
{
- return blake2b( out, in, NULL, BLAKE2B_OUTBYTES, inlen, 0 );
+ return blake2b( out, BLAKE2B_OUTBYTES, in, inlen, NULL, 0 );
}
#endif
#if defined(BLAKE2B_SELFTEST)
#include <string.h>
#include "blake2-kat.h"
-int main( int argc, char **argv )
+int main( void )
{
uint8_t key[BLAKE2B_KEYBYTES];
uint8_t buf[BLAKE2_KAT_LENGTH];
@@ -441,7 +359,7 @@ int main( int argc, char **argv )
for( i = 0; i < BLAKE2_KAT_LENGTH; ++i )
{
uint8_t hash[BLAKE2B_OUTBYTES];
- blake2b( hash, buf, key, BLAKE2B_OUTBYTES, i, BLAKE2B_KEYBYTES );
+ blake2b( hash, BLAKE2B_OUTBYTES, buf, i, key, BLAKE2B_KEYBYTES );
if( 0 != memcmp( hash, blake2b_keyed_kat[i], BLAKE2B_OUTBYTES ) )
{
diff --git a/sse/blake2bp.c b/sse/blake2bp.c
index d158d14..952a498 100644
--- a/sse/blake2bp.c
+++ b/sse/blake2bp.c
@@ -27,11 +27,11 @@
#define PARALLELISM_DEGREE 4
-static int blake2bp_init_leaf( blake2b_state *S, uint8_t outlen, uint8_t keylen, uint64_t offset )
+static int blake2bp_init_leaf( blake2b_state *S, size_t outlen, size_t keylen, uint64_t offset )
{
blake2b_param P[1];
- P->digest_length = outlen;
- P->key_length = keylen;
+ P->digest_length = (uint8_t)outlen;
+ P->key_length = (uint8_t)keylen;
P->fanout = PARALLELISM_DEGREE;
P->depth = 2;
P->leaf_length = 0;
@@ -44,11 +44,11 @@ static int blake2bp_init_leaf( blake2b_state *S, uint8_t outlen, uint8_t keylen,
return blake2b_init_param( S, P );
}
-static int blake2bp_init_root( blake2b_state *S, uint8_t outlen, uint8_t keylen )
+static int blake2bp_init_root( blake2b_state *S, size_t outlen, size_t keylen )
{
blake2b_param P[1];
- P->digest_length = outlen;
- P->key_length = keylen;
+ P->digest_length = (uint8_t)outlen;
+ P->key_length = (uint8_t)keylen;
P->fanout = PARALLELISM_DEGREE;
P->depth = 2;
P->leaf_length = 0;
@@ -62,7 +62,7 @@ static int blake2bp_init_root( blake2b_state *S, uint8_t outlen, uint8_t keylen
}
-int blake2bp_init( blake2bp_state *S, const uint8_t outlen )
+int blake2bp_init( blake2bp_state *S, size_t outlen )
{
size_t i;
if( !outlen || outlen > BLAKE2B_OUTBYTES ) return -1;
@@ -81,7 +81,7 @@ int blake2bp_init( blake2bp_state *S, const uint8_t outlen )
return 0;
}
-int blake2bp_init_key( blake2bp_state *S, const uint8_t outlen, const void *key, const uint8_t keylen )
+int blake2bp_init_key( blake2bp_state *S, size_t outlen, const void *key, size_t keylen )
{
size_t i;
@@ -114,8 +114,9 @@ int blake2bp_init_key( blake2bp_state *S, const uint8_t outlen, const void *key,
}
-int blake2bp_update( blake2bp_state *S, const uint8_t *in, uint64_t inlen )
+int blake2bp_update( blake2bp_state *S, const void *pin, size_t inlen )
{
+ const unsigned char * in = (const unsigned char *)pin;
size_t left = S->buflen;
size_t fill = sizeof( S->buf ) - left;
size_t i;
@@ -142,8 +143,8 @@ int blake2bp_update( blake2bp_state *S, const uint8_t *in, uint64_t inlen )
#if defined(_OPENMP)
size_t i = omp_get_thread_num();
#endif
- uint64_t inlen__ = inlen;
- const uint8_t *in__ = ( const uint8_t * )in;
+ size_t inlen__ = inlen;
+ const unsigned char *in__ = ( const unsigned char * )in;
in__ += i * BLAKE2B_BLOCKBYTES;
while( inlen__ >= PARALLELISM_DEGREE * BLAKE2B_BLOCKBYTES )
@@ -166,7 +167,7 @@ int blake2bp_update( blake2bp_state *S, const uint8_t *in, uint64_t inlen )
-int blake2bp_final( blake2bp_state *S, uint8_t *out, const uint8_t outlen )
+int blake2bp_final( blake2bp_state *S, void *out, size_t outlen )
{
uint8_t hash[PARALLELISM_DEGREE][BLAKE2B_OUTBYTES];
size_t i;
@@ -191,7 +192,7 @@ int blake2bp_final( blake2bp_state *S, uint8_t *out, const uint8_t outlen )
return blake2b_final( S->R, out, outlen );
}
-int blake2bp( uint8_t *out, const void *in, const void *key, uint8_t outlen, uint64_t inlen, uint8_t keylen )
+int blake2bp( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen )
{
uint8_t hash[PARALLELISM_DEGREE][BLAKE2B_OUTBYTES];
blake2b_state S[PARALLELISM_DEGREE][1];
@@ -236,8 +237,8 @@ int blake2bp( uint8_t *out, const void *in, const void *key, uint8_t outlen, uin
#if defined(_OPENMP)
size_t i = omp_get_thread_num();
#endif
- uint64_t inlen__ = inlen;
- const uint8_t *in__ = ( const uint8_t * )in;
+ size_t inlen__ = inlen;
+ const unsigned char *in__ = ( const unsigned char * )in;
in__ += i * BLAKE2B_BLOCKBYTES;
while( inlen__ >= PARALLELISM_DEGREE * BLAKE2B_BLOCKBYTES )
@@ -272,7 +273,7 @@ int blake2bp( uint8_t *out, const void *in, const void *key, uint8_t outlen, uin
#if defined(BLAKE2BP_SELFTEST)
#include <string.h>
#include "blake2-kat.h"
-int main( int argc, char **argv )
+int main( void )
{
uint8_t key[BLAKE2B_KEYBYTES];
uint8_t buf[BLAKE2_KAT_LENGTH];
diff --git a/sse/blake2s.c b/sse/blake2s.c
index d554e10..d7cba9f 100644
--- a/sse/blake2s.c
+++ b/sse/blake2s.c
@@ -60,17 +60,15 @@ static const uint8_t blake2s_sigma[10][16] =
};
-/* Some helper functions, not necessarily useful */
-static int blake2s_set_lastnode( blake2s_state *S )
+/* Some helper functions */
+static void blake2s_set_lastnode( blake2s_state *S )
{
- S->f[1] = -1;
- return 0;
+ S->f[1] = (uint32_t)-1;
}
-static int blake2s_clear_lastnode( blake2s_state *S )
+static void blake2s_clear_lastnode( blake2s_state *S )
{
S->f[1] = 0;
- return 0;
}
static int blake2s_is_lastblock( const blake2s_state *S )
@@ -78,95 +76,34 @@ static int blake2s_is_lastblock( const blake2s_state *S )
return S->f[0] != 0;
}
-static int blake2s_set_lastblock( blake2s_state *S )
+static void blake2s_set_lastblock( blake2s_state *S )
{
if( S->last_node ) blake2s_set_lastnode( S );
- S->f[0] = -1;
- return 0;
+ S->f[0] = (uint32_t)-1;
}
-static int blake2s_clear_lastblock( blake2s_state *S )
+static void blake2s_clear_lastblock( blake2s_state *S )
{
if( S->last_node ) blake2s_clear_lastnode( S );
S->f[0] = 0;
- return 0;
}
-static int blake2s_increment_counter( blake2s_state *S, const uint32_t inc )
+static void blake2s_increment_counter( blake2s_state *S, const uint32_t inc )
{
uint64_t t = ( ( uint64_t )S->t[1] << 32 ) | S->t[0];
t += inc;
S->t[0] = ( uint32_t )( t >> 0 );
S->t[1] = ( uint32_t )( t >> 32 );
- return 0;
-}
-
-
-/* Parameter-related functions */
-static int blake2s_param_set_digest_length( blake2s_param *P, const uint8_t digest_length )
-{
- P->digest_length = digest_length;
- return 0;
-}
-
-static int blake2s_param_set_fanout( blake2s_param *P, const uint8_t fanout )
-{
- P->fanout = fanout;
- return 0;
-}
-
-static int blake2s_param_set_max_depth( blake2s_param *P, const uint8_t depth )
-{
- P->depth = depth;
- return 0;
-}
-
-static int blake2s_param_set_leaf_length( blake2s_param *P, const uint32_t leaf_length )
-{
- P->leaf_length = leaf_length;
- return 0;
-}
-
-static int blake2s_param_set_node_offset( blake2s_param *P, const uint64_t node_offset )
-{
- store48( P->node_offset, node_offset );
- return 0;
}
-static int blake2s_param_set_node_depth( blake2s_param *P, const uint8_t node_depth )
-{
- P->node_depth = node_depth;
- return 0;
-}
-
-static int blake2s_param_set_inner_length( blake2s_param *P, const uint8_t inner_length )
-{
- P->inner_length = inner_length;
- return 0;
-}
-
-static int blake2s_param_set_salt( blake2s_param *P, const uint8_t salt[BLAKE2S_SALTBYTES] )
-{
- memcpy( P->salt, salt, BLAKE2S_SALTBYTES );
- return 0;
-}
-
-static int blake2s_param_set_personal( blake2s_param *P, const uint8_t personal[BLAKE2S_PERSONALBYTES] )
-{
- memcpy( P->personal, personal, BLAKE2S_PERSONALBYTES );
- return 0;
-}
-
-static int blake2s_init0( blake2s_state *S )
+static void blake2s_init0( blake2s_state *S )
{
int i;
memset( S, 0, sizeof( blake2s_state ) );
for( i = 0; i < 8; ++i ) S->h[i] = blake2s_IV[i];
-
- return 0;
}
/* init2 xors IV with input parameter block */
@@ -187,11 +124,11 @@ int blake2s_init_param( blake2s_state *S, const blake2s_param *P )
/* Some sort of default parameter block initialization, for sequential blake2s */
-int blake2s_init( blake2s_state *S, const uint8_t outlen )
+int blake2s_init( blake2s_state *S, size_t outlen )
{
const blake2s_param P =
{
- outlen,
+ (uint8_t)outlen,
0,
1,
1,
@@ -208,12 +145,12 @@ int blake2s_init( blake2s_state *S, const uint8_t outlen )
}
-int blake2s_init_key( blake2s_state *S, const uint8_t outlen, const void *key, const uint8_t keylen )
+int blake2s_init_key( blake2s_state *S, size_t outlen, const void *key, size_t keylen )
{
const blake2s_param P =
{
- outlen,
- keylen,
+ (uint8_t)outlen,
+ (uint8_t)keylen,
1,
1,
0,
@@ -243,7 +180,7 @@ int blake2s_init_key( blake2s_state *S, const uint8_t outlen, const void *key, c
}
-static int blake2s_compress( blake2s_state *S, const uint8_t block[BLAKE2S_BLOCKBYTES] )
+static void blake2s_compress( blake2s_state *S, const uint8_t block[BLAKE2S_BLOCKBYTES] )
{
__m128i row1, row2, row3, row4;
__m128i buf1, buf2, buf3, buf4;
@@ -297,42 +234,36 @@ static int blake2s_compress( blake2s_state *S, const uint8_t block[BLAKE2S_BLOCK
ROUND( 9 );
STOREU( &S->h[0], _mm_xor_si128( ff0, _mm_xor_si128( row1, row3 ) ) );
STOREU( &S->h[4], _mm_xor_si128( ff1, _mm_xor_si128( row2, row4 ) ) );
- return 0;
}
-/* inlen now in bytes */
-int blake2s_update( blake2s_state *S, const uint8_t *in, uint64_t inlen )
+int blake2s_update( blake2s_state *S, const void *pin, size_t inlen )
{
- while( inlen > 0 )
+ const unsigned char * in = (const unsigned char *)pin;
+ if( inlen > 0 )
{
size_t left = S->buflen;
- size_t fill = 2 * BLAKE2S_BLOCKBYTES - left;
-
+ size_t fill = BLAKE2S_BLOCKBYTES - left;
if( inlen > fill )
{
+ S->buflen = 0;
memcpy( S->buf + left, in, fill ); /* Fill buffer */
- S->buflen += fill;
blake2s_increment_counter( S, BLAKE2S_BLOCKBYTES );
blake2s_compress( S, S->buf ); /* Compress */
- memcpy( S->buf, S->buf + BLAKE2S_BLOCKBYTES, BLAKE2S_BLOCKBYTES ); /* Shift buffer left */
- S->buflen -= BLAKE2S_BLOCKBYTES;
- in += fill;
- inlen -= fill;
- }
- else /* inlen <= fill */
- {
- memcpy( S->buf + left, in, inlen );
- S->buflen += inlen; /* Be lazy, do not compress */
- in += inlen;
- inlen -= inlen;
+ in += fill; inlen -= fill;
+ while(inlen > BLAKE2S_BLOCKBYTES) {
+ blake2s_increment_counter(S, BLAKE2S_BLOCKBYTES);
+ blake2s_compress( S, in );
+ in += BLAKE2S_BLOCKBYTES;
+ inlen -= BLAKE2S_BLOCKBYTES;
+ }
}
+ memcpy( S->buf + S->buflen, in, inlen );
+ S->buflen += inlen;
}
-
return 0;
}
-/* Is this correct? */
-int blake2s_final( blake2s_state *S, uint8_t *out, uint8_t outlen )
+int blake2s_final( blake2s_state *S, void *out, size_t outlen )
{
uint8_t buffer[BLAKE2S_OUTBYTES] = {0};
int i;
@@ -343,28 +274,21 @@ int blake2s_final( blake2s_state *S, uint8_t *out, uint8_t outlen )
if( blake2s_is_lastblock( S ) )
return -1;
- if( S->buflen > BLAKE2S_BLOCKBYTES )
- {
- blake2s_increment_counter( S, BLAKE2S_BLOCKBYTES );
- blake2s_compress( S, S->buf );
- S->buflen -= BLAKE2S_BLOCKBYTES;
- memcpy( S->buf, S->buf + BLAKE2S_BLOCKBYTES, S->buflen );
- }
-
- blake2s_increment_counter( S, ( uint32_t )S->buflen );
+ blake2s_increment_counter( S, (uint32_t)S->buflen );
blake2s_set_lastblock( S );
- memset( S->buf + S->buflen, 0, 2 * BLAKE2S_BLOCKBYTES - S->buflen ); /* Padding */
+ memset( S->buf + S->buflen, 0, BLAKE2S_BLOCKBYTES - S->buflen ); /* Padding */
blake2s_compress( S, S->buf );
for( i = 0; i < 8; ++i ) /* Output full hash to temp buffer */
store32( buffer + sizeof( S->h[i] ) * i, S->h[i] );
memcpy( out, buffer, outlen );
+ secure_zero_memory( buffer, sizeof(buffer) );
return 0;
}
/* inlen, at least, should be uint64_t. Others can be size_t. */
-int blake2s( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen )
+int blake2s( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen )
{
blake2s_state S[1];
@@ -396,14 +320,14 @@ int blake2s( uint8_t *out, const void *in, const void *key, const uint8_t outlen
#if defined(SUPERCOP)
int crypto_hash( unsigned char *out, unsigned char *in, unsigned long long inlen )
{
- return blake2s( out, in, NULL, BLAKE2S_OUTBYTES, inlen, 0 );
+ return blake2s( out, BLAKE2S_OUTBYTES, in, inlen, NULL, 0 );
}
#endif
#if defined(BLAKE2S_SELFTEST)
#include <string.h>
#include "blake2-kat.h"
-int main( int argc, char **argv )
+int main( void )
{
uint8_t key[BLAKE2S_KEYBYTES];
uint8_t buf[BLAKE2_KAT_LENGTH];
@@ -419,7 +343,7 @@ int main( int argc, char **argv )
{
uint8_t hash[BLAKE2S_OUTBYTES];
- if( blake2s( hash, buf, key, BLAKE2S_OUTBYTES, i, BLAKE2S_KEYBYTES ) < 0 ||
+ if( blake2s( hash, BLAKE2S_OUTBYTES, buf, i, key, BLAKE2S_KEYBYTES ) < 0 ||
0 != memcmp( hash, blake2s_keyed_kat[i], BLAKE2S_OUTBYTES ) )
{
puts( "error" );
diff --git a/sse/blake2sp.c b/sse/blake2sp.c
index 673d7ec..961f3d6 100644
--- a/sse/blake2sp.c
+++ b/sse/blake2sp.c
@@ -26,11 +26,11 @@
#define PARALLELISM_DEGREE 8
-static int blake2sp_init_leaf( blake2s_state *S, uint8_t outlen, uint8_t keylen, uint64_t offset )
+static int blake2sp_init_leaf( blake2s_state *S, size_t outlen, size_t keylen, uint64_t offset )
{
blake2s_param P[1];
- P->digest_length = outlen;
- P->key_length = keylen;
+ P->digest_length = (uint8_t)outlen;
+ P->key_length = (uint8_t)keylen;
P->fanout = PARALLELISM_DEGREE;
P->depth = 2;
P->leaf_length = 0;
@@ -42,11 +42,11 @@ static int blake2sp_init_leaf( blake2s_state *S, uint8_t outlen, uint8_t keylen,
return blake2s_init_param( S, P );
}
-static int blake2sp_init_root( blake2s_state *S, uint8_t outlen, uint8_t keylen )
+static int blake2sp_init_root( blake2s_state *S, size_t outlen, size_t keylen )
{
blake2s_param P[1];
- P->digest_length = outlen;
- P->key_length = keylen;
+ P->digest_length = (uint8_t)outlen;
+ P->key_length = (uint8_t)keylen;
P->fanout = PARALLELISM_DEGREE;
P->depth = 2;
P->leaf_length = 0;
@@ -59,7 +59,7 @@ static int blake2sp_init_root( blake2s_state *S, uint8_t outlen, uint8_t keylen
}
-int blake2sp_init( blake2sp_state *S, const uint8_t outlen )
+int blake2sp_init( blake2sp_state *S, size_t outlen )
{
size_t i;
@@ -79,7 +79,7 @@ int blake2sp_init( blake2sp_state *S, const uint8_t outlen )
return 0;
}
-int blake2sp_init_key( blake2sp_state *S, const uint8_t outlen, const void *key, const uint8_t keylen )
+int blake2sp_init_key( blake2sp_state *S, size_t outlen, const void *key, size_t keylen )
{
size_t i;
@@ -112,8 +112,9 @@ int blake2sp_init_key( blake2sp_state *S, const uint8_t outlen, const void *key,
}
-int blake2sp_update( blake2sp_state *S, const uint8_t *in, uint64_t inlen )
+int blake2sp_update( blake2sp_state *S, const void *pin, size_t inlen )
{
+ const unsigned char * in = (const unsigned char *)pin;
size_t left = S->buflen;
size_t fill = sizeof( S->buf ) - left;
size_t i;
@@ -140,8 +141,8 @@ int blake2sp_update( blake2sp_state *S, const uint8_t *in, uint64_t inlen )
#if defined(_OPENMP)
size_t i = omp_get_thread_num();
#endif
- uint64_t inlen__ = inlen;
- const uint8_t *in__ = ( const uint8_t * )in;
+ size_t inlen__ = inlen;
+ const unsigned char *in__ = ( const unsigned char * )in;
in__ += i * BLAKE2S_BLOCKBYTES;
while( inlen__ >= PARALLELISM_DEGREE * BLAKE2S_BLOCKBYTES )
@@ -163,7 +164,7 @@ int blake2sp_update( blake2sp_state *S, const uint8_t *in, uint64_t inlen )
}
-int blake2sp_final( blake2sp_state *S, uint8_t *out, const uint8_t outlen )
+int blake2sp_final( blake2sp_state *S, void *out, size_t outlen )
{
uint8_t hash[PARALLELISM_DEGREE][BLAKE2S_OUTBYTES];
size_t i;
@@ -189,7 +190,7 @@ int blake2sp_final( blake2sp_state *S, uint8_t *out, const uint8_t outlen )
}
-int blake2sp( uint8_t *out, const void *in, const void *key, uint8_t outlen, uint64_t inlen, uint8_t keylen )
+int blake2sp( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen )
{
uint8_t hash[PARALLELISM_DEGREE][BLAKE2S_OUTBYTES];
blake2s_state S[PARALLELISM_DEGREE][1];
@@ -234,8 +235,8 @@ int blake2sp( uint8_t *out, const void *in, const void *key, uint8_t outlen, uin
#if defined(_OPENMP)
size_t i = omp_get_thread_num();
#endif
- uint64_t inlen__ = inlen;
- const uint8_t *in__ = ( const uint8_t * )in;
+ size_t inlen__ = inlen;
+ const unsigned char *in__ = ( const unsigned char * )in;
in__ += i * BLAKE2S_BLOCKBYTES;
while( inlen__ >= PARALLELISM_DEGREE * BLAKE2S_BLOCKBYTES )
@@ -269,7 +270,7 @@ int blake2sp( uint8_t *out, const void *in, const void *key, uint8_t outlen, uin
#if defined(BLAKE2SP_SELFTEST)
#include <string.h>
#include "blake2-kat.h"
-int main( int argc, char **argv )
+int main( void )
{
uint8_t key[BLAKE2S_KEYBYTES];
uint8_t buf[BLAKE2_KAT_LENGTH];
@@ -284,7 +285,7 @@ int main( int argc, char **argv )
for( i = 0; i < BLAKE2_KAT_LENGTH; ++i )
{
uint8_t hash[BLAKE2S_OUTBYTES];
- blake2sp( hash, buf, key, BLAKE2S_OUTBYTES, i, BLAKE2S_KEYBYTES );
+ blake2sp( hash, BLAKE2S_OUTBYTES, buf, i, key, BLAKE2S_KEYBYTES );
if( 0 != memcmp( hash, blake2sp_keyed_kat[i], BLAKE2S_OUTBYTES ) )
{
diff --git a/sse/genkat-json.c b/sse/genkat-json.c
index 81a5cbe..eda1146 100644
--- a/sse/genkat-json.c
+++ b/sse/genkat-json.c
@@ -88,7 +88,7 @@ int main( int argc, char **argv )
for( size_t i = 0; i < sizeof( key ); ++i )
key[i] = i;
- printf("[");
+ printf("[");
MAKE_KAT( blake2s, BLAKE2S );
MAKE_KEYED_KAT( blake2s, BLAKE2S );
MAKE_KAT( blake2b, BLAKE2B );
@@ -97,7 +97,7 @@ int main( int argc, char **argv )
MAKE_KEYED_KAT( blake2sp, BLAKE2S );
MAKE_KAT( blake2bp, BLAKE2B );
MAKE_KEYED_KAT( blake2bp, BLAKE2B );
- printf("\n]\n");
+ printf("\n]\n");
fflush(stdout);
return 0;
}