summaryrefslogtreecommitdiffstats
path: root/crypto/aes
diff options
context:
space:
mode:
authorBernd Edlinger <bernd.edlinger@hotmail.de>2018-04-24 21:10:13 +0200
committerBernd Edlinger <bernd.edlinger@hotmail.de>2020-05-27 20:14:24 +0200
commitd03ffeaf45da6541875bff05b3f79d8dba355c97 (patch)
treeac35aaa2f7db75b06bbce9c54623fa6abdc644cc /crypto/aes
parentefdfc392aac6d56fe385223cd26687fa26ca9af3 (diff)
Avoid undefined behavior with unaligned accesses
Fixes: #4983 [extended tests] Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com> (Merged from https://github.com/openssl/openssl/pull/11781)
Diffstat (limited to 'crypto/aes')
-rw-r--r--crypto/aes/aes_ige.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/crypto/aes/aes_ige.c b/crypto/aes/aes_ige.c
index dce4ef11be..0df04b3bb2 100644
--- a/crypto/aes/aes_ige.c
+++ b/crypto/aes/aes_ige.c
@@ -12,11 +12,6 @@
#include <openssl/aes.h>
#include "aes_local.h"
-#define N_WORDS (AES_BLOCK_SIZE / sizeof(unsigned long))
-typedef struct {
- unsigned long data[N_WORDS];
-} aes_block_t;
-
/* XXX: probably some better way to do this */
#if defined(__i386__) || defined(__x86_64__)
# define UNALIGNED_MEMOPS_ARE_FAST 1
@@ -24,6 +19,15 @@ typedef struct {
# define UNALIGNED_MEMOPS_ARE_FAST 0
#endif
+#define N_WORDS (AES_BLOCK_SIZE / sizeof(unsigned long))
+typedef struct {
+ unsigned long data[N_WORDS];
+#if defined(__GNUC__) && UNALIGNED_MEMOPS_ARE_FAST
+} aes_block_t __attribute((__aligned__(1)));
+#else
+} aes_block_t;
+#endif
+
#if UNALIGNED_MEMOPS_ARE_FAST
# define load_block(d, s) (d) = *(const aes_block_t *)(s)
# define store_block(d, s) *(aes_block_t *)(d) = (s)