[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [libmicrohttpd] 03/03: Moved bit manipulation to separate h
From: |
gnunet |
Subject: |
[GNUnet-SVN] [libmicrohttpd] 03/03: Moved bit manipulation to separate header file. |
Date: |
Wed, 17 Apr 2019 19:45:43 +0200 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a commit to branch master
in repository libmicrohttpd.
commit e67fdd04a842d1261a45baaf0ee5820fe48d164f
Author: Evgeny Grin (Karlson2k) <address@hidden>
AuthorDate: Wed Apr 17 17:00:20 2019 +0300
Moved bit manipulation to separate header file.
---
src/microhttpd/Makefile.am | 3 ++-
src/microhttpd/md5.c | 32 +++++-----------------
src/microhttpd/mhd_bithelpers.h | 60 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 68 insertions(+), 27 deletions(-)
diff --git a/src/microhttpd/Makefile.am b/src/microhttpd/Makefile.am
index 64890de3..16db5009 100644
--- a/src/microhttpd/Makefile.am
+++ b/src/microhttpd/Makefile.am
@@ -133,6 +133,7 @@ endif
if ENABLE_DAUTH
libmicrohttpd_la_SOURCES += \
digestauth.c \
+ mhd_bithelpers.h \
md5.c md5.h \
sha256.c sha256.h
endif
@@ -319,7 +320,7 @@ test_http_reasons_SOURCES = \
test_md5_SOURCES = \
test_md5.c test_helpers.h \
- md5.c md5.h
+ md5.c md5.h mhd_bithelpers.h
test_options_SOURCES = \
test_options.c
diff --git a/src/microhttpd/md5.c b/src/microhttpd/md5.c
index a88dd711..7838ac10 100644
--- a/src/microhttpd/md5.c
+++ b/src/microhttpd/md5.c
@@ -20,29 +20,9 @@
#include "md5.h"
#include "mhd_byteorder.h"
+#include "mhd_bithelpers.h"
#include "mhd_assert.h"
-#if _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN
-#define PUT_64BIT_LE(addr, value64) ((*(uint64_t*)(addr)) =
(uint64_t)(value64))
-#define PUT_32BIT_LE(addr, value32) ((*(uint32_t*)(addr)) =
(uint32_t)(value32))
-#else
-#define PUT_64BIT_LE(addr, value) do { \
- (addr)[7] = (uint8_t)((value64) >> 56); \
- (addr)[6] = (uint8_t)((value64) >> 48); \
- (addr)[5] = (uint8_t)((value64) >> 40); \
- (addr)[4] = (uint8_t)((value64) >> 32); \
- (addr)[3] = (uint8_t)((value64) >> 24); \
- (addr)[2] = (uint8_t)((value64) >> 16); \
- (addr)[1] = (uint8_t)((value64) >> 8); \
- (addr)[0] = (uint8_t)((value64)); } while (0)
-
-#define PUT_32BIT_LE(addr, value32) do { \
- (addr)[3] = (uint8_t)((value32) >> 24); \
- (addr)[2] = (uint8_t)((value32) >> 16); \
- (addr)[1] = (uint8_t)((value32) >> 8); \
- (addr)[0] = (uint8_t)((value32)); } while (0)
-#endif
-
/**
* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
@@ -102,14 +82,14 @@ MD5Final (void *ctx_,
/* Put number of bits */
count_bits = ctx->count << 3;
- PUT_64BIT_LE(ctx->buffer + 56, count_bits);
+ _MHD_PUT_64BIT_LE(ctx->buffer + 56, count_bits);
MD5Transform(ctx->state, ctx->buffer);
/* Put digest in LE mode */
- PUT_32BIT_LE(digest, ctx->state[0]);
- PUT_32BIT_LE(digest + 4, ctx->state[1]);
- PUT_32BIT_LE(digest + 8, ctx->state[2]);
- PUT_32BIT_LE(digest + 12, ctx->state[3]);
+ _MHD_PUT_32BIT_LE(digest, ctx->state[0]);
+ _MHD_PUT_32BIT_LE(digest + 4, ctx->state[1]);
+ _MHD_PUT_32BIT_LE(digest + 8, ctx->state[2]);
+ _MHD_PUT_32BIT_LE(digest + 12, ctx->state[3]);
/* Erase buffer */
memset(ctx, 0, sizeof(*ctx));
diff --git a/src/microhttpd/mhd_bithelpers.h b/src/microhttpd/mhd_bithelpers.h
new file mode 100644
index 00000000..d4a47ce4
--- /dev/null
+++ b/src/microhttpd/mhd_bithelpers.h
@@ -0,0 +1,60 @@
+/*
+ This file is part of libmicrohttpd
+ Copyright (C) 2019 Karlson2k (Evgeny Grin)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library.
+ If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * @file microhttpd/mhd_bithelpers.h
+ * @brief macros for bits manipulations
+ * @author Karlson2k (Evgeny Grin)
+ */
+
+#ifndef MHD_BITHELPERS_H
+#define MHD_BITHELPERS_H 1
+
+#include "mhd_byteorder.h"
+#include <stdint.h>
+
+
+#if _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN
+#define _MHD_PUT_64BIT_LE(addr, value64) \
+ ((*(uint64_t*)(addr)) = (uint64_t)(value64))
+#else /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */
+#define _MHD_PUT_64BIT_LE(addr, value64) do { \
+ (uint8_t*(addr))[7] = (uint8_t)((value64) >> 56); \
+ (uint8_t*(addr))[6] = (uint8_t)((value64) >> 48); \
+ (uint8_t*(addr))[5] = (uint8_t)((value64) >> 40); \
+ (uint8_t*(addr))[4] = (uint8_t)((value64) >> 32); \
+ (uint8_t*(addr))[3] = (uint8_t)((value64) >> 24); \
+ (uint8_t*(addr))[2] = (uint8_t)((value64) >> 16); \
+ (uint8_t*(addr))[1] = (uint8_t)((value64) >> 8); \
+ (uint8_t*(addr))[0] = (uint8_t)((value64)); } while (0)
+#endif /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */
+
+#if _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN
+#define _MHD_PUT_32BIT_LE(addr, value32) \
+ ((*(uint32_t*)(addr)) = (uint32_t)(value32))
+#else /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */
+
+#define _MHD_PUT_32BIT_LE(addr, value32) do { \
+ (uint8_t*(addr))[3] = (uint8_t)((value32) >> 24); \
+ (uint8_t*(addr))[2] = (uint8_t)((value32) >> 16); \
+ (uint8_t*(addr))[1] = (uint8_t)((value32) >> 8); \
+ (uint8_t*(addr))[0] = (uint8_t)((value32)); } while (0)
+#endif /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */
+
+#endif /* ! MHD_BITHELPERS_H */
--
To stop receiving notification emails like this one, please contact
address@hidden