Mixe for Privacy and Anonymity in the Internet
Public Member Functions | Static Private Member Functions | Static Private Attributes | List of all members
CACryptoBenchmark Class Reference

#include <CACryptoBenchmark.hpp>

Collaboration diagram for CACryptoBenchmark:

Public Member Functions

 CACryptoBenchmark ()
 
 ~CACryptoBenchmark ()
 
void doBenchmark ()
 

Static Private Member Functions

static THREAD_RETURN benchmarkThread (void *param)
 
static THREAD_RETURN timerThread (void *param)
 

Static Private Attributes

static const UINT32 ms_NUM_BLOCKSIZES = 5
 
static const UINT32 ms_BlockSizes [ms_NUM_BLOCKSIZES] = { 16,64,256,512,1024 }
 

Detailed Description

Definition at line 25 of file CACryptoBenchmark.hpp.

Constructor & Destructor Documentation

◆ CACryptoBenchmark()

CACryptoBenchmark::CACryptoBenchmark ( )

Definition at line 39 of file CACryptoBenchmark.cpp.

40 {
41 }

◆ ~CACryptoBenchmark()

CACryptoBenchmark::~CACryptoBenchmark ( )

Definition at line 44 of file CACryptoBenchmark.cpp.

45 {
46 }

Member Function Documentation

◆ benchmarkThread()

THREAD_RETURN CACryptoBenchmark::benchmarkThread ( void *  param)
staticprivate

Definition at line 94 of file CACryptoBenchmark.cpp.

95 {
96  tBenchmarkParams* pParams = (tBenchmarkParams*)a_pParams;
97  CASymChannelCipher* pCipher = new CASymCipherCTR();
98  UINT8 iv[32];
99  UINT8 key[32];
100  pCipher->setKeys(key, 32);
101  pCipher->setIVs(iv);
102  volatile bool bTimer = true;
103  CAThread* pTimerThread = new CAThread();
104  pTimerThread->setMainLoop(timerThread);
105  tBenchmarkTimerParams* pTimerParams = new tBenchmarkTimerParams();
106  pTimerParams->timerInMillis = 3000;
107  pTimerParams->bTimer = &bTimer;
108  UINT32 blocksize = pParams->blocksize;
109  UINT8* in = new UINT8[blocksize];
110  UINT8* out = new UINT8[blocksize];
111  UINT64 numCrypts = 0;
112  UINT64 startTime, endTime, time;
113  pTimerThread->start(pTimerParams,true,true);
114  getcurrentTimeMillis(startTime);
115  while (bTimer)
116  {
117  pCipher->crypt1(in, out, blocksize);
118  numCrypts++;
119  }
120  getcurrentTimeMillis(endTime);
121  time =diff64( endTime,startTime);
122  pParams->pMutexTotalBytesProcessed->lock();
123  *(pParams->outparam_pTotalBytesProcessed) += blocksize * numCrypts;
124  pParams->pMutexTotalBytesProcessed->unlock();
125  UINT64 bytes = numCrypts * 1000 * blocksize;
126  UINT8 tmpbuff[256];
127  formatBytesPerSecond(tmpbuff, 256, bytes / time);
128 
129  CAMsg::printMsg(LOG_DEBUG,"Did %llu crypts in %u ms - blocksize %u - %s\n", numCrypts,(UINT32) time, blocksize, tmpbuff);
130  delete pCipher;
131  delete pTimerThread;
132  delete pTimerParams;
133  delete[] in;
134  delete[] out;
136 
137 }
struct t_benchmarkTimerParams tBenchmarkTimerParams
SINT32 getcurrentTimeMillis(UINT64 &u64Time)
Gets the current Systemtime in milli seconds.
Definition: CAUtil.cpp:252
void formatBytesPerSecond(UINT8 *buff, UINT32 buffsize, UINT64 bytespersecond)
Definition: CAUtil.cpp:1821
UINT32 diff64(const UINT64 &bigop, const UINT64 &smallop)
Definition: CAUtil.hpp:398
#define THREAD_RETURN_SUCCESS
Definition: StdAfx.h:542
unsigned char UINT8
Definition: basetypedefs.h:135
unsigned int UINT32
Definition: basetypedefs.h:131
static THREAD_RETURN timerThread(void *param)
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
Definition: CAMsg.cpp:251
SINT32 unlock()
Definition: CAMutex.hpp:52
SINT32 lock()
Definition: CAMutex.hpp:41
virtual SINT32 setKeys(const UINT8 *key, UINT32 keysize)=0
Sets the keys for crypt1() and crypt2() either to the same key (if keysize==KEY_SIZE) or to different...
virtual SINT32 setIVs(const UINT8 *p_iv)=0
Sets iv1 and iv2 to p_iv.
virtual SINT32 crypt1(const UINT8 *in, UINT8 *out, UINT32 len)=0
This class could be used for encryption/decryption of data (streams) with AES using 128bit CTR mode.
SINT32 start(void *param, bool bDaemon=false, bool bSilent=false)
Starts the execution of the main function of this thread.
Definition: CAThread.cpp:115
SINT32 setMainLoop(THREAD_MAIN_TYP fnc)
Sets the main function which will be executed within this thread.
Definition: CAThread.hpp:148
volatile UINT64 * outparam_pTotalBytesProcessed
CAMutex * pMutexTotalBytesProcessed

