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 02:06:51 +0300
committerSamuel Neves <sneves@dei.uc.pt>2016-06-11 02:06:51 +0300
commite971a0428f61a2d07f253b979eaf24b85e3cda50 (patch)
tree1803ada22843183202888d3d5c2e849402d83dfe
parentef9d717e460ec5a432e19d6a5ed7afecad48f144 (diff)
more tyding up
-rw-r--r--sse/blake2.h32
-rw-r--r--sse/blake2b.c49
-rw-r--r--sse/blake2bp.c59
-rw-r--r--sse/blake2s.c50
-rw-r--r--sse/blake2sp.c60
5 files changed, 139 insertions, 111 deletions
diff --git a/sse/blake2.h b/sse/blake2.h
index 31b5022..fd25987 100644
--- a/sse/blake2.h
+++ b/sse/blake2.h
@@ -19,12 +19,10 @@
#include <stddef.h>
#include <stdint.h>
-#ifdef BLAKE2_NO_INLINE
-#define BLAKE2_LOCAL_INLINE(type) static type
-#endif
-
-#ifndef BLAKE2_LOCAL_INLINE
-#define BLAKE2_LOCAL_INLINE(type) static inline type
+#if defined(_MSC_VER)
+#define BLAKE2_PACKED(x) __pragma(pack(push, 1)) x __pragma(pack(pop))
+#else
+#define BLAKE2_PACKED(x) x __attribute__((packed))
#endif
#if defined(__cplusplus)
@@ -86,23 +84,24 @@ extern "C" {
} blake2bp_state;
-#pragma pack(push, 1)
- typedef struct __blake2s_param
+ BLAKE2_PACKED(struct __blake2s_param
{
uint8_t digest_length; /* 1 */
uint8_t key_length; /* 2 */
uint8_t fanout; /* 3 */
uint8_t depth; /* 4 */
uint32_t leaf_length; /* 8 */
- uint8_t node_offset[6];// 14
+ uint8_t node_offset[6];/* 14 */
uint8_t node_depth; /* 15 */
uint8_t inner_length; /* 16 */
/* uint8_t reserved[0]; */
uint8_t salt[BLAKE2S_SALTBYTES]; /* 24 */
uint8_t personal[BLAKE2S_PERSONALBYTES]; /* 32 */
- } blake2s_param;
+ });
+
+ typedef struct __blake2s_param blake2s_param;
- typedef struct __blake2b_param
+ BLAKE2_PACKED(struct __blake2b_param
{
uint8_t digest_length; /* 1 */
uint8_t key_length; /* 2 */
@@ -115,8 +114,15 @@ extern "C" {
uint8_t reserved[14]; /* 32 */
uint8_t salt[BLAKE2B_SALTBYTES]; /* 48 */
uint8_t personal[BLAKE2B_PERSONALBYTES]; /* 64 */
- } blake2b_param;
-#pragma pack(pop)
+ });
+
+ typedef struct __blake2b_param blake2b_param;
+
+ /* Padded structs result in a compile-time error */
+ enum {
+ BLAKE2_DUMMY_1 = 1/(sizeof(blake2s_param) == BLAKE2S_OUTBYTES),
+ BLAKE2_DUMMY_2 = 1/(sizeof(blake2b_param) == BLAKE2B_OUTBYTES)
+ };
/* Streaming API */
int blake2s_init( blake2s_state *S, const uint8_t outlen );
diff --git a/sse/blake2b.c b/sse/blake2b.c
index be465b1..2b2e639 100644
--- a/sse/blake2b.c
+++ b/sse/blake2b.c
@@ -67,24 +67,24 @@ static const uint8_t blake2b_sigma[12][16] =
/* Some helper functions, not necessarily useful */
-BLAKE2_LOCAL_INLINE(int) blake2b_set_lastnode( blake2b_state *S )
+static int blake2b_set_lastnode( blake2b_state *S )
{
S->f[1] = -1;
return 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2b_clear_lastnode( blake2b_state *S )
+static int blake2b_clear_lastnode( blake2b_state *S )
{
S->f[1] = 0;
return 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2b_is_lastblock( const blake2b_state *S )
+static int blake2b_is_lastblock( const blake2b_state *S )
{
return S->f[0] != 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2b_set_lastblock( blake2b_state *S )
+static int blake2b_set_lastblock( blake2b_state *S )
{
if( S->last_node ) blake2b_set_lastnode( S );
@@ -92,7 +92,7 @@ BLAKE2_LOCAL_INLINE(int) blake2b_set_lastblock( blake2b_state *S )
return 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2b_clear_lastblock( blake2b_state *S )
+static int blake2b_clear_lastblock( blake2b_state *S )
{
if( S->last_node ) blake2b_clear_lastnode( S );
@@ -101,9 +101,9 @@ BLAKE2_LOCAL_INLINE(int) blake2b_clear_lastblock( blake2b_state *S )
}
-BLAKE2_LOCAL_INLINE(int) blake2b_increment_counter( blake2b_state *S, const uint64_t inc )
+static int blake2b_increment_counter( blake2b_state *S, const uint64_t inc )
{
-#if __x86_64__
+#if defined(__x86_64__)
/* ADD/ADC chain */
__uint128_t t = ( ( __uint128_t )S->t[1] << 64 ) | S->t[0];
t += inc;
@@ -118,65 +118,66 @@ BLAKE2_LOCAL_INLINE(int) blake2b_increment_counter( blake2b_state *S, const uint
/* Parameter-related functions */
-BLAKE2_LOCAL_INLINE(int) blake2b_param_set_digest_length( blake2b_param *P, const uint8_t digest_length )
+static int blake2b_param_set_digest_length( blake2b_param *P, const uint8_t digest_length )
{
P->digest_length = digest_length;
return 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2b_param_set_fanout( blake2b_param *P, const uint8_t fanout )
+static int blake2b_param_set_fanout( blake2b_param *P, const uint8_t fanout )
{
P->fanout = fanout;
return 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2b_param_set_max_depth( blake2b_param *P, const uint8_t depth )
+static int blake2b_param_set_max_depth( blake2b_param *P, const uint8_t depth )
{
P->depth = depth;
return 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2b_param_set_leaf_length( blake2b_param *P, const uint32_t leaf_length )
+static int blake2b_param_set_leaf_length( blake2b_param *P, const uint32_t leaf_length )
{
P->leaf_length = leaf_length;
return 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2b_param_set_node_offset( blake2b_param *P, const uint64_t node_offset )
+static int blake2b_param_set_node_offset( blake2b_param *P, const uint64_t node_offset )
{
P->node_offset = node_offset;
return 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2b_param_set_node_depth( blake2b_param *P, const uint8_t node_depth )
+static int blake2b_param_set_node_depth( blake2b_param *P, const uint8_t node_depth )
{
P->node_depth = node_depth;
return 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2b_param_set_inner_length( blake2b_param *P, const uint8_t inner_length )
+static int blake2b_param_set_inner_length( blake2b_param *P, const uint8_t inner_length )
{
P->inner_length = inner_length;
return 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2b_param_set_salt( blake2b_param *P, const uint8_t salt[BLAKE2B_SALTBYTES] )
+static int blake2b_param_set_salt( blake2b_param *P, const uint8_t salt[BLAKE2B_SALTBYTES] )
{
memcpy( P->salt, salt, BLAKE2B_SALTBYTES );
return 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2b_param_set_personal( blake2b_param *P, const uint8_t personal[BLAKE2B_PERSONALBYTES] )
+static int blake2b_param_set_personal( blake2b_param *P, const uint8_t personal[BLAKE2B_PERSONALBYTES] )
{
memcpy( P->personal, personal, BLAKE2B_PERSONALBYTES );
return 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2b_init0( blake2b_state *S )
+static int blake2b_init0( blake2b_state *S )
{
+ int i;
memset( S, 0, sizeof( blake2b_state ) );
- for( int i = 0; i < 8; ++i ) S->h[i] = blake2b_IV[i];
+ for( i = 0; i < 8; ++i ) S->h[i] = blake2b_IV[i];
return 0;
}
@@ -184,6 +185,7 @@ BLAKE2_LOCAL_INLINE(int) blake2b_init0( blake2b_state *S )
/* init xors IV with input parameter block */
int blake2b_init_param( blake2b_state *S, const blake2b_param *P )
{
+ int i;
/*blake2b_init0( S ); */
const uint8_t * v = ( const uint8_t * )( blake2b_IV );
const uint8_t * p = ( const uint8_t * )( P );
@@ -191,7 +193,7 @@ int blake2b_init_param( blake2b_state *S, const blake2b_param *P )
/* IV XOR ParamBlock */
memset( S, 0, sizeof( blake2b_state ) );
- for( int i = 0; i < BLAKE2B_OUTBYTES; ++i ) h[i] = v[i] ^ p[i];
+ for( i = 0; i < BLAKE2B_OUTBYTES; ++i ) h[i] = v[i] ^ p[i];
return 0;
}
@@ -254,7 +256,7 @@ int blake2b_init_key( blake2b_state *S, const uint8_t outlen, const void *key, c
return 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] )
+static int blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] )
{
__m128i row1l, row1h;
__m128i row2l, row2h;
@@ -428,14 +430,15 @@ int main( int argc, char **argv )
{
uint8_t key[BLAKE2B_KEYBYTES];
uint8_t buf[KAT_LENGTH];
+ size_t i;
- for( size_t i = 0; i < BLAKE2B_KEYBYTES; ++i )
+ for( i = 0; i < BLAKE2B_KEYBYTES; ++i )
key[i] = ( uint8_t )i;
- for( size_t i = 0; i < KAT_LENGTH; ++i )
+ for( i = 0; i < KAT_LENGTH; ++i )
buf[i] = ( uint8_t )i;
- for( size_t i = 0; i < KAT_LENGTH; ++i )
+ for( i = 0; i < KAT_LENGTH; ++i )
{
uint8_t hash[BLAKE2B_OUTBYTES];
blake2b( hash, buf, key, BLAKE2B_OUTBYTES, i, BLAKE2B_KEYBYTES );
diff --git a/sse/blake2bp.c b/sse/blake2bp.c
index 459c669..c265970 100644
--- a/sse/blake2bp.c
+++ b/sse/blake2bp.c
@@ -27,7 +27,7 @@
#define PARALLELISM_DEGREE 4
-BLAKE2_LOCAL_INLINE(int) blake2bp_init_leaf( blake2b_state *S, uint8_t outlen, uint8_t keylen, uint64_t offset )
+static int blake2bp_init_leaf( blake2b_state *S, uint8_t outlen, uint8_t keylen, uint64_t offset )
{
blake2b_param P[1];
P->digest_length = outlen;
@@ -44,7 +44,7 @@ BLAKE2_LOCAL_INLINE(int) blake2bp_init_leaf( blake2b_state *S, uint8_t outlen, u
return blake2b_init_param( S, P );
}
-BLAKE2_LOCAL_INLINE(int) blake2bp_init_root( blake2b_state *S, uint8_t outlen, uint8_t keylen )
+static int blake2bp_init_root( blake2b_state *S, uint8_t outlen, uint8_t keylen )
{
blake2b_param P[1];
P->digest_length = outlen;
@@ -64,6 +64,7 @@ BLAKE2_LOCAL_INLINE(int) blake2bp_init_root( blake2b_state *S, uint8_t outlen, u
int blake2bp_init( blake2bp_state *S, const uint8_t outlen )
{
+ size_t i;
if( !outlen || outlen > BLAKE2B_OUTBYTES ) return -1;
memset( S->buf, 0, sizeof( S->buf ) );
@@ -72,7 +73,7 @@ int blake2bp_init( blake2bp_state *S, const uint8_t outlen )
if( blake2bp_init_root( S->R, outlen, 0 ) < 0 )
return -1;
- for( size_t i = 0; i < PARALLELISM_DEGREE; ++i )
+ for( i = 0; i < PARALLELISM_DEGREE; ++i )
if( blake2bp_init_leaf( S->S[i], outlen, 0, i ) < 0 ) return -1;
S->R->last_node = 1;
@@ -82,6 +83,8 @@ 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 )
{
+ size_t i;
+
if( !outlen || outlen > BLAKE2B_OUTBYTES ) return -1;
if( !key || !keylen || keylen > BLAKE2B_KEYBYTES ) return -1;
@@ -92,7 +95,7 @@ int blake2bp_init_key( blake2bp_state *S, const uint8_t outlen, const void *key,
if( blake2bp_init_root( S->R, outlen, keylen ) < 0 )
return -1;
- for( size_t i = 0; i < PARALLELISM_DEGREE; ++i )
+ for( i = 0; i < PARALLELISM_DEGREE; ++i )
if( blake2bp_init_leaf( S->S[i], outlen, keylen, i ) < 0 ) return -1;
S->R->last_node = 1;
@@ -102,7 +105,7 @@ int blake2bp_init_key( blake2bp_state *S, const uint8_t outlen, const void *key,
memset( block, 0, BLAKE2B_BLOCKBYTES );
memcpy( block, key, keylen );
- for( size_t i = 0; i < PARALLELISM_DEGREE; ++i )
+ for( i = 0; i < PARALLELISM_DEGREE; ++i )
blake2b_update( S->S[i], block, BLAKE2B_BLOCKBYTES );
secure_zero_memory( block, BLAKE2B_BLOCKBYTES ); /* Burn the key from stack */
@@ -115,12 +118,13 @@ int blake2bp_update( blake2bp_state *S, const uint8_t *in, uint64_t inlen )
{
size_t left = S->buflen;
size_t fill = sizeof( S->buf ) - left;
+ size_t i;
if( left && inlen >= fill )
{
memcpy( S->buf + left, in, fill );
- for( size_t i = 0; i < PARALLELISM_DEGREE; ++i )
+ for( i = 0; i < PARALLELISM_DEGREE; ++i )
blake2b_update( S->S[i], S->buf + i * BLAKE2B_BLOCKBYTES, BLAKE2B_BLOCKBYTES );
in += fill;
@@ -132,19 +136,19 @@ int blake2bp_update( blake2bp_state *S, const uint8_t *in, uint64_t inlen )
#pragma omp parallel shared(S), num_threads(PARALLELISM_DEGREE)
#else
- for( size_t id__ = 0; id__ < PARALLELISM_DEGREE; ++id__ )
+ for( i = 0; i < PARALLELISM_DEGREE; ++i )
#endif
{
#if defined(_OPENMP)
- size_t id__ = omp_get_thread_num();
+ size_t i = omp_get_thread_num();
#endif
uint64_t inlen__ = inlen;
const uint8_t *in__ = ( const uint8_t * )in;
- in__ += id__ * BLAKE2B_BLOCKBYTES;
+ in__ += i * BLAKE2B_BLOCKBYTES;
while( inlen__ >= PARALLELISM_DEGREE * BLAKE2B_BLOCKBYTES )
{
- blake2b_update( S->S[id__], in__, BLAKE2B_BLOCKBYTES );
+ blake2b_update( S->S[i], in__, BLAKE2B_BLOCKBYTES );
in__ += PARALLELISM_DEGREE * BLAKE2B_BLOCKBYTES;
inlen__ -= PARALLELISM_DEGREE * BLAKE2B_BLOCKBYTES;
}
@@ -165,8 +169,9 @@ 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 )
{
uint8_t hash[PARALLELISM_DEGREE][BLAKE2B_OUTBYTES];
+ size_t i;
- for( size_t i = 0; i < PARALLELISM_DEGREE; ++i )
+ for( i = 0; i < PARALLELISM_DEGREE; ++i )
{
if( S->buflen > i * BLAKE2B_BLOCKBYTES )
{
@@ -180,7 +185,7 @@ int blake2bp_final( blake2bp_state *S, uint8_t *out, const uint8_t outlen )
blake2b_final( S->S[i], hash[i], BLAKE2B_OUTBYTES );
}
- for( size_t i = 0; i < PARALLELISM_DEGREE; ++i )
+ for( i = 0; i < PARALLELISM_DEGREE; ++i )
blake2b_update( S->R, hash[i], BLAKE2B_OUTBYTES );
return blake2b_final( S->R, out, outlen );
@@ -191,6 +196,7 @@ int blake2bp( uint8_t *out, const void *in, const void *key, uint8_t outlen, uin
uint8_t hash[PARALLELISM_DEGREE][BLAKE2B_OUTBYTES];
blake2b_state S[PARALLELISM_DEGREE][1];
blake2b_state FS[1];
+ size_t i;
/* Verify parameters */
if ( NULL == in && inlen > 0 ) return -1;
@@ -203,7 +209,7 @@ int blake2bp( uint8_t *out, const void *in, const void *key, uint8_t outlen, uin
if( keylen > BLAKE2B_KEYBYTES ) return -1;
- for( size_t i = 0; i < PARALLELISM_DEGREE; ++i )
+ for( i = 0; i < PARALLELISM_DEGREE; ++i )
if( blake2bp_init_leaf( S[i], outlen, keylen, i ) < 0 ) return -1;
S[PARALLELISM_DEGREE - 1]->last_node = 1; /* mark last node */
@@ -214,7 +220,7 @@ int blake2bp( uint8_t *out, const void *in, const void *key, uint8_t outlen, uin
memset( block, 0, BLAKE2B_BLOCKBYTES );
memcpy( block, key, keylen );
- for( size_t i = 0; i < PARALLELISM_DEGREE; ++i )
+ for( i = 0; i < PARALLELISM_DEGREE; ++i )
blake2b_update( S[i], block, BLAKE2B_BLOCKBYTES );
secure_zero_memory( block, BLAKE2B_BLOCKBYTES ); /* Burn the key from stack */
@@ -224,31 +230,31 @@ int blake2bp( uint8_t *out, const void *in, const void *key, uint8_t outlen, uin
#pragma omp parallel shared(S,hash), num_threads(PARALLELISM_DEGREE)
#else
- for( size_t id__ = 0; id__ < PARALLELISM_DEGREE; ++id__ )
+ for( i = 0; i < PARALLELISM_DEGREE; ++i )
#endif
{
#if defined(_OPENMP)
- size_t id__ = omp_get_thread_num();
+ size_t i = omp_get_thread_num();
#endif
uint64_t inlen__ = inlen;
const uint8_t *in__ = ( const uint8_t * )in;
- in__ += id__ * BLAKE2B_BLOCKBYTES;
+ in__ += i * BLAKE2B_BLOCKBYTES;
while( inlen__ >= PARALLELISM_DEGREE * BLAKE2B_BLOCKBYTES )
{
- blake2b_update( S[id__], in__, BLAKE2B_BLOCKBYTES );
+ blake2b_update( S[i], in__, BLAKE2B_BLOCKBYTES );
in__ += PARALLELISM_DEGREE * BLAKE2B_BLOCKBYTES;
inlen__ -= PARALLELISM_DEGREE * BLAKE2B_BLOCKBYTES;
}
- if( inlen__ > id__ * BLAKE2B_BLOCKBYTES )
+ if( inlen__ > i * BLAKE2B_BLOCKBYTES )
{
- const size_t left = inlen__ - id__ * BLAKE2B_BLOCKBYTES;
+ const size_t left = inlen__ - i * BLAKE2B_BLOCKBYTES;
const size_t len = left <= BLAKE2B_BLOCKBYTES ? left : BLAKE2B_BLOCKBYTES;
- blake2b_update( S[id__], in__, len );
+ blake2b_update( S[i], in__, len );
}
- blake2b_final( S[id__], hash[id__], BLAKE2B_OUTBYTES );
+ blake2b_final( S[i], hash[i], BLAKE2B_OUTBYTES );
}
if( blake2bp_init_root( FS, outlen, keylen ) < 0 )
@@ -256,7 +262,7 @@ int blake2bp( uint8_t *out, const void *in, const void *key, uint8_t outlen, uin
FS->last_node = 1; /* Mark as last node */
- for( size_t i = 0; i < PARALLELISM_DEGREE; ++i )
+ for( i = 0; i < PARALLELISM_DEGREE; ++i )
blake2b_update( FS, hash[i], BLAKE2B_OUTBYTES );
return blake2b_final( FS, out, outlen );
@@ -270,14 +276,15 @@ int main( int argc, char **argv )
{
uint8_t key[BLAKE2B_KEYBYTES];
uint8_t buf[KAT_LENGTH];
+ size_t i;
- for( size_t i = 0; i < BLAKE2B_KEYBYTES; ++i )
+ for( i = 0; i < BLAKE2B_KEYBYTES; ++i )
key[i] = ( uint8_t )i;
- for( size_t i = 0; i < KAT_LENGTH; ++i )
+ for( i = 0; i < KAT_LENGTH; ++i )
buf[i] = ( uint8_t )i;
- for( size_t i = 0; i < KAT_LENGTH; ++i )
+ for( i = 0; i < KAT_LENGTH; ++i )
{
uint8_t hash[BLAKE2B_OUTBYTES];
/*blake2bp( hash, buf, key, BLAKE2B_OUTBYTES, i, BLAKE2B_KEYBYTES ); */
diff --git a/sse/blake2s.c b/sse/blake2s.c
index 030a85e..4da9cf6 100644
--- a/sse/blake2s.c
+++ b/sse/blake2s.c
@@ -61,24 +61,24 @@ static const uint8_t blake2s_sigma[10][16] =
/* Some helper functions, not necessarily useful */
-BLAKE2_LOCAL_INLINE(int) blake2s_set_lastnode( blake2s_state *S )
+static int blake2s_set_lastnode( blake2s_state *S )
{
S->f[1] = -1;
return 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2s_clear_lastnode( blake2s_state *S )
+static int blake2s_clear_lastnode( blake2s_state *S )
{
S->f[1] = 0;
return 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2s_is_lastblock( const blake2s_state *S )
+static int blake2s_is_lastblock( const blake2s_state *S )
{
return S->f[0] != 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2s_set_lastblock( blake2s_state *S )
+static int blake2s_set_lastblock( blake2s_state *S )
{
if( S->last_node ) blake2s_set_lastnode( S );
@@ -86,7 +86,7 @@ BLAKE2_LOCAL_INLINE(int) blake2s_set_lastblock( blake2s_state *S )
return 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2s_clear_lastblock( blake2s_state *S )
+static int blake2s_clear_lastblock( blake2s_state *S )
{
if( S->last_node ) blake2s_clear_lastnode( S );
@@ -94,7 +94,7 @@ BLAKE2_LOCAL_INLINE(int) blake2s_clear_lastblock( blake2s_state *S )
return 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2s_increment_counter( blake2s_state *S, const uint32_t inc )
+static int blake2s_increment_counter( blake2s_state *S, const uint32_t inc )
{
uint64_t t = ( ( uint64_t )S->t[1] << 32 ) | S->t[0];
t += inc;
@@ -105,65 +105,66 @@ BLAKE2_LOCAL_INLINE(int) blake2s_increment_counter( blake2s_state *S, const uint
/* Parameter-related functions */
-BLAKE2_LOCAL_INLINE(int) blake2s_param_set_digest_length( blake2s_param *P, const uint8_t digest_length )
+static int blake2s_param_set_digest_length( blake2s_param *P, const uint8_t digest_length )
{
P->digest_length = digest_length;
return 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2s_param_set_fanout( blake2s_param *P, const uint8_t fanout )
+static int blake2s_param_set_fanout( blake2s_param *P, const uint8_t fanout )
{
P->fanout = fanout;
return 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2s_param_set_max_depth( blake2s_param *P, const uint8_t depth )
+static int blake2s_param_set_max_depth( blake2s_param *P, const uint8_t depth )
{
P->depth = depth;
return 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2s_param_set_leaf_length( blake2s_param *P, const uint32_t leaf_length )
+static int blake2s_param_set_leaf_length( blake2s_param *P, const uint32_t leaf_length )
{
P->leaf_length = leaf_length;
return 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2s_param_set_node_offset( blake2s_param *P, const uint64_t node_offset )
+static int blake2s_param_set_node_offset( blake2s_param *P, const uint64_t node_offset )
{
store48( P->node_offset, node_offset );
return 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2s_param_set_node_depth( blake2s_param *P, const uint8_t node_depth )
+static int blake2s_param_set_node_depth( blake2s_param *P, const uint8_t node_depth )
{
P->node_depth = node_depth;
return 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2s_param_set_inner_length( blake2s_param *P, const uint8_t inner_length )
+static int blake2s_param_set_inner_length( blake2s_param *P, const uint8_t inner_length )
{
P->inner_length = inner_length;
return 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2s_param_set_salt( blake2s_param *P, const uint8_t salt[BLAKE2S_SALTBYTES] )
+static int blake2s_param_set_salt( blake2s_param *P, const uint8_t salt[BLAKE2S_SALTBYTES] )
{
memcpy( P->salt, salt, BLAKE2S_SALTBYTES );
return 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2s_param_set_personal( blake2s_param *P, const uint8_t personal[BLAKE2S_PERSONALBYTES] )
+static int blake2s_param_set_personal( blake2s_param *P, const uint8_t personal[BLAKE2S_PERSONALBYTES] )
{
memcpy( P->personal, personal, BLAKE2S_PERSONALBYTES );
return 0;
}
-BLAKE2_LOCAL_INLINE(int) blake2s_init0( blake2s_state *S )
+static int blake2s_init0( blake2s_state *S )
{
+ int i;
memset( S, 0, sizeof( blake2s_state ) );
- for( int i = 0; i < 8; ++i ) S->h[i] = blake2s_IV[i];
+ for( i = 0; i < 8; ++i ) S->h[i] = blake2s_IV[i];
return 0;
}
@@ -171,6 +172,7 @@ BLAKE2_LOCAL_INLINE(int) blake2s_init0( blake2s_state *S )
/* init2 xors IV with input parameter block */
int blake2s_init_param( blake2s_state *S, const blake2s_param *P )
{
+ int i;
/*blake2s_init0( S ); */
const uint8_t * v = ( const uint8_t * )( blake2s_IV );
const uint8_t * p = ( const uint8_t * )( P );
@@ -178,7 +180,7 @@ int blake2s_init_param( blake2s_state *S, const blake2s_param *P )
/* IV XOR ParamBlock */
memset( S, 0, sizeof( blake2s_state ) );
- for( int i = 0; i < BLAKE2S_OUTBYTES; ++i ) h[i] = v[i] ^ p[i];
+ for( i = 0; i < BLAKE2S_OUTBYTES; ++i ) h[i] = v[i] ^ p[i];
return 0;
}
@@ -241,7 +243,7 @@ int blake2s_init_key( blake2s_state *S, const uint8_t outlen, const void *key, c
}
-BLAKE2_LOCAL_INLINE(int) blake2s_compress( blake2s_state *S, const uint8_t block[BLAKE2S_BLOCKBYTES] )
+static int blake2s_compress( blake2s_state *S, const uint8_t block[BLAKE2S_BLOCKBYTES] )
{
__m128i row1, row2, row3, row4;
__m128i buf1, buf2, buf3, buf4;
@@ -333,6 +335,7 @@ 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 )
{
uint8_t buffer[BLAKE2S_OUTBYTES] = {0};
+ int i;
if( outlen > BLAKE2S_OUTBYTES )
return -1;
@@ -353,7 +356,7 @@ int blake2s_final( blake2s_state *S, uint8_t *out, uint8_t outlen )
memset( S->buf + S->buflen, 0, 2 * BLAKE2S_BLOCKBYTES - S->buflen ); /* Padding */
blake2s_compress( S, S->buf );
- for( int i = 0; i < 8; ++i ) /* Output full hash to temp buffer */
+ 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 );
@@ -404,14 +407,15 @@ int main( int argc, char **argv )
{
uint8_t key[BLAKE2S_KEYBYTES];
uint8_t buf[KAT_LENGTH];
+ size_t i;
- for( size_t i = 0; i < BLAKE2S_KEYBYTES; ++i )
+ for( i = 0; i < BLAKE2S_KEYBYTES; ++i )
key[i] = ( uint8_t )i;
- for( size_t i = 0; i < KAT_LENGTH; ++i )
+ for( i = 0; i < KAT_LENGTH; ++i )
buf[i] = ( uint8_t )i;
- for( size_t i = 0; i < KAT_LENGTH; ++i )
+ for( i = 0; i < KAT_LENGTH; ++i )
{
uint8_t hash[BLAKE2S_OUTBYTES];
diff --git a/sse/blake2sp.c b/sse/blake2sp.c
index 7f554b8..cb31c06 100644
--- a/sse/blake2sp.c
+++ b/sse/blake2sp.c
@@ -26,7 +26,7 @@
#define PARALLELISM_DEGREE 8
-BLAKE2_LOCAL_INLINE(int) blake2sp_init_leaf( blake2s_state *S, uint8_t outlen, uint8_t keylen, uint64_t offset )
+static int blake2sp_init_leaf( blake2s_state *S, uint8_t outlen, uint8_t keylen, uint64_t offset )
{
blake2s_param P[1];
P->digest_length = outlen;
@@ -42,7 +42,7 @@ BLAKE2_LOCAL_INLINE(int) blake2sp_init_leaf( blake2s_state *S, uint8_t outlen, u
return blake2s_init_param( S, P );
}
-BLAKE2_LOCAL_INLINE(int) blake2sp_init_root( blake2s_state *S, uint8_t outlen, uint8_t keylen )
+static int blake2sp_init_root( blake2s_state *S, uint8_t outlen, uint8_t keylen )
{
blake2s_param P[1];
P->digest_length = outlen;
@@ -61,6 +61,8 @@ BLAKE2_LOCAL_INLINE(int) blake2sp_init_root( blake2s_state *S, uint8_t outlen, u
int blake2sp_init( blake2sp_state *S, const uint8_t outlen )
{
+ size_t i;
+
if( !outlen || outlen > BLAKE2S_OUTBYTES ) return -1;
memset( S->buf, 0, sizeof( S->buf ) );
@@ -69,7 +71,7 @@ int blake2sp_init( blake2sp_state *S, const uint8_t outlen )
if( blake2sp_init_root( S->R, outlen, 0 ) < 0 )
return -1;
- for( size_t i = 0; i < PARALLELISM_DEGREE; ++i )
+ for( i = 0; i < PARALLELISM_DEGREE; ++i )
if( blake2sp_init_leaf( S->S[i], outlen, 0, i ) < 0 ) return -1;
S->R->last_node = 1;
@@ -79,6 +81,8 @@ 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 )
{
+ size_t i;
+
if( !outlen || outlen > BLAKE2S_OUTBYTES ) return -1;
if( !key || !keylen || keylen > BLAKE2S_KEYBYTES ) return -1;
@@ -89,7 +93,7 @@ int blake2sp_init_key( blake2sp_state *S, const uint8_t outlen, const void *key,
if( blake2sp_init_root( S->R, outlen, keylen ) < 0 )
return -1;
- for( size_t i = 0; i < PARALLELISM_DEGREE; ++i )
+ for( i = 0; i < PARALLELISM_DEGREE; ++i )
if( blake2sp_init_leaf( S->S[i], outlen, keylen, i ) < 0 ) return -1;
S->R->last_node = 1;
@@ -99,7 +103,7 @@ int blake2sp_init_key( blake2sp_state *S, const uint8_t outlen, const void *key,
memset( block, 0, BLAKE2S_BLOCKBYTES );
memcpy( block, key, keylen );
- for( size_t i = 0; i < PARALLELISM_DEGREE; ++i )
+ for( i = 0; i < PARALLELISM_DEGREE; ++i )
blake2s_update( S->S[i], block, BLAKE2S_BLOCKBYTES );
secure_zero_memory( block, BLAKE2S_BLOCKBYTES ); /* Burn the key from stack */
@@ -112,12 +116,13 @@ int blake2sp_update( blake2sp_state *S, const uint8_t *in, uint64_t inlen )
{
size_t left = S->buflen;
size_t fill = sizeof( S->buf ) - left;
+ size_t i;
if( left && inlen >= fill )
{
memcpy( S->buf + left, in, fill );
- for( size_t i = 0; i < PARALLELISM_DEGREE; ++i )
+ for( i = 0; i < PARALLELISM_DEGREE; ++i )
blake2s_update( S->S[i], S->buf + i * BLAKE2S_BLOCKBYTES, BLAKE2S_BLOCKBYTES );
in += fill;
@@ -129,19 +134,19 @@ int blake2sp_update( blake2sp_state *S, const uint8_t *in, uint64_t inlen )
#pragma omp parallel shared(S), num_threads(PARALLELISM_DEGREE)
#else
- for( size_t id__ = 0; id__ < PARALLELISM_DEGREE; ++id__ )
+ for( i = 0; i < PARALLELISM_DEGREE; ++i )
#endif
{
#if defined(_OPENMP)
- size_t id__ = omp_get_thread_num();
+ size_t i = omp_get_thread_num();
#endif
uint64_t inlen__ = inlen;
const uint8_t *in__ = ( const uint8_t * )in;
- in__ += id__ * BLAKE2S_BLOCKBYTES;
+ in__ += i * BLAKE2S_BLOCKBYTES;
while( inlen__ >= PARALLELISM_DEGREE * BLAKE2S_BLOCKBYTES )
{
- blake2s_update( S->S[id__], in__, BLAKE2S_BLOCKBYTES );
+ blake2s_update( S->S[i], in__, BLAKE2S_BLOCKBYTES );
in__ += PARALLELISM_DEGREE * BLAKE2S_BLOCKBYTES;
inlen__ -= PARALLELISM_DEGREE * BLAKE2S_BLOCKBYTES;
}
@@ -161,8 +166,9 @@ 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 )
{
uint8_t hash[PARALLELISM_DEGREE][BLAKE2S_OUTBYTES];
+ size_t i;
- for( size_t i = 0; i < PARALLELISM_DEGREE; ++i )
+ for( i = 0; i < PARALLELISM_DEGREE; ++i )
{
if( S->buflen > i * BLAKE2S_BLOCKBYTES )
{
@@ -176,7 +182,7 @@ int blake2sp_final( blake2sp_state *S, uint8_t *out, const uint8_t outlen )
blake2s_final( S->S[i], hash[i], BLAKE2S_OUTBYTES );
}
- for( size_t i = 0; i < PARALLELISM_DEGREE; ++i )
+ for( i = 0; i < PARALLELISM_DEGREE; ++i )
blake2s_update( S->R, hash[i], BLAKE2S_OUTBYTES );
return blake2s_final( S->R, out, outlen );
@@ -188,6 +194,7 @@ int blake2sp( uint8_t *out, const void *in, const void *key, uint8_t outlen, uin
uint8_t hash[PARALLELISM_DEGREE][BLAKE2S_OUTBYTES];
blake2s_state S[PARALLELISM_DEGREE][1];
blake2s_state FS[1];
+ size_t i;
/* Verify parameters */
if ( NULL == in && inlen > 0 ) return -1;
@@ -200,7 +207,7 @@ int blake2sp( uint8_t *out, const void *in, const void *key, uint8_t outlen, uin
if( keylen > BLAKE2S_KEYBYTES ) return -1;
- for( size_t i = 0; i < PARALLELISM_DEGREE; ++i )
+ for( i = 0; i < PARALLELISM_DEGREE; ++i )
if( blake2sp_init_leaf( S[i], outlen, keylen, i ) < 0 ) return -1;
S[PARALLELISM_DEGREE - 1]->last_node = 1; /* mark last node */
@@ -211,7 +218,7 @@ int blake2sp( uint8_t *out, const void *in, const void *key, uint8_t outlen, uin
memset( block, 0, BLAKE2S_BLOCKBYTES );
memcpy( block, key, keylen );
- for( size_t i = 0; i < PARALLELISM_DEGREE; ++i )
+ for( i = 0; i < PARALLELISM_DEGREE; ++i )
blake2s_update( S[i], block, BLAKE2S_BLOCKBYTES );
secure_zero_memory( block, BLAKE2S_BLOCKBYTES ); /* Burn the key from stack */
@@ -221,31 +228,31 @@ int blake2sp( uint8_t *out, const void *in, const void *key, uint8_t outlen, uin
#pragma omp parallel shared(S,hash), num_threads(PARALLELISM_DEGREE)
#else
- for( size_t id__ = 0; id__ < PARALLELISM_DEGREE; ++id__ )
+ for( i = 0; i < PARALLELISM_DEGREE; ++i )
#endif
{
#if defined(_OPENMP)
- size_t id__ = omp_get_thread_num();
+ size_t i = omp_get_thread_num();
#endif
uint64_t inlen__ = inlen;
const uint8_t *in__ = ( const uint8_t * )in;
- in__ += id__ * BLAKE2S_BLOCKBYTES;
+ in__ += i * BLAKE2S_BLOCKBYTES;
while( inlen__ >= PARALLELISM_DEGREE * BLAKE2S_BLOCKBYTES )
{
- blake2s_update( S[id__], in__, BLAKE2S_BLOCKBYTES );
+ blake2s_update( S[i], in__, BLAKE2S_BLOCKBYTES );
in__ += PARALLELISM_DEGREE * BLAKE2S_BLOCKBYTES;
inlen__ -= PARALLELISM_DEGREE * BLAKE2S_BLOCKBYTES;
}
- if( inlen__ > id__ * BLAKE2S_BLOCKBYTES )
+ if( inlen__ > i * BLAKE2S_BLOCKBYTES )
{
- const size_t left = inlen__ - id__ * BLAKE2S_BLOCKBYTES;
+ const size_t left = inlen__ - i * BLAKE2S_BLOCKBYTES;
const size_t len = left <= BLAKE2S_BLOCKBYTES ? left : BLAKE2S_BLOCKBYTES;
- blake2s_update( S[id__], in__, len );
+ blake2s_update( S[i], in__, len );
}
- blake2s_final( S[id__], hash[id__], BLAKE2S_OUTBYTES );
+ blake2s_final( S[i], hash[i], BLAKE2S_OUTBYTES );
}
if( blake2sp_init_root( FS, outlen, keylen ) < 0 )
@@ -253,7 +260,7 @@ int blake2sp( uint8_t *out, const void *in, const void *key, uint8_t outlen, uin
FS->last_node = 1;
- for( size_t i = 0; i < PARALLELISM_DEGREE; ++i )
+ for( i = 0; i < PARALLELISM_DEGREE; ++i )
blake2s_update( FS, hash[i], BLAKE2S_OUTBYTES );
return blake2s_final( FS, out, outlen );
@@ -266,14 +273,15 @@ int main( int argc, char **argv )
{
uint8_t key[BLAKE2S_KEYBYTES];
uint8_t buf[KAT_LENGTH];
+ size_t i;
- for( size_t i = 0; i < BLAKE2S_KEYBYTES; ++i )
+ for( i = 0; i < BLAKE2S_KEYBYTES; ++i )
key[i] = ( uint8_t )i;
- for( size_t i = 0; i < KAT_LENGTH; ++i )
+ for( i = 0; i < KAT_LENGTH; ++i )
buf[i] = ( uint8_t )i;
- for( size_t i = 0; i < KAT_LENGTH; ++i )
+ for( i = 0; i < KAT_LENGTH; ++i )
{
uint8_t hash[BLAKE2S_OUTBYTES];
blake2sp( hash, buf, key, BLAKE2S_OUTBYTES, i, BLAKE2S_KEYBYTES );