bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] crypto: use byteswap


From: Paul Eggert
Subject: [PATCH] crypto: use byteswap
Date: Sun, 17 Jun 2018 14:38:29 -0700

* lib/md4.c, lib/md5.c, lib/sha1.c, lib/sha256.c, lib/sha512.c:
* lib/sm3.c: Include <byteswap.h>.
(SWAP): Use its macros rather than reinventing the wheel.
* modules/crypto/md4, modules/crypto/md5-buffer:
* modules/crypto/sha1-buffer, modules/crypto/sha256-buffer:
* modules/crypto/sha512-buffer, modules/crypto/sm3:
(Depends-on): Add byteswap.
---
 ChangeLog                    | 11 +++++++++++
 lib/md4.c                    |  4 ++--
 lib/md5.c                    |  4 ++--
 lib/sha1.c                   |  4 ++--
 lib/sha256.c                 |  4 ++--
 lib/sha512.c                 | 11 ++---------
 lib/sm3.c                    |  4 ++--
 modules/crypto/md4           |  1 +
 modules/crypto/md5-buffer    |  1 +
 modules/crypto/sha1-buffer   |  1 +
 modules/crypto/sha256-buffer |  1 +
 modules/crypto/sha512-buffer |  1 +
 modules/crypto/sm3           |  1 +
 13 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8f99c167f..1bda21b27 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2018-06-17  Paul Eggert  <address@hidden>
+
+       crypto: use byteswap
+       * lib/md4.c, lib/md5.c, lib/sha1.c, lib/sha256.c, lib/sha512.c:
+       * lib/sm3.c: Include <byteswap.h>.
+       (SWAP): Use its macros rather than reinventing the wheel.
+       * modules/crypto/md4, modules/crypto/md5-buffer:
+       * modules/crypto/sha1-buffer, modules/crypto/sha256-buffer:
+       * modules/crypto/sha512-buffer, modules/crypto/sm3:
+       (Depends-on): Add byteswap.
+
 2018-06-17  Pádraig Brady  <address@hidden>
 
        gendocs.sh: fix support for legacy --texi2html
diff --git a/lib/md4.c b/lib/md4.c
index b24ad1ca5..6474e6387 100644
--- a/lib/md4.c
+++ b/lib/md4.c
@@ -33,9 +33,9 @@
 # include "unlocked-io.h"
 #endif
 
+#include <byteswap.h>
 #ifdef WORDS_BIGENDIAN
