/home/dko/Projects/mobilec/src/security/xyssl-0.9/library/md5.c File Reference

#include "xyssl/config.h"
#include "xyssl/md5.h"
#include <string.h>
#include <stdio.h>

Go to the source code of this file.

Defines

#define GET_ULONG_LE(n, b, i)
#define PUT_ULONG_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)
 MD5 context setup.
static void md5_process (md5_context *ctx, unsigned char data[64])
void md5_update (md5_context *ctx, unsigned char *input, int ilen)
 MD5 process buffer.
void md5_finish (md5_context *ctx, unsigned char output[16])
 MD5 final digest.
void md5 (unsigned char *input, int ilen, unsigned char output[16])
 Output = MD5( input buffer ).
int md5_file (char *path, unsigned char output[16])
 Output = MD5( file contents ).
void md5_hmac_starts (md5_context *ctx, unsigned char *key, int keylen)
 MD5 HMAC context setup.
void md5_hmac_update (md5_context *ctx, unsigned char *input, int ilen)
 MD5 HMAC process buffer.
void md5_hmac_finish (md5_context *ctx, unsigned char output[16])
 MD5 HMAC final digest.
void md5_hmac (unsigned char *key, int keylen, unsigned char *input, int ilen, unsigned char output[16])
 Output = HMAC-MD5( hmac key, input buffer ).
int md5_self_test (int verbose)
 Checkup routine.

Variables

static const unsigned char md5_padding [64]
static unsigned char md5_test_buf [7][81]
static const int md5_test_buflen [7]
static const unsigned char md5_test_sum [7][16]
static unsigned char md5_hmac_test_key [7][26]
static const int md5_hmac_test_keylen [7]
static unsigned char md5_hmac_test_buf [7][74]
static const int md5_hmac_test_buflen [7]
static const unsigned char md5_hmac_test_sum [7][16]

Define Documentation

#define F ( x,
y,
 )     (y ^ (x | ~z))
#define F ( x,
y,
 )     (x ^ y ^ z)
#define F ( x,
y,
 )     (y ^ (z & (x ^ y)))
#define F ( x,
y,
 )     (z ^ (x & (y ^ z)))

Referenced by sha2_process(), and sha4_process().

#define GET_ULONG_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 39 of file md5.c.

#define P ( a,
b,
c,
d,
k,
s,
 ) 
Value:
{                                                       \
    a += F(b,c,d) + X[k] + t; a = S(a,s) + b;           \
}

Referenced by main(), md5_process(), rsa_decryption(), sha1_process(), sha2_process(), and sha4_process().

#define PUT_ULONG_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 49 of file md5.c.

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

Function Documentation

void md5 ( unsigned char *  input,
int  ilen,
unsigned char  output[16] 
)

Output = MD5( input buffer ).

Parameters:
input buffer holding the data
ilen length of the input data
output MD5 checksum result

Definition at line 278 of file md5.c.

References md5_finish(), md5_starts(), and md5_update().

Referenced by initiate_migration_process(), main(), md5_hmac_starts(), md5_self_test(), reply_migration_process(), ssl_calc_verify(), ssl_derive_keys(), ssl_mac_md5(), ssl_parse_finished(), ssl_parse_server_key_exchange(), ssl_write_finished(), ssl_write_server_key_exchange(), and x509_hash().

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

Output = MD5( file contents ).

Parameters:
path input file name
output MD5 checksum result
Returns:
0 if successful, 1 if fopen failed, or 2 if fread failed

Definition at line 292 of file md5.c.

References buf, f, md5_finish(), md5_starts(), and md5_update().

Referenced by md5_wrapper().

void md5_finish ( md5_context ctx,
unsigned char  output[16] 
)
void md5_hmac ( unsigned char *  key,
int  keylen,
unsigned char *  input,
int  ilen,
unsigned char  output[16] 
)

Output = HMAC-MD5( hmac key, input buffer ).

Parameters:
key HMAC secret key
keylen length of the HMAC key
input buffer holding the data
ilen length of the input data
output HMAC-MD5 result

Definition at line 378 of file md5.c.

References md5_hmac_finish(), md5_hmac_starts(), and md5_hmac_update().

Referenced by ssl_decrypt_buf(), ssl_encrypt_buf(), and tls1_prf().

void md5_hmac_finish ( md5_context ctx,
unsigned char  output[16] 
)

MD5 HMAC final digest.

Parameters:
ctx HMAC context
output MD5 HMAC checksum result

Definition at line 362 of file md5.c.

References md5_finish(), md5_starts(), md5_update(), and md5_context::opad.

Referenced by md5_hmac(), and md5_self_test().

void md5_hmac_starts ( md5_context ctx,
unsigned char *  key,
int  keylen 
)

MD5 HMAC context setup.

Parameters:
ctx HMAC context to be initialized
key HMAC secret key
keylen length of the HMAC key

Definition at line 324 of file md5.c.

