Browse code

core: added md5 wrapper functions to build with Colin Plumb's md5 code

Author: Tzafrir Cohen <tzafrir@debian.org>

Daniel-Constantin Mierla authored on 02/08/2012 08:16:31
Showing 2 changed files
... ...
@@ -17,9 +17,6 @@
17 17
  * will fill a supplied 16-byte array with the digest.
18 18
  */
19 19
 
20
-#include <config.h>
21
-#include <compat.h>
22
-
23 20
 #include <sys/types.h>
24 21
 #include <string.h>
25 22
 
... ...
@@ -66,7 +63,7 @@ MD5Init(MD5_CTX *ctx)
66 66
  * of bytes.
67 67
  */
68 68
 void
69
-MD5Update(MD5_CTX *ctx, const unsigned char *input, size_t len)
69
+U_MD5Update(MD5_CTX *ctx, const unsigned char *input, size_t len)
70 70
 {
71 71
 	size_t have, need;
72 72
 
... ...
@@ -117,15 +114,15 @@ MD5Pad(MD5_CTX *ctx)
117 117
 	    ((ctx->count >> 3) & (MD5_BLOCK_LENGTH - 1));
118 118
 	if (padlen < 1 + 8)
119 119
 		padlen += MD5_BLOCK_LENGTH;
120
-	MD5Update(ctx, PADDING, padlen - 8);		/* padlen - 8 <= 64 */
121
-	MD5Update(ctx, count, 8);
120
+	U_MD5Update(ctx, PADDING, padlen - 8);		/* padlen - 8 <= 64 */
121
+	U_MD5Update(ctx, count, 8);
122 122
 }
123 123
 
124 124
 /*
125 125
  * Final wrapup--call MD5Pad, fill in digest and zero out ctx.
126 126
  */
127 127
 void
128
-MD5Final(unsigned char digest[MD5_DIGEST_LENGTH], MD5_CTX *ctx)
128
+U_MD5Final(unsigned char digest[MD5_DIGEST_LENGTH], MD5_CTX *ctx)
129 129
 {
130 130
 	int i;
131 131
 
... ...
@@ -19,16 +19,27 @@
19 19
 #define	MD5_DIGEST_LENGTH		16
20 20
 #define	MD5_DIGEST_STRING_LENGTH	(MD5_DIGEST_LENGTH * 2 + 1)
21 21
 
22
+/* Probably not the proper place, but will do for Debian: */
23
+#include <sys/types.h>
24
+
22 25
 typedef struct MD5Context {
23 26
 	u_int32_t state[4];			/* state */
24 27
 	u_int64_t count;			/* number of bits, mod 2^64 */
25
-	u_int8_t buffer[MD5_BLOCK_LENGTH];	/* input buffer */
28
+	unsigned char buffer[MD5_BLOCK_LENGTH];	/* input buffer */
26 29
 } MD5_CTX;
27 30
 
28 31
 void	 MD5Init(MD5_CTX *);
29
-void	 MD5Update(MD5_CTX *, const u_int8_t *, size_t);
32
+void	 U_MD5Update(MD5_CTX *, const unsigned char *, size_t);
30 33
 void	 MD5Pad(MD5_CTX *);
31
-void	 MD5Final(u_int8_t [MD5_DIGEST_LENGTH], MD5_CTX *);
32
-void	 MD5Transform(u_int32_t [4], const u_int8_t [MD5_BLOCK_LENGTH]);
34
+void	 U_MD5Final(unsigned char [MD5_DIGEST_LENGTH], MD5_CTX *);
35
+void	 MD5Transform(u_int32_t [4], const unsigned char [MD5_BLOCK_LENGTH]);
36
+
37
+static inline void MD5Update(MD5_CTX *ctx, const char *str, size_t len) {
38
+	U_MD5Update(ctx, (const unsigned char *)str, len);
39
+}
40
+
41
+static inline void MD5Final(char buf[MD5_DIGEST_LENGTH], MD5_CTX *ctx) {
42
+	U_MD5Final((unsigned char *)buf, ctx);
43
+}
33 44
 
34 45
 #endif /* _MD5_H_ */