SDL  2.0
SDL_test_md5.h File Reference
#include "begin_code.h"
#include "close_code.h"
+ Include dependency graph for SDL_test_md5.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SDLTest_Md5Context

Typedefs

typedef unsigned long int MD5UINT4

Functions

void SDLTest_Md5Init (SDLTest_Md5Context *mdContext)
 initialize the context
void SDLTest_Md5Update (SDLTest_Md5Context *mdContext, unsigned char *inBuf, unsigned int inLen)
 update digest from variable length data
void SDLTest_Md5Final (SDLTest_Md5Context *mdContext)
 complete digest computation

Detailed Description

Include file for SDL test framework.

This code is a part of the SDL2_test library, not the main SDL library.

Definition in file SDL_test_md5.h.

Typedef Documentation

typedef unsigned long int MD5UINT4

Definition at line 68 of file SDL_test_md5.h.

Function Documentation

void SDLTest_Md5Final ( SDLTest_Md5Context mdContext)

complete digest computation

Parameters
mdContextpointer to context variable

Note: The function terminates the message-digest computation and ends with the desired message digest in mdContext.digest[0..15]. Always call before using the digest[] variable.

Definition at line 180 of file SDL_test_md5.c.

References SDLTest_Md5Context::buf, SDLTest_Md5Context::digest, i, SDLTest_Md5Context::i, SDLTest_Md5Context::in, MD5PADDING, NULL, SDLTest_Md5Transform(), and SDLTest_Md5Update().

Referenced by SDLTest_GenerateExecKey().

{
MD5UINT4 in[16];
int mdi;
unsigned int i, ii;
unsigned int padLen;
if (mdContext == NULL) return;
/*
* save number of bits
*/
in[14] = mdContext->i[0];
in[15] = mdContext->i[1];
/*
* compute number of bytes mod 64
*/
mdi = (int) ((mdContext->i[0] >> 3) & 0x3F);
/*
* pad out to 56 mod 64
*/
padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi);
SDLTest_Md5Update(mdContext, MD5PADDING, padLen);
/*
* append length in bits and transform
*/
for (i = 0, ii = 0; i < 14; i++, ii += 4)
in[i] = (((MD5UINT4) mdContext->in[ii + 3]) << 24) |
(((MD5UINT4) mdContext->in[ii + 2]) << 16) |
(((MD5UINT4) mdContext->in[ii + 1]) << 8) |
((MD5UINT4) mdContext->in[ii]);
SDLTest_Md5Transform(mdContext->buf, in);
/*
* store buffer in digest
*/
for (i = 0, ii = 0; i < 4; i++, ii += 4) {
mdContext->digest[ii] = (unsigned char) (mdContext->buf[i] & 0xFF);
mdContext->digest[ii + 1] =
(unsigned char) ((mdContext->buf[i] >> 8) & 0xFF);
mdContext->digest[ii + 2] =
(unsigned char) ((mdContext->buf[i] >> 16) & 0xFF);
mdContext->digest[ii + 3] =
(unsigned char) ((mdContext->buf[i] >> 24) & 0xFF);
}
}
void SDLTest_Md5Init ( SDLTest_Md5Context mdContext)

initialize the context

Parameters
mdContextpointer to context variable

Note: The function initializes the message-digest context mdContext. Call before each new use of the context - all fields are set to zero.

Definition at line 110 of file SDL_test_md5.c.

References SDLTest_Md5Context::buf, SDLTest_Md5Context::i, and NULL.

Referenced by SDLTest_GenerateExecKey().

{
if (mdContext==NULL) return;
mdContext->i[0] = mdContext->i[1] = (MD5UINT4) 0;
/*
* Load magic initialization constants.
*/
mdContext->buf[0] = (MD5UINT4) 0x67452301;
mdContext->buf[1] = (MD5UINT4) 0xefcdab89;
mdContext->buf[2] = (MD5UINT4) 0x98badcfe;
mdContext->buf[3] = (MD5UINT4) 0x10325476;
}
void SDLTest_Md5Update ( SDLTest_Md5Context mdContext,
unsigned char *  inBuf,
unsigned int  inLen 
)

update digest from variable length data

Parameters
mdContextpointer to context variable
inBufpointer to data array/string
inLenlength of data array/string

Note: The function updates the message-digest context to account for the presence of each of the characters inBuf[0..inLen-1] in the message whose digest is being computed.

Definition at line 131 of file SDL_test_md5.c.

References SDLTest_Md5Context::buf, i, SDLTest_Md5Context::i, SDLTest_Md5Context::in, NULL, and SDLTest_Md5Transform().

Referenced by SDLTest_GenerateExecKey(), and SDLTest_Md5Final().

{
MD5UINT4 in[16];
int mdi;
unsigned int i, ii;
if (mdContext == NULL) return;
if (inBuf == NULL || inLen < 1) return;
/*
* compute number of bytes mod 64
*/
mdi = (int) ((mdContext->i[0] >> 3) & 0x3F);
/*
* update number of bits
*/
if ((mdContext->i[0] + ((MD5UINT4) inLen << 3)) < mdContext->i[0])
mdContext->i[1]++;
mdContext->i[0] += ((MD5UINT4) inLen << 3);
mdContext->i[1] += ((MD5UINT4) inLen >> 29);
while (inLen--) {
/*
* add new character to buffer, increment mdi
*/
mdContext->in[mdi++] = *inBuf++;
/*
* transform if necessary
*/
if (mdi == 0x40) {
for (i = 0, ii = 0; i < 16; i++, ii += 4)
in[i] = (((MD5UINT4) mdContext->in[ii + 3]) << 24) |
(((MD5UINT4) mdContext->in[ii + 2]) << 16) |
(((MD5UINT4) mdContext->in[ii + 1]) << 8) |
((MD5UINT4) mdContext->in[ii]);
SDLTest_Md5Transform(mdContext->buf, in);
mdi = 0;
}
}
}