Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
md2.c File Reference
#include "prerr.h"
#include "secerr.h"
#include "prtypes.h"
#include "blapi.h"

Go to the source code of this file.

Classes

struct  MD2ContextStr

Defines

#define MD2_DIGEST_LEN   16
#define MD2_BUFSIZE   16
#define MD2_X_SIZE   48 /* The X array, [CV | INPUT | TMP VARS] */
#define MD2_CV   0 /* index into X for chaining variables */
#define MD2_INPUT   16 /* index into X for input */
#define MD2_TMPVARS   32 /* index into X for temporary variables */
#define MD2_CHECKSUM_SIZE   16
#define CKSUMFN(n)
#define COMPRESS(n)

Functions

SECStatus MD2_Hash (unsigned char *dest, const char *src)
MD2Context * MD2_NewContext (void)
void MD2_DestroyContext (MD2Context *cx, PRBool freeit)
void MD2_Begin (MD2Context *cx)
static void md2_compress (MD2Context *cx)
void MD2_Update (MD2Context *cx, const unsigned char *input, unsigned int inputLen)
void MD2_End (MD2Context *cx, unsigned char *digest, unsigned int *digestLen, unsigned int maxDigestLen)
unsigned int MD2_FlattenSize (MD2Context *cx)
SECStatus MD2_Flatten (MD2Context *cx, unsigned char *space)
MD2Context * MD2_Resurrect (unsigned char *space, void *arg)
void MD2_Clone (MD2Context *dest, MD2Context *src)

Variables

static const PRUint8 MD2S [256]

Class Documentation

struct MD2ContextStr

Definition at line 52 of file md2.c.

Class Members
unsigned char checksum
PRUint8 unusedBuffer
unsigned char X

Define Documentation

#define CKSUMFN (   n)
Value:
P = cx->checksum[n] ^ MD2S[cx->X[MD2_INPUT+n] ^ P]; \
       cx->checksum[n] = P; \
       cx->X[MD2_TMPVARS+n] = cx->X[n] ^ cx->X[MD2_INPUT+n];
#define COMPRESS (   n)
Value:
P = cx->X[n] ^ MD2S[P]; \
       cx->X[n] = P;
#define MD2_BUFSIZE   16

Definition at line 45 of file md2.c.

Definition at line 50 of file md2.c.

#define MD2_CV   0 /* index into X for chaining variables */

Definition at line 47 of file md2.c.

Definition at line 44 of file md2.c.

#define MD2_INPUT   16 /* index into X for input */

Definition at line 48 of file md2.c.

#define MD2_TMPVARS   32 /* index into X for temporary variables */

Definition at line 49 of file md2.c.

#define MD2_X_SIZE   48 /* The X array, [CV | INPUT | TMP VARS] */

Definition at line 46 of file md2.c.


Function Documentation

void MD2_Begin ( MD2Context *  cx)

Definition at line 128 of file md2.c.

