diff --git a/crypto/blake2.h b/crypto/blake2.h index ad62f260..e51d8696 100644 --- a/crypto/blake2.h +++ b/crypto/blake2.h @@ -188,6 +188,8 @@ extern "C" { /* This is simply an alias for blake2b */ int blake2( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ); + void blake2_init_accel(void); + #if defined(__cplusplus) } #endif diff --git a/crypto/blake2b-ref.c b/crypto/blake2b-ref.c index 19589451..b39cd59d 100644 --- a/crypto/blake2b-ref.c +++ b/crypto/blake2b-ref.c @@ -224,21 +224,25 @@ void blake2b_compress_sse2( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKB void blake2b_compress_sse41( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] ); void blake2b_compress_avx2( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] ); -static void blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] ) +static void (*blake2b_compress)( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] ) = blake2b_compress_ref; + +void blake2_init_accel(void) { + if (0); #if HAVE_AVX2 - if (cpu_has_feature(CPU_FLAG_AVX2)) - return blake2b_compress_avx2(S, block); + else if (cpu_has_feature(CPU_FLAG_AVX2)) + blake2b_compress = blake2b_compress_avx2; #endif #if HAVE_SSE41 - if (cpu_has_feature(CPU_FLAG_SSE41)) - return blake2b_compress_sse41(S, block); + else if (cpu_has_feature(CPU_FLAG_SSE41)) + blake2b_compress = blake2b_compress_sse41; #endif #if HAVE_SSE2 - if (cpu_has_feature(CPU_FLAG_SSE2)) - return blake2b_compress_sse2(S, block); + else if (cpu_has_feature(CPU_FLAG_SSE2)) + blake2b_compress = blake2b_compress_sse2; #endif - return blake2b_compress_ref(S, block); + else + blake2b_compress = blake2b_compress_ref; } int blake2b_update( blake2b_state *S, const void *pin, size_t inlen ) diff --git a/crypto/hash.c b/crypto/hash.c index 4ee65385..0ccdab75 100644 --- a/crypto/hash.c +++ b/crypto/hash.c @@ -23,6 +23,12 @@ void hash_init_accel(void) { crc32c_optimization_init(); + blake2_init_accel(); +} + +void hash_init_blake2(void) +{ + blake2_init_accel(); } /* diff --git a/crypto/hash.h b/crypto/hash.h index 40a579ce..e1e073c3 100644 --- a/crypto/hash.h +++ b/crypto/hash.h @@ -27,5 +27,6 @@ int hash_sha256(const u8 *buf, size_t length, u8 *out); int hash_blake2b(const u8 *buf, size_t length, u8 *out); void hash_init_accel(void); +void hash_init_blake2(void); #endif