Fixing the previous commit.
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/test/test-automation/fuzzer/fuzzer.c Sun Jul 24 18:58:36 2011 +0300
1.3 @@ -0,0 +1,119 @@
1.4 +#include <stdio.h>
1.5 +#include <stdlib.h>
1.6 +
1.7 +#include <string.h>
1.8 +
1.9 +
1.10 +#include "../SDL_test.h"
1.11 +
1.12 +#include "fuzzer.h"
1.13 +
1.14 +
1.15 +//! context for test-specific random number generator
1.16 +RND_CTX rndContext3;
1.17 +
1.18 +int
1.19 +GenerateExecKey(CRC32_CTX crcContext, char *runSeed, char *suiteName,
1.20 + char *testName, int iterationNumber)
1.21 +{
1.22 + if(runSeed == NULL || suiteName == NULL ||
1.23 + testName == NULL || iterationNumber < 0) {
1.24 + fprintf(stderr, "Incorrect parameter given to GenerateExecKey function\n");
1.25 + return -1;
1.26 + }
1.27 +
1.28 + char iterationString[256];
1.29 + memset(iterationString, 0, sizeof(iterationString));
1.30 +
1.31 + snprintf(iterationString, sizeof(iterationString), "%d", iterationNumber);
1.32 +
1.33 + // combine the parameters
1.34 + const int runSeedLength = strlen(runSeed);
1.35 + const int suiteNameLength = strlen(suiteName);
1.36 + const int testNameLength = strlen(testName);
1.37 + const int iterationStringLength = strlen(iterationString);
1.38 +
1.39 + // size of the entire + 3 for slashes and + 1 for '\0'
1.40 + const int entireString = runSeedLength + suiteNameLength +
1.41 + testNameLength + iterationString + 3 + 1;
1.42 +
1.43 + int result = 0;
1.44 +
1.45 + /* Let's take a hash from the strings separately because
1.46 + * it's really slow to calculate md5 or crc32 for a really long string
1.47 + * like 'runSeed/testSuiteName/testName/iteration'
1.48 + */
1.49 + MD5_CTX md5Context;
1.50 + utl_md5Init(&md5Context);
1.51 +
1.52 + utl_md5Update(&md5Context, runSeed, runSeedLength);
1.53 + utl_md5Update(&md5Context, suiteName, suiteNameLength);
1.54 + utl_md5Update(&md5Context, testName, testNameLength);
1.55 + utl_md5Update(&md5Context, iterationString, iterationStringLength);
1.56 +
1.57 + utl_md5Final(&md5Context);
1.58 +
1.59 + utl_crc32Calc(&crcContext, md5Context.digest, sizeof(md5Context.digest), &result);
1.60 +
1.61 + return result;
1.62 +}
1.63 +
1.64 +void
1.65 +InitFuzzer(const int execKey)
1.66 +{
1.67 + utl_randomInit(&rndContext3, globalExecKey, globalExecKey / 0xfafafafa);
1.68 +}
1.69 +
1.70 +void
1.71 +DeinitFuzzer()
1.72 +{
1.73 +
1.74 +}
1.75 +
1.76 +int
1.77 +RandomInteger()
1.78 +{
1.79 + return utl_randomInt(&rndContext3);
1.80 +}
1.81 +
1.82 +int
1.83 +RandomPositiveIntegerInRange(int min, int max)
1.84 +{
1.85 + int number = utl_randomInt(&rndContext3);
1.86 + number = abs(number);
1.87 +
1.88 + return (number % (max - min)) + min;
1.89 +}
1.90 +
1.91 +int
1.92 +RandomBoundaryValue(const int max)
1.93 +{
1.94 + // Note: somehow integrate with RandomInteger?
1.95 + // try to make more sensible & add new values
1.96 + int boundaryValues[] = {0, 1, 15, 16, 17, 31, 32, 33, 63, 64, 65};
1.97 + int retValue = -1;
1.98 +
1.99 + do {
1.100 + int index = RandomPositiveIntegerInRange(0, 10);
1.101 + retValue = boundaryValues[index];
1.102 +
1.103 + } while( !(retValue <= max) );
1.104 +
1.105 + return retValue;
1.106 +}
1.107 +
1.108 +
1.109 +char *
1.110 +RandomAsciiString()
1.111 +{
1.112 + const int size = abs(RandomInteger);
1.113 + char *string = SDL_malloc(size * sizeof(size));
1.114 +
1.115 + int counter = 0;
1.116 + for( ; counter < size; ++counter) {
1.117 + char character = (char) RandomPositiveIntegerInRange(0, 127);
1.118 + string[counter] = character;
1.119 + }
1.120 +
1.121 + return string;
1.122 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/test/test-automation/fuzzer/fuzzer.h Sun Jul 24 18:58:36 2011 +0300
2.3 @@ -0,0 +1,80 @@
2.4 +/*
2.5 + Copyright (C) 2011 Markus Kauppila <markus.kauppila@gmail.com>
2.6 +
2.7 + This software is provided 'as-is', without any express or implied
2.8 + warranty. In no event will the authors be held liable for any damages
2.9 + arising from the use of this software.
2.10 +
2.11 + Permission is granted to anyone to use this software for any purpose,
2.12 + including commercial applications, and to alter it and redistribute it
2.13 + freely, subject to the following restrictions:
2.14 +
2.15 + 1. The origin of this software must not be misrepresented; you must not
2.16 + claim that you wrote the original software. If you use this software
2.17 + in a product, an acknowledgment in the product documentation would be
2.18 + appreciated but is not required.
2.19 + 2. Altered source versions must be plainly marked as such, and must not be
2.20 + misrepresented as being the original software.
2.21 + 3. This notice may not be removed or altered from any source distribution.
2.22 +*/
2.23 +
2.24 +#ifndef _FUZZER_H
2.25 +#define _FUZZER_H
2.26 +
2.27 +#include "utl_crc32.h"
2.28 +#include "utl_md5.h"
2.29 +#include "utl_random.h"
2.30 +
2.31 +/*!
2.32 + * Inits the fuzzer for a test
2.33 + */
2.34 +void InitFuzzer(const int execKey);
2.35 +
2.36 +/*!
2.37 + * Deinits the fuzzer (for a test)
2.38 + */
2.39 +void DeinitFuzzer();
2.40 +
2.41 +
2.42 +/*!
2.43 + * Returns random integer
2.44 + *
2.45 + * \returns Generated integer
2.46 + */
2.47 +int RandomInteger();
2.48 +
2.49 +/*!
2.50 + * Returns positive integer in range [min, max]
2.51 + *
2.52 + * \returns Generated integer
2.53 + */
2.54 +int RandomPositiveIntegerInRange(int min, int max);
2.55 +
2.56 +/*!
2.57 + * Generates random ASCII string
2.58 + *
2.59 + * \returns newly allocated random string
2.60 + */
2.61 +char *RandomAsciiString();
2.62 +
2.63 +/*!
2.64 + * Generates a random boundary value. Max is the biggest
2.65 + * value the function can return.
2.66 + *
2.67 + * \returns a boundary value
2.68 + */
2.69 +int RandomBoundaryValue(const int max);
2.70 +
2.71 +/*!
2.72 + * Generates execution key (used for random seed) for a test
2.73 + *
2.74 + * \param runSeed Seed of the harness
2.75 + * \param suiteName Test suite name
2.76 + * \param testName Test name
2.77 + * \param iteration Number of test iteration
2.78 + *
2.79 + * \return Generated execution key
2.80 + */
2.81 +int GenerateExecKey(CRC32_CTX crcContext, char *runSeed, char *suiteName, char *testName, int interationNumber);
2.82 +
2.83 +#endif
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/test/test-automation/fuzzer/utl_crc32.c Sun Jul 24 18:58:36 2011 +0300
3.3 @@ -0,0 +1,125 @@
3.4 +
3.5 +#include "utl_crc32.h"
3.6 +
3.7 +int utl_crc32Init(CRC32_CTX *crcContext)
3.8 +{
3.9 + int i,j;
3.10 + CrcUint32 c;
3.11 +
3.12 + /* Sanity check context pointer */
3.13 + if (crcContext==NULL) {
3.14 + return(-1);
3.15 + }
3.16 +
3.17 + /*
3.18 + * Build auxiliary table for parallel byte-at-a-time CRC-32
3.19 + */
3.20 +#ifdef ORIGINAL_METHOD
3.21 + for (i = 0; i < 256; ++i) {
3.22 + for (c = i << 24, j = 8; j > 0; --j) {
3.23 + c = c & 0x80000000 ? (c << 1) ^ CRC32_POLY : (c << 1);
3.24 + }
3.25 + crcContext->crc32_table[i] = c;
3.26 + }
3.27 +#else
3.28 + for (i=0; i<256; i++) {
3.29 + c = i;
3.30 + for (j=8; j>0; j--) {
3.31 + if (c & 1) {
3.32 + c = (c >> 1) ^ CRC32_POLY;
3.33 + } else {
3.34 + c >>= 1;
3.35 + }
3.36 + }
3.37 + crcContext->crc32_table[i] = c;
3.38 + }
3.39 +#endif
3.40 +
3.41 + return(0);
3.42 +}
3.43 +
3.44 +/* Complete CRC32 calculation on a memory block */
3.45 +
3.46 +int utl_crc32Calc(CRC32_CTX * crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32)
3.47 +{
3.48 + if (utl_crc32CalcStart(crcContext,crc32)) {
3.49 + return(-1);
3.50 + }
3.51 + if (utl_crc32CalcBuffer(crcContext, inBuf, inLen, crc32)) {
3.52 + return(-1);
3.53 + }
3.54 + if (utl_crc32CalcEnd(crcContext, crc32)) {
3.55 + return(-1);
3.56 + }
3.57 + return(0);
3.58 +}
3.59 +
3.60 +/* Start crc calculation */
3.61 +
3.62 +int utl_crc32CalcStart(CRC32_CTX * crcContext, CrcUint32 *crc32)
3.63 +{
3.64 + /* Sanity check pointers */
3.65 + if (crcContext==NULL) {
3.66 + *crc32=0;
3.67 + return(-1);
3.68 + }
3.69 +
3.70 + /*
3.71 + * Preload shift register, per CRC-32 spec
3.72 + */
3.73 + *crc32 = 0xffffffff;
3.74 +
3.75 + return(0);
3.76 +}
3.77 +
3.78 +/* Finish crc calculation */
3.79 +
3.80 +int utl_crc32CalcEnd(CRC32_CTX * crcContext, CrcUint32 *crc32)
3.81 +{
3.82 + /*
3.83 + * Return complement, per CRC-32 spec
3.84 + */
3.85 + *crc32 = (~(*crc32));
3.86 +
3.87 + return(0);
3.88 +}
3.89 +
3.90 +/* Include memory block in crc */
3.91 +
3.92 +int utl_crc32CalcBuffer(CRC32_CTX * crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32)
3.93 +{
3.94 + CrcUint8 *p;
3.95 + register CrcUint32 crc;
3.96 +
3.97 + /* Sanity check pointers */
3.98 + if (crcContext==NULL) {
3.99 + *crc32=0;
3.100 + return(-1);
3.101 + }
3.102 +
3.103 +
3.104 + /*
3.105 + * Calculate CRC from data
3.106 + */
3.107 + crc = *crc32;
3.108 + for (p = inBuf; inLen > 0; ++p, --inLen) {
3.109 +#ifdef ORIGINAL_METHOD
3.110 + crc = (crc << 8) ^ crcContext->crc32_table[(crc >> 24) ^ *p];
3.111 +#else
3.112 + crc = ((crc >> 8) & 0x00FFFFFF) ^ crcContext->crc32_table[ (crc ^ *p) & 0xFF ];
3.113 +#endif
3.114 + }
3.115 + *crc32 = crc;
3.116 +
3.117 + return(0);
3.118 +}
3.119 +
3.120 +int utl_crc32Done(CRC32_CTX * crcContext)
3.121 +{
3.122 + /* Sanity check context pointer */
3.123 + if (crcContext==NULL) {
3.124 + return(-1);
3.125 + }
3.126 +
3.127 + return(0);
3.128 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/test/test-automation/fuzzer/utl_crc32.h Sun Jul 24 18:58:36 2011 +0300
4.3 @@ -0,0 +1,113 @@
4.4 +#ifndef _utl_crc32_h
4.5 +#define _utl_crc32_h
4.6 +
4.7 +/* Set up for C function definitions, even when using C++ */
4.8 +#ifdef __cplusplus
4.9 +extern "C" {
4.10 +#endif
4.11 +
4.12 +/* ----------- Includes -------------- */
4.13 +
4.14 +#include <stdlib.h>
4.15 +
4.16 +/* ------------ Definitions --------- */
4.17 +
4.18 +/* Definition shared by all CRC routines */
4.19 +
4.20 +#ifndef CrcUint32
4.21 + #define CrcUint32 unsigned int
4.22 +#endif
4.23 +#ifndef CrcUint8
4.24 + #define CrcUint8 unsigned char
4.25 +#endif
4.26 +
4.27 +#ifdef ORIGINAL_METHOD
4.28 + #define CRC32_POLY 0x04c11db7 /* AUTODIN II, Ethernet, & FDDI */
4.29 +#else
4.30 + #define CRC32_POLY 0xEDB88320 /* Perl String::CRC32 compatible */
4.31 +#endif
4.32 +
4.33 +/* Data structure for CRC32 (checksum) computation */
4.34 +
4.35 + typedef struct {
4.36 + CrcUint32 crc32_table[256]; /* CRC table */
4.37 + } CRC32_CTX;
4.38 +
4.39 +/* ---------- Function Prototypes ------------- */
4.40 +
4.41 +#ifdef WIN32
4.42 +#ifdef BUILD_DLL
4.43 +#define DLLINTERFACE __declspec(dllexport)
4.44 +#else
4.45 +#define DLLINTERFACE __declspec(dllimport)
4.46 +#endif
4.47 +#else
4.48 +#define DLLINTERFACE
4.49 +#endif
4.50 +
4.51 +/*
4.52 + * utl_crc32Init: initialize the CRC context
4.53 + *
4.54 + * Parameters:
4.55 + *
4.56 + * crcContext pointer to context variable
4.57 + *
4.58 + * Return value:
4.59 + *
4.60 + * 0 OK
4.61 + * -1 error
4.62 + *
4.63 + * Note: The function initializes the crc table required for crc calcs.
4.64 + */
4.65 + DLLINTERFACE int utl_crc32Init(CRC32_CTX * crcContext);
4.66 +
4.67 +
4.68 +/*
4.69 + * utl_crc32Calc: calculate a crc32 from a data block
4.70 + *
4.71 + * Parameters:
4.72 + *
4.73 + * crcContext pointer to context variable
4.74 + * inBuf input buffer to checksum
4.75 + * inLen length of input buffer
4.76 + * crc32 pointer to Uint32 to store the final CRC into
4.77 + *
4.78 + * Return value:
4.79 + *
4.80 + * 0 OK
4.81 + * -1 error
4.82 + *
4.83 +*/
4.84 +
4.85 + DLLINTERFACE int utl_crc32Calc(CRC32_CTX * crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32);
4.86 +
4.87 +/* Same routine broken down into three steps */
4.88 +
4.89 + DLLINTERFACE int utl_crc32CalcStart(CRC32_CTX * crcContext, CrcUint32 *crc32);
4.90 + DLLINTERFACE int utl_crc32CalcEnd(CRC32_CTX * crcContext, CrcUint32 *crc32);
4.91 + DLLINTERFACE int utl_crc32CalcBuffer(CRC32_CTX * crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32);
4.92 +
4.93 +
4.94 +/*
4.95 + * utl_crc32Done: clean up CRC context
4.96 + *
4.97 + * Parameters:
4.98 + *
4.99 + * crcContext pointer to context variable
4.100 + *
4.101 + * Return value:
4.102 + *
4.103 + * 0 OK
4.104 + * -1 error
4.105 + *
4.106 +*/
4.107 +
4.108 + DLLINTERFACE int utl_crc32Done(CRC32_CTX * crcContext);
4.109 +
4.110 +
4.111 +/* Ends C function definitions when using C++ */
4.112 +#ifdef __cplusplus
4.113 +};
4.114 +#endif
4.115 +
4.116 +#endif /* _utl_crc32_h */
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/test/test-automation/fuzzer/utl_md5.c Sun Jul 24 18:58:36 2011 +0300
5.3 @@ -0,0 +1,314 @@
5.4 +
5.5 +/*
5.6 + ***********************************************************************
5.7 + ** utl_md5.c -- the source code for MD5 routines **
5.8 + ** RSA Data Security, Inc. MD5 Message-Digest Algorithm **
5.9 + ** Created: 2/17/90 RLR **
5.10 + ** Revised: 1/91 SRD,AJ,BSK,JT Reference C ver., 7/10 constant corr. **
5.11 + ***********************************************************************
5.12 + */
5.13 +
5.14 +/*
5.15 + ***********************************************************************
5.16 + ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. **
5.17 + ** **
5.18 + ** License to copy and use this software is granted provided that **
5.19 + ** it is identified as the "RSA Data Security, Inc. MD5 Message- **
5.20 + ** Digest Algorithm" in all material mentioning or referencing this **
5.21 + ** software or this function. **
5.22 + ** **
5.23 + ** License is also granted to make and use derivative works **
5.24 + ** provided that such works are identified as "derived from the RSA **
5.25 + ** Data Security, Inc. MD5 Message-Digest Algorithm" in all **
5.26 + ** material mentioning or referencing the derived work. **
5.27 + ** **
5.28 + ** RSA Data Security, Inc. makes no representations concerning **
5.29 + ** either the merchantability of this software or the suitability **
5.30 + ** of this software for any particular purpose. It is provided "as **
5.31 + ** is" without express or implied warranty of any kind. **
5.32 + ** **
5.33 + ** These notices must be retained in any copies of any part of this **
5.34 + ** documentation and/or software. **
5.35 + ***********************************************************************
5.36 + */
5.37 +
5.38 +#include "utl_md5.h"
5.39 +
5.40 +/* forward declaration */
5.41 +static void Transform(MD5UINT4 * buf, MD5UINT4 * in);
5.42 +
5.43 +static unsigned char MD5PADDING[64] = {
5.44 + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5.45 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5.46 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5.47 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5.48 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5.49 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5.50 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5.51 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
5.52 +};
5.53 +
5.54 +/* F, G, H and I are basic MD5 functions */
5.55 +#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
5.56 +#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
5.57 +#define H(x, y, z) ((x) ^ (y) ^ (z))
5.58 +#define I(x, y, z) ((y) ^ ((x) | (~z)))
5.59 +
5.60 +/* ROTATE_LEFT rotates x left n bits */
5.61 +#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
5.62 +
5.63 +/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */
5.64 +
5.65 +/* Rotation is separate from addition to prevent recomputation */
5.66 +#define FF(a, b, c, d, x, s, ac) \
5.67 + {(a) += F ((b), (c), (d)) + (x) + (MD5UINT4)(ac); \
5.68 + (a) = ROTATE_LEFT ((a), (s)); \
5.69 + (a) += (b); \
5.70 + }
5.71 +#define GG(a, b, c, d, x, s, ac) \
5.72 + {(a) += G ((b), (c), (d)) + (x) + (MD5UINT4)(ac); \
5.73 + (a) = ROTATE_LEFT ((a), (s)); \
5.74 + (a) += (b); \
5.75 + }
5.76 +#define HH(a, b, c, d, x, s, ac) \
5.77 + {(a) += H ((b), (c), (d)) + (x) + (MD5UINT4)(ac); \
5.78 + (a) = ROTATE_LEFT ((a), (s)); \
5.79 + (a) += (b); \
5.80 + }
5.81 +#define II(a, b, c, d, x, s, ac) \
5.82 + {(a) += I ((b), (c), (d)) + (x) + (MD5UINT4)(ac); \
5.83 + (a) = ROTATE_LEFT ((a), (s)); \
5.84 + (a) += (b); \
5.85 + }
5.86 +
5.87 +/*
5.88 + The routine MD5Init initializes the message-digest context
5.89 + mdContext. All fields are set to zero.
5.90 +*/
5.91 +
5.92 +void utl_md5Init(MD5_CTX * mdContext)
5.93 +{
5.94 + mdContext->i[0] = mdContext->i[1] = (MD5UINT4) 0;
5.95 +
5.96 + /*
5.97 + * Load magic initialization constants.
5.98 + */
5.99 + mdContext->buf[0] = (MD5UINT4) 0x67452301;
5.100 + mdContext->buf[1] = (MD5UINT4) 0xefcdab89;
5.101 + mdContext->buf[2] = (MD5UINT4) 0x98badcfe;
5.102 + mdContext->buf[3] = (MD5UINT4) 0x10325476;
5.103 +}
5.104 +
5.105 +/*
5.106 + The routine MD5Update updates the message-digest context to
5.107 + account for the presence of each of the characters inBuf[0..inLen-1]
5.108 + in the message whose digest is being computed.
5.109 +*/
5.110 +
5.111 +void utl_md5Update(MD5_CTX * mdContext, unsigned char *inBuf,
5.112 + unsigned int inLen)
5.113 +{
5.114 + MD5UINT4 in[16];
5.115 + int mdi;
5.116 + unsigned int i, ii;
5.117 +
5.118 + /*
5.119 + * compute number of bytes mod 64
5.120 + */
5.121 + mdi = (int) ((mdContext->i[0] >> 3) & 0x3F);
5.122 +
5.123 + /*
5.124 + * update number of bits
5.125 + */
5.126 + if ((mdContext->i[0] + ((MD5UINT4) inLen << 3)) < mdContext->i[0])
5.127 + mdContext->i[1]++;
5.128 + mdContext->i[0] += ((MD5UINT4) inLen << 3);
5.129 + mdContext->i[1] += ((MD5UINT4) inLen >> 29);
5.130 +
5.131 + while (inLen--) {
5.132 + /*
5.133 + * add new character to buffer, increment mdi
5.134 + */
5.135 + mdContext->in[mdi++] = *inBuf++;
5.136 +
5.137 + /*
5.138 + * transform if necessary
5.139 + */
5.140 + if (mdi == 0x40) {
5.141 + for (i = 0, ii = 0; i < 16; i++, ii += 4)
5.142 + in[i] = (((MD5UINT4) mdContext->in[ii + 3]) << 24) |
5.143 + (((MD5UINT4) mdContext->in[ii + 2]) << 16) |
5.144 + (((MD5UINT4) mdContext->in[ii + 1]) << 8) |
5.145 + ((MD5UINT4) mdContext->in[ii]);
5.146 + Transform(mdContext->buf, in);
5.147 + mdi = 0;
5.148 + }
5.149 + }
5.150 +}
5.151 +
5.152 +/*
5.153 + The routine MD5Final terminates the message-digest computation and
5.154 + ends with the desired message digest in mdContext->digest[0...15].
5.155 +*/
5.156 +
5.157 +void utl_md5Final(MD5_CTX * mdContext)
5.158 +{
5.159 + MD5UINT4 in[16];
5.160 + int mdi;
5.161 + unsigned int i, ii;
5.162 + unsigned int padLen;
5.163 +
5.164 + /*
5.165 + * save number of bits
5.166 + */
5.167 + in[14] = mdContext->i[0];
5.168 + in[15] = mdContext->i[1];
5.169 +
5.170 + /*
5.171 + * compute number of bytes mod 64
5.172 + */
5.173 + mdi = (int) ((mdContext->i[0] >> 3) & 0x3F);
5.174 +
5.175 + /*
5.176 + * pad out to 56 mod 64
5.177 + */
5.178 + padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi);
5.179 + utl_md5Update(mdContext, MD5PADDING, padLen);
5.180 +
5.181 + /*
5.182 + * append length in bits and transform
5.183 + */
5.184 + for (i = 0, ii = 0; i < 14; i++, ii += 4)
5.185 + in[i] = (((MD5UINT4) mdContext->in[ii + 3]) << 24) |
5.186 + (((MD5UINT4) mdContext->in[ii + 2]) << 16) |
5.187 + (((MD5UINT4) mdContext->in[ii + 1]) << 8) |
5.188 + ((MD5UINT4) mdContext->in[ii]);
5.189 + Transform(mdContext->buf, in);
5.190 +
5.191 + /*
5.192 + * store buffer in digest
5.193 + */
5.194 + for (i = 0, ii = 0; i < 4; i++, ii += 4) {
5.195 + mdContext->digest[ii] = (unsigned char) (mdContext->buf[i] & 0xFF);
5.196 + mdContext->digest[ii + 1] =
5.197 + (unsigned char) ((mdContext->buf[i] >> 8) & 0xFF);
5.198 + mdContext->digest[ii + 2] =
5.199 + (unsigned char) ((mdContext->buf[i] >> 16) & 0xFF);
5.200 + mdContext->digest[ii + 3] =
5.201 + (unsigned char) ((mdContext->buf[i] >> 24) & 0xFF);
5.202 + }
5.203 +}
5.204 +
5.205 +/* Basic MD5 step. Transforms buf based on in.
5.206 + */
5.207 +static void Transform(MD5UINT4 * buf, MD5UINT4 * in)
5.208 +{
5.209 + MD5UINT4 a = buf[0], b = buf[1], c = buf[2], d = buf[3];
5.210 +
5.211 + /*
5.212 + * Round 1
5.213 + */
5.214 +#define S11 7
5.215 +#define S12 12
5.216 +#define S13 17
5.217 +#define S14 22
5.218 + FF(a, b, c, d, in[0], S11, 3614090360u); /* 1 */
5.219 + FF(d, a, b, c, in[1], S12, 3905402710u); /* 2 */
5.220 + FF(c, d, a, b, in[2], S13, 606105819u); /* 3 */
5.221 + FF(b, c, d, a, in[3], S14, 3250441966u); /* 4 */
5.222 + FF(a, b, c, d, in[4], S11, 4118548399u); /* 5 */
5.223 + FF(d, a, b, c, in[5], S12, 1200080426u); /* 6 */
5.224 + FF(c, d, a, b, in[6], S13, 2821735955u); /* 7 */
5.225 + FF(b, c, d, a, in[7], S14, 4249261313u); /* 8 */
5.226 + FF(a, b, c, d, in[8], S11, 1770035416u); /* 9 */
5.227 + FF(d, a, b, c, in[9], S12, 2336552879u); /* 10 */
5.228 + FF(c, d, a, b, in[10], S13, 4294925233u); /* 11 */
5.229 + FF(b, c, d, a, in[11], S14, 2304563134u); /* 12 */
5.230 + FF(a, b, c, d, in[12], S11, 1804603682u); /* 13 */
5.231 + FF(d, a, b, c, in[13], S12, 4254626195u); /* 14 */
5.232 + FF(c, d, a, b, in[14], S13, 2792965006u); /* 15 */
5.233 + FF(b, c, d, a, in[15], S14, 1236535329u); /* 16 */
5.234 +
5.235 + /*
5.236 + * Round 2
5.237 + */
5.238 +#define S21 5
5.239 +#define S22 9
5.240 +#define S23 14
5.241 +#define S24 20
5.242 + GG(a, b, c, d, in[1], S21, 4129170786u); /* 17 */
5.243 + GG(d, a, b, c, in[6], S22, 3225465664u); /* 18 */
5.244 + GG(c, d, a, b, in[11], S23, 643717713u); /* 19 */
5.245 + GG(b, c, d, a, in[0], S24, 3921069994u); /* 20 */
5.246 + GG(a, b, c, d, in[5], S21, 3593408605u); /* 21 */
5.247 + GG(d, a, b, c, in[10], S22, 38016083u); /* 22 */
5.248 + GG(c, d, a, b, in[15], S23, 3634488961u); /* 23 */
5.249 + GG(b, c, d, a, in[4], S24, 3889429448u); /* 24 */
5.250 + GG(a, b, c, d, in[9], S21, 568446438u); /* 25 */
5.251 + GG(d, a, b, c, in[14], S22, 3275163606u); /* 26 */
5.252 + GG(c, d, a, b, in[3], S23, 4107603335u); /* 27 */
5.253 + GG(b, c, d, a, in[8], S24, 1163531501u); /* 28 */
5.254 + GG(a, b, c, d, in[13], S21, 2850285829u); /* 29 */
5.255 + GG(d, a, b, c, in[2], S22, 4243563512u); /* 30 */
5.256 + GG(c, d, a, b, in[7], S23, 1735328473u); /* 31 */
5.257 + GG(b, c, d, a, in[12], S24, 2368359562u); /* 32 */
5.258 +
5.259 + /*
5.260 + * Round 3
5.261 + */
5.262 +#define S31 4
5.263 +#define S32 11
5.264 +#define S33 16
5.265 +#define S34 23
5.266 + HH(a, b, c, d, in[5], S31, 4294588738u); /* 33 */
5.267 + HH(d, a, b, c, in[8], S32, 2272392833u); /* 34 */
5.268 + HH(c, d, a, b, in[11], S33, 1839030562u); /* 35 */
5.269 + HH(b, c, d, a, in[14], S34, 4259657740u); /* 36 */
5.270 + HH(a, b, c, d, in[1], S31, 2763975236u); /* 37 */
5.271 + HH(d, a, b, c, in[4], S32, 1272893353u); /* 38 */
5.272 + HH(c, d, a, b, in[7], S33, 4139469664u); /* 39 */
5.273 + HH(b, c, d, a, in[10], S34, 3200236656u); /* 40 */
5.274 + HH(a, b, c, d, in[13], S31, 681279174u); /* 41 */
5.275 + HH(d, a, b, c, in[0], S32, 3936430074u); /* 42 */
5.276 + HH(c, d, a, b, in[3], S33, 3572445317u); /* 43 */
5.277 + HH(b, c, d, a, in[6], S34, 76029189u); /* 44 */
5.278 + HH(a, b, c, d, in[9], S31, 3654602809u); /* 45 */
5.279 + HH(d, a, b, c, in[12], S32, 3873151461u); /* 46 */
5.280 + HH(c, d, a, b, in[15], S33, 530742520u); /* 47 */
5.281 + HH(b, c, d, a, in[2], S34, 3299628645u); /* 48 */
5.282 +
5.283 + /*
5.284 + * Round 4
5.285 + */
5.286 +#define S41 6
5.287 +#define S42 10
5.288 +#define S43 15
5.289 +#define S44 21
5.290 + II(a, b, c, d, in[0], S41, 4096336452u); /* 49 */
5.291 + II(d, a, b, c, in[7], S42, 1126891415u); /* 50 */
5.292 + II(c, d, a, b, in[14], S43, 2878612391u); /* 51 */
5.293 + II(b, c, d, a, in[5], S44, 4237533241u); /* 52 */
5.294 + II(a, b, c, d, in[12], S41, 1700485571u); /* 53 */
5.295 + II(d, a, b, c, in[3], S42, 2399980690u); /* 54 */
5.296 + II(c, d, a, b, in[10], S43, 4293915773u); /* 55 */
5.297 + II(b, c, d, a, in[1], S44, 2240044497u); /* 56 */
5.298 + II(a, b, c, d, in[8], S41, 1873313359u); /* 57 */
5.299 + II(d, a, b, c, in[15], S42, 4264355552u); /* 58 */
5.300 + II(c, d, a, b, in[6], S43, 2734768916u); /* 59 */
5.301 + II(b, c, d, a, in[13], S44, 1309151649u); /* 60 */
5.302 + II(a, b, c, d, in[4], S41, 4149444226u); /* 61 */
5.303 + II(d, a, b, c, in[11], S42, 3174756917u); /* 62 */
5.304 + II(c, d, a, b, in[2], S43, 718787259u); /* 63 */
5.305 + II(b, c, d, a, in[9], S44, 3951481745u); /* 64 */
5.306 +
5.307 + buf[0] += a;
5.308 + buf[1] += b;
5.309 + buf[2] += c;
5.310 + buf[3] += d;
5.311 +}
5.312 +
5.313 +/*
5.314 + ***********************************************************************
5.315 + ** End of utl_md5.c **
5.316 + ******************************** (cut) ********************************
5.317 + */
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/test/test-automation/fuzzer/utl_md5.h Sun Jul 24 18:58:36 2011 +0300
6.3 @@ -0,0 +1,125 @@
6.4 +
6.5 +/*
6.6 + ***********************************************************************
6.7 + ** utl_md5.h -- header file for implementation of MD5 **
6.8 + ** RSA Data Security, Inc. MD5 Message-Digest Algorithm **
6.9 + ** Created: 2/17/90 RLR **
6.10 + ** Revised: 12/27/90 SRD,AJ,BSK,JT Reference C version **
6.11 + ** Revised (for MD5): RLR 4/27/91 **
6.12 + ** -- G modified to have y&~z instead of y&z **
6.13 + ** -- FF, GG, HH modified to add in last register done **
6.14 + ** -- Access pattern: round 2 works mod 5, round 3 works mod 3 **
6.15 + ** -- distinct additive constant for each step **
6.16 + ** -- round 4 added, working mod 7 **
6.17 + ***********************************************************************
6.18 +*/
6.19 +
6.20 +/*
6.21 + ***********************************************************************
6.22 + ** Message-digest routines: **
6.23 + ** To form the message digest for a message M **
6.24 + ** (1) Initialize a context buffer mdContext using MD5Init **
6.25 + ** (2) Call MD5Update on mdContext and M **
6.26 + ** (3) Call MD5Final on mdContext **
6.27 + ** The message digest is now in mdContext->digest[0...15] **
6.28 + ***********************************************************************
6.29 +*/
6.30 +
6.31 +#ifndef _utl_md5_h
6.32 +#define _utl_md5_h
6.33 +
6.34 +/* Set up for C function definitions, even when using C++ */
6.35 +#ifdef __cplusplus
6.36 +extern "C" {
6.37 +#endif
6.38 +
6.39 +/* ------------ Definitions --------- */
6.40 +
6.41 +/* typedef a 32-bit type */
6.42 + typedef unsigned long int MD5UINT4;
6.43 +
6.44 +/* Data structure for MD5 (Message-Digest) computation */
6.45 + typedef struct {
6.46 + MD5UINT4 i[2]; /* number of _bits_ handled mod 2^64 */
6.47 + MD5UINT4 buf[4]; /* scratch buffer */
6.48 + unsigned char in[64]; /* input buffer */
6.49 + unsigned char digest[16]; /* actual digest after MD5Final call */
6.50 + } MD5_CTX;
6.51 +
6.52 +/* ---------- Function Prototypes ------------- */
6.53 +
6.54 +#ifdef WIN32
6.55 +#ifdef BUILD_DLL
6.56 +#define DLLINTERFACE __declspec(dllexport)
6.57 +#else
6.58 +#define DLLINTERFACE __declspec(dllimport)
6.59 +#endif
6.60 +#else
6.61 +#define DLLINTERFACE
6.62 +#endif
6.63 +
6.64 +/*
6.65 + * utl_md5Init: initialize the context
6.66 + *
6.67 + * Parameters:
6.68 + *
6.69 + * mdContext pointer to context variable
6.70 + *
6.71 + * Return value:
6.72 + *
6.73 + * none
6.74 + *
6.75 + * Note: The function initializes the message-digest context
6.76 + * mdContext. Call before each new use of the context -
6.77 + * all fields are set to zero.
6.78 + */
6.79 + DLLINTERFACE void utl_md5Init(MD5_CTX * mdContext);
6.80 +
6.81 +
6.82 +/*
6.83 + * utl_md5update: update digest from variable length data
6.84 + *
6.85 + * Parameters:
6.86 + *
6.87 + * mdContext pointer to context variable
6.88 + * inBuf pointer to data array/string
6.89 + * inLen length of data array/string
6.90 + *
6.91 + * Return value:
6.92 + *
6.93 + * none
6.94 + *
6.95 + * Note: The function updates the message-digest context to account
6.96 + * for the presence of each of the characters inBuf[0..inLen-1]
6.97 + * in the message whose digest is being computed.
6.98 +*/
6.99 +
6.100 + DLLINTERFACE void utl_md5Update(MD5_CTX * mdContext, unsigned char *inBuf,
6.101 + unsigned int inLen);
6.102 +
6.103 +
6.104 +/*
6.105 + * utl_md5Final: complete digest computation
6.106 + *
6.107 + * Parameters:
6.108 + *
6.109 + * mdContext pointer to context variable
6.110 + *
6.111 + * Return value:
6.112 + *
6.113 + * none
6.114 + *
6.115 + * Note: The function terminates the message-digest computation and
6.116 + * ends with the desired message digest in mdContext.digest[0..15].
6.117 + * Always call before using the digest[] variable.
6.118 +*/
6.119 +
6.120 + DLLINTERFACE void utl_md5Final(MD5_CTX * mdContext);
6.121 +
6.122 +
6.123 +/* Ends C function definitions when using C++ */
6.124 +#ifdef __cplusplus
6.125 +};
6.126 +#endif
6.127 +
6.128 +#endif /* _utl_md5_h */
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/test/test-automation/fuzzer/utl_random.c Sun Jul 24 18:58:36 2011 +0300
7.3 @@ -0,0 +1,63 @@
7.4 +
7.5 +/*
7.6 +
7.7 + utl_random
7.8 +
7.9 + A "32-bit Multiply with carry" random number generator.
7.10 +
7.11 +*/
7.12 +
7.13 +
7.14 +#include "utl_random.h"
7.15 +
7.16 +
7.17 +/* Initialize random number generator with two integer variables */
7.18 +
7.19 +void utl_randomInit(RND_CTX * rndContext, unsigned int xi, unsigned int ci)
7.20 +{
7.21 + /*
7.22 + * Choose a value for 'a' from this list
7.23 + * 1791398085 1929682203 1683268614 1965537969 1675393560
7.24 + * 1967773755 1517746329 1447497129 1655692410 1606218150
7.25 + * 2051013963 1075433238 1557985959 1781943330 1893513180
7.26 + * 1631296680 2131995753 2083801278 1873196400 1554115554
7.27 + */
7.28 + rndContext->a = 1655692410;
7.29 + rndContext->x = 30903;
7.30 + rndContext->c = 0;
7.31 + if (xi != 0)
7.32 + rndContext->x = xi;
7.33 + rndContext->c = ci;
7.34 + rndContext->ah = rndContext->a >> 16;
7.35 + rndContext->al = rndContext->a & 65535;
7.36 +}
7.37 +
7.38 +/* Initialize random number generator from time */
7.39 +
7.40 +void utl_randomInitTime(RND_CTX * rndContext)
7.41 +{
7.42 + int a,b;
7.43 +
7.44 + srand(time(NULL));
7.45 + a=rand();
7.46 + srand(clock());
7.47 + b=rand();
7.48 + utl_randomInit(rndContext, a, b);
7.49 +}
7.50 +
7.51 +/* Returns random numbers */
7.52 +
7.53 +unsigned int utl_random(RND_CTX * rndContext)
7.54 +{
7.55 + unsigned int xh, xl;
7.56 +
7.57 + xh = rndContext->x >> 16, xl = rndContext->x & 65535;
7.58 + rndContext->x = rndContext->x * rndContext->a + rndContext->c;
7.59 + rndContext->c =
7.60 + xh * rndContext->ah + ((xh * rndContext->al) >> 16) +
7.61 + ((xl * rndContext->ah) >> 16);
7.62 + if (xl * rndContext->al >= (~rndContext->c + 1))
7.63 + rndContext->c++;
7.64 +
7.65 + return (rndContext->x);
7.66 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/test/test-automation/fuzzer/utl_random.h Sun Jul 24 18:58:36 2011 +0300
8.3 @@ -0,0 +1,112 @@
8.4 +/*
8.5 +
8.6 + A "32-bit Multiply with carry: random number generator.
8.7 + Has a list of recommended multipliers. Very fast and good.
8.8 +
8.9 + multiply-with-carry generator" x(n) = a*x(n-1) + carry mod 2^32.
8.10 + period" (a*2^31)-1
8.11 +
8.12 +*/
8.13 +
8.14 +#ifndef _utl_random_h
8.15 +#define _utl_random_h
8.16 +
8.17 +/* Set up for C function definitions, even when using C++ */
8.18 +#ifdef __cplusplus
8.19 +extern "C" {
8.20 +#endif
8.21 +
8.22 +/* ------- Includes ---------- */
8.23 +
8.24 +#include <stdlib.h>
8.25 +#include <stdio.h>
8.26 +#include <time.h>
8.27 +
8.28 +/* ------- Definitions ------- */
8.29 +
8.30 +/*
8.31 + * Macros that return random number in a specific format. See utl_random()
8.32 + * below for details. Float values are in the range [0.0-1.0].
8.33 + */
8.34 +#define utl_randomInt(c) ((int)utl_random(c))
8.35 +#define utl_randomFloat(c) ((double)utl_random(c)/(unsigned long)0xffffffff)
8.36 +
8.37 + typedef struct {
8.38 + unsigned int a;
8.39 + unsigned int x;
8.40 + unsigned int c;
8.41 + unsigned int ah;
8.42 + unsigned int al;
8.43 + } RND_CTX;
8.44 +
8.45 +/* ---- Function Prototypes -------- */
8.46 +
8.47 +#ifdef WIN32
8.48 +#ifdef BUILD_DLL
8.49 +#define DLLINTERFACE __declspec(dllexport)
8.50 +#else
8.51 +#define DLLINTERFACE __declspec(dllimport)
8.52 +#endif
8.53 +#else
8.54 +#define DLLINTERFACE
8.55 +#endif
8.56 +
8.57 +/*
8.58 + * utl_randomInit: Initialize random number generator with two integers.
8.59 + *
8.60 + * Paramaters:
8.61 + *
8.62 + * rndContext pointer to context structure
8.63 + * xi, ci integers that define the random sequence
8.64 + *
8.65 + * Return value:
8.66 + *
8.67 + * none
8.68 + *
8.69 + * Note: The random sequence of numbers returned by utl_random() is the
8.70 + * same for the same two integers and has a period of 2^31.
8.71 + *
8.72 + */
8.73 + DLLINTERFACE void utl_randomInit(RND_CTX * rndContext, unsigned int xi,
8.74 + unsigned int ci);
8.75 +
8.76 +/*
8.77 + * utl_randomInitTime: Initialize random number generator with the time
8.78 + *
8.79 + * Parameters:
8.80 + *
8.81 + * rndContext pointer to context structure
8.82 + *
8.83 + * Return value:
8.84 + *
8.85 + * none
8.86 + *
8.87 + */
8.88 + DLLINTERFACE void utl_randomInitTime(RND_CTX * rndContext);
8.89 +
8.90 +
8.91 +/*
8.92 + * utl_random: Returns random numbers
8.93 + *
8.94 + * Parameters:
8.95 + *
8.96 + * rndContext pointer to context structure
8.97 + *
8.98 + * Return value:
8.99 + *
8.100 + * random number (32bit unsigned integer)
8.101 + *
8.102 + * Note: utl_randomInit() or utl_randomInitTime() must have been called
8.103 + * before using this function.
8.104 + *
8.105 + */
8.106 + DLLINTERFACE unsigned int utl_random(RND_CTX * rndContext);
8.107 +
8.108 +
8.109 +
8.110 +/* Ends C function definitions when using C++ */
8.111 +#ifdef __cplusplus
8.112 +};
8.113 +#endif
8.114 +
8.115 +#endif /* _utl_random_h */
9.1 --- a/test/test-automation/runner.c Sun Jul 24 18:21:53 2011 +0300
9.2 +++ b/test/test-automation/runner.c Sun Jul 24 18:58:36 2011 +0300
9.3 @@ -865,7 +865,8 @@
9.4 printf("Usage: ./runner [--in-proc] [--suite SUITE] [--test TEST]\n");
9.5 printf(" [--name-contains SUBSTR] [--show-tests]\n");
9.6 printf(" [--xml] [--xsl [STYLESHEET]] [--timeout VALUE]\n");
9.7 - printf(" [--version] [--help]\n");
9.8 + printf(" [--exec-key KEY] [--iterations VALUE]\n");
9.9 + printf(" [--seed VALUE] [--version] [--help]\n");
9.10 printf("Options:\n");
9.11 printf(" --in-proc Executes tests in-process\n");
9.12 printf(" --show-tests Prints out all the executable tests\n");
9.13 @@ -873,6 +874,9 @@
9.14 printf(" --xsl [STYLESHEET] Adds XSL stylesheet to the XML test reports for\n");
9.15 printf(" browser viewing. Optionally uses the specified XSL\n");
9.16 printf(" file or URL instead of the default one\n");
9.17 + printf(" --seed VALUE Specify fuzzing seed for the harness\n");
9.18 + printf(" --iterations VALUE Specify how many times a test will be executed\n");
9.19 + printf(" --exec-key KEY Run test(s) with specific execution key\n");
9.20 printf(" -tm --timeout VALUE Specify common timeout value for all tests\n");
9.21 printf(" Timeout is given in seconds and it'll override\n");
9.22 printf(" test specific timeout value only if the given\n");