summaryrefslogtreecommitdiff
path: root/libwardrobe
diff options
context:
space:
mode:
Diffstat (limited to 'libwardrobe')
-rw-r--r--libwardrobe/src/md5.c41
1 files changed, 21 insertions, 20 deletions
diff --git a/libwardrobe/src/md5.c b/libwardrobe/src/md5.c
index 4b8d038..b028451 100644
--- a/libwardrobe/src/md5.c
+++ b/libwardrobe/src/md5.c
@@ -23,6 +23,7 @@ documentation and/or software.
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdint.h>
#include "md5.h"
@@ -46,8 +47,8 @@ documentation and/or software.
/* MD5 context. */
typedef struct {
- unsigned long int state[4]; /* state (ABCD) */
- unsigned long int count[2]; /* number of bits, modulo 2^64 (lsb first) */
+ uint32_t state[4]; /* state (ABCD) */
+ uint32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */
unsigned char buffer[64]; /* input buffer */
} MD5_CTX;
@@ -55,9 +56,9 @@ static void MD5Init (MD5_CTX *);
static void MD5Update (MD5_CTX *, unsigned char *, unsigned int);
static void MD5Final (unsigned char [16], MD5_CTX *);
-static void MD5Transform (unsigned long int [4], unsigned char [64]);
-static void Encode (unsigned char *, unsigned long int *, unsigned int);
-static void Decode (unsigned long int *, unsigned char *, unsigned int);
+static void MD5Transform (uint32_t [4], unsigned char [64]);
+static void Encode (unsigned char *, uint32_t *, unsigned int);
+static void Decode (uint32_t *, unsigned char *, unsigned int);
static unsigned char PADDING[64] = {
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -78,22 +79,22 @@ static unsigned char PADDING[64] = {
Rotation is separate from addition to prevent recomputation.
*/
#define FF(a, b, c, d, x, s, ac) { \
- (a) += F ((b), (c), (d)) + (x) + (unsigned long int)(ac); \
+ (a) += F ((b), (c), (d)) + (x) + (uint32_t)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define GG(a, b, c, d, x, s, ac) { \
- (a) += G ((b), (c), (d)) + (x) + (unsigned long int)(ac); \
+ (a) += G ((b), (c), (d)) + (x) + (uint32_t)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define HH(a, b, c, d, x, s, ac) { \
- (a) += H ((b), (c), (d)) + (x) + (unsigned long int)(ac); \
+ (a) += H ((b), (c), (d)) + (x) + (uint32_t)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define II(a, b, c, d, x, s, ac) { \
- (a) += I ((b), (c), (d)) + (x) + (unsigned long int)(ac); \
+ (a) += I ((b), (c), (d)) + (x) + (uint32_t)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
@@ -125,11 +126,11 @@ static void MD5Update (MD5_CTX *context, unsigned char *input,
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
/* Update number of bits */
- if ((context->count[0] += ((unsigned long int) inputLen << 3)) <
- ((unsigned long int)inputLen << 3)) {
+ if ((context->count[0] += ((uint32_t) inputLen << 3)) <
+ ((uint32_t)inputLen << 3)) {
context->count[1]++;
}
- context->count[1] += ((unsigned long int) inputLen >> 29);
+ context->count[1] += ((uint32_t) inputLen >> 29);
partLen = 64 - index;
@@ -178,9 +179,9 @@ static void MD5Final (unsigned char digest[16], MD5_CTX *context) {
}
/* MD5 basic transformation. Transforms state based on block. */
-static void MD5Transform (unsigned long int state[4],
+static void MD5Transform (uint32_t state[4],
unsigned char block[64]) {
- unsigned long int a = state[0], b = state[1], c = state[2],
+ uint32_t a = state[0], b = state[1], c = state[2],
d = state[3], x[16];
Decode (x, block, 64);
@@ -271,7 +272,7 @@ static void MD5Transform (unsigned long int state[4],
/* Encodes input (UINT4) into output (unsigned char). Assumes len is
* a multiple of 4.
*/
-static void Encode (unsigned char *output, unsigned long int *input,
+static void Encode (unsigned char *output, uint32_t *input,
unsigned int len) {
unsigned int i, j;
@@ -286,15 +287,15 @@ static void Encode (unsigned char *output, unsigned long int *input,
/* Decodes input (unsigned char) into output (UINT4). Assumes len is
* a multiple of 4.
*/
-static void Decode (unsigned long int *output, unsigned char *input,
+static void Decode (uint32_t *output, unsigned char *input,
unsigned int len) {
unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4) {
- output[i] = ((unsigned long int)input[j]) |
- (((unsigned long int)input[j+1]) << 8) |
- (((unsigned long int)input[j+2]) << 16) |
- (((unsigned long int)input[j+3]) << 24);
+ output[i] = ((uint32_t)input[j]) |
+ (((uint32_t)input[j+1]) << 8) |
+ (((uint32_t)input[j+2]) << 16) |
+ (((uint32_t)input[j+3]) << 24);
}
}