summaryrefslogtreecommitdiffstats
path: root/base/md5.cc
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-18 16:54:58 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-18 16:54:58 +0000
commit0ad1d2d6eb6f1e4edff72dabb8e2b2f9ba051f88 (patch)
tree34d232d10e6415100d5b660317c23a14e157ba83 /base/md5.cc
parentdac096590a0f00f124eb71b12ff6a32cee439fca (diff)
downloadchromium_src-0ad1d2d6eb6f1e4edff72dabb8e2b2f9ba051f88.zip
chromium_src-0ad1d2d6eb6f1e4edff72dabb8e2b2f9ba051f88.tar.gz
chromium_src-0ad1d2d6eb6f1e4edff72dabb8e2b2f9ba051f88.tar.bz2
base: Put md5.* into base namespace.
BUG=89274 TEST=None R=evan@chromium.org Review URL: http://codereview.chromium.org/7395021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92861 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/md5.cc')
-rw-r--r--base/md5.cc27
1 files changed, 18 insertions, 9 deletions
diff --git a/base/md5.cc b/base/md5.cc
index ff69dc0..2211a28 100644
--- a/base/md5.cc
+++ b/base/md5.cc
@@ -22,6 +22,8 @@
#include "base/basictypes.h"
+namespace {
+
struct Context {
uint32 buf[4];
uint32 bits[2];
@@ -31,7 +33,7 @@ struct Context {
/*
* Note: this code is harmless on little-endian machines.
*/
-static void byteReverse(unsigned char *buf, unsigned longs){
+void byteReverse(unsigned char *buf, unsigned longs) {
uint32 t;
do {
t = (uint32)((unsigned)buf[3]<<8 | buf[2]) << 16 |
@@ -40,6 +42,7 @@ static void byteReverse(unsigned char *buf, unsigned longs){
buf += 4;
} while (--longs);
}
+
/* The four core functions - F1 is optimized somewhat */
/* #define F1(x, y, z) (x & y | ~x & z) */
@@ -57,7 +60,7 @@ static void byteReverse(unsigned char *buf, unsigned longs){
* reflect the addition of 16 longwords of new data. MD5Update blocks
* the data and converts bytes into longwords for this routine.
*/
-static void MD5Transform(uint32 buf[4], const uint32 in[16]){
+void MD5Transform(uint32 buf[4], const uint32 in[16]) {
register uint32 a, b, c, d;
a = buf[0];
@@ -139,12 +142,16 @@ static void MD5Transform(uint32 buf[4], const uint32 in[16]){
buf[3] += d;
}
+} // namespace
+
+namespace base {
+
/*
* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
* initialization constants.
*/
-void MD5Init(MD5Context *pCtx){
- struct Context *ctx = (struct Context *)pCtx;
+void MD5Init(MD5Context* context) {
+ struct Context *ctx = (struct Context *)context;
ctx->buf[0] = 0x67452301;
ctx->buf[1] = 0xefcdab89;
ctx->buf[2] = 0x98badcfe;
@@ -157,8 +164,8 @@ void MD5Init(MD5Context *pCtx){
* Update context to reflect the concatenation of another buffer full
* of bytes.
*/
-void MD5Update(MD5Context *pCtx, const void *inbuf, size_t len){
- struct Context *ctx = (struct Context *)pCtx;
+void MD5Update(MD5Context* context, const void* inbuf, size_t len) {
+ struct Context *ctx = (struct Context *)context;
const unsigned char* buf = (const unsigned char*)inbuf;
uint32 t;
@@ -207,8 +214,8 @@ void MD5Update(MD5Context *pCtx, const void *inbuf, size_t len){
* Final wrapup - pad to 64-byte boundary with the bit pattern
* 1 0* (64-bit count of bits processed, MSB-first)
*/
-void MD5Final(MD5Digest* digest, MD5Context *pCtx){
- struct Context *ctx = (struct Context *)pCtx;
+void MD5Final(MD5Digest* digest, MD5Context* context) {
+ struct Context *ctx = (struct Context *)context;
unsigned count;
unsigned char *p;
@@ -248,7 +255,7 @@ void MD5Final(MD5Digest* digest, MD5Context *pCtx){
memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */
}
-std::string MD5DigestToBase16(const MD5Digest& digest){
+std::string MD5DigestToBase16(const MD5Digest& digest) {
static char const zEncode[] = "0123456789abcdef";
std::string ret;
@@ -275,3 +282,5 @@ std::string MD5String(const std::string& str) {
MD5Sum(str.data(), str.length(), &digest);
return MD5DigestToBase16(digest);
}
+
+} // namespace base