From: Paul Eggert Date: Mon, 17 Oct 2011 00:17:47 +0000 (-0700) Subject: crypto libraries: use stdalign X-Git-Tag: v0.1~1529 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=2d540c2cb293bff09a2fe1b1bab9d1775d7e2832;p=gnulib.git crypto libraries: use stdalign * lib/md4.c, lib/md5.c, lib/sha1.c, lib/sha256.c, lib/sha512.c: Include and . Do not include . Do not include twice, in md4.c. (UNALIGNED_P): Simplify by using alignof. Use uintptr_t, not size_t, because we are accessing a pointer's bit-pattern, not a size. * modules/crypto/gc-md4 (Depends-on): Add stdalign. * modules/crypto/gc-md5, modules/crypto/gc-sha1, modules/crypto/md4: * modules/crypto/md5, modules/crypto/sha1, modules/crypto/sha256: * modules/crypto/sha512: Likewise. --- diff --git a/ChangeLog b/ChangeLog index 0b9d921381..b8fcdcca49 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,6 +14,17 @@ (alignof): Remove. * modules/argp (Depends-on): Add stdalign. + crypto libraries: use stdalign + * lib/md4.c, lib/md5.c, lib/sha1.c, lib/sha256.c, lib/sha512.c: + Include and . Do not include . + Do not include twice, in md4.c. + (UNALIGNED_P): Simplify by using alignof. Use uintptr_t, not size_t, + because we are accessing a pointer's bit-pattern, not a size. + * modules/crypto/gc-md4 (Depends-on): Add stdalign. + * modules/crypto/gc-md5, modules/crypto/gc-sha1, modules/crypto/md4: + * modules/crypto/md5, modules/crypto/sha1, modules/crypto/sha256: + * modules/crypto/sha512: Likewise. + 2011-10-27 Bruno Haible raise test: Avoid a test failure on Linux/MIPS. diff --git a/lib/md4.c b/lib/md4.c index aaa82e2864..6807a830d3 100644 --- a/lib/md4.c +++ b/lib/md4.c @@ -24,8 +24,8 @@ #include "md4.h" -#include -#include +#include +#include #include #include #include @@ -239,14 +239,7 @@ md4_process_bytes (const void *buffer, size_t len, struct md4_ctx *ctx) if (len >= 64) { #if !_STRING_ARCH_unaligned - /* To check alignment gcc has an appropriate operator. Other - compilers don't. */ -# if __GNUC__ >= 2 -# define UNALIGNED_P(p) (((uintptr_t) p) % __alignof__ (uint32_t) != 0) -# else -# define alignof(type) offsetof (struct { char c; type x; }, x) -# define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0) -# endif +# define UNALIGNED_P(p) ((uintptr_t) (p) % alignof (uint32_t) != 0) if (UNALIGNED_P (buffer)) while (len > 64) { diff --git a/lib/md5.c b/lib/md5.c index d37ca722c2..7d575ac6e9 100644 --- a/lib/md5.c +++ b/lib/md5.c @@ -24,7 +24,8 @@ #include "md5.h" -#include +#include +#include #include #include #include @@ -254,8 +255,7 @@ md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx) if (len >= 64) { #if !_STRING_ARCH_unaligned -# define alignof(type) offsetof (struct { char c; type x; }, x) -# define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0) +# define UNALIGNED_P(p) ((uintptr_t) (p) % alignof (uint32_t) != 0) if (UNALIGNED_P (buffer)) while (len > 64) { diff --git a/lib/sha1.c b/lib/sha1.c index 7ec950e94e..828810bb88 100644 --- a/lib/sha1.c +++ b/lib/sha1.c @@ -26,7 +26,8 @@ #include "sha1.h" -#include +#include +#include #include #include @@ -241,8 +242,7 @@ sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx) if (len >= 64) { #if !_STRING_ARCH_unaligned -# define alignof(type) offsetof (struct { char c; type x; }, x) -# define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0) +# define UNALIGNED_P(p) ((uintptr_t) (p) % alignof (uint32_t) != 0) if (UNALIGNED_P (buffer)) while (len > 64) { diff --git a/lib/sha256.c b/lib/sha256.c index c125542248..aa529c6b6c 100644 --- a/lib/sha256.c +++ b/lib/sha256.c @@ -24,7 +24,8 @@ #include "sha256.h" -#include +#include +#include #include #include @@ -373,8 +374,7 @@ sha256_process_bytes (const void *buffer, size_t len, struct sha256_ctx *ctx) if (len >= 64) { #if !_STRING_ARCH_unaligned -# define alignof(type) offsetof (struct { char c; type x; }, x) -# define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0) +# define UNALIGNED_P(p) ((uintptr_t) (p) % alignof (uint32_t) != 0) if (UNALIGNED_P (buffer)) while (len > 64) { diff --git a/lib/sha512.c b/lib/sha512.c index c0bed95758..1c5117fa1c 100644 --- a/lib/sha512.c +++ b/lib/sha512.c @@ -24,7 +24,8 @@ #include "sha512.h" -#include +#include +#include #include #include @@ -381,8 +382,7 @@ sha512_process_bytes (const void *buffer, size_t len, struct sha512_ctx *ctx) if (len >= 128) { #if !_STRING_ARCH_unaligned -# define alignof(type) offsetof (struct { char c; type x; }, x) -# define UNALIGNED_P(p) (((size_t) p) % alignof (u64) != 0) +# define UNALIGNED_P(p) ((uintptr_t) (p) % alignof (u64) != 0) if (UNALIGNED_P (buffer)) while (len > 128) { diff --git a/modules/crypto/gc-md4 b/modules/crypto/gc-md4 index cdc600590b..e527db5897 100644 --- a/modules/crypto/gc-md4 +++ b/modules/crypto/gc-md4 @@ -8,6 +8,7 @@ lib/md4.c m4/md4.m4 Depends-on: +stdalign stdint crypto/gc diff --git a/modules/crypto/gc-md5 b/modules/crypto/gc-md5 index a1075b8693..efa1c1832e 100644 --- a/modules/crypto/gc-md5 +++ b/modules/crypto/gc-md5 @@ -8,6 +8,7 @@ lib/md5.c m4/md5.m4 Depends-on: +stdalign stdint crypto/gc diff --git a/modules/crypto/gc-sha1 b/modules/crypto/gc-sha1 index b9efddaad7..4ee0a221f8 100644 --- a/modules/crypto/gc-sha1 +++ b/modules/crypto/gc-sha1 @@ -8,6 +8,7 @@ lib/sha1.c m4/sha1.m4 Depends-on: +stdalign stdint crypto/gc diff --git a/modules/crypto/md4 b/modules/crypto/md4 index 0a4d061698..e0b2b0443a 100644 --- a/modules/crypto/md4 +++ b/modules/crypto/md4 @@ -7,6 +7,7 @@ lib/md4.c m4/md4.m4 Depends-on: +stdalign stdint configure.ac: diff --git a/modules/crypto/md5 b/modules/crypto/md5 index 8cad978273..4ae0c57faa 100644 --- a/modules/crypto/md5 +++ b/modules/crypto/md5 @@ -7,6 +7,7 @@ lib/md5.c m4/md5.m4 Depends-on: +stdalign stdint configure.ac: diff --git a/modules/crypto/sha1 b/modules/crypto/sha1 index 2a347b0b38..8d00f312b6 100644 --- a/modules/crypto/sha1 +++ b/modules/crypto/sha1 @@ -7,6 +7,7 @@ lib/sha1.c m4/sha1.m4 Depends-on: +stdalign stdint configure.ac: diff --git a/modules/crypto/sha256 b/modules/crypto/sha256 index a5732bd83b..f3f1d6460d 100644 --- a/modules/crypto/sha256 +++ b/modules/crypto/sha256 @@ -7,6 +7,7 @@ lib/sha256.c m4/sha256.m4 Depends-on: +stdalign stdint configure.ac: diff --git a/modules/crypto/sha512 b/modules/crypto/sha512 index 9d871d46df..a5065c4563 100644 --- a/modules/crypto/sha512 +++ b/modules/crypto/sha512 @@ -7,6 +7,7 @@ lib/sha512.c m4/sha512.m4 Depends-on: +stdalign stdint u64