diff --git a/wolfcrypt/src/chacha.c b/wolfcrypt/src/chacha.c index 598e1aefb..a4654bec0 100644 --- a/wolfcrypt/src/chacha.c +++ b/wolfcrypt/src/chacha.c @@ -399,8 +399,8 @@ static INLINE void wc_Chacha_wordtobyte(word32 output[CHACHA_CHUNK_WORDS], static void chacha_encrypt_avx(ChaCha* ctx, const byte* m, byte* c, word32 bytes) { - word32 X[4*CHACHA_CHUNK_WORDS]; /* used to make sure aligned */ - word32 x[2*CHACHA_CHUNK_WORDS]; + ALIGN128 word32 X[4*CHACHA_CHUNK_WORDS]; /* used to make sure aligned */ + ALIGN128 word32 x[2*CHACHA_CHUNK_WORDS]; /* used to make sure aligned */ byte* output; word32 i; word32 cnt = 0; @@ -664,8 +664,8 @@ static void chacha_encrypt_avx(ChaCha* ctx, const byte* m, byte* c, static void chacha_encrypt_avx2(ChaCha* ctx, const byte* m, byte* c, word32 bytes) { - word32 X[8*CHACHA_CHUNK_WORDS]; /* used to make sure aligned */ - word32 x[4*CHACHA_CHUNK_WORDS]; + ALIGN256 word32 X[8*CHACHA_CHUNK_WORDS]; /* used to make sure aligned */ + ALIGN256 word32 x[4*CHACHA_CHUNK_WORDS]; /* used to make sure aligned */ byte* output; word32 i; word32 cnt = 0; diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h index 1eb69db14..4149b1ecc 100755 --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -510,7 +510,7 @@ #endif #endif - #if !defined(ALIGN32) + #if !defined(ALIGN32) #if defined(__GNUC__) #define ALIGN32 __attribute__ ( (aligned (32))) #elif defined(_MSC_VER) @@ -521,6 +521,27 @@ #define ALIGN32 #endif #endif /* !ALIGN32 */ + + #if defined(__GNUC__) + #define ALIGN128 __attribute__ ( (aligned (128))) + #elif defined(_MSC_VER) + /* disable align warning, we want alignment ! */ + #pragma warning(disable: 4324) + #define ALIGN128 __declspec (align (128)) + #else + #define ALIGN128 + #endif + + #if defined(__GNUC__) + #define ALIGN256 __attribute__ ( (aligned (256))) + #elif defined(_MSC_VER) + /* disable align warning, we want alignment ! */ + #pragma warning(disable: 4324) + #define ALIGN256 __declspec (align (256)) + #else + #define ALIGN256 + #endif + #else #ifndef ALIGN16 #define ALIGN16 @@ -528,6 +549,12 @@ #ifndef ALIGN32 #define ALIGN32 #endif + #ifndef ALIGN128 + #define ALIGN128 + #endif + #ifndef ALIGN256 + #define ALIGN256 + #endif #endif /* WOLFSSL_AESNI || WOLFSSL_ARMASM */