summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Modules/_blake2/impl/blake2b.c
diff options
context:
space:
mode:
authorshadchin <[email protected]>2022-02-10 16:44:39 +0300
committerDaniil Cherednik <[email protected]>2022-02-10 16:44:39 +0300
commite9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch)
tree64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/tools/python3/src/Modules/_blake2/impl/blake2b.c
parent2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff)
Restoring authorship annotation for <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Modules/_blake2/impl/blake2b.c')
-rw-r--r--contrib/tools/python3/src/Modules/_blake2/impl/blake2b.c198
1 files changed, 99 insertions, 99 deletions
diff --git a/contrib/tools/python3/src/Modules/_blake2/impl/blake2b.c b/contrib/tools/python3/src/Modules/_blake2/impl/blake2b.c
index 0807184dd5c..c1068e86405 100644
--- a/contrib/tools/python3/src/Modules/_blake2/impl/blake2b.c
+++ b/contrib/tools/python3/src/Modules/_blake2/impl/blake2b.c
@@ -1,14 +1,14 @@
/*
BLAKE2 reference source code package - optimized C implementations
-
- Written in 2012 by Samuel Neves <[email protected]>
-
- To the extent possible under law, the author(s) have dedicated all copyright
- and related and neighboring rights to this software to the public domain
- worldwide. This software is distributed without any warranty.
-
- You should have received a copy of the CC0 Public Domain Dedication along with
- this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
+
+ Written in 2012 by Samuel Neves <[email protected]>
+
+ To the extent possible under law, the author(s) have dedicated all copyright
+ and related and neighboring rights to this software to the public domain
+ worldwide. This software is distributed without any warranty.
+
+ You should have received a copy of the CC0 Public Domain Dedication along with
+ this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#include <stdint.h>
@@ -20,36 +20,36 @@
#include "blake2-config.h"
-#if defined(_MSC_VER)
-#include <intrin.h>
+#if defined(_MSC_VER)
+#include <intrin.h>
#endif
-
-#if defined(HAVE_SSE2)
+
+#if defined(HAVE_SSE2)
#include <emmintrin.h>
-// MSVC only defines _mm_set_epi64x for x86_64...
-#if defined(_MSC_VER) && !defined(_M_X64)
-static inline __m128i _mm_set_epi64x( const uint64_t u1, const uint64_t u0 )
-{
- return _mm_set_epi32( u1 >> 32, u1, u0 >> 32, u0 );
-}
-#endif
-#endif
-
+// MSVC only defines _mm_set_epi64x for x86_64...
+#if defined(_MSC_VER) && !defined(_M_X64)
+static inline __m128i _mm_set_epi64x( const uint64_t u1, const uint64_t u0 )
+{
+ return _mm_set_epi32( u1 >> 32, u1, u0 >> 32, u0 );
+}
+#endif
+#endif
+
#if defined(HAVE_SSSE3)
#include <tmmintrin.h>
#endif
-#if defined(HAVE_SSE4_1)
+#if defined(HAVE_SSE4_1)
#include <smmintrin.h>
#endif
#if defined(HAVE_AVX)
#include <immintrin.h>
#endif
-#if defined(HAVE_XOP) && !defined(_MSC_VER)
+#if defined(HAVE_XOP) && !defined(_MSC_VER)
#include <x86intrin.h>
#endif
-
-
+
+
#include "blake2b-round.h"
static const uint64_t blake2b_IV[8] =
@@ -78,39 +78,39 @@ static const uint8_t blake2b_sigma[12][16] =
/* Some helper functions, not necessarily useful */
-static inline int blake2b_set_lastnode( blake2b_state *S )
+static inline int blake2b_set_lastnode( blake2b_state *S )
{
- S->f[1] = ~0ULL;
+ S->f[1] = ~0ULL;
return 0;
}
-static inline int blake2b_clear_lastnode( blake2b_state *S )
+static inline int blake2b_clear_lastnode( blake2b_state *S )
{
- S->f[1] = 0ULL;
+ S->f[1] = 0ULL;
return 0;
}
-static inline int blake2b_set_lastblock( blake2b_state *S )
+static inline int blake2b_set_lastblock( blake2b_state *S )
{
if( S->last_node ) blake2b_set_lastnode( S );
- S->f[0] = ~0ULL;
+ S->f[0] = ~0ULL;
return 0;
}
-static inline int blake2b_clear_lastblock( blake2b_state *S )
+static inline int blake2b_clear_lastblock( blake2b_state *S )
{
if( S->last_node ) blake2b_clear_lastnode( S );
- S->f[0] = 0ULL;
+ S->f[0] = 0ULL;
return 0;
}
-static inline int blake2b_increment_counter( blake2b_state *S, const uint64_t inc )
+static inline int blake2b_increment_counter( blake2b_state *S, const uint64_t inc )
{
-#if defined(__x86_64__) && (defined(__GNUC__) || defined(__clang__))
- // ADD/ADC chain
+#if defined(__x86_64__) && (defined(__GNUC__) || defined(__clang__))
+ // ADD/ADC chain
__uint128_t t = ( ( __uint128_t )S->t[1] << 64 ) | S->t[0];
t += inc;
S->t[0] = ( uint64_t )( t >> 0 );
@@ -123,112 +123,112 @@ static inline int blake2b_increment_counter( blake2b_state *S, const uint64_t in
}
-// Parameter-related functions
-static inline int blake2b_param_set_digest_length( blake2b_param *P, const uint8_t digest_length )
+// Parameter-related functions
+static inline int blake2b_param_set_digest_length( blake2b_param *P, const uint8_t digest_length )
{
P->digest_length = digest_length;
return 0;
}
-static inline int blake2b_param_set_fanout( blake2b_param *P, const uint8_t fanout )
+static inline int blake2b_param_set_fanout( blake2b_param *P, const uint8_t fanout )
{
P->fanout = fanout;
return 0;
}
-static inline int blake2b_param_set_max_depth( blake2b_param *P, const uint8_t depth )
+static inline int blake2b_param_set_max_depth( blake2b_param *P, const uint8_t depth )
{
P->depth = depth;
return 0;
}
-static inline int blake2b_param_set_leaf_length( blake2b_param *P, const uint32_t leaf_length )
+static inline int blake2b_param_set_leaf_length( blake2b_param *P, const uint32_t leaf_length )
{
P->leaf_length = leaf_length;
return 0;
}
-static inline int blake2b_param_set_node_offset( blake2b_param *P, const uint64_t node_offset )
+static inline int blake2b_param_set_node_offset( blake2b_param *P, const uint64_t node_offset )
{
P->node_offset = node_offset;
return 0;
}
-static inline int blake2b_param_set_node_depth( blake2b_param *P, const uint8_t node_depth )
+static inline int blake2b_param_set_node_depth( blake2b_param *P, const uint8_t node_depth )
{
P->node_depth = node_depth;
return 0;
}
-static inline int blake2b_param_set_inner_length( blake2b_param *P, const uint8_t inner_length )
+static inline int blake2b_param_set_inner_length( blake2b_param *P, const uint8_t inner_length )
{
P->inner_length = inner_length;
return 0;
}
-static inline int blake2b_param_set_salt( blake2b_param *P, const uint8_t salt[BLAKE2B_SALTBYTES] )
+static inline int blake2b_param_set_salt( blake2b_param *P, const uint8_t salt[BLAKE2B_SALTBYTES] )
{
memcpy( P->salt, salt, BLAKE2B_SALTBYTES );
return 0;
}
-static inline int blake2b_param_set_personal( blake2b_param *P, const uint8_t personal[BLAKE2B_PERSONALBYTES] )
+static inline int blake2b_param_set_personal( blake2b_param *P, const uint8_t personal[BLAKE2B_PERSONALBYTES] )
{
memcpy( P->personal, personal, BLAKE2B_PERSONALBYTES );
return 0;
}
-static inline int blake2b_init0( blake2b_state *S )
+static inline int blake2b_init0( blake2b_state *S )
{
memset( S, 0, sizeof( blake2b_state ) );
- for( int i = 0; i < 8; ++i ) S->h[i] = blake2b_IV[i];
+ for( int i = 0; i < 8; ++i ) S->h[i] = blake2b_IV[i];
return 0;
}
-
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
- int blake2b_init( blake2b_state *S, size_t outlen );
- int blake2b_init_param( blake2b_state *S, const blake2b_param *P );
- int blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t keylen );
- int blake2b_update( blake2b_state *S, const uint8_t *in, size_t inlen );
- int blake2b_final( blake2b_state *S, uint8_t *out, size_t outlen );
- int blake2b( uint8_t *out, const void *in, const void *key, size_t outlen, size_t inlen, size_t keylen );
-#if defined(__cplusplus)
-}
-#endif
-
+
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+ int blake2b_init( blake2b_state *S, size_t outlen );
+ int blake2b_init_param( blake2b_state *S, const blake2b_param *P );
+ int blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t keylen );
+ int blake2b_update( blake2b_state *S, const uint8_t *in, size_t inlen );
+ int blake2b_final( blake2b_state *S, uint8_t *out, size_t outlen );
+ int blake2b( uint8_t *out, const void *in, const void *key, size_t outlen, size_t inlen, size_t keylen );
+#if defined(__cplusplus)
+}
+#endif
+
/* init xors IV with input parameter block */
int blake2b_init_param( blake2b_state *S, const blake2b_param *P )
{
- uint8_t *p, *h, *v;
- //blake2b_init0( S );
- v = ( uint8_t * )( blake2b_IV );
- h = ( uint8_t * )( S->h );
- p = ( uint8_t * )( P );
+ uint8_t *p, *h, *v;
+ //blake2b_init0( S );
+ v = ( uint8_t * )( blake2b_IV );
+ h = ( uint8_t * )( S->h );
+ p = ( uint8_t * )( 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( int i = 0; i < BLAKE2B_OUTBYTES; ++i ) h[i] = v[i] ^ p[i];
- S->outlen = P->digest_length;
+ S->outlen = P->digest_length;
return 0;
}
/* Some sort of default parameter block initialization, for sequential blake2b */
-
-int blake2b_init( blake2b_state *S, size_t outlen )
+
+int blake2b_init( blake2b_state *S, size_t outlen )
{
- if ( ( !outlen ) || ( outlen > BLAKE2B_OUTBYTES ) ) return -1;
-
+ if ( ( !outlen ) || ( outlen > BLAKE2B_OUTBYTES ) ) return -1;
+
const blake2b_param P =
{
- ( uint8_t ) outlen,
+ ( uint8_t ) outlen,
0,
1,
1,
@@ -240,19 +240,19 @@ int blake2b_init( blake2b_state *S, size_t outlen )
{0},
{0}
};
- return blake2b_init_param( S, &P );
-}
+ return blake2b_init_param( S, &P );
+}
-int blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t keylen )
-{
+int blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t keylen )
+{
if ( ( !outlen ) || ( outlen > BLAKE2B_OUTBYTES ) ) return -1;
- if ( ( !keylen ) || keylen > BLAKE2B_KEYBYTES ) return -1;
+ if ( ( !keylen ) || keylen > BLAKE2B_KEYBYTES ) return -1;
const blake2b_param P =
{
- ( uint8_t ) outlen,
- ( uint8_t ) keylen,
+ ( uint8_t ) outlen,
+ ( uint8_t ) keylen,
1,
1,
0,
@@ -277,7 +277,7 @@ int blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t k
return 0;
}
-static inline int blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] )
+static inline int blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] )
{
__m128i row1l, row1h;
__m128i row2l, row2h;
@@ -289,7 +289,7 @@ static inline int blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2
const __m128i r16 = _mm_setr_epi8( 2, 3, 4, 5, 6, 7, 0, 1, 10, 11, 12, 13, 14, 15, 8, 9 );
const __m128i r24 = _mm_setr_epi8( 3, 4, 5, 6, 7, 0, 1, 2, 11, 12, 13, 14, 15, 8, 9, 10 );
#endif
-#if defined(HAVE_SSE4_1)
+#if defined(HAVE_SSE4_1)
const __m128i m0 = LOADU( block + 00 );
const __m128i m1 = LOADU( block + 16 );
const __m128i m2 = LOADU( block + 32 );
@@ -348,28 +348,28 @@ static inline int blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2
}
-int blake2b_update( blake2b_state *S, const uint8_t *in, size_t inlen )
+int blake2b_update( blake2b_state *S, const uint8_t *in, size_t inlen )
{
while( inlen > 0 )
{
- uint32_t left = S->buflen;
- uint32_t fill = 2 * BLAKE2B_BLOCKBYTES - left;
+ uint32_t left = S->buflen;
+ uint32_t fill = 2 * BLAKE2B_BLOCKBYTES - left;
if( inlen > fill )
{
- memcpy( S->buf + left, in, fill ); // Fill buffer
+ 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
+ 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
+ else // inlen <= fill
{
memcpy( S->buf + left, in, inlen );
- S->buflen += ( uint32_t ) inlen; // Be lazy, do not compress
+ S->buflen += ( uint32_t ) inlen; // Be lazy, do not compress
in += inlen;
inlen -= inlen;
}
@@ -379,16 +379,16 @@ int blake2b_update( blake2b_state *S, const uint8_t *in, size_t inlen )
}
-int blake2b_final( blake2b_state *S, uint8_t *out, size_t outlen )
+int blake2b_final( blake2b_state *S, uint8_t *out, size_t outlen )
{
- if(S->outlen != outlen) return -1;
+ if(S->outlen != outlen) return -1;
if( S->buflen > BLAKE2B_BLOCKBYTES )
{
blake2b_increment_counter( S, BLAKE2B_BLOCKBYTES );
blake2b_compress( S, S->buf );
S->buflen -= BLAKE2B_BLOCKBYTES;
- memmove( S->buf, S->buf + BLAKE2B_BLOCKBYTES, S->buflen );
+ memmove( S->buf, S->buf + BLAKE2B_BLOCKBYTES, S->buflen );
}
blake2b_increment_counter( S, S->buflen );
@@ -400,7 +400,7 @@ int blake2b_final( blake2b_state *S, uint8_t *out, size_t outlen )
}
-int blake2b( uint8_t *out, const void *in, const void *key, size_t outlen, size_t inlen, size_t keylen )
+int blake2b( uint8_t *out, const void *in, const void *key, size_t outlen, size_t inlen, size_t keylen )
{
blake2b_state S[1];
@@ -424,8 +424,8 @@ int blake2b( uint8_t *out, const void *in, const void *key, size_t outlen, size_
if( blake2b_init( S, outlen ) < 0 ) return -1;
}
- if( blake2b_update( S, ( uint8_t * )in, inlen ) < 0) return -1;
- return blake2b_final( S, out, outlen );
+ if( blake2b_update( S, ( uint8_t * )in, inlen ) < 0) return -1;
+ return blake2b_final( S, out, outlen );
}
#if defined(SUPERCOP)