Skip to content

Commit 3de9337

Browse files
committed
Let's see if that makes MSVC happy
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
1 parent f17403e commit 3de9337

3 files changed

Lines changed: 32 additions & 20 deletions

File tree

src/hashes/sha1_x86.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@
1010

1111
#ifdef LTC_SHA1_X86
1212

13-
#if defined __GNUC__
13+
#if defined(__GNUC__)
1414
#pragma GCC diagnostic push
1515
#pragma GCC diagnostic ignored "-Wdeclaration-after-statement"
1616
#pragma GCC diagnostic ignored "-Wuninitialized"
1717
#pragma GCC diagnostic ignored "-Wunused-function"
18+
#elif defined(_MSC_VER)
19+
#include <intrin.h>
20+
#endif
1821
#include <emmintrin.h> /* SSE2 _mm_load_si128 _mm_loadu_si128 _mm_store_si128 _mm_set_epi32 _mm_set_epi64x _mm_setzero_si128 _mm_xor_si128 _mm_add_epi32 _mm_shuffle_epi32 */
1922
#include <tmmintrin.h> /* SSSE3 _mm_shuffle_epi8 */
2023
#include <smmintrin.h> /* SSE4.1 _mm_extract_epi32 */
2124
#include <immintrin.h> /* SHA _mm_sha1msg1_epu32 _mm_sha1msg2_epu32 _mm_sha1rnds4_epu32 _mm_sha1nexte_epu32 */
22-
#include <stdint.h> /* uintptr_t */
23-
#define ltc_attribute_sha1 __attribute__((__target__("sse2,ssse3,sse4.1,sha")))
25+
26+
#if defined(__GNUC__)
2427
#pragma GCC diagnostic pop
25-
#else
26-
#define ltc_attribute_sha1
2728
#endif
2829

2930
const struct ltc_hash_descriptor sha1_x86_desc =
@@ -45,9 +46,9 @@ const struct ltc_hash_descriptor sha1_x86_desc =
4546
};
4647

4748
#ifdef LTC_CLEAN_STACK
48-
static int ltc_attribute_sha1 ss_sha1_x86_compress(hash_state *md, const unsigned char *buf)
49+
static int LTC_SHA_TARGET ss_sha1_x86_compress(hash_state *md, const unsigned char *buf)
4950
#else
50-
static int ltc_attribute_sha1 s_sha1_x86_compress(hash_state *md, const unsigned char *buf)
51+
static int LTC_SHA_TARGET s_sha1_x86_compress(hash_state *md, const unsigned char *buf)
5152
#endif
5253
{
5354
#define k_reverse_32 ((0x0 << (3 * 2)) | (0x1 << (2 * 2)) | (0x2 << (1 * 2)) | (0x3 << (0 * 2)))
@@ -65,7 +66,7 @@ static int ltc_attribute_sha1 s_sha1_x86_compress(hash_state *md, const unsigned
6566

6667
LTC_ARGCHK(md != NULL);
6768
LTC_ARGCHK(buf != NULL);
68-
LTC_ARGCHK(((uintptr_t)(&md->sha1.state[0])) % 16 == 0);
69+
LTC_ARGCHK(((ltc_uintptr)(&md->sha1.state[0])) % 16 == 0);
6970
LTC_ARGCHK(sizeof(int) == 4);
7071

7172
reverse_8 = _mm_set_epi64x(0x0001020304050607ull, 0x08090a0b0c0d0e0full);

src/hashes/sha2/sha256_x86.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,26 @@
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

2834
const 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);

src/headers/tomcrypt_cfg.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,13 @@ typedef unsigned long ltc_mp_digit;
323323
#endif
324324

325325
#if defined(__GNUC__)
326+
#define LTC_ALIGN_MSVC(n)
326327
#define LTC_ALIGN(n) __attribute__((aligned(n)))
328+
#elif defined(_MSC_VER)
329+
#define LTC_ALIGN_MSVC(n) __declspec(align(n))
330+
#define LTC_ALIGN(n)
327331
#else
332+
#define LTC_ALIGN_MSVC(n)
328333
#define LTC_ALIGN(n)
329334
#endif
330335

@@ -386,8 +391,10 @@ typedef unsigned long ltc_mp_digit;
386391

387392
#if defined(__clang__) || defined(__GNUC__)
388393
#define LTC_GCM_PCLMUL_TARGET __attribute__((target("pclmul,ssse3")))
394+
#define LTC_SHA_TARGET __attribute__((__target__("sse2,ssse3,sse4.1,sha")))
389395
#else
390396
#define LTC_GCM_PCLMUL_TARGET
397+
#define LTC_SHA_TARGET
391398
#endif
392399

393400
#if !defined(LTC_NO_GCM_PMULL) && (defined(__aarch64__) || defined(_M_ARM64))

0 commit comments

Comments
 (0)