[sr-dev] git:3.3: core: added md5 wrapper functions to build with Colin Plumb' s md5 code

Daniel-Constantin Mierla miconda at gmail.com
Sun Sep 2 15:02:30 CEST 2012


Module: sip-router
Branch: 3.3
Commit: d7452228134c42522ef84c1dbdcdc2cfd0bbf331
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=d7452228134c42522ef84c1dbdcdc2cfd0bbf331

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Thu Aug  2 10:16:31 2012 +0200

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

Author: Tzafrir Cohen <tzafrir at debian.org>
(cherry picked from commit bcff862df5b937e3a6ff87e4415e0039fd989908)

---

 md5.c |   11 ++++-------
 md5.h |   19 +++++++++++++++----
 2 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/md5.c b/md5.c
index 3da18c9..a0a036a 100644
--- a/md5.c
+++ b/md5.c
@@ -17,9 +17,6 @@
  * will fill a supplied 16-byte array with the digest.
  */
 
-#include <config.h>
-#include <compat.h>
-
 #include <sys/types.h>
 #include <string.h>
 
@@ -66,7 +63,7 @@ MD5Init(MD5_CTX *ctx)
  * of bytes.
  */
 void
-MD5Update(MD5_CTX *ctx, const unsigned char *input, size_t len)
+U_MD5Update(MD5_CTX *ctx, const unsigned char *input, size_t len)
 {
 	size_t have, need;
 
@@ -117,15 +114,15 @@ MD5Pad(MD5_CTX *ctx)
 	    ((ctx->count >> 3) & (MD5_BLOCK_LENGTH - 1));
 	if (padlen < 1 + 8)
 		padlen += MD5_BLOCK_LENGTH;
-	MD5Update(ctx, PADDING, padlen - 8);		/* padlen - 8 <= 64 */
-	MD5Update(ctx, count, 8);
+	U_MD5Update(ctx, PADDING, padlen - 8);		/* padlen - 8 <= 64 */
+	U_MD5Update(ctx, count, 8);
 }
 
 /*
  * Final wrapup--call MD5Pad, fill in digest and zero out ctx.
  */
 void
-MD5Final(unsigned char digest[MD5_DIGEST_LENGTH], MD5_CTX *ctx)
+U_MD5Final(unsigned char digest[MD5_DIGEST_LENGTH], MD5_CTX *ctx)
 {
 	int i;
 
diff --git a/md5.h b/md5.h
index f624360..211a131 100644
--- a/md5.h
+++ b/md5.h
@@ -19,16 +19,27 @@
 #define	MD5_DIGEST_LENGTH		16
 #define	MD5_DIGEST_STRING_LENGTH	(MD5_DIGEST_LENGTH * 2 + 1)
 
+/* Probably not the proper place, but will do for Debian: */
+#include <sys/types.h>
+
 typedef struct MD5Context {
 	u_int32_t state[4];			/* state */
 	u_int64_t count;			/* number of bits, mod 2^64 */
-	u_int8_t buffer[MD5_BLOCK_LENGTH];	/* input buffer */
+	unsigned char buffer[MD5_BLOCK_LENGTH];	/* input buffer */
 } MD5_CTX;
 
 void	 MD5Init(MD5_CTX *);
-void	 MD5Update(MD5_CTX *, const u_int8_t *, size_t);
+void	 U_MD5Update(MD5_CTX *, const unsigned char *, size_t);
 void	 MD5Pad(MD5_CTX *);
-void	 MD5Final(u_int8_t [MD5_DIGEST_LENGTH], MD5_CTX *);
-void	 MD5Transform(u_int32_t [4], const u_int8_t [MD5_BLOCK_LENGTH]);
+void	 U_MD5Final(unsigned char [MD5_DIGEST_LENGTH], MD5_CTX *);
+void	 MD5Transform(u_int32_t [4], const unsigned char [MD5_BLOCK_LENGTH]);
+
+static inline void MD5Update(MD5_CTX *ctx, const char *str, size_t len) {
+	U_MD5Update(ctx, (const unsigned char *)str, len);
+}
+
+static inline void MD5Final(char buf[MD5_DIGEST_LENGTH], MD5_CTX *ctx) {
+	U_MD5Final((unsigned char *)buf, ctx);
+}
 
 #endif /* _MD5_H_ */




More information about the sr-dev mailing list