diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2019-04-19 22:35:15 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2019-04-19 22:35:15 +0300 |
commit | f5970c7804f6bb6f5d99172e048d7a126657b570 (patch) | |
tree | e961f3f3628345840dcf11c51ec2bae34aa252b7 | |
parent | a50b4d566f089ae46402a6f38096a0ff9c50eae2 (diff) | |
download | libmicrohttpd-f5970c7804f6bb6f5d99172e048d7a126657b570.tar.gz libmicrohttpd-f5970c7804f6bb6f5d99172e048d7a126657b570.zip |
mhd_bithelpers.h: define _MHD_GET_32BIT_LE() and use it in md5.c
-rw-r--r-- | src/microhttpd/md5.c | 18 | ||||
-rw-r--r-- | 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_, | |||
96 | } | 96 | } |
97 | 97 | ||
98 | 98 | ||
99 | /** | ||
100 | * Number of bytes in single SHA-256 word | ||
101 | * used to process data | ||
102 | */ | ||
103 | #define MD5_BYTES_IN_WORD (32 / 8) | ||
104 | |||
99 | /* The four core functions - F1 is optimized somewhat */ | 105 | /* The four core functions - F1 is optimized somewhat */ |
100 | 106 | ||
101 | /* #define F1(x, y, z) (x & y | ~x & z) */ | 107 | /* #define F1(x, y, z) (x & y | ~x & z) */ |
@@ -122,14 +128,12 @@ MD5Transform (uint32_t state[4], | |||
122 | #if _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN | 128 | #if _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN |
123 | const uint32_t *in = (const uint32_t *)block; | 129 | const uint32_t *in = (const uint32_t *)block; |
124 | #else | 130 | #else |
125 | uint32_t in[MD5_BLOCK_SIZE / 4]; | 131 | uint32_t in[MD5_BLOCK_SIZE / MD5_BYTES_IN_WORD]; |
126 | for (a = 0; a < MD5_BLOCK_SIZE / 4; a++) | 132 | int i; |
133 | |||
134 | for (i = 0; i < MD5_BLOCK_SIZE / MD5_BYTES_IN_WORD; i++) | ||
127 | { | 135 | { |
128 | in[a] = (uint32_t)( | 136 | in[i] = _MHD_GET_32BIT_LE(block + i * MD5_BYTES_IN_WORD); |
129 | (uint32_t)(block[a * 4 + 0]) | | ||
130 | (uint32_t)(block[a * 4 + 1]) << 8 | | ||
131 | (uint32_t)(block[a * 4 + 2]) << 16 | | ||
132 | (uint32_t)(block[a * 4 + 3]) << 24); | ||
133 | } | 137 | } |
134 | #endif | 138 | #endif |
135 | 139 | ||
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 @@ | |||
101 | } while (0) | 101 | } while (0) |
102 | #endif /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */ | 102 | #endif /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */ |
103 | 103 | ||
104 | /* _MHD_GET_32BIT_LE (addr) | ||
105 | * get little-endian 32-bit value storied at addr | ||
106 | * and return it in native-endian mode. | ||
107 | */ | ||
108 | #if _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN | ||
109 | #define _MHD_GET_32BIT_LE(addr) \ | ||
110 | (*(uint32_t*)(addr)) | ||
111 | #elif _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN | ||
112 | #define _MHD_GET_32BIT_LE(addr) \ | ||
113 | _MHD_BYTES_SWAP32(*(uint32_t*)(addr)) | ||
114 | #else /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */ | ||
115 | /* Endianess was not detected or non-standard like PDP-endian */ | ||
116 | #define _MHD_GET_32BIT_LE(addr) \ | ||
117 | ( ( (uint32_t)(((uint8_t*)addr)[0])) | \ | ||
118 | (((uint32_t)(((uint8_t*)addr)[1])) << 8) | \ | ||
119 | (((uint32_t)(((uint8_t*)addr)[2])) << 16) | \ | ||
120 | (((uint32_t)(((uint8_t*)addr)[3])) << 24) ) | ||
121 | #endif /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */ | ||
122 | |||
104 | 123 | ||
105 | /* _MHD_PUT_64BIT_BE (addr, value64) | 124 | /* _MHD_PUT_64BIT_BE (addr, value64) |
106 | * put native-endian 64-bit value64 to addr | 125 | * put native-endian 64-bit value64 to addr |