99
1010#if defined(LTC_SHA256 ) && defined(LTC_SHA256_X86 )
1111
12- #if defined __GNUC__
12+ #if defined( __GNUC__ )
1313#pragma GCC diagnostic push
1414#pragma GCC diagnostic ignored "-Wdeclaration-after-statement"
1515#pragma GCC diagnostic ignored "-Wuninitialized"
1616#pragma GCC diagnostic ignored "-Wunused-function"
17+ #elif defined(_MSC_VER )
18+ #include <intrin.h>
19+ #endif
1720#include <emmintrin.h> /* SSE2 _mm_load_si128 _mm_loadu_si128 _mm_store_si128 _mm_set_epi64x _mm_add_epi32 _mm_shuffle_epi32 */
1821#include <tmmintrin.h> /* SSSE3 _mm_alignr_epi8 _mm_shuffle_epi8 */
1922#include <smmintrin.h> /* SSE4.1 _mm_blend_epi16 */
2023#include <immintrin.h> /* SHA _mm_sha256msg1_epu32 _mm_sha256msg2_epu32 _mm_sha256rnds2_epu32 */
21- #include <stdint.h> /* uintptr_t */
22- #define ltc_attribute_sha256 __attribute__((__target__("sse2,ssse3,sse4.1,sha")))
24+ #if defined(__GNUC__ )
2325#pragma GCC diagnostic pop
26+ #endif
27+
28+ #if defined(__clang__ ) || defined(__GNUC__ )
29+ #define LTC_SHA_TARGET __attribute__((__target__("sse2,ssse3,sse4.1,sha")))
2430#else
25- #define ltc_attribute_sha256
31+ #define LTC_SHA_TARGET
2632#endif
2733
2834const struct ltc_hash_descriptor sha256_x86_desc =
@@ -45,9 +51,8 @@ const struct ltc_hash_descriptor sha256_x86_desc =
4551
4652/* the K array */
4753#define K sha256_x86_K
48- #pragma pack(push)
49- #pragma pack(16) /* todo #pragma pack might not work */
50- static const ulong32 K [64 ] = {
54+ LTC_ALIGN_MSVC (16 )
55+ static const ulong32 K [64 ] LTC_ALIGN (16 ) = {
5156 0x428a2f98UL , 0x71374491UL , 0xb5c0fbcfUL , 0xe9b5dba5UL , 0x3956c25bUL ,
5257 0x59f111f1UL , 0x923f82a4UL , 0xab1c5ed5UL , 0xd807aa98UL , 0x12835b01UL ,
5358 0x243185beUL , 0x550c7dc3UL , 0x72be5d74UL , 0x80deb1feUL , 0x9bdc06a7UL ,
@@ -62,13 +67,12 @@ static const ulong32 K[64] = {
6267 0x682e6ff3UL , 0x748f82eeUL , 0x78a5636fUL , 0x84c87814UL , 0x8cc70208UL ,
6368 0x90befffaUL , 0xa4506cebUL , 0xbef9a3f7UL , 0xc67178f2UL
6469};
65- #pragma pack(pop)
6670
6771/* compress 512-bits */
6872#ifdef LTC_CLEAN_STACK
69- static int ltc_attribute_sha256 ss_sha256_x86_compress (hash_state * md , const unsigned char * buf )
73+ static int LTC_SHA_TARGET ss_sha256_x86_compress (hash_state * md , const unsigned char * buf )
7074#else
71- static int ltc_attribute_sha256 s_sha256_x86_compress (hash_state * md , const unsigned char * buf )
75+ static int LTC_SHA_TARGET s_sha256_x86_compress (hash_state * md , const unsigned char * buf )
7276#endif
7377{
7478#define k_blend_epi16 (a , b , c , d , e , f , g , h ) ((((a) & 0x1) << 7) | (((b) & 0x1) << 6) | (((c) & 0x1) << 5) | (((d) & 0x1) << 4) | (((e) & 0x1) << 3) | (((f) & 0x1) << 2) | (((g) & 0x1) << 1) | (((h) & 0x1) << 0))
@@ -94,8 +98,8 @@ static int ltc_attribute_sha256 s_sha256_x86_compress(hash_state * md, const uns
9498
9599 LTC_ARGCHK (md != NULL );
96100 LTC_ARGCHK (buf != NULL );
97- LTC_ARGCHK (((uintptr_t )(& md -> sha256 .state [0 ])) % 16 == 0 );
98- LTC_ARGCHK (((uintptr_t )(& K [0 ])) % 16 == 0 );
101+ LTC_ARGCHK (((ltc_uintptr )(& md -> sha256 .state [0 ])) % 16 == 0 );
102+ LTC_ARGCHK (((ltc_uintptr )(& K [0 ])) % 16 == 0 );
99103 LTC_ARGCHK (sizeof (int ) == 4 );
100104
101105 reverse = _mm_set_epi64x (0x0c0d0e0f08090a0bull , 0x0405060700010203ull );
0 commit comments