2 * md5.c: checksum routines
\r
4 * ====================================================================
\r
5 * Copyright (c) 2000-2004, 2008 CollabNet. All rights reserved.
\r
7 * This software is licensed as described in the file COPYING, which
\r
8 * you should have received as part of this distribution. The terms
\r
9 * are also available at http://subversion.tigris.org/license-1.html.
\r
10 * If newer versions of this license are posted there, you may use a
\r
11 * newer version instead, at your option.
\r
13 * This software consists of voluntary contributions made by many
\r
14 * individuals. For exact contribution history, see the revision
\r
15 * history and logs, available at http://subversion.tigris.org/.
\r
16 * ====================================================================
\r
20 #include <apr_md5.h>
\r
22 #include "svn_md5.h"
\r
26 /* The MD5 digest for the empty string. */
\r
27 static const unsigned char svn_md5__empty_string_digest_array[] = {
\r
28 212, 29, 140, 217, 143, 0, 178, 4, 233, 128, 9, 152, 236, 248, 66, 126
\r
31 const unsigned char *
\r
32 svn_md5__empty_string_digest(void)
\r
34 return svn_md5__empty_string_digest_array;
\r
39 svn_md5__digest_to_cstring_display(const unsigned char digest[],
\r
42 static const char *hex = "0123456789abcdef";
\r
43 char *str = apr_palloc(pool, (APR_MD5_DIGESTSIZE * 2) + 1);
\r
46 for (i = 0; i < APR_MD5_DIGESTSIZE; i++)
\r
48 str[i*2] = hex[digest[i] >> 4];
\r
49 str[i*2+1] = hex[digest[i] & 0x0f];
\r
58 svn_md5__digest_to_cstring(const unsigned char digest[], apr_pool_t *pool)
\r
60 static const unsigned char zeros_digest[APR_MD5_DIGESTSIZE] = { 0 };
\r
62 if (memcmp(digest, zeros_digest, APR_MD5_DIGESTSIZE) != 0)
\r
63 return svn_md5__digest_to_cstring_display(digest, pool);
\r
70 svn_md5__digests_match(const unsigned char d1[], const unsigned char d2[])
\r
72 static const unsigned char zeros[APR_MD5_DIGESTSIZE] = { 0 };
\r
74 return ((memcmp(d1, zeros, APR_MD5_DIGESTSIZE) == 0)
\r
75 || (memcmp(d2, zeros, APR_MD5_DIGESTSIZE) == 0)
\r
76 || (memcmp(d1, d2, APR_MD5_DIGESTSIZE) == 0));
\r
79 /* These are all deprecated, and just wrap the internal functions defined
\r
81 const unsigned char *
\r
82 svn_md5_empty_string_digest(void)
\r
84 return svn_md5__empty_string_digest();
\r
88 svn_md5_digest_to_cstring_display(const unsigned char digest[],
\r
91 return svn_md5__digest_to_cstring_display(digest, pool);
\r
95 svn_md5_digest_to_cstring(const unsigned char digest[], apr_pool_t *pool)
\r
97 return svn_md5__digest_to_cstring(digest, pool);
\r
101 svn_md5_digests_match(const unsigned char d1[], const unsigned char d2[])
\r
103 return svn_md5__digests_match(d1, d2);
\r