embedded IPsec source code documentation


md5.c File Reference


Detailed Description

RFC 1321 - The MD5 Message-Digest Algorithm and RFC 2104 - HMAC: Keyed-Hashing for Message Authentication.

Author:
Christian Scheurer <http://www.christianscheurer.ch>
OUTLINE: This module contains mainly code extracted from the libssl library. We use this code to implement a HMAC. The functions used to implement the HMAC-MD5 are MD5_Init MD5_Update and MD5_Finish.

IMPLEMENTATION: "This product includes cryptographic software written by Eric Young (eay@cryptsoft.com)" (taken form www.openssl.org)"

NOTES:

This document is part of embedded IPsec
Copyright (c) 2003 Niklaus Schild and Christian Scheurer, HTI Biel/Bienne
All rights reserved.
This file contains code from the OpenSSL Project
portions Copyright (c) 1998-2003 OpenSSL (www.openssl.org)


Definition in file md5.c.

#include <string.h>
#include "ipsec/md5.h"
#include "ipsec/debug.h"

Go to the source code of this file.

Defines

#define INIT_DATA_A   (unsigned long)0x67452301L
#define INIT_DATA_B   (unsigned long)0xefcdab89L
#define INIT_DATA_C   (unsigned long)0x98badcfeL
#define INIT_DATA_D   (unsigned long)0x10325476L
#define HOST_c2l(c, l)
#define HOST_p_c2l(c, l, n)
#define HOST_p_c2l_p(c, l, sc, len)
#define HOST_c2l_p(c, l, n)
#define HOST_l2c(l, c)
#define F(b, c, d)   ((((c) ^ (d)) & (b)) ^ (d))
#define G(b, c, d)   ((((b) ^ (c)) & (d)) ^ (c))
#define H(b, c, d)   ((b) ^ (c) ^ (d))
#define I(b, c, d)   (((~(d)) | (b)) ^ (c))
#define R0(a, b, c, d, k, s, t)
#define R1(a, b, c, d, k, s, t)
#define R2(a, b, c, d, k, s, t)
#define R3(a, b, c, d, k, s, t)
#define X(i)   XX##i

Functions

unsigned char * MD5 (const unsigned char *d, unsigned long n, unsigned char *md)
void MD5_Init (MD5_CTX *c)
void md5_block_host_order (MD5_CTX *c, const void *p, int num)
void md5_block_data_order (MD5_CTX *c, const void *p, int num)
void MD5_Update (MD5_CTX *c, const void *data_, unsigned long len)
void MD5_Transform (MD5_CTX *c, const unsigned char *data)
void MD5_Final (unsigned char *md, MD5_CTX *c)
void hmac_md5 (unsigned char *text, int text_len, unsigned char *key, int key_len, unsigned char *digest)


Define Documentation

#define F b,
c,
 )     ((((c) ^ (d)) & (b)) ^ (d))
 

Definition at line 310 of file md5.c.

#define G b,
c,
 )     ((((b) ^ (c)) & (d)) ^ (c))
 

Definition at line 311 of file md5.c.

#define H b,
c,
 )     ((b) ^ (c) ^ (d))
 

Definition at line 312 of file md5.c.

#define HOST_c2l c,
 ) 
 

Value:

(l =(((unsigned long)(*((c)++)))    ),          \
                         l|=(((unsigned long)(*((c)++)))<< 8),          \
                         l|=(((unsigned long)(*((c)++)))<<16),          \
                         l|=(((unsigned long)(*((c)++)))<<24),          \
                         l)

Definition at line 116 of file md5.c.

#define HOST_c2l_p c,
l,
 ) 
 

Value:

{                                       \
                        l=0; (c)+=n;                                    \
                        switch (n) {                                    \
                        case 3: l =((unsigned long)(*(--(c))))<<16;     \
                        case 2: l|=((unsigned long)(*(--(c))))<< 8;     \
                        case 1: l|=((unsigned long)(*(--(c))));         \
                                } }

Definition at line 137 of file md5.c.

#define HOST_l2c l,
 ) 
 

Value:

