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 /ref/blake2s-ref.c
parent259e61dedee5383eac1a90db6ef88f9ccdcf6002 (diff)
api cleanup, sse edition
Diffstat (limited to 'ref/blake2s-ref.c')
-rw-r--r--ref/blake2s-ref.c90
1 files changed, 14 insertions, 76 deletions
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;