diff --git a/configure.ac b/configure.ac index 7e474cae..b6cfe943 100644 --- a/configure.ac +++ b/configure.ac @@ -327,7 +327,7 @@ AS_IF([test "x$EMSCRIPTEN" = "x"],[ ]], [[ __m128i x = _mm_minpos_epu16(_mm_setzero_si128()); ]])], [AC_MSG_RESULT(yes) AC_DEFINE([HAVE_SMMINTRIN_H], [1], [sse4.1 is available]) - AX_CHECK_COMPILE_FLAG([-msse4.1], [CFLAGS_SSE4_1="-msse4.1"])], + AX_CHECK_COMPILE_FLAG([-msse4.1], [CFLAGS_SSE41="-msse4.1"])], [AC_MSG_RESULT(no)]) CFLAGS="$oldcflags" @@ -355,7 +355,7 @@ AC_SUBST(CFLAGS_MMX) AC_SUBST(CFLAGS_SSE2) AC_SUBST(CFLAGS_SSE3) AC_SUBST(CFLAGS_SSSE3) -AC_SUBST(CFLAGS_SSE4_1) +AC_SUBST(CFLAGS_SSE41) AC_SUBST(CFLAGS_AESNI) AC_SUBST(CFLAGS_PCLMUL) diff --git a/src/libsodium/Makefile.am b/src/libsodium/Makefile.am index 5f94c407..c11890b2 100644 --- a/src/libsodium/Makefile.am +++ b/src/libsodium/Makefile.am @@ -36,7 +36,10 @@ libsodium_la_SOURCES = \ crypto_generichash/blake2/ref/api.h \ crypto_generichash/blake2/ref/blake2-impl.h \ crypto_generichash/blake2/ref/blake2.h \ + crypto_generichash/blake2/ref/blake2b-load-sse2.h \ + crypto_generichash/blake2/ref/blake2b-load-sse41.h \ crypto_generichash/blake2/ref/blake2b-ref.c \ + crypto_generichash/blake2/ref/blake2b-round.h \ crypto_generichash/blake2/ref/generichash_blake2b.c \ crypto_hash/crypto_hash.c \ crypto_hash/sha256/hash_sha256_api.c \ @@ -268,19 +271,29 @@ endif SUBDIRS = \ include -libsodium_la_LIBADD = libaesni.la libsse2.la -noinst_LTLIBRARIES = libaesni.la libsse2.la +libsodium_la_LIBADD = libaesni.la libsse2.la libssse3.la libsse41.la +noinst_LTLIBRARIES = libaesni.la libsse2.la libssse3.la libsse41.la libaesni_la_LDFLAGS = $(libsodium_la_LDFLAGS) libaesni_la_CPPFLAGS = $(libsodium_la_CPPFLAGS) \ @CFLAGS_SSSE3@ @CFLAGS_AESNI@ @CFLAGS_PCLMUL@ - libaesni_la_SOURCES = \ crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c libsse2_la_LDFLAGS = $(libsodium_la_LDFLAGS) libsse2_la_CPPFLAGS = $(libsodium_la_CPPFLAGS) \ @CFLAGS_SSE2@ - libsse2_la_SOURCES = \ crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c + +libssse3_la_LDFLAGS = $(libsodium_la_LDFLAGS) +libssse3_la_CPPFLAGS = $(libsodium_la_CPPFLAGS) \ + @CFLAGS_SSE2@ @CFLAGS_SSSE3@ +libssse3_la_SOURCES = \ + crypto_generichash/blake2/ref/blake2b-compress-ssse3.c + +libsse41_la_LDFLAGS = $(libsodium_la_LDFLAGS) +libsse41_la_CPPFLAGS = $(libsodium_la_CPPFLAGS) \ + @CFLAGS_SSE2@ @CFLAGS_SSSE3@ @CFLAGS_SSE41@ +libsse41_la_SOURCES = \ + crypto_generichash/blake2/ref/blake2b-compress-sse41.c diff --git a/src/libsodium/crypto_generichash/blake2/ref/blake2.h b/src/libsodium/crypto_generichash/blake2/ref/blake2.h index d11fa27a..85e00847 100644 --- a/src/libsodium/crypto_generichash/blake2/ref/blake2.h +++ b/src/libsodium/crypto_generichash/blake2/ref/blake2.h @@ -179,6 +179,9 @@ typedef crypto_generichash_blake2b_state blake2b_state; return blake2b( out, in, key, outlen, inlen, keylen ); } + int blake2b_compress_ssse3( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] ); + int blake2b_compress_sse41( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] ); + #if defined(__cplusplus) } #endif diff --git a/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-sse41.c b/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-sse41.c new file mode 100644 index 00000000..4ce1abcc --- /dev/null +++ b/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-sse41.c @@ -0,0 +1,83 @@ + +#define BLAKE2_USE_SSSE2 +#define BLAKE2_USE_SSE41 + +#include +#include +#include + +#if defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H) && defined(HAVE_SMMINTRIN_H) + +#pragma GCC target("sse2") +#pragma GCC target("ssse3") +#pragma GCC target("sse4.1") + +#ifdef _MSC_VER +# include /* for _mm_set_epi64x */ +#endif +#include +#include +#include + +#include "blake2.h" +#include "blake2-impl.h" +#include "blake2b-round.h" + +static const uint64_t blake2b_IV[8] = +{ + 0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL, + 0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL, + 0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL, + 0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL +}; + +int blake2b_compress_sse41( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] ) +{ + __m128i row1l, row1h; + __m128i row2l, row2h; + __m128i row3l, row3h; + __m128i row4l, row4h; + __m128i b0, b1; + __m128i t0, t1; + 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 ); + const __m128i m0 = LOADU( block + 00 ); + const __m128i m1 = LOADU( block + 16 ); + const __m128i m2 = LOADU( block + 32 ); + const __m128i m3 = LOADU( block + 48 ); + const __m128i m4 = LOADU( block + 64 ); + const __m128i m5 = LOADU( block + 80 ); + const __m128i m6 = LOADU( block + 96 ); + const __m128i m7 = LOADU( block + 112 ); + row1l = LOADU( &S->h[0] ); + row1h = LOADU( &S->h[2] ); + row2l = LOADU( &S->h[4] ); + row2h = LOADU( &S->h[6] ); + row3l = LOADU( &blake2b_IV[0] ); + row3h = LOADU( &blake2b_IV[2] ); + row4l = _mm_xor_si128( LOADU( &blake2b_IV[4] ), LOADU( &S->t[0] ) ); + row4h = _mm_xor_si128( LOADU( &blake2b_IV[6] ), LOADU( &S->f[0] ) ); + ROUND( 0 ); + ROUND( 1 ); + ROUND( 2 ); + ROUND( 3 ); + ROUND( 4 ); + ROUND( 5 ); + ROUND( 6 ); + ROUND( 7 ); + ROUND( 8 ); + ROUND( 9 ); + ROUND( 10 ); + ROUND( 11 ); + row1l = _mm_xor_si128( row3l, row1l ); + row1h = _mm_xor_si128( row3h, row1h ); + STOREU( &S->h[0], _mm_xor_si128( LOADU( &S->h[0] ), row1l ) ); + STOREU( &S->h[2], _mm_xor_si128( LOADU( &S->h[2] ), row1h ) ); + row2l = _mm_xor_si128( row4l, row2l ); + 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; +} + +#endif diff --git a/src/libsodium/crypto_generichash/blake2/sse/blake2b-compress.c b/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-ssse3.c similarity index 80% rename from src/libsodium/crypto_generichash/blake2/sse/blake2b-compress.c rename to src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-ssse3.c index e20e222a..78cc70ff 100644 --- a/src/libsodium/crypto_generichash/blake2/sse/blake2b-compress.c +++ b/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-ssse3.c @@ -1,19 +1,23 @@ -#include "blake2-config.h" -#include "blake2.h" -#include "blake2-impl.h" +#define BLAKE2_USE_SSSE2 -#define BLAKE2_USE_SSSE3 +#include +#include +#include + +#if defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H) + +#pragma GCC target("sse2") +#pragma GCC target("ssse3") #ifdef _MSC_VER -#include /* for _mm_set_epi64x */ +# include /* for _mm_set_epi64x */ #endif #include #include -#if defined(BLAKE2_USE_SSE41) -#include -#endif +#include "blake2.h" +#include "blake2-impl.h" #include "blake2b-round.h" static const uint64_t blake2b_IV[8] = @@ -24,7 +28,7 @@ static const uint64_t blake2b_IV[8] = 0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL }; -int blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] ) +int blake2b_compress_ssse3( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] ) { __m128i row1l, row1h; __m128i row2l, row2h; @@ -34,16 +38,6 @@ int blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] __m128i t0, t1; 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 ); -#if defined(BLAKE2_USE_SSE41) - const __m128i m0 = LOADU( block + 00 ); - const __m128i m1 = LOADU( block + 16 ); - const __m128i m2 = LOADU( block + 32 ); - const __m128i m3 = LOADU( block + 48 ); - const __m128i m4 = LOADU( block + 64 ); - const __m128i m5 = LOADU( block + 80 ); - const __m128i m6 = LOADU( block + 96 ); - const __m128i m7 = LOADU( block + 112 ); -#else const uint64_t m0 = ( ( uint64_t * )block )[ 0]; const uint64_t m1 = ( ( uint64_t * )block )[ 1]; const uint64_t m2 = ( ( uint64_t * )block )[ 2]; @@ -60,7 +54,7 @@ int blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] const uint64_t m13 = ( ( uint64_t * )block )[13]; const uint64_t m14 = ( ( uint64_t * )block )[14]; const uint64_t m15 = ( ( uint64_t * )block )[15]; -#endif + row1l = LOADU( &S->h[0] ); row1h = LOADU( &S->h[2] ); row2l = LOADU( &S->h[4] ); @@ -91,3 +85,5 @@ int blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] STOREU( &S->h[6], _mm_xor_si128( LOADU( &S->h[6] ), row2h ) ); return 0; } + +#endif diff --git a/src/libsodium/crypto_generichash/blake2/sse/blake2b-load-sse2.h b/src/libsodium/crypto_generichash/blake2/ref/blake2b-load-sse2.h similarity index 98% rename from src/libsodium/crypto_generichash/blake2/sse/blake2b-load-sse2.h rename to src/libsodium/crypto_generichash/blake2/ref/blake2b-load-sse2.h index 1ba153c8..fb05a191 100644 --- a/src/libsodium/crypto_generichash/blake2/sse/blake2b-load-sse2.h +++ b/src/libsodium/crypto_generichash/blake2/ref/blake2b-load-sse2.h @@ -10,9 +10,9 @@ You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see . */ -#pragma once -#ifndef __BLAKE2B_LOAD_SSE2_H__ -#define __BLAKE2B_LOAD_SSE2_H__ + +#ifndef blake2b_load_sse2_H +#define blake2b_load_sse2_H #define LOAD_MSG_0_1(b0, b1) b0 = _mm_set_epi64x(m2, m0); b1 = _mm_set_epi64x(m6, m4) #define LOAD_MSG_0_2(b0, b1) b0 = _mm_set_epi64x(m3, m1); b1 = _mm_set_epi64x(m7, m5) diff --git a/src/libsodium/crypto_generichash/blake2/sse/blake2b-load-sse41.h b/src/libsodium/crypto_generichash/blake2/ref/blake2b-load-sse41.h similarity index 98% rename from src/libsodium/crypto_generichash/blake2/sse/blake2b-load-sse41.h rename to src/libsodium/crypto_generichash/blake2/ref/blake2b-load-sse41.h index f6c1bc83..38ca244b 100644 --- a/src/libsodium/crypto_generichash/blake2/sse/blake2b-load-sse41.h +++ b/src/libsodium/crypto_generichash/blake2/ref/blake2b-load-sse41.h @@ -10,9 +10,9 @@ You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see . */ -#pragma once -#ifndef __BLAKE2B_LOAD_SSE41_H__ -#define __BLAKE2B_LOAD_SSE41_H__ + +#ifndef blake2b_load_sse41_H +#define blake2b_load_sse41_H #define LOAD_MSG_0_1(b0, b1) \ do \ diff --git a/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c b/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c index 2cf03cc4..96ebc9c4 100644 --- a/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c +++ b/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c @@ -12,8 +12,8 @@ */ #include +#include #include -#include #include "blake2.h" #include "blake2-impl.h" diff --git a/src/libsodium/crypto_generichash/blake2/sse/blake2b-round.h b/src/libsodium/crypto_generichash/blake2/ref/blake2b-round.h similarity index 96% rename from src/libsodium/crypto_generichash/blake2/sse/blake2b-round.h rename to src/libsodium/crypto_generichash/blake2/ref/blake2b-round.h index 7508317c..dad8a1d9 100644 --- a/src/libsodium/crypto_generichash/blake2/sse/blake2b-round.h +++ b/src/libsodium/crypto_generichash/blake2/ref/blake2b-round.h @@ -11,8 +11,12 @@ this software. If not, see . */ -#ifndef __BLAKE2B_ROUND_H__ -#define __BLAKE2B_ROUND_H__ +#ifndef blake2b_round_H +#define blake2b_round_H + +#ifndef BLAKE2_USE_SSSE2 +# error BLAKE2_USE_SSSE2 must be defined in order to use this file +#endif #define LOADU(p) _mm_loadu_si128( (const __m128i *)(p) ) #define STOREU(p,r) _mm_storeu_si128((__m128i *)(p), r) diff --git a/src/libsodium/crypto_generichash/blake2/sse/blake2-config.h b/src/libsodium/crypto_generichash/blake2/sse/blake2-config.h deleted file mode 100644 index 70d61f10..00000000 --- a/src/libsodium/crypto_generichash/blake2/sse/blake2-config.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - BLAKE2 reference source code package - optimized C implementations - - Written in 2012 by Samuel Neves - - 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 . -*/ -#pragma once -#ifndef __BLAKE2_CONFIG_H__ -#define __BLAKE2_CONFIG_H__ - -// These don't work everywhere -#if defined(__SSE2__) -#define HAVE_SSE2 -#endif - -#if defined(__SSSE3__) -#define HAVE_SSSE3 -#endif - -#if defined(__SSE4_1__) -#define HAVE_SSE41 -#endif - -#if defined(__AVX__) -#define HAVE_AVX -#endif - -#if defined(__XOP__) -#define HAVE_XOP -#endif - - -#ifdef HAVE_AVX2 -#ifndef HAVE_AVX -#define HAVE_AVX -#endif -#endif - -#ifdef HAVE_XOP -#ifndef HAVE_AVX -#define HAVE_AVX -#endif -#endif - -#ifdef HAVE_AVX -#ifndef HAVE_SSE41 -#define HAVE_SSE41 -#endif -#endif - -#ifdef HAVE_SSE41 -#ifndef HAVE_SSSE3 -#define HAVE_SSSE3 -#endif -#endif - -#ifdef HAVE_SSSE3 -#define HAVE_SSE2 -#endif - -#if !defined(HAVE_SSE2) -#error "This code requires at least SSE2." -#endif - -#endif - diff --git a/src/libsodium/crypto_generichash/blake2/sse/blake2-impl.h b/src/libsodium/crypto_generichash/blake2/sse/blake2-impl.h deleted file mode 100644 index b14728df..00000000 --- a/src/libsodium/crypto_generichash/blake2/sse/blake2-impl.h +++ /dev/null @@ -1,137 +0,0 @@ -/* - BLAKE2 reference source code package - reference C implementations - - Written in 2012 by Samuel Neves - - 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 . -*/ - -#ifndef blake2_impl_H -#define blake2_impl_H - -#include -#include - -#include "utils.h" - -static inline uint32_t load32( const void *src ) -{ -#ifdef NATIVE_LITTLE_ENDIAN - uint32_t w; - memcpy(&w, src, sizeof w); - return w; -#else - const uint8_t *p = ( const uint8_t * )src; - uint32_t w = *p++; - w |= ( uint32_t )( *p++ ) << 8; - w |= ( uint32_t )( *p++ ) << 16; - w |= ( uint32_t )( *p++ ) << 24; - return w; -#endif -} - -static inline uint64_t load64( const void *src ) -{ -#ifdef NATIVE_LITTLE_ENDIAN - uint64_t w; - memcpy(&w, src, sizeof w); - return w; -#else - const uint8_t *p = ( const uint8_t * )src; - uint64_t w = *p++; - w |= ( uint64_t )( *p++ ) << 8; - w |= ( uint64_t )( *p++ ) << 16; - w |= ( uint64_t )( *p++ ) << 24; - w |= ( uint64_t )( *p++ ) << 32; - w |= ( uint64_t )( *p++ ) << 40; - w |= ( uint64_t )( *p++ ) << 48; - w |= ( uint64_t )( *p++ ) << 56; - return w; -#endif -} - -static inline void store32( void *dst, uint32_t w ) -{ -#ifdef NATIVE_LITTLE_ENDIAN - memcpy(dst, &w, sizeof w); -#else - uint8_t *p = ( uint8_t * )dst; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; -#endif -} - -static inline void store64( void *dst, uint64_t w ) -{ -#ifdef NATIVE_LITTLE_ENDIAN - memcpy(dst, &w, sizeof w); -#else - uint8_t *p = ( uint8_t * )dst; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; -#endif -} - -static inline uint64_t load48( const void *src ) -{ - const uint8_t *p = ( const uint8_t * )src; - uint64_t w = *p++; - w |= ( uint64_t )( *p++ ) << 8; - w |= ( uint64_t )( *p++ ) << 16; - w |= ( uint64_t )( *p++ ) << 24; - w |= ( uint64_t )( *p++ ) << 32; - w |= ( uint64_t )( *p++ ) << 40; - return w; -} - -static inline void store48( void *dst, uint64_t w ) -{ - uint8_t *p = ( uint8_t * )dst; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; w >>= 8; - *p++ = ( uint8_t )w; -} - -static inline uint32_t rotl32( const uint32_t w, const unsigned c ) -{ - return ( w << c ) | ( w >> ( 32 - c ) ); -} - -static inline uint64_t rotl64( const uint64_t w, const unsigned c ) -{ - return ( w << c ) | ( w >> ( 64 - c ) ); -} - -static inline uint32_t rotr32( const uint32_t w, const unsigned c ) -{ - return ( w >> c ) | ( w << ( 32 - c ) ); -} - -static inline uint64_t rotr64( const uint64_t w, const unsigned c ) -{ - return ( w >> c ) | ( w << ( 64 - c ) ); -} - -/* prevents compiler optimizing out memset() */ -static inline void secure_zero_memory( void *v, size_t n ) -{ - sodium_memzero(v, n); -} - -#endif diff --git a/src/libsodium/crypto_generichash/blake2/sse/blake2.h b/src/libsodium/crypto_generichash/blake2/sse/blake2.h deleted file mode 100644 index 20bc22da..00000000 --- a/src/libsodium/crypto_generichash/blake2/sse/blake2.h +++ /dev/null @@ -1,150 +0,0 @@ -/* - BLAKE2 reference source code package - optimized C implementations - - Written in 2012 by Samuel Neves - - 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 . -*/ -#pragma once -#ifndef __BLAKE2_H__ -#define __BLAKE2_H__ - -#include -#include - -#if defined(__cplusplus) -extern "C" { -#endif - - enum blake2s_constant - { - BLAKE2S_BLOCKBYTES = 64, - BLAKE2S_OUTBYTES = 32, - BLAKE2S_KEYBYTES = 32, - BLAKE2S_SALTBYTES = 8, - BLAKE2S_PERSONALBYTES = 8 - }; - - enum blake2b_constant - { - BLAKE2B_BLOCKBYTES = 128, - BLAKE2B_OUTBYTES = 64, - BLAKE2B_KEYBYTES = 64, - BLAKE2B_SALTBYTES = 16, - BLAKE2B_PERSONALBYTES = 16 - }; - -#pragma pack(push, 1) - typedef 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_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_state - { - uint32_t h[8]; - uint32_t t[2]; - uint32_t f[2]; - uint8_t buf[2 * BLAKE2S_BLOCKBYTES]; - size_t buflen; - uint8_t last_node; - } blake2s_state; - - typedef struct __blake2b_param - { - uint8_t digest_length; // 1 - uint8_t key_length; // 2 - uint8_t fanout; // 3 - uint8_t depth; // 4 - uint32_t leaf_length; // 8 - uint64_t node_offset; // 16 - uint8_t node_depth; // 17 - uint8_t inner_length; // 18 - uint8_t reserved[14]; // 32 - uint8_t salt[BLAKE2B_SALTBYTES]; // 48 - uint8_t personal[BLAKE2B_PERSONALBYTES]; // 64 - } blake2b_param; - - typedef struct __blake2b_state - { - uint64_t h[8]; - uint64_t t[2]; - uint64_t f[2]; - uint8_t buf[2 * BLAKE2B_BLOCKBYTES]; - size_t buflen; - uint8_t last_node; - } blake2b_state; - - typedef struct __blake2sp_state - { - blake2s_state S[8][1]; - blake2s_state R[1]; - uint8_t buf[8 * BLAKE2S_BLOCKBYTES]; - size_t buflen; - } blake2sp_state; - - typedef struct __blake2bp_state - { - blake2b_state S[4][1]; - blake2b_state R[1]; - uint8_t buf[4 * BLAKE2B_BLOCKBYTES]; - size_t buflen; - } blake2bp_state; -#pragma pack(pop) - - // 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_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 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_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 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 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 ); - - // 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 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 ); - - static inline 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 ); - } - -#if defined(__cplusplus) -} -#endif - -#endif -