0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Macros | Functions | Variables
md5.cc File Reference

md5 digest routines. More...

#include <string.h>
#include <stdio.h>
#include <stdint.h>
#include "md5.h"
Include dependency graph for md5.cc:

Go to the source code of this file.

Macros

#define SELF_TEST   1
 
#define _CRT_SECURE_NO_DEPRECATE   1
 
#define GET_UINT32_LE(n, b, i)
 
#define PUT_UINT32_LE(n, b, i)
 
#define S(x, n)   ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
 
#define P(a, b, c, d, k, s, t)
 
#define F(x, y, z)   (z ^ (x & (y ^ z)))
 
#define F(x, y, z)   (y ^ (z & (x ^ y)))
 
#define F(x, y, z)   (x ^ y ^ z)
 
#define F(x, y, z)   (y ^ (x | ~z))
 

Functions

void md5_starts (md5_context *ctx)
 Initialize and setup a MD5 context structure. More...
 
static void md5_process (md5_context *ctx, const unsigned char data[64])
 
void md5_update (md5_context *ctx, const unsigned char *input, int ilen)
 Adds data to the MD5 process buffer. More...
 
void md5_finish (md5_context *ctx, unsigned char output[16])
 Retrieve the final MD5 digest. More...
 
int md5_file (char *path, unsigned char output[16])
 
void md5_csum (const unsigned char *input, int ilen, unsigned char output[16])
 Convenience function to calculate the MD5 sum of an input buffer. More...
 
void md5_hmac (unsigned char *key, int keylen, const unsigned char *input, int ilen, unsigned char output[16])
 Calculates a "Hashed MAC" of an input buffer combined with a secret key. More...
 
void md5_hex (const void *input, size_t len, char output[33])
 Convenience function to calculate the MD5 sum of an input buffer; returns string with the MD5 encoded in hexadecimal. More...
 
void md5_string (const char *input, char output[33])
 Calculates the hex string of MD5 of null terminated input. More...
 
int64_t md5_hash (const char *input)
 Returns a 64-bit hash checksum of a null terminated input buffer. More...
 
void digest_to_trunc_modified_base64 (const char digest[16], char output[17])
 Get the modified base64 encoded string of a 16 byte message digest see http://en.wikipedia.org/wiki/Base64#URL_applications for more information. More...
 
void md5_trunc_modified_base64 (const char *input, char output[17])
 Get the modified base64 encoded string of the first 12 Bytes of the 16 Byte MD5 code of a null terminated output; see http://en.wikipedia.org/wiki/Base64#URL_applications for more information. More...
 
int md5_self_test (void)
 Runs a self test. More...
 

Variables

static const char mb64_charset [] ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
 
static const unsigned char md5_padding [64]
 
static const char _md5_src [] = "_md5_src"
 
static const char hex_digits [] = "0123456789ABCDEF"
 
static const char md5_test_str [7][81]
 
static const unsigned char md5_test_sum [7][16]
 

Detailed Description

md5 digest routines.

This file implements the md5 digest algorithm and also has several helper functions like calculating the md5 of a file or a string. The MD5 algorithm was designed by Ron Rivest in 1991 (http://www.ietf.org/rfc/rfc1321.txt).

Definition in file md5.cc.

Macro Definition Documentation

#define _CRT_SECURE_NO_DEPRECATE   1

Definition at line 32 of file md5.cc.

#define F (   x,
  y,
 
)    (z ^ (x & (y ^ z)))
#define F (   x,
  y,
 
)    (y ^ (z & (x ^ y)))
#define F (   x,
  y,
 
)    (x ^ y ^ z)
#define F (   x,
  y,
 
)    (y ^ (x | ~z))
#define GET_UINT32_LE (   n,
  b,
 
)
Value:
{ \
(n) = ( (unsigned long) (b)[(i) ] ) \
| ( (unsigned long) (b)[(i) + 1] << 8 ) \
| ( (unsigned long) (b)[(i) + 2] << 16 ) \
| ( (unsigned long) (b)[(i) + 3] << 24 ); \
}

Definition at line 50 of file md5.cc.

#define P (   a,
  b,
  c,
  d,
  k,
  s,
 
)
Value:
{ \
a += F(b,c,d) + X[k] + t; a = S(a,s) + b; \
}
#define S(x, n)
#define F(x, y, z)
#define PUT_UINT32_LE (   n,
  b,
 
)
Value:
{ \
(b)[(i) ] = (unsigned char) ( (n) ); \
(b)[(i) + 1] = (unsigned char) ( (n) >> 8 ); \
(b)[(i) + 2] = (unsigned char) ( (n) >> 16 ); \
(b)[(i) + 3] = (unsigned char) ( (n) >> 24 ); \
}

Definition at line 59 of file md5.cc.

#define S (   x,
 
)    ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
#define SELF_TEST   1

Definition at line 30 of file md5.cc.

Function Documentation

int md5_file ( char *  path,
unsigned char  output[16] 
)

Definition at line 288 of file md5.cc.

static void md5_process ( md5_context ctx,
const unsigned char  data[64] 
)
static

Definition at line 82 of file md5.cc.

Variable Documentation

const char _md5_src[] = "_md5_src"
static

Definition at line 362 of file md5.cc.

const char hex_digits[] = "0123456789ABCDEF"
static

Definition at line 364 of file md5.cc.

const char mb64_charset[] ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
static

Definition at line 44 of file md5.cc.

const unsigned char md5_padding[64]
static
Initial value:
=
{
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
}

Definition at line 249 of file md5.cc.

const char md5_test_str[7][81]
static
Initial value:
=
{
{ "" },
{ "a" },
{ "abc" },
{ "message digest" },
{ "abcdefghijklmnopqrstuvwxyz" },
{ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" },
{ "12345678901234567890123456789012345678901234567890123456789012"
"345678901234567890" }
}

Definition at line 442 of file md5.cc.

const unsigned char md5_test_sum[7][16]
static
Initial value:
=
{
{ 0xD4, 0x1D, 0x8C, 0xD9, 0x8F, 0x00, 0xB2, 0x04,
0xE9, 0x80, 0x09, 0x98, 0xEC, 0xF8, 0x42, 0x7E },
{ 0x0C, 0xC1, 0x75, 0xB9, 0xC0, 0xF1, 0xB6, 0xA8,
0x31, 0xC3, 0x99, 0xE2, 0x69, 0x77, 0x26, 0x61 },
{ 0x90, 0x01, 0x50, 0x98, 0x3C, 0xD2, 0x4F, 0xB0,
0xD6, 0x96, 0x3F, 0x7D, 0x28, 0xE1, 0x7F, 0x72 },
{ 0xF9, 0x6B, 0x69, 0x7D, 0x7C, 0xB7, 0x93, 0x8D,
0x52, 0x5A, 0x2F, 0x31, 0xAA, 0xF1, 0x61, 0xD0 },
{ 0xC3, 0xFC, 0xD3, 0xD7, 0x61, 0x92, 0xE4, 0x00,
0x7D, 0xFB, 0x49, 0x6C, 0xCA, 0x67, 0xE1, 0x3B },
{ 0xD1, 0x74, 0xAB, 0x98, 0xD2, 0x77, 0xD9, 0xF5,
0xA5, 0x61, 0x1C, 0x2C, 0x9F, 0x41, 0x9D, 0x9F },
{ 0x57, 0xED, 0xF4, 0xA2, 0x2B, 0xE3, 0xC9, 0x55,
0xAC, 0x49, 0xDA, 0x2E, 0x21, 0x07, 0xB6, 0x7A }
}

Definition at line 454 of file md5.cc.