aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-10-15 06:17:58 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-10-15 06:17:58 +0300
commit428d5035d0803f135e65e7c968d2a90888099c8d (patch)
tree5f5c805c4ac3202f46d1a510ba7d1f5c48eadf58
parentCMakeLists.txt fixes (diff)
downloadaes-tools-428d5035d0803f135e65e7c968d2a90888099c8d.tar.gz
aes-tools-428d5035d0803f135e65e7c968d2a90888099c8d.zip
add "portable" alignment macro
-rw-r--r--include/aes/all.h1
-rw-r--r--include/aes/workarounds.h14
-rw-r--r--src/aes.c24
3 files changed, 27 insertions, 12 deletions
diff --git a/include/aes/all.h b/include/aes/all.h
index 959e10c..ff27c18 100644
--- a/include/aes/all.h
+++ b/include/aes/all.h
@@ -18,3 +18,4 @@
#include "error.h"
#include "mode.h"
#include "padding.h"
+#include "workarounds.h"
diff --git a/include/aes/workarounds.h b/include/aes/workarounds.h
new file mode 100644
index 0000000..45fece2
--- /dev/null
+++ b/include/aes/workarounds.h
@@ -0,0 +1,14 @@
+// Copyright (c) 2016 Egor Tensin <Egor.Tensin@gmail.com>
+// This file is part of the "AES tools" project.
+// For details, see https://github.com/egor-tensin/aes-tools.
+// Distributed under the MIT License.
+
+#pragma once
+
+#if defined(_MSC_VER)
+#define AES_ALIGN(t, x) __declspec(align(x)) t
+#elif defined(__GNUC__) || defined(__MINGW32__)
+#define AES_ALIGN(t, x) t __attribute__((aligned(x)))
+#else
+#warning "couldn't determine alignment attribute"
+#endif
diff --git a/src/aes.c b/src/aes.c
index 0aded1a..1f7da13 100644
--- a/src/aes.c
+++ b/src/aes.c
@@ -26,7 +26,7 @@ AES_StatusCode aes_AES_format_block(
char* cursor = str->str;
- __declspec(align(16)) unsigned char bytes[16];
+ AES_ALIGN(unsigned char, 16) bytes[16];
aes_store_block128_aligned(bytes, *block);
for (int i = 0; i < 16; ++i, cursor += 2)
@@ -51,7 +51,7 @@ AES_StatusCode aes_AES_format_block_as_matrix(
char* cursor = str->str;
- __declspec(align(16)) unsigned char bytes[4][4];
+ AES_ALIGN(unsigned char, 16) bytes[4][4];
aes_store_block128_aligned(bytes, *block);
for (int i = 0; i < 4; ++i, cursor += 3)
@@ -118,7 +118,7 @@ AES_StatusCode aes_AES_parse_block(
const char* cursor = src;
- __declspec(align(16)) unsigned char bytes[16];
+ AES_ALIGN(unsigned char, 16) bytes[16];
for (int i = 0; i < 16; ++i)
{
@@ -149,7 +149,7 @@ AES_StatusCode aes_AES128_format_key(
char* cursor = str->str;
- __declspec(align(16)) unsigned char bytes[16];
+ AES_ALIGN(unsigned char, 16) bytes[16];
aes_store_block128_aligned(bytes, key->key);
for (int i = 0; i < 16; ++i, cursor += 2)
@@ -175,7 +175,7 @@ AES_StatusCode aes_AES192_format_key(
char* cursor = str->str;
{
- __declspec(align(16)) unsigned char bytes[16];
+ AES_ALIGN(unsigned char, 16) bytes[16];
aes_store_block128_aligned(bytes, key->lo);
for (int i = 0; i < 16; ++i, cursor += 2)
@@ -183,7 +183,7 @@ AES_StatusCode aes_AES192_format_key(
}
{
- __declspec(align(16)) unsigned char bytes[16];
+ AES_ALIGN(unsigned char, 16) bytes[16];
aes_store_block128_aligned(bytes, key->hi);
for (int i = 0; i < 8; ++i, cursor += 2)
@@ -210,7 +210,7 @@ AES_StatusCode aes_AES256_format_key(
char* cursor = str->str;
{
- __declspec(align(16)) unsigned char bytes[16];
+ AES_ALIGN(unsigned char, 16) bytes[16];
aes_store_block128_aligned(bytes, key->lo);
for (int i = 0; i < 16; ++i, cursor += 2)
@@ -218,7 +218,7 @@ AES_StatusCode aes_AES256_format_key(
}
{
- __declspec(align(16)) unsigned char bytes[16];
+ AES_ALIGN(unsigned char, 16) bytes[16];
aes_store_block128_aligned(bytes, key->hi);
for (int i = 0; i < 16; ++i, cursor += 2)
@@ -298,7 +298,7 @@ AES_StatusCode aes_AES192_parse_key(
const char* cursor = src;
{
- __declspec(align(16)) unsigned char bytes[16];
+ AES_ALIGN(unsigned char, 16) bytes[16];
for (int i = 0; i < 16; ++i)
{
@@ -314,7 +314,7 @@ AES_StatusCode aes_AES192_parse_key(
}
{
- __declspec(align(16)) unsigned char bytes[16];
+ AES_ALIGN(unsigned char, 16) bytes[16];
for (int i = 0; i < 8; ++i)
{
@@ -349,7 +349,7 @@ AES_StatusCode aes_AES256_parse_key(
const char* cursor = src;
{
- __declspec(align(16)) unsigned char bytes[16];
+ AES_ALIGN(unsigned char, 16) bytes[16];
for (int i = 0; i < 16; ++i)
{
@@ -365,7 +365,7 @@ AES_StatusCode aes_AES256_parse_key(
}
{
- __declspec(align(16)) unsigned char bytes[16];
+ AES_ALIGN(unsigned char, 16) bytes[16];
for (int i = 0; i < 16; ++i)
{