Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Add crc32 and md5 to test lib
Browse files Browse the repository at this point in the history
  • Loading branch information
ferzkopp committed Nov 29, 2012
1 parent 5faee44 commit 4a744e7
Show file tree
Hide file tree
Showing 6 changed files with 775 additions and 13 deletions.
10 changes: 6 additions & 4 deletions include/SDL_test.h
Expand Up @@ -20,20 +20,22 @@
*/

/**
* \file SDLTest.h
* \file SDL_test.h
*
* Include file for SDL test framework.
*
* This code is a part of the SDL2_test library, not the main SDL library.
*/

#ifndef _SDLTest_h
#define _SDLTest_h
#ifndef _SDL_test_h
#define _SDL_test_h

#include "SDL.h"
#include "SDL_test_font.h"
#include "SDL_test_random.h"
#include "SDL_test_fuzzer.h"
#include "SDL_test_crc32.h"
#include "SDL_test_md5.h"

#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
Expand All @@ -55,6 +57,6 @@ extern "C" {
#endif
#include "close_code.h"

#endif /* _SDLTest_h */
#endif /* _SDL_test_h */

/* vi: set ts=4 sw=4 expandtab: */
128 changes: 128 additions & 0 deletions include/SDL_test_crc32.h
@@ -0,0 +1,128 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/

/**
* \file SDL_test_crc32.h
*
* Include file for SDL test framework.
*
* This code is a part of the SDL2_test library, not the main SDL library.
*/

/*
Implements CRC32 calculations (default output is Perl String::CRC32 compatible).
*/

#ifndef _SDL_test_crc32_h
#define _SDL_test_crc32_h

#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif


/* ------------ Definitions --------- */

/* Definition shared by all CRC routines */

#ifndef CrcUint32
#define CrcUint32 unsigned int
#endif
#ifndef CrcUint8
#define CrcUint8 unsigned char
#endif

#ifdef ORIGINAL_METHOD
#define CRC32_POLY 0x04c11db7 /* AUTODIN II, Ethernet, & FDDI */
#else
#define CRC32_POLY 0xEDB88320 /* Perl String::CRC32 compatible */
#endif

/**
* Data structure for CRC32 (checksum) computation
*/
typedef struct {
CrcUint32 crc32_table[256]; /* CRC table */
} SDLTest_Crc32Context;

/* ---------- Function Prototypes ------------- */

/**
* /brief Initialize the CRC context
*
* Note: The function initializes the crc table required for all crc calculations.
*
* /param crcContext pointer to context variable
*
* /returns 0 for OK, -1 on error
*
*/
int SDLTest_Crc32Init(SDLTest_Crc32Context * crcContext);


/**
* /brief calculate a crc32 from a data block
*
* /param crcContext pointer to context variable
* /param inBuf input buffer to checksum
* /param inLen length of input buffer
* /param crc32 pointer to Uint32 to store the final CRC into
*
* /returns 0 for OK, -1 on error
*
*/
int SDLTest_crc32Calc(SDLTest_Crc32Context * crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32);

/* Same routine broken down into three steps */
int SDLTest_Crc32CalcStart(SDLTest_Crc32Context * crcContext, CrcUint32 *crc32);
int SDLTest_Crc32CalcEnd(SDLTest_Crc32Context * crcContext, CrcUint32 *crc32);
int SDLTest_Crc32CalcBuffer(SDLTest_Crc32Context * crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32);


/**
* /brief clean up CRC context
*
* /param crcContext pointer to context variable
*
* /returns 0 for OK, -1 on error
*
*/

int SDLTest_Crc32Done(SDLTest_Crc32Context * crcContext);


/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"

#endif /* _SDL_test_crc32_h */

/* vi: set ts=4 sw=4 expandtab: */
133 changes: 133 additions & 0 deletions include/SDL_test_md5.h
@@ -0,0 +1,133 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/

/**
* \file SDL_test_md5.h
*
* Include file for SDL test framework.
*
* This code is a part of the SDL2_test library, not the main SDL library.
*/

/*
***********************************************************************
** Header file for implementation of MD5 **
** RSA Data Security, Inc. MD5 Message-Digest Algorithm **
** Created: 2/17/90 RLR **
** Revised: 12/27/90 SRD,AJ,BSK,JT Reference C version **
** Revised (for MD5): RLR 4/27/91 **
** -- G modified to have y&~z instead of y&z **
** -- FF, GG, HH modified to add in last register done **
** -- Access pattern: round 2 works mod 5, round 3 works mod 3 **
** -- distinct additive constant for each step **
** -- round 4 added, working mod 7 **
***********************************************************************
*/

/*
***********************************************************************
** Message-digest routines: **
** To form the message digest for a message M **
** (1) Initialize a context buffer mdContext using MD5Init **
** (2) Call MD5Update on mdContext and M **
** (3) Call MD5Final on mdContext **
** The message digest is now in mdContext->digest[0...15] **
***********************************************************************
*/

#ifndef _SDL_test_md5_h
#define _SDL_test_md5_h

#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif

/* ------------ Definitions --------- */

/* typedef a 32-bit type */
typedef unsigned long int MD5UINT4;

/* Data structure for MD5 (Message-Digest) computation */
typedef struct {
MD5UINT4 i[2]; /* number of _bits_ handled mod 2^64 */
MD5UINT4 buf[4]; /* scratch buffer */
unsigned char in[64]; /* input buffer */
unsigned char digest[16]; /* actual digest after Md5Final call */
} SDLTest_Md5Context;

/* ---------- Function Prototypes ------------- */

/**
* /brief initialize the context
*
* /param mdContext pointer 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.
*/
void SDLTest_Md5Init(SDLTest_Md5Context * mdContext);


/**
* /brief update digest from variable length data
*
* /param mdContext pointer to context variable
* /param inBuf pointer to data array/string
* /param inLen length 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.
*/

void SDLTest_Md5Update(SDLTest_Md5Context * mdContext, unsigned char *inBuf,
unsigned int inLen);


/*
* /brief complete digest computation
*
* /param mdContext pointer 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.
*/

void SDLTest_Md5Final(SDLTest_Md5Context * mdContext);


/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"

#endif /* _SDL_test_md5_h */

/* vi: set ts=4 sw=4 expandtab: */
16 changes: 7 additions & 9 deletions include/SDL_test_random.h
Expand Up @@ -48,10 +48,7 @@ extern "C" {
/* *INDENT-ON* */
#endif

/* Function prototypes */


/* ------- Definitions ------- */
/* --- Definitions */

/*
* Macros that return a random number in a specific format.
Expand All @@ -69,13 +66,14 @@ extern "C" {
unsigned int al;
} SDLTest_RandomContext;

/* ---- Function Prototypes -------- */

/* --- Function prototypes */

/**
* \brief Initialize random number generator with two integers.
*
* Note: The random sequence of numbers returned by ...Random() is the
* same for the same two integers and has a period of 2^31.
* Note: The random sequence of numbers returned by ...Random() is the
* same for the same two integers and has a period of 2^31.
*
* \param rndContext pointer to context structure
* \param xi integer that defines the random sequence
Expand All @@ -97,8 +95,8 @@ extern "C" {
/**
* \brief Initialize random number generator based on current system time.
*
* Note: ...RandomInit() or ...RandomInitTime() must have been called
* before using this function.
* Note: ...RandomInit() or ...RandomInitTime() must have been called
* before using this function.
*
* \param rndContext pointer to context structure
*
Expand Down

0 comments on commit 4a744e7

Please sign in to comment.