Skip to content

Commit c82024d

Browse files
committed
Create macros to make GCC's aligned instructions cross-platform compatible. Fixes "error C2146: syntax error: missing ';' before identifier '__attribute__'"
1 parent ee5f2ab commit c82024d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

sha1.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
#include <string.h>
44
#include <openssl/sha.h>
55

6+
#if defined(_MSC_VER)
7+
#define __align(boundary, type) __declspec(align(boundary)) type
8+
#else
9+
#define __align(boundary, type) type __attribute__((aligned(boundary)))
10+
#endif
11+
612
inline void encodeb64(const unsigned char* pch, char* buff)
713
{
814
const char *pbase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -33,9 +39,9 @@ inline void encodeb64(const unsigned char* pch, char* buff)
3339

3440
void sha1_hash(const char* input, char* output, uint32_t len)
3541
{
36-
char str[38] __attribute__((aligned(32))); // 26 + 11 + 1
37-
uint32_t prehash[5] __attribute__((aligned(32)));
38-
uint32_t hash[5] __attribute__((aligned(32))) = { 0 };
42+
__align(32, char str[38]); // 26 + 11 + 1
43+
__align(32, uint32_t prehash[5]);
44+
__align(32, uint32_t hash[5]) = { 0 };
3945
int i = 0;
4046
SHA_CTX ctx;
4147
SHA1_Init(&ctx);

0 commit comments

Comments
 (0)