Add AVX2-optimized Argon2 blamka function
This commit is contained in:
parent
b1d847d6dd
commit
935557cdf7
@ -117,6 +117,7 @@
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\crypto_pwhash.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-core.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-encoding.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-fill-block-avx2.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-fill-block-ref.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-fill-block-ssse3.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2.c" />
|
||||
@ -202,6 +203,7 @@
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-encoding.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blake2b-long.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blamka-round-avx2.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blamka-round-ref.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blamka-round-ssse3.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\scryptsalsa208sha256\crypto_scrypt.h" />
|
||||
|
@ -141,6 +141,9 @@
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-encoding.c">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-fill-block-avx2.c">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-fill-block-ref.c">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClCompile>
|
||||
@ -392,6 +395,9 @@
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blake2b-long.h">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blamka-round-avx2.h">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blamka-round-ref.h">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClInclude>
|
||||
|
@ -117,6 +117,7 @@
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\crypto_pwhash.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-core.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-encoding.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-fill-block-avx2.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-fill-block-ref.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-fill-block-ssse3.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2.c" />
|
||||
@ -202,6 +203,7 @@
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-encoding.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blake2b-long.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blamka-round-avx2.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blamka-round-ref.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blamka-round-ssse3.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\scryptsalsa208sha256\crypto_scrypt.h" />
|
||||
|
@ -141,6 +141,9 @@
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-encoding.c">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-fill-block-avx2.c">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-fill-block-ref.c">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClCompile>
|
||||
@ -392,6 +395,9 @@
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blake2b-long.h">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blamka-round-avx2.h">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blamka-round-ref.h">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClInclude>
|
||||
|
@ -117,6 +117,7 @@
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\crypto_pwhash.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-core.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-encoding.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-fill-block-avx2.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-fill-block-ref.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-fill-block-ssse3.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2.c" />
|
||||
@ -202,6 +203,7 @@
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-encoding.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blake2b-long.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blamka-round-avx2.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blamka-round-ref.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blamka-round-ssse3.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\scryptsalsa208sha256\crypto_scrypt.h" />
|
||||
|
@ -141,6 +141,9 @@
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-encoding.c">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-fill-block-avx2.c">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-fill-block-ref.c">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClCompile>
|
||||
@ -392,6 +395,9 @@
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blake2b-long.h">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blamka-round-avx2.h">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blamka-round-ref.h">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClInclude>
|
||||
|
@ -117,6 +117,7 @@
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\crypto_pwhash.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-core.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-encoding.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-fill-block-avx2.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-fill-block-ref.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-fill-block-ssse3.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2.c" />
|
||||
@ -202,6 +203,7 @@
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-encoding.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blake2b-long.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blamka-round-avx2.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blamka-round-ref.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blamka-round-ssse3.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\scryptsalsa208sha256\crypto_scrypt.h" />
|
||||
|
@ -141,6 +141,9 @@
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-encoding.c">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-fill-block-avx2.c">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-fill-block-ref.c">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClCompile>
|
||||
@ -392,6 +395,9 @@
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blake2b-long.h">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blamka-round-avx2.h">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blamka-round-ref.h">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClInclude>
|
||||
|
@ -117,6 +117,7 @@
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\crypto_pwhash.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-core.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-encoding.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-fill-block-avx2.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-fill-block-ref.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-fill-block-ssse3.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2.c" />
|
||||
@ -202,6 +203,7 @@
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-encoding.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blake2b-long.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blamka-round-avx2.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blamka-round-ref.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blamka-round-ssse3.h" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\scryptsalsa208sha256\crypto_scrypt.h" />
|
||||
|
@ -141,6 +141,9 @@
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-encoding.c">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-fill-block-avx2.c">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\argon2-fill-block-ref.c">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClCompile>
|
||||
@ -392,6 +395,9 @@
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blake2b-long.h">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blamka-round-avx2.h">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_pwhash\argon2\blamka-round-ref.h">
|
||||
<Filter>crypto_pwhash\argon2</Filter>
|
||||
</ClInclude>
|
||||
|
@ -355,6 +355,7 @@
|
||||
<ClCompile Include="src\libsodium\crypto_pwhash\crypto_pwhash.c" />
|
||||
<ClCompile Include="src\libsodium\crypto_pwhash\argon2\argon2-core.c" />
|
||||
<ClCompile Include="src\libsodium\crypto_pwhash\argon2\argon2-encoding.c" />
|
||||
<ClCompile Include="src\libsodium\crypto_pwhash\argon2\argon2-fill-block-avx2.c" />
|
||||
<ClCompile Include="src\libsodium\crypto_pwhash\argon2\argon2-fill-block-ref.c" />
|
||||
<ClCompile Include="src\libsodium\crypto_pwhash\argon2\argon2-fill-block-ssse3.c" />
|
||||
<ClCompile Include="src\libsodium\crypto_pwhash\argon2\argon2.c" />
|
||||
@ -440,6 +441,7 @@
|
||||
<ClInclude Include="src\libsodium\crypto_pwhash\argon2\argon2-encoding.h" />
|
||||
<ClInclude Include="src\libsodium\crypto_pwhash\argon2\argon2.h" />
|
||||
<ClInclude Include="src\libsodium\crypto_pwhash\argon2\blake2b-long.h" />
|
||||
<ClInclude Include="src\libsodium\crypto_pwhash\argon2\blamka-round-avx2.h" />
|
||||
<ClInclude Include="src\libsodium\crypto_pwhash\argon2\blamka-round-ref.h" />
|
||||
<ClInclude Include="src\libsodium\crypto_pwhash\argon2\blamka-round-ssse3.h" />
|
||||
<ClInclude Include="src\libsodium\crypto_pwhash\scryptsalsa208sha256\crypto_scrypt.h" />
|
||||
|
@ -135,6 +135,9 @@
|
||||
<ClCompile Include="src\libsodium\crypto_pwhash\argon2\argon2-encoding.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\libsodium\crypto_pwhash\argon2\argon2-fill-block-avx2.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\libsodium\crypto_pwhash\argon2\argon2-fill-block-ref.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
@ -386,6 +389,9 @@
|
||||
<ClInclude Include="src\libsodium\crypto_pwhash\argon2\blake2b-long.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\libsodium\crypto_pwhash\argon2\blamka-round-avx2.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\libsodium\crypto_pwhash\argon2\blamka-round-ref.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
@ -256,6 +256,8 @@ libavx2_la_CPPFLAGS = $(libsodium_la_CPPFLAGS) \
|
||||
libavx2_la_SOURCES = \
|
||||
crypto_generichash/blake2b/ref/blake2b-compress-avx2.c \
|
||||
crypto_generichash/blake2b/ref/blake2b-compress-avx2.h \
|
||||
crypto_pwhash/argon2/argon2-fill-block-avx2.c \
|
||||
crypto_pwhash/argon2/blamka-round-avx2.h \
|
||||
crypto_stream/chacha20/dolbeau/chacha20_dolbeau-avx2.c \
|
||||
crypto_stream/chacha20/dolbeau/chacha20_dolbeau-avx2.h \
|
||||
crypto_stream/chacha20/dolbeau/u8.h \
|
||||
|
@ -591,6 +591,13 @@ int
|
||||
argon2_pick_best_implementation(void)
|
||||
{
|
||||
/* LCOV_EXCL_START */
|
||||
#if defined(HAVE_AVX2INTRIN_H) && defined(HAVE_TMMINTRIN_H) && \
|
||||
defined(HAVE_SMMINTRIN_H)
|
||||
if (sodium_runtime_has_avx2()) {
|
||||
fill_segment = fill_segment_avx2;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#if defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H)
|
||||
if (sodium_runtime_has_ssse3()) {
|
||||
fill_segment = fill_segment_ssse3;
|
||||
|
@ -27,6 +27,7 @@ enum argon2_ctx_constants {
|
||||
ARGON2_BLOCK_SIZE = 1024,
|
||||
ARGON2_QWORDS_IN_BLOCK = ARGON2_BLOCK_SIZE / 8,
|
||||
ARGON2_OWORDS_IN_BLOCK = ARGON2_BLOCK_SIZE / 16,
|
||||
ARGON2_HWORDS_IN_BLOCK = ARGON2_BLOCK_SIZE / 32,
|
||||
|
||||
/* Number of pseudo-random values generated by one call to Blake in Argon2i
|
||||
to
|
||||
@ -184,6 +185,8 @@ void finalize(const argon2_context *context, argon2_instance_t *instance);
|
||||
typedef int (*fill_segment_fn)(const argon2_instance_t *instance,
|
||||
argon2_position_t position);
|
||||
int argon2_pick_best_implementation(void);
|
||||
int fill_segment_avx2(const argon2_instance_t *instance,
|
||||
argon2_position_t position);
|
||||
int fill_segment_ssse3(const argon2_instance_t *instance,
|
||||
argon2_position_t position);
|
||||
int fill_segment_ref(const argon2_instance_t *instance,
|
||||
|
241
src/libsodium/crypto_pwhash/argon2/argon2-fill-block-avx2.c
Normal file
241
src/libsodium/crypto_pwhash/argon2/argon2-fill-block-avx2.c
Normal file
@ -0,0 +1,241 @@
|
||||
/*
|
||||
* Argon2 source code package
|
||||
*
|
||||
* Written by Daniel Dinu and Dmitry Khovratovich, 2015
|
||||
*
|
||||
* This work is licensed under a Creative Commons CC0 1.0 License/Waiver.
|
||||
*
|
||||
* 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>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "argon2-core.h"
|
||||
#include "argon2.h"
|
||||
#include "private/common.h"
|
||||
#include "private/sse2_64_32.h"
|
||||
|
||||
#if defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H)
|
||||
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC target("sse2")
|
||||
# pragma GCC target("ssse3")
|
||||
# pragma GCC target("sse4.1")
|
||||
# pragma GCC target("avx2")
|
||||
# endif
|
||||
|
||||
# ifdef _MSC_VER
|
||||
# include <intrin.h> /* for _mm_set_epi64x */
|
||||
# endif
|
||||
#include <emmintrin.h>
|
||||
#include <immintrin.h>
|
||||
#include <smmintrin.h>
|
||||
#include <tmmintrin.h>
|
||||
|
||||
# include "blamka-round-avx2.h"
|
||||
|
||||
static void
|
||||
fill_block(__m256i *state, const uint8_t *ref_block, uint8_t *next_block)
|
||||
{
|
||||
__m256i block_XY[ARGON2_HWORDS_IN_BLOCK];
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < ARGON2_HWORDS_IN_BLOCK; i++) {
|
||||
block_XY[i] = state[i] = _mm256_xor_si256(
|
||||
state[i], _mm256_loadu_si256((__m256i const *) (&ref_block[32 * i])));
|
||||
}
|
||||
|
||||
for (i = 0; i < 4; ++i) {
|
||||
BLAKE2_ROUND_1(state[8 * i + 0], state[8 * i + 4], state[8 * i + 1], state[8 * i + 5],
|
||||
state[8 * i + 2], state[8 * i + 6], state[8 * i + 3], state[8 * i + 7]);
|
||||
}
|
||||
|
||||
for (i = 0; i < 4; ++i) {
|
||||
BLAKE2_ROUND_2(state[ 0 + i], state[ 4 + i], state[ 8 + i], state[12 + i],
|
||||
state[16 + i], state[20 + i], state[24 + i], state[28 + i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < ARGON2_HWORDS_IN_BLOCK; i++) {
|
||||
state[i] = _mm256_xor_si256(state[i], block_XY[i]);
|
||||
_mm256_storeu_si256((__m256i *) (&next_block[32 * i]), state[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
fill_block_with_xor(__m256i *state, const uint8_t *ref_block,
|
||||
uint8_t *next_block)
|
||||
{
|
||||
__m256i block_XY[ARGON2_HWORDS_IN_BLOCK];
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < ARGON2_HWORDS_IN_BLOCK; i++) {
|
||||
state[i] = _mm256_xor_si256(
|
||||
state[i], _mm256_loadu_si256((__m256i const *) (&ref_block[32 * i])));
|
||||
block_XY[i] = _mm256_xor_si256(
|
||||
state[i], _mm256_loadu_si256((__m256i const *) (&next_block[32 * i])));
|
||||
}
|
||||
|
||||
for (i = 0; i < 4; ++i) {
|
||||
BLAKE2_ROUND_1(state[8 * i + 0], state[8 * i + 4], state[8 * i + 1], state[8 * i + 5],
|
||||
state[8 * i + 2], state[8 * i + 6], state[8 * i + 3], state[8 * i + 7]);
|
||||
}
|
||||
|
||||
for (i = 0; i < 4; ++i) {
|
||||
BLAKE2_ROUND_2(state[ 0 + i], state[ 4 + i], state[ 8 + i], state[12 + i],
|
||||
state[16 + i], state[20 + i], state[24 + i], state[28 + i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < ARGON2_HWORDS_IN_BLOCK; i++) {
|
||||
state[i] = _mm256_xor_si256(state[i], block_XY[i]);
|
||||
_mm256_storeu_si256((__m256i *) (&next_block[32 * i]), state[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
generate_addresses(const argon2_instance_t *instance,
|
||||
const argon2_position_t *position, uint64_t *pseudo_rands)
|
||||
{
|
||||
block address_block, input_block, tmp_block;
|
||||
uint32_t i;
|
||||
|
||||
init_block_value(&address_block, 0);
|
||||
init_block_value(&input_block, 0);
|
||||
|
||||
if (instance != NULL && position != NULL) {
|
||||
input_block.v[0] = position->pass;
|
||||
input_block.v[1] = position->lane;
|
||||
input_block.v[2] = position->slice;
|
||||
input_block.v[3] = instance->memory_blocks;
|
||||
input_block.v[4] = instance->passes;
|
||||
input_block.v[5] = instance->type;
|
||||
|
||||
for (i = 0; i < instance->segment_length; ++i) {
|
||||
if (i % ARGON2_ADDRESSES_IN_BLOCK == 0) {
|
||||
/* Temporary zero-initialized blocks */
|
||||
__m256i zero_block[ARGON2_HWORDS_IN_BLOCK];
|
||||
__m256i zero2_block[ARGON2_HWORDS_IN_BLOCK];
|
||||
|
||||
memset(zero_block, 0, sizeof(zero_block));
|
||||
memset(zero2_block, 0, sizeof(zero2_block));
|
||||
init_block_value(&address_block, 0);
|
||||
init_block_value(&tmp_block, 0);
|
||||
/* Increasing index counter */
|
||||
input_block.v[6]++;
|
||||
/* First iteration of G */
|
||||
fill_block_with_xor(zero_block, (uint8_t *) &input_block.v,
|
||||
(uint8_t *) &tmp_block.v);
|
||||
/* Second iteration of G */
|
||||
fill_block_with_xor(zero2_block, (uint8_t *) &tmp_block.v,
|
||||
(uint8_t *) &address_block.v);
|
||||
}
|
||||
|
||||
pseudo_rands[i] = address_block.v[i % ARGON2_ADDRESSES_IN_BLOCK];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
fill_segment_avx2(const argon2_instance_t *instance,
|
||||
argon2_position_t position)
|
||||
{
|
||||
block *ref_block = NULL, *curr_block = NULL;
|
||||
uint64_t pseudo_rand, ref_index, ref_lane;
|
||||
uint32_t prev_offset, curr_offset;
|
||||
uint32_t starting_index, i;
|
||||
__m256i state[32];
|
||||
const int data_independent_addressing = 1; /* instance->type == Argon2_i */
|
||||
|
||||
/* Pseudo-random values that determine the reference block position */
|
||||
uint64_t *pseudo_rands = NULL;
|
||||
|
||||
if (instance == NULL) {
|
||||
return ARGON2_OK;
|
||||
}
|
||||
|
||||
pseudo_rands =
|
||||
(uint64_t *) malloc(sizeof(uint64_t) * instance->segment_length);
|
||||
if (pseudo_rands == NULL) {
|
||||
return ARGON2_MEMORY_ALLOCATION_ERROR;
|
||||
}
|
||||
|
||||
if (data_independent_addressing) {
|
||||
generate_addresses(instance, &position, pseudo_rands);
|
||||
}
|
||||
|
||||
starting_index = 0;
|
||||
|
||||
if ((0 == position.pass) && (0 == position.slice)) {
|
||||
starting_index = 2; /* we have already generated the first two blocks */
|
||||
}
|
||||
|
||||
/* Offset of the current block */
|
||||
curr_offset = position.lane * instance->lane_length +
|
||||
position.slice * instance->segment_length + starting_index;
|
||||
|
||||
if (0 == curr_offset % instance->lane_length) {
|
||||
/* Last block in this lane */
|
||||
prev_offset = curr_offset + instance->lane_length - 1;
|
||||
} else {
|
||||
/* Previous block */
|
||||
prev_offset = curr_offset - 1;
|
||||
}
|
||||
|
||||
memcpy(state, ((instance->region->memory + prev_offset)->v),
|
||||
ARGON2_BLOCK_SIZE);
|
||||
|
||||
for (i = starting_index; i < instance->segment_length;
|
||||
++i, ++curr_offset, ++prev_offset) {
|
||||
/*1.1 Rotating prev_offset if needed */
|
||||
if (curr_offset % instance->lane_length == 1) {
|
||||
prev_offset = curr_offset - 1;
|
||||
}
|
||||
|
||||
/* 1.2 Computing the index of the reference block */
|
||||
/* 1.2.1 Taking pseudo-random value from the previous block */
|
||||
if (data_independent_addressing) {
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 6385)
|
||||
pseudo_rand = pseudo_rands[i];
|
||||
#pragma warning(pop)
|
||||
} else {
|
||||
pseudo_rand = instance->region->memory[prev_offset].v[0];
|
||||
}
|
||||
|
||||
/* 1.2.2 Computing the lane of the reference block */
|
||||
ref_lane = ((pseudo_rand >> 32)) % instance->lanes;
|
||||
|
||||
if ((position.pass == 0) && (position.slice == 0)) {
|
||||
/* Can not reference other lanes yet */
|
||||
ref_lane = position.lane;
|
||||
}
|
||||
|
||||
/* 1.2.3 Computing the number of possible reference block within the
|
||||
* lane.
|
||||
*/
|
||||
position.index = i;
|
||||
ref_index = index_alpha(instance, &position, pseudo_rand & 0xFFFFFFFF,
|
||||
ref_lane == position.lane);
|
||||
|
||||
/* 2 Creating a new block */
|
||||
ref_block = instance->region->memory +
|
||||
instance->lane_length * ref_lane + ref_index;
|
||||
curr_block = instance->region->memory + curr_offset;
|
||||
if (position.pass != 0) {
|
||||
fill_block_with_xor(state, (uint8_t *) ref_block->v,
|
||||
(uint8_t *) curr_block->v);
|
||||
} else {
|
||||
fill_block(state, (uint8_t *) ref_block->v,
|
||||
(uint8_t *) curr_block->v);
|
||||
}
|
||||
}
|
||||
|
||||
free(pseudo_rands);
|
||||
|
||||
return ARGON2_OK;
|
||||
}
|
||||
#endif
|
150
src/libsodium/crypto_pwhash/argon2/blamka-round-avx2.h
Normal file
150
src/libsodium/crypto_pwhash/argon2/blamka-round-avx2.h
Normal file
@ -0,0 +1,150 @@
|
||||
#ifndef blamka_round_avx2_H
|
||||
#define blamka_round_avx2_H
|
||||
|
||||
#include "private/common.h"
|
||||
#include "private/sse2_64_32.h"
|
||||
|
||||
#define rotr32(x) _mm256_shuffle_epi32(x, _MM_SHUFFLE(2, 3, 0, 1))
|
||||
#define rotr24(x) _mm256_shuffle_epi8(x, _mm256_setr_epi8(3, 4, 5, 6, 7, 0, 1, 2, 11, 12, 13, 14, 15, 8, 9, 10, 3, 4, 5, 6, 7, 0, 1, 2, 11, 12, 13, 14, 15, 8, 9, 10))
|
||||
#define rotr16(x) _mm256_shuffle_epi8(x, _mm256_setr_epi8(2, 3, 4, 5, 6, 7, 0, 1, 10, 11, 12, 13, 14, 15, 8, 9, 2, 3, 4, 5, 6, 7, 0, 1, 10, 11, 12, 13, 14, 15, 8, 9))
|
||||
#define rotr63(x) _mm256_xor_si256(_mm256_srli_epi64((x), 63), _mm256_add_epi64((x), (x)))
|
||||
|
||||
#define G1_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \
|
||||
do { \
|
||||
__m256i ml = _mm256_mul_epu32(A0, B0); \
|
||||
ml = _mm256_add_epi64(ml, ml); \
|
||||
A0 = _mm256_add_epi64(A0, _mm256_add_epi64(B0, ml)); \
|
||||
D0 = _mm256_xor_si256(D0, A0); \
|
||||
D0 = rotr32(D0); \
|
||||
\
|
||||
ml = _mm256_mul_epu32(C0, D0); \
|
||||
ml = _mm256_add_epi64(ml, ml); \
|
||||
C0 = _mm256_add_epi64(C0, _mm256_add_epi64(D0, ml)); \
|
||||
\
|
||||
B0 = _mm256_xor_si256(B0, C0); \
|
||||
B0 = rotr24(B0); \
|
||||
\
|
||||
ml = _mm256_mul_epu32(A1, B1); \
|
||||
ml = _mm256_add_epi64(ml, ml); \
|
||||
A1 = _mm256_add_epi64(A1, _mm256_add_epi64(B1, ml)); \
|
||||
D1 = _mm256_xor_si256(D1, A1); \
|
||||
D1 = rotr32(D1); \
|
||||
\
|
||||
ml = _mm256_mul_epu32(C1, D1); \
|
||||
ml = _mm256_add_epi64(ml, ml); \
|
||||
C1 = _mm256_add_epi64(C1, _mm256_add_epi64(D1, ml)); \
|
||||
\
|
||||
B1 = _mm256_xor_si256(B1, C1); \
|
||||
B1 = rotr24(B1); \
|
||||
} while((void)0, 0);
|
||||
|
||||
#define G2_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \
|
||||
do { \
|
||||
__m256i ml = _mm256_mul_epu32(A0, B0); \
|
||||
ml = _mm256_add_epi64(ml, ml); \
|
||||
A0 = _mm256_add_epi64(A0, _mm256_add_epi64(B0, ml)); \
|
||||
D0 = _mm256_xor_si256(D0, A0); \
|
||||
D0 = rotr16(D0); \
|
||||
\
|
||||
ml = _mm256_mul_epu32(C0, D0); \
|
||||
ml = _mm256_add_epi64(ml, ml); \
|
||||
C0 = _mm256_add_epi64(C0, _mm256_add_epi64(D0, ml)); \
|
||||
B0 = _mm256_xor_si256(B0, C0); \
|
||||
B0 = rotr63(B0); \
|
||||
\
|
||||
ml = _mm256_mul_epu32(A1, B1); \
|
||||
ml = _mm256_add_epi64(ml, ml); \
|
||||
A1 = _mm256_add_epi64(A1, _mm256_add_epi64(B1, ml)); \
|
||||
D1 = _mm256_xor_si256(D1, A1); \
|
||||
D1 = rotr16(D1); \
|
||||
\
|
||||
ml = _mm256_mul_epu32(C1, D1); \
|
||||
ml = _mm256_add_epi64(ml, ml); \
|
||||
C1 = _mm256_add_epi64(C1, _mm256_add_epi64(D1, ml)); \
|
||||
B1 = _mm256_xor_si256(B1, C1); \
|
||||
B1 = rotr63(B1); \
|
||||
} while((void)0, 0);
|
||||
|
||||
#define DIAGONALIZE_1(A0, B0, C0, D0, A1, B1, C1, D1) \
|
||||
do { \
|
||||
B0 = _mm256_permute4x64_epi64(B0, _MM_SHUFFLE(0, 3, 2, 1)); \
|
||||
C0 = _mm256_permute4x64_epi64(C0, _MM_SHUFFLE(1, 0, 3, 2)); \
|
||||
D0 = _mm256_permute4x64_epi64(D0, _MM_SHUFFLE(2, 1, 0, 3)); \
|
||||
\
|
||||
B1 = _mm256_permute4x64_epi64(B1, _MM_SHUFFLE(0, 3, 2, 1)); \
|
||||
C1 = _mm256_permute4x64_epi64(C1, _MM_SHUFFLE(1, 0, 3, 2)); \
|
||||
D1 = _mm256_permute4x64_epi64(D1, _MM_SHUFFLE(2, 1, 0, 3)); \
|
||||
} while((void)0, 0);
|
||||
|
||||
#define DIAGONALIZE_2(A0, A1, B0, B1, C0, C1, D0, D1) \
|
||||
do { \
|
||||
__m256i tmp1 = _mm256_blend_epi32(B0, B1, 0xCC); \
|
||||
__m256i tmp2 = _mm256_blend_epi32(B0, B1, 0x33); \
|
||||
B1 = _mm256_permute4x64_epi64(tmp1, _MM_SHUFFLE(2,3,0,1)); \
|
||||
B0 = _mm256_permute4x64_epi64(tmp2, _MM_SHUFFLE(2,3,0,1)); \
|
||||
\
|
||||
tmp1 = C0; \
|
||||
C0 = C1; \
|
||||
C1 = tmp1; \
|
||||
\
|
||||
tmp1 = _mm256_blend_epi32(D0, D1, 0xCC); \
|
||||
tmp2 = _mm256_blend_epi32(D0, D1, 0x33); \
|
||||
D0 = _mm256_permute4x64_epi64(tmp1, _MM_SHUFFLE(2,3,0,1)); \
|
||||
D1 = _mm256_permute4x64_epi64(tmp2, _MM_SHUFFLE(2,3,0,1)); \
|
||||
} while(0);
|
||||
|
||||
#define UNDIAGONALIZE_1(A0, B0, C0, D0, A1, B1, C1, D1) \
|
||||
do { \
|
||||
B0 = _mm256_permute4x64_epi64(B0, _MM_SHUFFLE(2, 1, 0, 3)); \
|
||||
C0 = _mm256_permute4x64_epi64(C0, _MM_SHUFFLE(1, 0, 3, 2)); \
|
||||
D0 = _mm256_permute4x64_epi64(D0, _MM_SHUFFLE(0, 3, 2, 1)); \
|
||||
\
|
||||
B1 = _mm256_permute4x64_epi64(B1, _MM_SHUFFLE(2, 1, 0, 3)); \
|
||||
C1 = _mm256_permute4x64_epi64(C1, _MM_SHUFFLE(1, 0, 3, 2)); \
|
||||
D1 = _mm256_permute4x64_epi64(D1, _MM_SHUFFLE(0, 3, 2, 1)); \
|
||||
} while((void)0, 0);
|
||||
|
||||
#define UNDIAGONALIZE_2(A0, A1, B0, B1, C0, C1, D0, D1) \
|
||||
do { \
|
||||
__m256i tmp1 = _mm256_blend_epi32(B0, B1, 0xCC); \
|
||||
__m256i tmp2 = _mm256_blend_epi32(B0, B1, 0x33); \
|
||||
B0 = _mm256_permute4x64_epi64(tmp1, _MM_SHUFFLE(2,3,0,1)); \
|
||||
B1 = _mm256_permute4x64_epi64(tmp2, _MM_SHUFFLE(2,3,0,1)); \
|
||||
\
|
||||
tmp1 = C0; \
|
||||
C0 = C1; \
|
||||
C1 = tmp1; \
|
||||
\
|
||||
tmp1 = _mm256_blend_epi32(D0, D1, 0x33); \
|
||||
tmp2 = _mm256_blend_epi32(D0, D1, 0xCC); \
|
||||
D0 = _mm256_permute4x64_epi64(tmp1, _MM_SHUFFLE(2,3,0,1)); \
|
||||
D1 = _mm256_permute4x64_epi64(tmp2, _MM_SHUFFLE(2,3,0,1)); \
|
||||
} while((void)0, 0);
|
||||
|
||||
#define BLAKE2_ROUND_1(A0, A1, B0, B1, C0, C1, D0, D1) \
|
||||
do{ \
|
||||
G1_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \
|
||||
G2_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \
|
||||
\
|
||||
DIAGONALIZE_1(A0, B0, C0, D0, A1, B1, C1, D1) \
|
||||
\
|
||||
G1_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \
|
||||
G2_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \
|
||||
\
|
||||
UNDIAGONALIZE_1(A0, B0, C0, D0, A1, B1, C1, D1) \
|
||||
} while((void)0, 0);
|
||||
|
||||
#define BLAKE2_ROUND_2(A0, A1, B0, B1, C0, C1, D0, D1) \
|
||||
do{ \
|
||||
G1_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \
|
||||
G2_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \
|
||||
\
|
||||
DIAGONALIZE_2(A0, A1, B0, B1, C0, C1, D0, D1) \
|
||||
\
|
||||
G1_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \
|
||||
G2_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \
|
||||
\
|
||||
UNDIAGONALIZE_2(A0, A1, B0, B1, C0, C1, D0, D1) \
|
||||
} while((void)0, 0);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user