Skip to content

Commit d113e2a

Browse files
committed
(libretro-common) Remove custom MD5 typedefs
1 parent 96ec45a commit d113e2a

3 files changed

Lines changed: 24 additions & 28 deletions

File tree

libretro-common/include/lrc_hash.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,11 @@ typedef CC_MD5_CTX MD5_CTX;
7272
#define MD5_Final CC_MD5_Final
7373
#else
7474

75-
/* Any 32-bit or wider unsigned integer data type will do */
76-
typedef unsigned int MD5_u32plus;
77-
7875
typedef struct {
79-
MD5_u32plus lo, hi;
80-
MD5_u32plus a, b, c, d;
76+
uint32_t lo, hi;
77+
uint32_t a, b, c, d;
8178
unsigned char buffer[64];
82-
MD5_u32plus block[16];
79+
uint32_t block[16];
8380
} MD5_CTX;
8481

8582
/*

libretro-common/include/utils/md5.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,16 @@
2828
#elif !defined(_MD5_H)
2929
#define _MD5_H
3030

31+
#include <stdint.h>
3132
#include <retro_common_api.h>
3233

3334
RETRO_BEGIN_DECLS
3435

35-
/* Any 32-bit or wider unsigned integer data type will do */
36-
typedef unsigned int MD5_u32plus;
37-
3836
typedef struct {
39-
MD5_u32plus lo, hi;
40-
MD5_u32plus a, b, c, d;
37+
uint32_t lo, hi;
38+
uint32_t a, b, c, d;
4139
unsigned char buffer[64];
42-
MD5_u32plus block[16];
40+
uint32_t block[16];
4341
} MD5_CTX;
4442

4543
extern void MD5_Init(MD5_CTX *ctx);

libretro-common/utils/md5.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
*/
3737
#include <lrc_hash.h>
3838

39+
#include <stdint.h>
3940
#include <string.h>
4041

4142
/*
@@ -69,16 +70,16 @@
6970
*/
7071
#if defined(__i386__) || defined(__x86_64__) || defined(__vax__)
7172
#define MD5_SET(n) \
72-
(*(MD5_u32plus *)&ptr[(n) * 4])
73+
(*(uint32_t*)&ptr[(n) * 4])
7374
#define MD5_GET(n) \
7475
MD5_SET(n)
7576
#else
7677
#define MD5_SET(n) \
7778
(ctx->block[(n)] = \
78-
(MD5_u32plus)ptr[(n) * 4] | \
79-
((MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \
80-
((MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \
81-
((MD5_u32plus)ptr[(n) * 4 + 3] << 24))
79+
(uint32_t)ptr[(n) * 4] | \
80+
((uint32_t)ptr[(n) * 4 + 1] << 8) | \
81+
((uint32_t)ptr[(n) * 4 + 2] << 16) | \
82+
((uint32_t)ptr[(n) * 4 + 3] << 24))
8283
#define MD5_GET(n) \
8384
(ctx->block[(n)])
8485
#endif
@@ -89,20 +90,20 @@
8990
*/
9091
static const void *MD5_body(MD5_CTX *ctx, const void *data, unsigned long size)
9192
{
92-
MD5_u32plus saved_a, saved_b, saved_c, saved_d;
93+
uint32_t saved_a, saved_b, saved_c, saved_d;
9394
const unsigned char *ptr = (const unsigned char *)data;
94-
MD5_u32plus a = ctx->a;
95-
MD5_u32plus b = ctx->b;
96-
MD5_u32plus c = ctx->c;
97-
MD5_u32plus d = ctx->d;
95+
uint32_t a = ctx->a;
96+
uint32_t b = ctx->b;
97+
uint32_t c = ctx->c;
98+
uint32_t d = ctx->d;
9899

99100
do {
100101
saved_a = a;
101102
saved_b = b;
102103
saved_c = c;
103104
saved_d = d;
104105

105-
/* Round 1 */
106+
/* Round 1 */
106107
MD5_STEP(MD5_F, a, b, c, d, MD5_SET(0), 0xd76aa478, 7)
107108
MD5_STEP(MD5_F, d, a, b, c, MD5_SET(1), 0xe8c7b756, 12)
108109
MD5_STEP(MD5_F, c, d, a, b, MD5_SET(2), 0x242070db, 17)
@@ -120,7 +121,7 @@ static const void *MD5_body(MD5_CTX *ctx, const void *data, unsigned long size)
120121
MD5_STEP(MD5_F, c, d, a, b, MD5_SET(14), 0xa679438e, 17)
121122
MD5_STEP(MD5_F, b, c, d, a, MD5_SET(15), 0x49b40821, 22)
122123

123-
/* Round 2 */
124+
/* Round 2 */
124125
MD5_STEP(MD5_G, a, b, c, d, MD5_GET(1), 0xf61e2562, 5)
125126
MD5_STEP(MD5_G, d, a, b, c, MD5_GET(6), 0xc040b340, 9)
126127
MD5_STEP(MD5_G, c, d, a, b, MD5_GET(11), 0x265e5a51, 14)
@@ -138,7 +139,7 @@ static const void *MD5_body(MD5_CTX *ctx, const void *data, unsigned long size)
138139
MD5_STEP(MD5_G, c, d, a, b, MD5_GET(7), 0x676f02d9, 14)
139140
MD5_STEP(MD5_G, b, c, d, a, MD5_GET(12), 0x8d2a4c8a, 20)
140141

141-
/* Round 3 */
142+
/* Round 3 */
142143
MD5_STEP(MD5_H, a, b, c, d, MD5_GET(5), 0xfffa3942, 4)
143144
MD5_STEP(MD5_H2, d, a, b, c, MD5_GET(8), 0x8771f681, 11)
144145
MD5_STEP(MD5_H, c, d, a, b, MD5_GET(11), 0x6d9d6122, 16)
@@ -156,7 +157,7 @@ static const void *MD5_body(MD5_CTX *ctx, const void *data, unsigned long size)
156157
MD5_STEP(MD5_H, c, d, a, b, MD5_GET(15), 0x1fa27cf8, 16)
157158
MD5_STEP(MD5_H2, b, c, d, a, MD5_GET(2), 0xc4ac5665, 23)
158159

159-
/* Round 4 */
160+
/* Round 4 */
160161
MD5_STEP(MD5_I, a, b, c, d, MD5_GET(0), 0xf4292244, 6)
161162
MD5_STEP(MD5_I, d, a, b, c, MD5_GET(7), 0x432aff97, 10)
162163
MD5_STEP(MD5_I, c, d, a, b, MD5_GET(14), 0xab9423a7, 15)
@@ -203,8 +204,8 @@ void MD5_Init(MD5_CTX *ctx)
203204

204205
void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size)
205206
{
206-
unsigned long used;
207-
MD5_u32plus saved_lo = ctx->lo;
207+
uint32_t used;
208+
uint32_t saved_lo = ctx->lo;
208209
if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo)
209210
ctx->hi++;
210211
ctx->hi += size >> 29;

0 commit comments

Comments
 (0)