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:
Diffstat (limited to 'ref/blake2s-ref.c')
-rw-r--r--ref/blake2s-ref.c59
1 files changed, 32 insertions, 27 deletions
diff --git a/ref/blake2s-ref.c b/ref/blake2s-ref.c
index 0e246c3..e24183c 100644
--- a/ref/blake2s-ref.c
+++ b/ref/blake2s-ref.c
@@ -40,25 +40,25 @@ static const uint8_t blake2s_sigma[10][16] =
{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 } ,
};
-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;
}
/* Some helper functions, not necessarily useful */
-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 );
@@ -66,7 +66,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 );
@@ -74,7 +74,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 )
{
S->t[0] += inc;
S->t[1] += ( S->t[0] < inc );
@@ -82,65 +82,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 )
{
store32( &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;
}
@@ -148,12 +149,13 @@ 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 )
{
+ size_t i;
const uint32_t *p = ( const uint32_t * )( P );
blake2s_init0( S );
/* IV XOR ParamBlock */
- for( size_t i = 0; i < 8; ++i )
+ for( i = 0; i < 8; ++i )
S->h[i] ^= load32( &p[i] );
return 0;
@@ -218,11 +220,12 @@ static int blake2s_compress( blake2s_state *S, const uint8_t block[BLAKE2S_BLOCK
{
uint32_t m[16];
uint32_t v[16];
+ size_t i;
- for( size_t i = 0; i < 16; ++i )
+ for( i = 0; i < 16; ++i )
m[i] = load32( block + i * sizeof( m[i] ) );
- for( size_t i = 0; i < 8; ++i )
+ for( i = 0; i < 8; ++i )
v[i] = S->h[i];
v[ 8] = blake2s_IV[0];
@@ -266,7 +269,7 @@ static int blake2s_compress( blake2s_state *S, const uint8_t block[BLAKE2S_BLOCK
ROUND( 8 );
ROUND( 9 );
- for( size_t i = 0; i < 8; ++i )
+ for( i = 0; i < 8; ++i )
S->h[i] = S->h[i] ^ v[i] ^ v[i + 8];
#undef G
@@ -308,6 +311,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( out == NULL || outlen == 0 || outlen > BLAKE2S_OUTBYTES )
return -1;
@@ -329,9 +333,9 @@ 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 );
return 0;
}
@@ -375,18 +379,19 @@ int crypto_hash( unsigned char *out, unsigned char *in, unsigned long long inlen
#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[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];
blake2s( hash, buf, key, BLAKE2S_OUTBYTES, i, BLAKE2S_KEYBYTES );