gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [libmicrohttpd] 03/03: mhd_bithelpers.h: define _MHD_GET_32


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] 03/03: mhd_bithelpers.h: define _MHD_GET_32BIT_LE() and use it in md5.c
Date: Fri, 19 Apr 2019 21:36:32 +0200

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit f5970c7804f6bb6f5d99172e048d7a126657b570
Author: Evgeny Grin (Karlson2k) <address@hidden>
AuthorDate: Fri Apr 19 22:35:15 2019 +0300

    mhd_bithelpers.h: define _MHD_GET_32BIT_LE() and use it in md5.c
---
 src/microhttpd/md5.c            | 18 +++++++++++-------
 src/microhttpd/mhd_bithelpers.h | 19 +++++++++++++++++++
 2 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/src/microhttpd/md5.c b/src/microhttpd/md5.c
index 7838ac10..3f239f2f 100644
--- a/src/microhttpd/md5.c
+++ b/src/microhttpd/md5.c
@@ -96,6 +96,12 @@ MD5Final (void *ctx_,
 }
 
 
+/**
+ * Number of bytes in single SHA-256 word
+ * used to process data
+ */
+#define MD5_BYTES_IN_WORD (32 / 8)
+
 /* The four core functions - F1 is optimized somewhat */
 
 /* #define F1(x, y, z) (x & y | ~x & z) */
@@ -122,14 +128,12 @@ MD5Transform (uint32_t state[4],
 #if _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN
   const uint32_t *in = (const uint32_t *)block;
 #else
-  uint32_t in[MD5_BLOCK_SIZE / 4];
-  for (a = 0; a < MD5_BLOCK_SIZE / 4; a++)
+  uint32_t in[MD5_BLOCK_SIZE / MD5_BYTES_IN_WORD];
+  int i;
+
+  for (i = 0; i < MD5_BLOCK_SIZE / MD5_BYTES_IN_WORD; i++)
   {
-    in[a] = (uint32_t)(
-      (uint32_t)(block[a * 4 + 0]) |
-      (uint32_t)(block[a * 4 + 1]) << 8 |
-      (uint32_t)(block[a * 4 + 2]) << 16 |
-      (uint32_t)(block[a * 4 + 3]) << 24);
+    in[i] = _MHD_GET_32BIT_LE(block + i * MD5_BYTES_IN_WORD);
   }
 #endif
 
diff --git a/src/microhttpd/mhd_bithelpers.h b/src/microhttpd/mhd_bithelpers.h
index fa09f92a..6c4f0fea 100644
--- a/src/microhttpd/mhd_bithelpers.h
+++ b/src/microhttpd/mhd_bithelpers.h
@@ -101,6 +101,25 @@
         } while (0)
 #endif /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
 
+/* _MHD_GET_32BIT_LE (addr)
+ * get little-endian 32-bit value storied at addr
+ * and return it in native-endian mode.
+ */
+#if _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN
+#define _MHD_GET_32BIT_LE(addr)             \
+        (*(uint32_t*)(addr))
+#elif _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN
+#define _MHD_GET_32BIT_LE(addr)             \
+        _MHD_BYTES_SWAP32(*(uint32_t*)(addr))
+#else  /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
+/* Endianess was not detected or non-standard like PDP-endian */
+#define _MHD_GET_32BIT_LE(addr)                       \
+        ( ( (uint32_t)(((uint8_t*)addr)[0]))        | \
+          (((uint32_t)(((uint8_t*)addr)[1])) << 8)  | \
+          (((uint32_t)(((uint8_t*)addr)[2])) << 16) | \
+          (((uint32_t)(((uint8_t*)addr)[3])) << 24) )
+#endif /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
+
 
 /* _MHD_PUT_64BIT_BE (addr, value64)
  * put native-endian 64-bit value64 to addr

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

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