]> Savannah Git Hosting - gnulib.git/commitdiff
crypto libraries: use stdalign
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 17 Oct 2011 00:17:47 +0000 (17:17 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 27 Oct 2011 20:05:42 +0000 (13:05 -0700)
* lib/md4.c, lib/md5.c, lib/sha1.c, lib/sha256.c, lib/sha512.c:
Include <stdalign.h> and <stdint.h>.  Do not include <stddef.h>.
Do not include <stdlib.h> 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.

14 files changed:
ChangeLog
lib/md4.c
lib/md5.c
lib/sha1.c
lib/sha256.c
lib/sha512.c
modules/crypto/gc-md4
modules/crypto/gc-md5
modules/crypto/gc-sha1
modules/crypto/md4
modules/crypto/md5
modules/crypto/sha1
modules/crypto/sha256
modules/crypto/sha512

index 0b9d921381215478093bc86cca7147dede5ffccf..b8fcdcca499ac1ceee98bfea232b318d10dbce1d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
        (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 <stdalign.h> and <stdint.h>.  Do not include <stddef.h>.
+       Do not include <stdlib.h> 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  <bruno@clisp.org>
 
        raise test: Avoid a test failure on Linux/MIPS.
index aaa82e28646c3df84ddb8cfffa7abdd34d89e21f..6807a830d32b92bfc86af5f83aff0eabb30d85db 100644 (file)
--- a/lib/md4.c
+++ b/lib/md4.c
@@ -24,8 +24,8 @@
 
 #include "md4.h"
 
-#include <stddef.h>
-#include <stdlib.h>
+#include <stdalign.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
@@ -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)
           {
index d37ca722c245d44ff96b25f30aa814d1f4f5a670..7d575ac6e98ff10b0c10a20bd7b4d1364ec49cbd 100644 (file)
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -24,7 +24,8 @@
 
 #include "md5.h"
 
-#include <stddef.h>
+#include <stdalign.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
@@ -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)
           {
index 7ec950e94eb2fcc788d6e6e4294d21600f45b593..828810bb88ecf3aed9e7817c3047a9a3541cd31a 100644 (file)
@@ -26,7 +26,8 @@
 
 #include "sha1.h"
 
-#include <stddef.h>
+#include <stdalign.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -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)
           {
index c125542248bc98ea80408c9b7fc4713bc45472da..aa529c6b6c0cfd78edb587cafe6d7c28d78addbf 100644 (file)
@@ -24,7 +24,8 @@
 
 #include "sha256.h"
 
-#include <stddef.h>
+#include <stdalign.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -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)
           {
index c0bed95758f4d3d605e894a3b3d30cf458cc0603..1c5117fa1cd4fb953944b9a59745d57d8adb1314 100644 (file)
@@ -24,7 +24,8 @@
 
 #include "sha512.h"
 
-#include <stddef.h>
+#include <stdalign.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -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)
           {
index cdc600590bbd2c92bd11f980f8e79b5aea2660f4..e527db58970bf86a97699f14fcce9ba999e5a37f 100644 (file)
@@ -8,6 +8,7 @@ lib/md4.c
 m4/md4.m4
 
 Depends-on:
+stdalign
 stdint
 crypto/gc
 
index a1075b86937ae4be2c3f1a6788afad4a45741db3..efa1c1832ef77238ba3641598cdccc54e46d66e7 100644 (file)
@@ -8,6 +8,7 @@ lib/md5.c
 m4/md5.m4
 
 Depends-on:
+stdalign
 stdint
 crypto/gc
 
index b9efddaad7db30018f3780008d9d28c75eadfd01..4ee0a221f883390223a5b283660ac95e37472ab2 100644 (file)
@@ -8,6 +8,7 @@ lib/sha1.c
 m4/sha1.m4
 
 Depends-on:
+stdalign
 stdint
 crypto/gc
 
index 0a4d0616983910e09704dad2a0c04acc377018f3..e0b2b0443a10d318baba8ead68c48b9f0a81df42 100644 (file)
@@ -7,6 +7,7 @@ lib/md4.c
 m4/md4.m4
 
 Depends-on:
+stdalign
 stdint
 
 configure.ac:
index 8cad97827345f89f4d09b55204c68ebedce9d042..4ae0c57faa39f5830ffab26265d3da55ff5a7ec7 100644 (file)
@@ -7,6 +7,7 @@ lib/md5.c
 m4/md5.m4
 
 Depends-on:
+stdalign
 stdint
 
 configure.ac:
index 2a347b0b38319a0ce3cb31c52bf9c38cf1f9b846..8d00f312b61f5361d39dfdd53aee8fe7dc101f33 100644 (file)
@@ -7,6 +7,7 @@ lib/sha1.c
 m4/sha1.m4
 
 Depends-on:
+stdalign
 stdint
 
 configure.ac:
index a5732bd83bc4a11c941891fe63423d5505f50d1d..f3f1d6460d78ffec618e157aa3bf6877e961f765 100644 (file)
@@ -7,6 +7,7 @@ lib/sha256.c
 m4/sha256.m4
 
 Depends-on:
+stdalign
 stdint
 
 configure.ac:
index 9d871d46dfed8bc8a6447f0a4fd4aa2aee3ca991..a5065c4563983d9d555af1846582404815f40674 100644 (file)
@@ -7,6 +7,7 @@ lib/sha512.c
 m4/sha512.m4
 
 Depends-on:
+stdalign
 stdint
 u64