diff options
author | Werner Koch <wk@gnupg.org> | 2015-09-04 12:32:16 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2015-09-04 12:32:16 +0200 |
commit | e2785a2268702312529521df3bd2f4e6b43cea3a (patch) | |
tree | e2e2be008b8d38c8122141fb574b78c3ebfcdeb2 /cipher/cipher-selftest.c | |
parent | c17f84bd02d7ee93845e92e20f6ddba814961588 (diff) | |
download | libgcrypt-e2785a2268702312529521df3bd2f4e6b43cea3a.tar.gz |
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 <wk@gnupg.org>
Diffstat (limited to 'cipher/cipher-selftest.c')
-rw-r--r-- | cipher/cipher-selftest.c | 23 |
1 files changed, 23 insertions, 0 deletions
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 <block cipher>-CBC-<block size>, tests bulk CBC decryption. Returns NULL on success. */ const char * |