References t_benchmarkParams::blocksize, t_benchmarkTimerParams::bTimer, CASymChannelCipher::crypt1(), diff64(), formatBytesPerSecond(), getcurrentTimeMillis(), CAMutex::lock(), t_benchmarkParams::outparam_pTotalBytesProcessed, t_benchmarkParams::pMutexTotalBytesProcessed, CAMsg::printMsg(), CASymChannelCipher::setIVs(), CASymChannelCipher::setKeys(), CAThread::setMainLoop(), CAThread::start(), THREAD_RETURN_SUCCESS, t_benchmarkTimerParams::timerInMillis, timerThread(), and CAMutex::unlock().

Referenced by doBenchmark().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ doBenchmark()

void CACryptoBenchmark::doBenchmark ( )

Definition at line 48 of file CACryptoBenchmark.cpp.

49 {
50  CAThreadList* pThreadList=new CAThreadList();
51  CAMutex* pMutexTotlaBytes = new CAMutex();
52  volatile UINT64 totalBytesProcessed;
53  for (UINT32 iBlocksize = 0; iBlocksize < ms_NUM_BLOCKSIZES; iBlocksize++)
54  {
55  for (UINT32 numThreads = 1; numThreads <= MAX_CRYPTOBENCHMARK_THREADS; numThreads += 4)
56  {
57  CAMsg::printMsg(LOG_DEBUG, "Do crypto benchmark for %u threads\n", numThreads);
58  totalBytesProcessed = 0;
59  UINT64 startTime, endTime, time;
60  getcurrentTimeMillis(startTime);
61  for (UINT32 nThreads = 0; nThreads < numThreads; nThreads++)
62  {
63  tBenchmarkParams* pParams = new tBenchmarkParams;
64  pParams->blocksize = ms_BlockSizes[iBlocksize];
65  pParams->pMutexTotalBytesProcessed = pMutexTotlaBytes;
66  pParams->outparam_pTotalBytesProcessed = &totalBytesProcessed;
67  CAThread* pThread = new CAThread();
68  pThread->setMainLoop(benchmarkThread);
69  pThread->start(pParams, false, true);
70  pThreadList->put(pThread);
71  }
72  pThreadList->waitAndRemoveAll();
73  getcurrentTimeMillis(endTime);
74  time = diff64(endTime, startTime);
75  UINT8 tmpbuff[256];
76  formatBytesPerSecond(tmpbuff, 256, (totalBytesProcessed * 1000) / time);
77  CAMsg::printMsg(LOG_DEBUG, "Total crypto speed (blocksize: %u): %llu bytes in %u ms -- %s\n", ms_BlockSizes[iBlocksize],totalBytesProcessed, (UINT32)time,tmpbuff);
78 
79  numThreads -= (numThreads % 4); // Produce a series like: 1,4,8,12,...
80  }
81  }
82  delete pThreadList;
83  delete pMutexTotlaBytes;
84 }
#define MAX_CRYPTOBENCHMARK_THREADS
struct t_benchmarkParams tBenchmarkParams
static const UINT32 ms_NUM_BLOCKSIZES
static const UINT32 ms_BlockSizes[ms_NUM_BLOCKSIZES]
static THREAD_RETURN benchmarkThread(void *param)
SINT32 waitAndRemoveAll()
Waits for finishing of all threads in list and removes them.
SINT32 put(const CAThread *const thread)

References benchmarkThread(), t_benchmarkParams::blocksize, diff64(), formatBytesPerSecond(), getcurrentTimeMillis(), MAX_CRYPTOBENCHMARK_THREADS, ms_BlockSizes, ms_NUM_BLOCKSIZES, t_benchmarkParams::outparam_pTotalBytesProcessed, t_benchmarkParams::pMutexTotalBytesProcessed, CAMsg::printMsg(), CAThreadList::put(), CAThread::setMainLoop(), CAThread::start(), and CAThreadList::waitAndRemoveAll().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timerThread()

THREAD_RETURN CACryptoBenchmark::timerThread ( void *  param)
staticprivate

Definition at line 86 of file CACryptoBenchmark.cpp.

87 {
88  tBenchmarkTimerParams* pTimerParams = (tBenchmarkTimerParams*)a_pParams;
89  msSleep(pTimerParams->timerInMillis);
90  *(pTimerParams->bTimer) = false;
92 }
SINT32 msSleep(UINT32 ms)
Sleeps ms milliseconds.
Definition: CAUtil.cpp:406

References t_benchmarkTimerParams::bTimer, msSleep(), THREAD_RETURN_SUCCESS, and t_benchmarkTimerParams::timerInMillis.

Referenced by benchmarkThread().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ ms_BlockSizes

const UINT32 CACryptoBenchmark::ms_BlockSizes = { 16,64,256,512,1024 }
staticprivate

Definition at line 34 of file CACryptoBenchmark.hpp.

Referenced by doBenchmark().

◆ ms_NUM_BLOCKSIZES

const UINT32 CACryptoBenchmark::ms_NUM_BLOCKSIZES = 5
staticprivate

Definition at line 33 of file CACryptoBenchmark.hpp.

Referenced by doBenchmark().


The documentation for this class was generated from the following files: