Skip to content

Commit

Permalink
Dynamic memory allocation in the DWordSmoker
Browse files Browse the repository at this point in the history
  • Loading branch information
Bulat-Ziganshin committed Feb 8, 2014
1 parent 4ad762a commit 01e3e91
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions smoke.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ class Smoker
{
public:
virtual const char* name() = 0;
virtual void smoke (void *buf, size_t bufsize, double *entropy) = 0;
virtual ~Smoker() {}
virtual void smoke (void *buf, size_t bufsize, double *entropy) = 0;
};


/**********************************************************************/
/* Byte smoker: calculate compression ratio with the order-0 model */
/**********************************************************************/
/*************************************************************************/
/* Byte smoker: calculate compression ratio with the 8-bit order-0 model */
/************************************************************************/

class ByteSmoker : public Smoker
{
Expand Down Expand Up @@ -63,36 +63,37 @@ void ByteSmoker::smoke (void *buf, size_t bufsize, double *entropy)
}


/**********************************************************************/
/* DWord smoker */
/**********************************************************************/

uint32_t hash_function (uint32_t x)
{
uint64_t hash = x * uint64_t(123456791u);
return uint32_t(hash>>32) ^ uint32_t(hash);
}
/***************************************************************************/
/* DWord smoker: calculate compression ratio with the 32-bit order-0 model */
/***************************************************************************/

const size_t HASHSIZE = 128*kb;

class DWordSmoker : public Smoker
{
byte *table;
size_t bits[256];
byte table[HASHSIZE];
public:
DWordSmoker();
virtual const char* name() {return "DWordSmoker";};
virtual ~DWordSmoker() {delete[] table;}
virtual void smoke (void *buf, size_t bufsize, double *entropy);
virtual ~DWordSmoker() {}
};

DWordSmoker::DWordSmoker()
{
table = new byte[HASHSIZE];
bits[0] = 0;
for (int i=1; i<256; i++)
bits[i] = bits[i/2] + (i%2);
}

uint32_t hash_function (uint32_t x)
{
uint64_t hash = x * uint64_t(123456791u);
return uint32_t(hash>>32) ^ uint32_t(hash);
}

void DWordSmoker::smoke (void *buf, size_t bufsize, double *entropy)
{
const size_t STEP = 4; // Check only every n'th position
Expand Down

0 comments on commit 01e3e91

Please sign in to comment.