From e2785a2268702312529521df3bd2f4e6b43cea3a Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 4 Sep 2015 12:32:16 +0200 Subject: w32: Fix alignment problem with AESNI on Windows >= 8 * cipher/cipher-selftest.c (_gcry_cipher_selftest_alloc_ctx): New. * cipher/rijndael.c (selftest_basic_128, selftest_basic_192) (selftest_basic_256): Allocate context on the heap. -- The stack alignment on Windows changed and because ld seems to limit stack variables to a 8 byte alignment (we request 16), we get bus errors from the selftests if AESNI is in use. GnuPG-bug-id: 2085 Signed-off-by: Werner Koch --- cipher/cipher-selftest.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'cipher/cipher-selftest.c') diff --git a/cipher/cipher-selftest.c b/cipher/cipher-selftest.c index 852368a0..470499fc 100644 --- a/cipher/cipher-selftest.c +++ b/cipher/cipher-selftest.c @@ -44,6 +44,29 @@ #endif +/* Return an allocated buffers of size CONTEXT_SIZE with an alignment + of 16. The caller must free that buffer using the address returned + at R_MEM. Returns NULL and sets ERRNO on failure. */ +void * +_gcry_cipher_selftest_alloc_ctx (const int context_size, unsigned char **r_mem) +{ + int offs; + unsigned int ctx_aligned_size, memsize; + + ctx_aligned_size = context_size + 15; + ctx_aligned_size -= ctx_aligned_size & 0xf; + + memsize = ctx_aligned_size + 16; + + *r_mem = xtrycalloc (1, memsize); + if (!*r_mem) + return NULL; + + offs = (16 - ((uintptr_t)*r_mem & 15)) & 15; + return (void*)(*r_mem + offs); +} + + /* Run the self-tests for -CBC-, tests bulk CBC decryption. Returns NULL on success. */ const char * -- cgit v1.2.1