Skip to content

Commit b9d7d16

Browse files
authored
Merge pull request doxygen#11604 from gruenich/feature/cleanup-libmd5
[libmd5] Smaller code cleanups
2 parents 7165996 + 817d9af commit b9d7d16

File tree

1 file changed

+12
-24
lines changed

1 file changed

+12
-24
lines changed

deps/libmd5/md5.c

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ detectEndianess()
3737
int nl = 0x12345678;
3838
short ns = 0x1234;
3939

40-
unsigned char *p = (unsigned char *)(&nl);
41-
unsigned char *sp = (unsigned char *)(&ns);
40+
const unsigned char *p = (unsigned char *)(&nl);
41+
const unsigned char *sp = (unsigned char *)(&ns);
4242

4343
if (g_endianessDetected) return;
4444
if ( p[0] == 0x12 && p[1] == 0x34 && p[2] == 0x56 && p[3] == 0x78 )
@@ -60,11 +60,9 @@ detectEndianess()
6060
static void
6161
byteSwap(UWORD32 *buf, unsigned words)
6262
{
63-
md5byte *p;
64-
6563
if (!g_bigEndian) return;
6664

67-
p = (md5byte *)buf;
65+
md5byte *p = (md5byte *)buf;
6866

6967
do {
7068
*buf++ = (UWORD32)((unsigned)p[3] << 8 | p[2]) << 16 |
@@ -98,11 +96,9 @@ MD5Init(struct MD5Context *ctx)
9896
void
9997
MD5Update(struct MD5Context *ctx, md5byte const *buf, unsigned len)
10098
{
101-
UWORD32 t;
102-
10399
/* Update byte count */
104100

105-
t = ctx->bytes[0];
101+
UWORD32 t = ctx->bytes[0];
106102
if ((ctx->bytes[0] = t + len) < t)
107103
ctx->bytes[1]++; /* Carry from low to high */
108104

@@ -189,12 +185,10 @@ MD5Final(md5byte digest[16], struct MD5Context *ctx)
189185
void
190186
MD5Transform(UWORD32 buf[4], UWORD32 const in[16])
191187
{
192-
UWORD32 a, b, c, d;
193-
194-
a = buf[0];
195-
b = buf[1];
196-
c = buf[2];
197-
d = buf[3];
188+
UWORD32 a = buf[0];
189+
UWORD32 b = buf[1];
190+
UWORD32 c = buf[2];
191+
UWORD32 d = buf[3];
198192

199193
MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
200194
MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
@@ -284,24 +278,18 @@ void MD5Buffer (const char *buf,unsigned int len,unsigned char sig[16])
284278

285279
void MD5SigToString(unsigned char signature[16],char str[33])
286280
{
287-
unsigned char *sig_p;
288-
char *str_p;
289-
unsigned int high, low;
281+
char *str_p = str;
290282

291-
str_p = str;
292-
293-
for (sig_p = (unsigned char *)signature;
283+
for (unsigned char *sig_p = (unsigned char *)signature;
294284
sig_p < (unsigned char *)signature + 16;
295285
sig_p++)
296286
{
297-
high = *sig_p / 16;
298-
low = *sig_p % 16;
287+
unsigned int high = *sig_p / 16;
288+
unsigned int low = *sig_p % 16;
299289
/* account for 2 chars */
300290
*str_p++ = HEX_STRING[high];
301291
*str_p++ = HEX_STRING[low];
302292
}
303293
/* account for 1 terminator */
304294
*str_p++ = '\0';
305295
}
306-
307-

0 commit comments

Comments
 (0)