X-Git-Url: http://www.wagner.pp.ru/gitweb/?a=blobdiff_plain;f=gosthash2012.h;h=99c9e3d694fd8305d099c1def5b8a114d3381e5e;hb=HEAD;hp=0556a5330a83996a3fc54c4a07915647c891470f;hpb=419263293a3075c630d028b94378107714ab6fa6;p=openssl-gost%2Fengine.git diff --git a/gosthash2012.h b/gosthash2012.h index 0556a53..99c9e3d 100644 --- a/gosthash2012.h +++ b/gosthash2012.h @@ -10,11 +10,18 @@ #include -#ifdef OPENSSL_IA32_SSE2 -# ifdef __MMX__ -# ifdef __SSE2__ -# define __GOST3411_HAS_SSE2__ -# endif +#ifdef __SSE2__ +# define __GOST3411_HAS_SSE2__ +# if !defined(__x86_64__) && !defined(__e2k__) +/* + * x86-64 bit Linux and Windows ABIs provide malloc function that returns + * 16-byte alignment memory buffers required by SSE load/store instructions. + * Other platforms require special trick for proper gost2012_hash_ctx structure + * allocation. It will be easier to switch to unaligned loadu/storeu memory + * access instructions in this case. + */ +# define UNALIGNED_SIMD_ACCESS +# pragma message "Use unaligned SIMD memory access" # endif #endif @@ -27,12 +34,19 @@ #ifndef L_ENDIAN # define __GOST3411_BIG_ENDIAN__ #endif + #if defined __GOST3411_HAS_SSE2__ # include "gosthash2012_sse2.h" #else # include "gosthash2012_ref.h" #endif +# if defined(__GNUC__) || defined(__clang__) +# define RESTRICT __restrict__ +# else +# define RESTRICT +# endif + #ifdef _MSC_VER # define ALIGN(x) __declspec(align(x)) #else @@ -42,6 +56,7 @@ ALIGN(16) typedef union uint512_u { unsigned long long QWORD[8]; + unsigned char B[64]; } uint512_u; #include "gosthash2012_const.h" @@ -49,8 +64,7 @@ typedef union uint512_u { /* GOST R 34.11-2012 hash context */ typedef struct gost2012_hash_ctx { - unsigned char buffer[64]; - union uint512_u hash; + union uint512_u buffer; union uint512_u h; union uint512_u N; union uint512_u Sigma;