From: Niels Möller Date: Tue, 27 May 2025 18:50:37 +0000 (+0200) Subject: Use alignas X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6bc4a8c053b920e9ba29725a62ca2039cd5190f3;p=thirdparty%2Fnettle.git Use alignas --- diff --git a/aes.h b/aes.h index f3d60ea7..3b6f9fb7 100644 --- a/aes.h +++ b/aes.h @@ -68,7 +68,7 @@ extern "C" { struct aes128_ctx { - uint32_t keys[4 * (_AES128_ROUNDS + 1)]; + uint32_t _NETTLE_ALIGN16 keys[4 * (_AES128_ROUNDS + 1)]; }; void diff --git a/ctr16.c b/ctr16.c index d744d2a9..341fac99 100644 --- a/ctr16.c +++ b/ctr16.c @@ -52,7 +52,7 @@ _nettle_ctr_crypt16(const void *ctx, nettle_cipher_func *f, size_t length, uint8_t *dst, const uint8_t *src) { - if (dst != src && !((uintptr_t) dst % sizeof(uint64_t))) + if (dst != src && !((uintptr_t) dst % alignof(union nettle_block16))) { size_t blocks = length / 16u; size_t done; diff --git a/nettle-types.h b/nettle-types.h index 04febc7c..da4195ab 100644 --- a/nettle-types.h +++ b/nettle-types.h @@ -34,6 +34,7 @@ /* For size_t */ #include +#include #include /* Attributes we want to use in installed header files, and hence @@ -57,11 +58,15 @@ extern "C" { #endif +/* On 64-bit platforms where uint64_t requires 8 byte alignment, use + twice the alignment. */ +#define _NETTLE_ALIGN16 alignas(alignof(uint64_t) == 8 ? 16 : 0) + /* An aligned 16-byte block. */ union nettle_block16 { uint8_t b[16]; - uint64_t u64[2]; + uint64_t _NETTLE_ALIGN16 u64[2]; }; union nettle_block8 diff --git a/umac.h b/umac.h index 5efb4338..01579f36 100644 --- a/umac.h +++ b/umac.h @@ -70,7 +70,7 @@ extern "C" { /* Subkeys and state for UMAC with tag size 32*n bits. */ #define _UMAC_STATE(n) \ - uint32_t l1_key[UMAC_BLOCK_SIZE/4 + 4*((n)-1)]; \ + uint32_t _NETTLE_ALIGN16 l1_key[UMAC_BLOCK_SIZE/4 + 4*((n)-1)]; \ /* Keys in 32-bit pieces, high first */ \ uint32_t l2_key[6*(n)]; \ uint64_t l3_key1[8*(n)]; \