cmake: fix building with both md4 and md5 in unity mode

Macro and static function names were colliding between
`lib/md4.c` and
`lib/md5.c`.

Fix it by namespacing these symbols.

Seen with a basic macOS build using these options:
`-DCMAKE_UNITY_BUILD=ON -DCURL_USE_SECTRANSP=ON`

Closes #13737
This commit is contained in:
Viktor Szakats 2024-05-21 22:31:12 +02:00
parent 4cc5657247
commit ca8cb245e1
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
2 changed files with 144 additions and 142 deletions

161
lib/md5.c
View file

@ -304,16 +304,16 @@ static void my_md5_final(unsigned char *result, my_md5_ctx *ctx);
* architectures that lack an AND-NOT instruction, just like in Colin Plumb's
* implementation.
*/
#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
#define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y))))
#define H(x, y, z) (((x) ^ (y)) ^ (z))
#define H2(x, y, z) ((x) ^ ((y) ^ (z)))
#define I(x, y, z) ((y) ^ ((x) | ~(z)))
#define MD5_F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
#define MD5_G(x, y, z) ((y) ^ ((z) & ((x) ^ (y))))
#define MD5_H(x, y, z) (((x) ^ (y)) ^ (z))
#define MD5_H2(x, y, z) ((x) ^ ((y) ^ (z)))
#define MD5_I(x, y, z) ((y) ^ ((x) | ~(z)))
/*
* The MD5 transformation for all four rounds.
*/
#define STEP(f, a, b, c, d, x, t, s) \
#define MD5_STEP(f, a, b, c, d, x, t, s) \
(a) += f((b), (c), (d)) + (x) + (t); \
(a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \
(a) += (b);
@ -327,18 +327,18 @@ static void my_md5_final(unsigned char *result, my_md5_ctx *ctx);
* doesn't work.
*/
#if defined(__i386__) || defined(__x86_64__) || defined(__vax__)
#define SET(n) \
#define MD5_SET(n) \
(*(MD5_u32plus *)(void *)&ptr[(n) * 4])
#define GET(n) \
SET(n)
#define MD5_GET(n) \
MD5_SET(n)
#else
#define SET(n) \
#define MD5_SET(n) \
(ctx->block[(n)] = \
(MD5_u32plus)ptr[(n) * 4] | \
((MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \
((MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \
((MD5_u32plus)ptr[(n) * 4 + 3] << 24))
#define GET(n) \
#define MD5_GET(n) \
(ctx->block[(n)])
#endif
@ -346,7 +346,8 @@ static void my_md5_final(unsigned char *result, my_md5_ctx *ctx);
* This processes one or more 64-byte data blocks, but does NOT update
* the bit counters. There are no alignment requirements.
*/
static const void *body(my_md5_ctx *ctx, const void *data, unsigned long size)
static const void *my_md5_body(my_md5_ctx *ctx,
const void *data, unsigned long size)
{
const unsigned char *ptr;
MD5_u32plus a, b, c, d;
@ -367,76 +368,76 @@ static const void *body(my_md5_ctx *ctx, const void *data, unsigned long size)
saved_d = d;
/* Round 1 */
STEP(F, a, b, c, d, SET(0), 0xd76aa478, 7)
STEP(F, d, a, b, c, SET(1), 0xe8c7b756, 12)
STEP(F, c, d, a, b, SET(2), 0x242070db, 17)
STEP(F, b, c, d, a, SET(3), 0xc1bdceee, 22)
STEP(F, a, b, c, d, SET(4), 0xf57c0faf, 7)
STEP(F, d, a, b, c, SET(5), 0x4787c62a, 12)
STEP(F, c, d, a, b, SET(6), 0xa8304613, 17)
STEP(F, b, c, d, a, SET(7), 0xfd469501, 22)
STEP(F, a, b, c, d, SET(8), 0x698098d8, 7)
STEP(F, d, a, b, c, SET(9), 0x8b44f7af, 12)
STEP(F, c, d, a, b, SET(10), 0xffff5bb1, 17)
STEP(F, b, c, d, a, SET(11), 0x895cd7be, 22)
STEP(F, a, b, c, d, SET(12), 0x6b901122, 7)
STEP(F, d, a, b, c, SET(13), 0xfd987193, 12)
STEP(F, c, d, a, b, SET(14), 0xa679438e, 17)
STEP(F, b, c, d, a, SET(15), 0x49b40821, 22)
MD5_STEP(MD5_F, a, b, c, d, MD5_SET(0), 0xd76aa478, 7)
MD5_STEP(MD5_F, d, a, b, c, MD5_SET(1), 0xe8c7b756, 12)
MD5_STEP(MD5_F, c, d, a, b, MD5_SET(2), 0x242070db, 17)
MD5_STEP(MD5_F, b, c, d, a, MD5_SET(3), 0xc1bdceee, 22)
MD5_STEP(MD5_F, a, b, c, d, MD5_SET(4), 0xf57c0faf, 7)
MD5_STEP(MD5_F, d, a, b, c, MD5_SET(5), 0x4787c62a, 12)
MD5_STEP(MD5_F, c, d, a, b, MD5_SET(6), 0xa8304613, 17)
MD5_STEP(MD5_F, b, c, d, a, MD5_SET(7), 0xfd469501, 22)
MD5_STEP(MD5_F, a, b, c, d, MD5_SET(8), 0x698098d8, 7)
MD5_STEP(MD5_F, d, a, b, c, MD5_SET(9), 0x8b44f7af, 12)
MD5_STEP(MD5_F, c, d, a, b, MD5_SET(10), 0xffff5bb1, 17)
MD5_STEP(MD5_F, b, c, d, a, MD5_SET(11), 0x895cd7be, 22)
MD5_STEP(MD5_F, a, b, c, d, MD5_SET(12), 0x6b901122, 7)
MD5_STEP(MD5_F, d, a, b, c, MD5_SET(13), 0xfd987193, 12)
MD5_STEP(MD5_F, c, d, a, b, MD5_SET(14), 0xa679438e, 17)
MD5_STEP(MD5_F, b, c, d, a, MD5_SET(15), 0x49b40821, 22)
/* Round 2 */
STEP(G, a, b, c, d, GET(1), 0xf61e2562, 5)
STEP(G, d, a, b, c, GET(6), 0xc040b340, 9)
STEP(G, c, d, a, b, GET(11), 0x265e5a51, 14)
STEP(G, b, c, d, a, GET(0), 0xe9b6c7aa, 20)
STEP(G, a, b, c, d, GET(5), 0xd62f105d, 5)
STEP(G, d, a, b, c, GET(10), 0x02441453, 9)
STEP(G, c, d, a, b, GET(15), 0xd8a1e681, 14)
STEP(G, b, c, d, a, GET(4), 0xe7d3fbc8, 20)
STEP(G, a, b, c, d, GET(9), 0x21e1cde6, 5)
STEP(G, d, a, b, c, GET(14), 0xc33707d6, 9)
STEP(G, c, d, a, b, GET(3), 0xf4d50d87, 14)
STEP(G, b, c, d, a, GET(8), 0x455a14ed, 20)
STEP(G, a, b, c, d, GET(13), 0xa9e3e905, 5)
STEP(G, d, a, b, c, GET(2), 0xfcefa3f8, 9)
STEP(G, c, d, a, b, GET(7), 0x676f02d9, 14)
STEP(G, b, c, d, a, GET(12), 0x8d2a4c8a, 20)
MD5_STEP(MD5_G, a, b, c, d, MD5_GET(1), 0xf61e2562, 5)
MD5_STEP(MD5_G, d, a, b, c, MD5_GET(6), 0xc040b340, 9)
MD5_STEP(MD5_G, c, d, a, b, MD5_GET(11), 0x265e5a51, 14)
MD5_STEP(MD5_G, b, c, d, a, MD5_GET(0), 0xe9b6c7aa, 20)
MD5_STEP(MD5_G, a, b, c, d, MD5_GET(5), 0xd62f105d, 5)
MD5_STEP(MD5_G, d, a, b, c, MD5_GET(10), 0x02441453, 9)
MD5_STEP(MD5_G, c, d, a, b, MD5_GET(15), 0xd8a1e681, 14)
MD5_STEP(MD5_G, b, c, d, a, MD5_GET(4), 0xe7d3fbc8, 20)
MD5_STEP(MD5_G, a, b, c, d, MD5_GET(9), 0x21e1cde6, 5)
MD5_STEP(MD5_G, d, a, b, c, MD5_GET(14), 0xc33707d6, 9)
MD5_STEP(MD5_G, c, d, a, b, MD5_GET(3), 0xf4d50d87, 14)
MD5_STEP(MD5_G, b, c, d, a, MD5_GET(8), 0x455a14ed, 20)
MD5_STEP(MD5_G, a, b, c, d, MD5_GET(13), 0xa9e3e905, 5)
MD5_STEP(MD5_G, d, a, b, c, MD5_GET(2), 0xfcefa3f8, 9)
MD5_STEP(MD5_G, c, d, a, b, MD5_GET(7), 0x676f02d9, 14)
MD5_STEP(MD5_G, b, c, d, a, MD5_GET(12), 0x8d2a4c8a, 20)
/* Round 3 */
STEP(H, a, b, c, d, GET(5), 0xfffa3942, 4)
STEP(H2, d, a, b, c, GET(8), 0x8771f681, 11)
STEP(H, c, d, a, b, GET(11), 0x6d9d6122, 16)
STEP(H2, b, c, d, a, GET(14), 0xfde5380c, 23)
STEP(H, a, b, c, d, GET(1), 0xa4beea44, 4)
STEP(H2, d, a, b, c, GET(4), 0x4bdecfa9, 11)
STEP(H, c, d, a, b, GET(7), 0xf6bb4b60, 16)
STEP(H2, b, c, d, a, GET(10), 0xbebfbc70, 23)
STEP(H, a, b, c, d, GET(13), 0x289b7ec6, 4)
STEP(H2, d, a, b, c, GET(0), 0xeaa127fa, 11)
STEP(H, c, d, a, b, GET(3), 0xd4ef3085, 16)
STEP(H2, b, c, d, a, GET(6), 0x04881d05, 23)
STEP(H, a, b, c, d, GET(9), 0xd9d4d039, 4)
STEP(H2, d, a, b, c, GET(12), 0xe6db99e5, 11)
STEP(H, c, d, a, b, GET(15), 0x1fa27cf8, 16)
STEP(H2, b, c, d, a, GET(2), 0xc4ac5665, 23)
MD5_STEP(MD5_H, a, b, c, d, MD5_GET(5), 0xfffa3942, 4)
MD5_STEP(MD5_H2, d, a, b, c, MD5_GET(8), 0x8771f681, 11)
MD5_STEP(MD5_H, c, d, a, b, MD5_GET(11), 0x6d9d6122, 16)
MD5_STEP(MD5_H2, b, c, d, a, MD5_GET(14), 0xfde5380c, 23)
MD5_STEP(MD5_H, a, b, c, d, MD5_GET(1), 0xa4beea44, 4)
MD5_STEP(MD5_H2, d, a, b, c, MD5_GET(4), 0x4bdecfa9, 11)
MD5_STEP(MD5_H, c, d, a, b, MD5_GET(7), 0xf6bb4b60, 16)
MD5_STEP(MD5_H2, b, c, d, a, MD5_GET(10), 0xbebfbc70, 23)
MD5_STEP(MD5_H, a, b, c, d, MD5_GET(13), 0x289b7ec6, 4)
MD5_STEP(MD5_H2, d, a, b, c, MD5_GET(0), 0xeaa127fa, 11)
MD5_STEP(MD5_H, c, d, a, b, MD5_GET(3), 0xd4ef3085, 16)
MD5_STEP(MD5_H2, b, c, d, a, MD5_GET(6), 0x04881d05, 23)
MD5_STEP(MD5_H, a, b, c, d, MD5_GET(9), 0xd9d4d039, 4)
MD5_STEP(MD5_H2, d, a, b, c, MD5_GET(12), 0xe6db99e5, 11)
MD5_STEP(MD5_H, c, d, a, b, MD5_GET(15), 0x1fa27cf8, 16)
MD5_STEP(MD5_H2, b, c, d, a, MD5_GET(2), 0xc4ac5665, 23)
/* Round 4 */
STEP(I, a, b, c, d, GET(0), 0xf4292244, 6)
STEP(I, d, a, b, c, GET(7), 0x432aff97, 10)
STEP(I, c, d, a, b, GET(14), 0xab9423a7, 15)
STEP(I, b, c, d, a, GET(5), 0xfc93a039, 21)
STEP(I, a, b, c, d, GET(12), 0x655b59c3, 6)
STEP(I, d, a, b, c, GET(3), 0x8f0ccc92, 10)
STEP(I, c, d, a, b, GET(10), 0xffeff47d, 15)
STEP(I, b, c, d, a, GET(1), 0x85845dd1, 21)
STEP(I, a, b, c, d, GET(8), 0x6fa87e4f, 6)
STEP(I, d, a, b, c, GET(15), 0xfe2ce6e0, 10)
STEP(I, c, d, a, b, GET(6), 0xa3014314, 15)
STEP(I, b, c, d, a, GET(13), 0x4e0811a1, 21)
STEP(I, a, b, c, d, GET(4), 0xf7537e82, 6)
STEP(I, d, a, b, c, GET(11), 0xbd3af235, 10)
STEP(I, c, d, a, b, GET(2), 0x2ad7d2bb, 15)
STEP(I, b, c, d, a, GET(9), 0xeb86d391, 21)
MD5_STEP(MD5_I, a, b, c, d, MD5_GET(0), 0xf4292244, 6)
MD5_STEP(MD5_I, d, a, b, c, MD5_GET(7), 0x432aff97, 10)
MD5_STEP(MD5_I, c, d, a, b, MD5_GET(14), 0xab9423a7, 15)
MD5_STEP(MD5_I, b, c, d, a, MD5_GET(5), 0xfc93a039, 21)
MD5_STEP(MD5_I, a, b, c, d, MD5_GET(12), 0x655b59c3, 6)
MD5_STEP(MD5_I, d, a, b, c, MD5_GET(3), 0x8f0ccc92, 10)
MD5_STEP(MD5_I, c, d, a, b, MD5_GET(10), 0xffeff47d, 15)
MD5_STEP(MD5_I, b, c, d, a, MD5_GET(1), 0x85845dd1, 21)
MD5_STEP(MD5_I, a, b, c, d, MD5_GET(8), 0x6fa87e4f, 6)
MD5_STEP(MD5_I, d, a, b, c, MD5_GET(15), 0xfe2ce6e0, 10)
MD5_STEP(MD5_I, c, d, a, b, MD5_GET(6), 0xa3014314, 15)
MD5_STEP(MD5_I, b, c, d, a, MD5_GET(13), 0x4e0811a1, 21)
MD5_STEP(MD5_I, a, b, c, d, MD5_GET(4), 0xf7537e82, 6)
MD5_STEP(MD5_I, d, a, b, c, MD5_GET(11), 0xbd3af235, 10)
MD5_STEP(MD5_I, c, d, a, b, MD5_GET(2), 0x2ad7d2bb, 15)
MD5_STEP(MD5_I, b, c, d, a, MD5_GET(9), 0xeb86d391, 21)
a += saved_a;
b += saved_b;
@ -492,11 +493,11 @@ static void my_md5_update(my_md5_ctx *ctx, const void *data,
memcpy(&ctx->buffer[used], data, available);
data = (const unsigned char *)data + available;
size -= available;
body(ctx, ctx->buffer, 64);
my_md5_body(ctx, ctx->buffer, 64);
}
if(size >= 64) {
data = body(ctx, data, size & ~(unsigned long)0x3f);
data = my_md5_body(ctx, data, size & ~(unsigned long)0x3f);
size &= 0x3f;
}
@ -515,7 +516,7 @@ static void my_md5_final(unsigned char *result, my_md5_ctx *ctx)
if(available < 8) {
memset(&ctx->buffer[used], 0, available);
body(ctx, ctx->buffer, 64);
my_md5_body(ctx, ctx->buffer, 64);
used = 0;
available = 64;
}
@ -532,7 +533,7 @@ static void my_md5_final(unsigned char *result, my_md5_ctx *ctx)
ctx->buffer[62] = curlx_ultouc((ctx->hi >> 16)&0xff);
ctx->buffer[63] = curlx_ultouc(ctx->hi >> 24);
body(ctx, ctx->buffer, 64);
my_md5_body(ctx, ctx->buffer, 64);
result[0] = curlx_ultouc((ctx->a)&0xff);
result[1] = curlx_ultouc((ctx->a >> 8)&0xff);