(*((c)++)=(unsigned char)(((l)    )&0xff),      \
                         *((c)++)=(unsigned char)(((l)>> 8)&0xff),      \
                         *((c)++)=(unsigned char)(((l)>>16)&0xff),      \
                         *((c)++)=(unsigned char)(((l)>>24)&0xff),      \
                         l)

Definition at line 144 of file md5.c.

#define HOST_p_c2l c,
l,
 ) 
 

Value:

{                                       \
                        switch (n) {                                    \
                        case 0: l =((unsigned long)(*((c)++)));         \
                        case 1: l|=((unsigned long)(*((c)++)))<< 8;     \
                        case 2: l|=((unsigned long)(*((c)++)))<<16;     \
                        case 3: l|=((unsigned long)(*((c)++)))<<24;     \
                                } }

Definition at line 121 of file md5.c.

#define HOST_p_c2l_p c,
l,
sc,
len   ) 
 

Value:

{                                       \
                        switch (sc) {                                   \
                        case 0: l =((unsigned long)(*((c)++)));         \
                                if (--len == 0) break;                  \
                        case 1: l|=((unsigned long)(*((c)++)))<< 8;     \
                                if (--len == 0) break;                  \
                        case 2: l|=((unsigned long)(*((c)++)))<<16;     \
                                } }

Definition at line 128 of file md5.c.

#define I b,
c,
 )     (((~(d)) | (b)) ^ (c))
 

Definition at line 313 of file md5.c.

#define INIT_DATA_A   (unsigned long)0x67452301L
 

Definition at line 74 of file md5.c.

#define INIT_DATA_B   (unsigned long)0xefcdab89L
 

Definition at line 75 of file md5.c.

#define INIT_DATA_C   (unsigned long)0x98badcfeL
 

Definition at line 76 of file md5.c.

#define INIT_DATA_D   (unsigned long)0x10325476L
 

Definition at line 77 of file md5.c.

#define R0 a,
b,
c,
d,
k,
s,
 ) 
 

Value:

{ \
        a+=((k)+(t)+F((b),(c),(d))); \
        a=ROTATE(a,s); \
        a+=b; };\

Definition at line 315 of file md5.c.

#define R1 a,
b,
c,
d,
k,
s,
 ) 
 

Value:

{ \
        a+=((k)+(t)+G((b),(c),(d))); \
        a=ROTATE(a,s); \
        a+=b; };

Definition at line 320 of file md5.c.

#define R2 a,
b,
c,
d,
k,
s,
 ) 
 

Value:

{ \
        a+=((k)+(t)+H((b),(c),(d))); \
        a=ROTATE(a,s); \
        a+=b; };

Definition at line 325 of file md5.c.

#define R3 a,
b,
c,
d,
k,
s,
 ) 
 

Value:

{ \
        a+=((k)+(t)+I((b),(c),(d))); \
        a=ROTATE(a,s); \
        a+=b; };

Definition at line 330 of file md5.c.

#define X  )     XX##i
 


Function Documentation

void hmac_md5 unsigned char *  text,
int  text_len,
unsigned char *  key,
int  key_len,
unsigned char *  digest
 

RFC 2104 hmac_md5 function calculates a digest from a given data buffer and a given key.

Parameters:
text pointer to data stream
text_len length of data stream
key pointer to authentication key
key_len length of authentication key
digest caller digest to be filled in 128-bit
Returns:
void

Definition at line 559 of file md5.c.

unsigned char* MD5 const unsigned char *  d,
unsigned long  n,
unsigned char *  md
 

Definition at line 60 of file md5.c.

void md5_block_data_order MD5_CTX c,
const void *  p,
int  num
 

Definition at line 440 of file md5.c.

void md5_block_host_order MD5_CTX c,
const void *  p,
int  num
 

Definition at line 337 of file md5.c.

void MD5_Final unsigned char *  md,
MD5_CTX c
 

Definition at line 261 of file md5.c.

void MD5_Init MD5_CTX c  ) 
 

Definition at line 79 of file md5.c.

void MD5_Transform MD5_CTX c,
const unsigned char *  data
 

Definition at line 251 of file md5.c.

void MD5_Update MD5_CTX c,
const void *  data_,
unsigned long  len
 

Definition at line 155 of file md5.c.


Copyright 2003 by Christian Scheurer and Niklaus Schild