-# define SWAP(n)                                                        \
-  (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
+# define SWAP(n) bswap_32 (n)
 #else
 # define SWAP(n) (n)
 #endif
diff --git a/lib/md5.c b/lib/md5.c
index b276a4545..a9b65b019 100644
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -52,9 +52,9 @@
 # define md5_buffer __md5_buffer
 #endif
 
+#include <byteswap.h>
 #ifdef WORDS_BIGENDIAN
-# define SWAP(n)                                                        \
-    (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
+# define SWAP(n) bswap_32 (n)
 #else
 # define SWAP(n) (n)
 #endif
diff --git a/lib/sha1.c b/lib/sha1.c
index bb370f3ff..6cfd6c6f3 100644
--- a/lib/sha1.c
+++ b/lib/sha1.c
@@ -37,11 +37,11 @@
 # include "unlocked-io.h"
 #endif
 
+#include <byteswap.h>
 #ifdef WORDS_BIGENDIAN
 # define SWAP(n) (n)
 #else
-# define SWAP(n) \
-    (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
+# define SWAP(n) bswap_32 (n)
 #endif
 
 #define BLOCKSIZE 32768
diff --git a/lib/sha256.c b/lib/sha256.c
index a036befca..d45cd184c 100644
--- a/lib/sha256.c
+++ b/lib/sha256.c
@@ -36,11 +36,11 @@
 # include "unlocked-io.h"
 #endif
 
+#include <byteswap.h>
 #ifdef WORDS_BIGENDIAN
 # define SWAP(n) (n)
 #else
-# define SWAP(n) \
-    (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
+# define SWAP(n) bswap_32 (n)
 #endif
 
 #define BLOCKSIZE 32768
diff --git a/lib/sha512.c b/lib/sha512.c
index e175e705f..503a54fe8 100644
--- a/lib/sha512.c
+++ b/lib/sha512.c
@@ -36,18 +36,11 @@
 # include "unlocked-io.h"
 #endif
 
+#include <byteswap.h>
 #ifdef WORDS_BIGENDIAN
 # define SWAP(n) (n)
 #else
-# define SWAP(n) \
-    u64or (u64or (u64or (u64shl (n, 56),                                \
-                         u64shl (u64and (n, u64lo (0x0000ff00)), 40)),  \
-                  u64or (u64shl (u64and (n, u64lo (0x00ff0000)), 24),   \
-                         u64shl (u64and (n, u64lo (0xff000000)),  8))), \
-           u64or (u64or (u64and (u64shr (n,  8), u64lo (0xff000000)),   \
-                         u64and (u64shr (n, 24), u64lo (0x00ff0000))),  \
-                  u64or (u64and (u64shr (n, 40), u64lo (0x0000ff00)),   \
-                         u64shr (n, 56))))
+# define SWAP(n) bswap_64 (n)
 #endif
 
 #define BLOCKSIZE 32768
diff --git a/lib/sm3.c b/lib/sm3.c
index 383028073..f82a74a60 100644
--- a/lib/sm3.c
+++ b/lib/sm3.c
@@ -49,11 +49,11 @@
 # define dbg_printf printf
 #endif
 
+#include <byteswap.h>
 #ifdef WORDS_BIGENDIAN
 # define SWAP(n) (n)
 #else
-# define SWAP(n) \
-    (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
+# define SWAP(n) bswap_32 (n)
 #endif
 
 #define BLOCKSIZE 32768
diff --git a/modules/crypto/md4 b/modules/crypto/md4
index e0b2b0443..03d28e971 100644
--- a/modules/crypto/md4
+++ b/modules/crypto/md4
@@ -7,6 +7,7 @@ lib/md4.c
 m4/md4.m4
 
 Depends-on:
+byteswap
 stdalign
 stdint
 
diff --git a/modules/crypto/md5-buffer b/modules/crypto/md5-buffer
index e5fb39ced..006bc81a4 100644
--- a/modules/crypto/md5-buffer
+++ b/modules/crypto/md5-buffer
@@ -9,6 +9,7 @@ m4/gl-openssl.m4
 m4/md5.m4
 
 Depends-on:
+byteswap
 extern-inline
 stdalign
 stdint
diff --git a/modules/crypto/sha1-buffer b/modules/crypto/sha1-buffer
index d65f99418..807f2dcc0 100644
--- a/modules/crypto/sha1-buffer
+++ b/modules/crypto/sha1-buffer
@@ -9,6 +9,7 @@ m4/gl-openssl.m4
 m4/sha1.m4
 
 Depends-on:
+byteswap
 extern-inline
 stdalign
 stdint
diff --git a/modules/crypto/sha256-buffer b/modules/crypto/sha256-buffer
index 37fabfd90..e5a4703ec 100644
--- a/modules/crypto/sha256-buffer
+++ b/modules/crypto/sha256-buffer
@@ -9,6 +9,7 @@ m4/gl-openssl.m4
 m4/sha256.m4
 
 Depends-on:
+byteswap
 extern-inline
 stdalign
 stdint
diff --git a/modules/crypto/sha512-buffer b/modules/crypto/sha512-buffer
index 4c97604cd..32170a9a8 100644
--- a/modules/crypto/sha512-buffer
+++ b/modules/crypto/sha512-buffer
@@ -9,6 +9,7 @@ m4/gl-openssl.m4
 m4/sha512.m4
 
 Depends-on:
+byteswap
 extern-inline
 stdalign
 stdint
diff --git a/modules/crypto/sm3 b/modules/crypto/sm3
index b62062444..007fbc46f 100644
--- a/modules/crypto/sm3
+++ b/modules/crypto/sm3
@@ -7,6 +7,7 @@ lib/sm3.c
 m4/sm3.m4
 
 Depends-on:
+byteswap
 extern-inline
 stdalign
 stdint
-- 
2.17.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]