UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
md5.cpp File Reference

An implementation of MD5. More...

#include "common.h"
#include <SDL_endian.h>

Go to the source code of this file.

Data Structures

struct  MD5Context
 

Macros

#define byteReverse(buf, len)   {} /* Nothing */
 
#define F1(x, y, z)   (z ^ (x & (y ^ z)))
 
#define F2(x, y, z)   F1(z, x, y)
 
#define F3(x, y, z)   (x ^ y ^ z)
 
#define F4(x, y, z)   (y ^ (x | ~z))
 
#define MD5STEP(f, w, x, y, z, data, s)   ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
 

Typedefs

typedef struct MD5Context MD5_CTX
 

Functions

static void MD5Init (struct MD5Context *ctx)
 Start MD5 accumulation. Set bit count to 0 and buffer to mysterious initialization constants. More...
 
static void MD5Transform (uint32_t buf[4], uint32_t const in[16])
 The core of the MD5 algorithm, this alters an existing MD5 hash to reflect the addition of 16 longwords of new data. MD5Update blocks the data and converts bytes into longwords for this routine. More...
 
static void MD5Update (struct MD5Context *ctx, unsigned char const *buf, unsigned len)
 Update context to reflect the concatenation of another buffer full of bytes. More...
 
static void MD5Final (struct MD5Context *ctx, unsigned char *digest)
 Final wrapup - pad to 64-byte boundary with the bit pattern 1 0* (64-bit count of bits processed, MSB-first) More...
 
const char * Com_MD5File (const char *fn, int length)
 Compute the md5sum of a given file. More...
 
const char * Com_MD5Buffer (const byte *buf, size_t len)
 Compute the md5sum of the given buffer. More...
 

Detailed Description

An implementation of MD5.

Definition in file md5.cpp.

Macro Definition Documentation

#define byteReverse (   buf,
  len 
)    {} /* Nothing */

Definition at line 33 of file md5.cpp.

Referenced by MD5Final(), and MD5Update().

#define F1 (   x,
  y,
 
)    (z ^ (x & (y ^ z)))

Definition at line 65 of file md5.cpp.

Referenced by MD5Transform().

#define F2 (   x,
  y,
 
)    F1(z, x, y)

Definition at line 66 of file md5.cpp.

Referenced by MD5Transform().

#define F3 (   x,
  y,
 
)    (x ^ y ^ z)

Definition at line 67 of file md5.cpp.

Referenced by MD5Transform().

#define F4 (   x,
  y,
 
)    (y ^ (x | ~z))

Definition at line 68 of file md5.cpp.

Referenced by MD5Transform().

#define MD5STEP (   f,
  w,
  x,
  y,
  z,
  data,
 
)    ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )

Definition at line 71 of file md5.cpp.

Referenced by MD5Transform().

Typedef Documentation

typedef struct MD5Context MD5_CTX

Function Documentation

const char* Com_MD5Buffer ( const byte buf,
size_t  len 
)

Compute the md5sum of the given buffer.

Parameters
[in]bufData to compute the md5 of
[in]lenBuffer length in bytes
Returns
the md5 sum buffer (char*)

Definition at line 300 of file md5.cpp.

References i, MD5Final(), MD5Init(), MD5Update(), and Q_strcat().

Referenced by TEST_F().

const char* Com_MD5File ( const char *  fn,
int  length 
)

Compute the md5sum of a given file.

Parameters
[in]fnFilename to compute the md5 of
[in]lengthCompute the md5 of the first 'length' bytes (if 0 - complete file)
Returns
the md5 sum buffer (char*)

Definition at line 257 of file md5.cpp.

References f, FILE_READ, FS_OpenFile(), FS_Read(), i, MD5Final(), MD5Init(), MD5Update(), and Q_strcat().

Referenced by TEST_F().

static void MD5Final ( struct MD5Context ctx,
unsigned char *  digest 
)
static

Final wrapup - pad to 64-byte boundary with the bit pattern 1 0* (64-bit count of bits processed, MSB-first)

Definition at line 211 of file md5.cpp.

References MD5Context::bits, MD5Context::buf, byteReverse, count, MD5Context::in, MD5Transform(), and OBJZERO.

Referenced by Com_MD5Buffer(), and Com_MD5File().

static void MD5Init ( struct MD5Context ctx)
static

Start MD5 accumulation. Set bit count to 0 and buffer to mysterious initialization constants.

Definition at line 52 of file md5.cpp.

References MD5Context::bits, and MD5Context::buf.

Referenced by Com_MD5Buffer(), and Com_MD5File().

static void MD5Transform ( uint32_t  buf[4],
uint32_t const  in[16] 
)
static

The core of the MD5 algorithm, this alters an existing MD5 hash to reflect the addition of 16 longwords of new data. MD5Update blocks the data and converts bytes into longwords for this routine.

Definition at line 79 of file md5.cpp.

References F1, F2, F3, F4, and MD5STEP.

Referenced by MD5Final(), and MD5Update().

static void MD5Update ( struct MD5Context ctx,
unsigned char const *  buf,
unsigned  len 
)
static

Update context to reflect the concatenation of another buffer full of bytes.

Definition at line 165 of file md5.cpp.

References MD5Context::bits, MD5Context::buf, byteReverse, MD5Context::in, and MD5Transform().

Referenced by Com_MD5Buffer(), and Com_MD5File().