{
       memset(cx, 0, sizeof(*cx));
       cx->unusedBuffer = MD2_BUFSIZE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void MD2_Clone ( MD2Context *  dest,
MD2Context *  src 
)

Definition at line 293 of file md2.c.

{
       memcpy(dest, src, sizeof *dest);
}

Here is the call graph for this function:

static void md2_compress ( MD2Context *  cx) [static]

Definition at line 135 of file md2.c.

{
       int j;
       unsigned char P;
       P = cx->checksum[MD2_CHECKSUM_SIZE-1];
       /* Compute the running checksum, and set the tmp variables to be 
        * CV[i] XOR input[i] 
        */
#define CKSUMFN(n) \
       P = cx->checksum[n] ^ MD2S[cx->X[MD2_INPUT+n] ^ P]; \
       cx->checksum[n] = P; \
       cx->X[MD2_TMPVARS+n] = cx->X[n] ^ cx->X[MD2_INPUT+n];
       CKSUMFN(0);
       CKSUMFN(1);
       CKSUMFN(2);
       CKSUMFN(3);
       CKSUMFN(4);
       CKSUMFN(5);
       CKSUMFN(6);
       CKSUMFN(7);
       CKSUMFN(8);
       CKSUMFN(9);
       CKSUMFN(10);
       CKSUMFN(11);
       CKSUMFN(12);
       CKSUMFN(13);
       CKSUMFN(14);
       CKSUMFN(15);
       /* The compression function. */
#define COMPRESS(n) \
       P = cx->X[n] ^ MD2S[P]; \
       cx->X[n] = P;
       P = 0x00;
       for (j=0; j<18; j++) {
              COMPRESS(0);
              COMPRESS(1);
              COMPRESS(2);
              COMPRESS(3);
              COMPRESS(4);
              COMPRESS(5);
              COMPRESS(6);
              COMPRESS(7);
              COMPRESS(8);
              COMPRESS(9);
              COMPRESS(10);
              COMPRESS(11);
              COMPRESS(12);
              COMPRESS(13);
              COMPRESS(14);
              COMPRESS(15);
              COMPRESS(16);
              COMPRESS(17);
              COMPRESS(18);
              COMPRESS(19);
              COMPRESS(20);
              COMPRESS(21);
              COMPRESS(22);
              COMPRESS(23);
              COMPRESS(24);
              COMPRESS(25);
              COMPRESS(26);
              COMPRESS(27);
              COMPRESS(28);
              COMPRESS(29);
              COMPRESS(30);
              COMPRESS(31);
              COMPRESS(32);
              COMPRESS(33);
              COMPRESS(34);
              COMPRESS(35);
              COMPRESS(36);
              COMPRESS(37);
              COMPRESS(38);
              COMPRESS(39);
              COMPRESS(40);
              COMPRESS(41);
              COMPRESS(42);
              COMPRESS(43);
              COMPRESS(44);
              COMPRESS(45);
              COMPRESS(46);
              COMPRESS(47);
              P = (P + j) % 256;
       }
       cx->unusedBuffer = MD2_BUFSIZE;
}

Here is the caller graph for this function:

void MD2_DestroyContext ( MD2Context *  cx,
PRBool  freeit 
)

Definition at line 121 of file md2.c.

{
       if (freeit)
              PORT_ZFree(cx, sizeof(*cx));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void MD2_End ( MD2Context *  cx,
unsigned char *  digest,
unsigned int digestLen,
unsigned int  maxDigestLen 
)

Definition at line 253 of file md2.c.

{
       PRUint8 padStart;
       if (maxDigestLen < MD2_BUFSIZE) {
              PORT_SetError(SEC_ERROR_INVALID_ARGS);
              return;
       }
       padStart = MD2_BUFSIZE - cx->unusedBuffer;
       memset(&cx->X[MD2_INPUT + padStart], cx->unusedBuffer, 
                   cx->unusedBuffer);
       md2_compress(cx);
       memcpy(&cx->X[MD2_INPUT], cx->checksum, MD2_BUFSIZE);
       md2_compress(cx);
       *digestLen = MD2_DIGEST_LEN;
       memcpy(digest, &cx->X[MD2_CV], MD2_DIGEST_LEN);
}

Here is the call graph for this function:

Here is the caller graph for this function:

SECStatus MD2_Flatten ( MD2Context *  cx,
unsigned char *  space 
)

Definition at line 278 of file md2.c.

{
       memcpy(space, cx, sizeof(*cx));
       return SECSuccess;
}

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int MD2_FlattenSize ( MD2Context *  cx)

Definition at line 272 of file md2.c.

{
       return sizeof(*cx);
}

Here is the call graph for this function:

Here is the caller graph for this function:

SECStatus MD2_Hash ( unsigned char *  dest,
const char *  src 
)

Definition at line 94 of file md2.c.

{
       unsigned int len;
       MD2Context *cx = MD2_NewContext();
       if (!cx) {
              PORT_SetError(PR_OUT_OF_MEMORY_ERROR);
              return SECFailure;
       }
       MD2_Begin(cx);
       MD2_Update(cx, (unsigned char *)src, PL_strlen(src));
       MD2_End(cx, dest, &len, MD2_DIGEST_LEN);
       MD2_DestroyContext(cx, PR_TRUE);
       return SECSuccess;
}

Here is the call graph for this function:

MD2Context* MD2_NewContext ( void  )

Definition at line 110 of file md2.c.

{
       MD2Context *cx = (MD2Context *)PORT_ZAlloc(sizeof(MD2Context));
       if (cx == NULL) {
              PORT_SetError(PR_OUT_OF_MEMORY_ERROR);
              return NULL;
       }
       return cx;
}

Here is the call graph for this function:

Here is the caller graph for this function:

MD2Context* MD2_Resurrect ( unsigned char *  space,
void arg 
)

Definition at line 285 of file md2.c.

{
       MD2Context *cx = MD2_NewContext();
       if (cx)
              memcpy(cx, space, sizeof(*cx));
       return cx;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void MD2_Update ( MD2Context *  cx,
const unsigned char *  input,
unsigned int  inputLen 
)

Definition at line 223 of file md2.c.

{
       PRUint32 bytesToConsume;
       
       /* Fill the remaining input buffer. */
       if (cx->unusedBuffer != MD2_BUFSIZE) {
              bytesToConsume = PR_MIN(inputLen, cx->unusedBuffer);
              memcpy(&cx->X[MD2_INPUT + (MD2_BUFSIZE - cx->unusedBuffer)],
                          input, bytesToConsume);
              if (cx->unusedBuffer + bytesToConsume >= MD2_BUFSIZE)
                     md2_compress(cx);
              inputLen -= bytesToConsume;
              input += bytesToConsume;
       }

       /* Iterate over 16-byte chunks of the input. */
       while (inputLen >= MD2_BUFSIZE) {
              memcpy(&cx->X[MD2_INPUT], input, MD2_BUFSIZE);
              md2_compress(cx);
              inputLen -= MD2_BUFSIZE;
              input += MD2_BUFSIZE;
       }

       /* Copy any input that remains into the buffer. */
       if (inputLen)
              memcpy(&cx->X[MD2_INPUT], input, inputLen);
       cx->unusedBuffer = MD2_BUFSIZE - inputLen;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const PRUint8 MD2S[256] [static]

Definition at line 58 of file md2.c.