References md5_context::ipad, md5(), md5_starts(), md5_update(), and md5_context::opad.

Referenced by md5_hmac(), and md5_self_test().

void md5_hmac_update ( md5_context ctx,
unsigned char *  input,
int  ilen 
)

MD5 HMAC process buffer.

Parameters:
ctx HMAC context
input buffer holding the data
ilen length of the input data

Definition at line 354 of file md5.c.

References md5_update().

Referenced by md5_hmac(), and md5_self_test().

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

Definition at line 72 of file md5.c.

References GET_ULONG_LE, P, and md5_context::state.

Referenced by md5_update().

int md5_self_test ( int  verbose  ) 

Checkup routine.

Returns:
0 if successful, or 1 if the test failed

Definition at line 495 of file md5.c.

References buf, md5(), md5_hmac_finish(), md5_hmac_starts(), md5_hmac_test_buf, md5_hmac_test_buflen, md5_hmac_test_key, md5_hmac_test_keylen, md5_hmac_test_sum, md5_hmac_update(), md5_test_buf, md5_test_buflen, and md5_test_sum.

Referenced by main().

void md5_starts ( md5_context ctx  ) 
void md5_update ( md5_context ctx,
unsigned char *  input,
int  ilen 
)

Variable Documentation

unsigned char md5_hmac_test_buf[7][74] [static]
Initial value:
{
    { "Hi There" },
    { "what do ya want for nothing?" },
    { "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
      "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
      "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
      "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
      "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" },
    { "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
      "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
      "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
      "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
      "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD" },
    { "Test With Truncation" },
    { "Test Using Larger Than Block-Size Key - Hash Key First" },
    { "Test Using Larger Than Block-Size Key and Larger"
      " Than One Block-Size Data" }
}

Definition at line 449 of file md5.c.

Referenced by md5_self_test().

const int md5_hmac_test_buflen[7] [static]
Initial value:
{
    8, 28, 50, 50, 20, 54, 73
}

Definition at line 469 of file md5.c.

Referenced by md5_self_test().

unsigned char md5_hmac_test_key[7][26] [static]
Initial value:
{
    { "\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B" },
    { "Jefe" },
    { "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA" },
    { "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10"
      "\x11\x12\x13\x14\x15\x16\x17\x18\x19" },
    { "\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C" },
    { "" }, 
    { "" }
}

Definition at line 432 of file md5.c.

Referenced by md5_self_test().

const int md5_hmac_test_keylen[7] [static]
Initial value:
{
    16, 4, 16, 25, 16, 80, 80
}

Definition at line 444 of file md5.c.

Referenced by md5_self_test().

const unsigned char md5_hmac_test_sum[7][16] [static]
Initial value:
{
    { 0x92, 0x94, 0x72, 0x7A, 0x36, 0x38, 0xBB, 0x1C,
      0x13, 0xF4, 0x8E, 0xF8, 0x15, 0x8B, 0xFC, 0x9D },
    { 0x75, 0x0C, 0x78, 0x3E, 0x6A, 0xB0, 0xB5, 0x03,
      0xEA, 0xA8, 0x6E, 0x31, 0x0A, 0x5D, 0xB7, 0x38 },
    { 0x56, 0xBE, 0x34, 0x52, 0x1D, 0x14, 0x4C, 0x88,
      0xDB, 0xB8, 0xC7, 0x33, 0xF0, 0xE8, 0xB3, 0xF6 },
    { 0x69, 0x7E, 0xAF, 0x0A, 0xCA, 0x3A, 0x3A, 0xEA,
      0x3A, 0x75, 0x16, 0x47, 0x46, 0xFF, 0xAA, 0x79 },
    { 0x56, 0x46, 0x1E, 0xF2, 0x34, 0x2E, 0xDC, 0x00,
      0xF9, 0xBA, 0xB9, 0x95 },
    { 0x6B, 0x1A, 0xB7, 0xFE, 0x4B, 0xD7, 0xBF, 0x8F,
      0x0B, 0x62, 0xE6, 0xCE, 0x61, 0xB9, 0xD0, 0xCD },
    { 0x6F, 0x63, 0x0F, 0xAD, 0x67, 0xCD, 0xA0, 0xEE,
      0x1F, 0xB1, 0xF5, 0x62, 0xDB, 0x3A, 0xA5, 0x3E }
}

Definition at line 474 of file md5.c.

Referenced by md5_self_test().

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 239 of file md5.c.

Referenced by md5_finish().

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

Definition at line 394 of file md5.c.

Referenced by md5_self_test().

const int md5_test_buflen[7] [static]
Initial value:
{
    0, 1, 3, 14, 26, 62, 80
}

Definition at line 406 of file md5.c.

Referenced by md5_self_test().

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 411 of file md5.c.

Referenced by md5_self_test().

Generated on Tue Dec 28 15:15:29 2010 for Mobile-C by  doxygen 1.6.3