Skip to content

Commit 62e6a72

Browse files
committed
fix md5
1 parent bfc0a99 commit 62e6a72

File tree

3 files changed

+29
-35
lines changed

3 files changed

+29
-35
lines changed

Sources/CMD5/md5.c renamed to Sources/CMD5/cmd5.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@
3535
* compile-time configuration.
3636
*/
3737

38-
#ifndef HAVE_OPENSSL
39-
4038
#include <string.h>
4139

42-
#include "md5.h"
40+
#include "cmd5.h"
4341

4442
/*
4543
* The basic MD5 functions.
@@ -79,16 +77,16 @@
7977
*/
8078
#if defined(__i386__) || defined(__x86_64__) || defined(__vax__)
8179
#define SET(n) \
82-
(*(MD5_u32plus *)&ptr[(n) * 4])
80+
(*(CMD5_u32plus *)&ptr[(n) * 4])
8381
#define GET(n) \
8482
SET(n)
8583
#else
8684
#define SET(n) \
8785
(ctx->block[(n)] = \
88-
(MD5_u32plus)ptr[(n) * 4] | \
89-
((MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \
90-
((MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \
91-
((MD5_u32plus)ptr[(n) * 4 + 3] << 24))
86+
(CMD5_u32plus)ptr[(n) * 4] | \
87+
((CMD5_u32plus)ptr[(n) * 4 + 1] << 8) | \
88+
((CMD5_u32plus)ptr[(n) * 4 + 2] << 16) | \
89+
((CMD5_u32plus)ptr[(n) * 4 + 3] << 24))
9290
#define GET(n) \
9391
(ctx->block[(n)])
9492
#endif
@@ -97,11 +95,11 @@ SET(n)
9795
* This processes one or more 64-byte data blocks, but does NOT update the bit
9896
* counters. There are no alignment requirements.
9997
*/
100-
static const void *body(MD5_CTX *ctx, const void *data, unsigned long size)
98+
static const void *body(CMD5_CTX *ctx, const void *data, unsigned long size)
10199
{
102100
const unsigned char *ptr;
103-
MD5_u32plus a, b, c, d;
104-
MD5_u32plus saved_a, saved_b, saved_c, saved_d;
101+
CMD5_u32plus a, b, c, d;
102+
CMD5_u32plus saved_a, saved_b, saved_c, saved_d;
105103

106104
ptr = (const unsigned char *)data;
107105

@@ -204,7 +202,7 @@ static const void *body(MD5_CTX *ctx, const void *data, unsigned long size)
204202
return ptr;
205203
}
206204

207-
void MD5_Init(MD5_CTX *ctx)
205+
void CMD5_Init(CMD5_CTX *ctx)
208206
{
209207
ctx->a = 0x67452301;
210208
ctx->b = 0xefcdab89;
@@ -215,9 +213,9 @@ void MD5_Init(MD5_CTX *ctx)
215213
ctx->hi = 0;
216214
}
217215

218-
void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size)
216+
void CMD5_Update(CMD5_CTX *ctx, const void *data, unsigned long size)
219217
{
220-
MD5_u32plus saved_lo;
218+
CMD5_u32plus saved_lo;
221219
unsigned long used, available;
222220

223221
saved_lo = ctx->lo;
@@ -255,7 +253,7 @@ void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size)
255253
(dst)[2] = (unsigned char)((src) >> 16); \
256254
(dst)[3] = (unsigned char)((src) >> 24);
257255

258-
void MD5_Final(unsigned char *result, MD5_CTX *ctx)
256+
void CMD5_Final(unsigned char *result, CMD5_CTX *ctx)
259257
{
260258
unsigned long used, available;
261259

@@ -287,5 +285,3 @@ void MD5_Final(unsigned char *result, MD5_CTX *ctx)
287285

288286
memset(ctx, 0, sizeof(*ctx));
289287
}
290-
291-
#endif

Sources/CMD5/include/md5.h renamed to Sources/CMD5/include/cmd5.h

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,22 @@
2222
*
2323
* See md5.c for more information.
2424
*/
25-
26-
#ifdef HAVE_OPENSSL
27-
#include <openssl/md5.h>
28-
#elif !defined(_MD5_H)
29-
#define _MD5_H
25+
26+
#ifndef CMD5_H
27+
#define CMD5_H
3028

3129
/* Any 32-bit or wider unsigned integer data type will do */
32-
typedef unsigned int MD5_u32plus;
30+
typedef unsigned int CMD5_u32plus;
3331

3432
typedef struct {
35-
MD5_u32plus lo, hi;
36-
MD5_u32plus a, b, c, d;
33+
CMD5_u32plus lo, hi;
34+
CMD5_u32plus a, b, c, d;
3735
unsigned char buffer[64];
38-
MD5_u32plus block[16];
39-
} MD5_CTX;
40-
41-
extern void MD5_Init(MD5_CTX *ctx);
42-
extern void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size);
43-
extern void MD5_Final(unsigned char *result, MD5_CTX *ctx);
36+
CMD5_u32plus block[16];
37+
} CMD5_CTX;
4438

39+
extern void CMD5_Init(CMD5_CTX *ctx);
40+
extern void CMD5_Update(CMD5_CTX *ctx, const void *data, unsigned long size);
41+
extern void CMD5_Final(unsigned char *result, CMD5_CTX *ctx);
42+
4543
#endif

Sources/PostgresNIO/Connection/PostgresConnection+Authenticate.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ private final class PostgresAuthenticationRequest: PostgresRequest {
9595

9696
private func md5(_ message: [UInt8]) -> [UInt8] {
9797
var message = message
98-
var ctx = MD5_CTX()
99-
MD5_Init(&ctx)
100-
MD5_Update(&ctx, &message, numericCast(message.count))
98+
var ctx = CMD5_CTX()
99+
CMD5_Init(&ctx)
100+
CMD5_Update(&ctx, &message, numericCast(message.count))
101101
var digest = [UInt8](repeating: 0, count: 16)
102-
MD5_Final(&digest, &ctx)
102+
CMD5_Final(&digest, &ctx)
103103
return digest
104104
}
105105

0 commit comments

Comments
 (0)