2 #ifdef DATA_RETENTION_LOG
33 strftime((
char*) strDate,255,
"%Y%m%d-%H%M%S",theTime);
34 m_Day=theTime->tm_mday;
36 m_Year=theTime->tm_year+1900;
38 m_nMaxLogTime=date-theTime->tm_min*60-theTime->tm_hour*3600-theTime->tm_sec+24*3600-1;
42 snprintf((
char*)strFileName,4096,
"%s/dataretentionlog_%s",strLogDir,strDate);
45 delete [] strFileName;
54 memset(&oHeader,0,
sizeof(oHeader));
73 if(write(
m_hLogFile,&oHeader,
sizeof(oHeader))!=
sizeof(oHeader))
86 keybuff[19]=(
m_Year&0x00FF);
89 memset(nonce,0xFF,11);
91 ::gcm_encrypt_64k(
m_pGCMCtx, nonce, 12, keybuff,20,
92 NULL,0,encKey,keybuff+20);
98 UINT8 md[SHA512_DIGEST_LENGTH];
99 SHA512(keybuff+16,4,md);
107 memset(keybuff,0,256);
109 if(write(
m_hLogFile,encKey,encKeyLen)!=encKeyLen)
115 memcpy(tmpBuff,&oHeader,
sizeof(oHeader));
116 memcpy(tmpBuff+
sizeof(oHeader),encKey,encKeyLen);
117 ::gcm_encrypt_64k(
m_pGCMCtx, nonce, 12, tmpBuff,
sizeof(oHeader)+encKeyLen,
118 NULL,0,tmpBuff+1024,keybuff);
139 CAMsg::printMsg(LOG_ERR,
"Error: data retention log entry was not fully written to disk!\n");
154 memset(nonce,0xFF,12);
190 CAMsg::printMsg(LOG_ERR,
"Error: data retention log entry was not fully written to disk!\n");
204 memset(nonce,0xFF,12);
205 UINT8 oneBlock[8192];
206 memset(oneBlock,0xd4,8192);
207 UINT8 encBlock[10000];
208 memset(keybuff,0xC1,16);
212 gcm_ctx_4k* pGCMCtx=
new gcm_ctx_4k;
216 gcm_init_4k(pGCMCtx,keybuff,128);
218 for(
UINT32 i =0;i<runs;i++)
219 ::gcm_encrypt_4k(pGCMCtx, nonce ,12, oneBlock,lenBlock,NULL,0,encBlock,tag);
223 double bytes=(double)(runs*lenBlock);
224 double thetime=(double)
diff64(end,start);
225 printf(
"Time for %u run of 4k encypt of %u bytes: %s [ms] (%f bytes/s)\n",runs,lenBlock,encBlock,bytes/thetime*1000.0);
228 gcm_ctx_64k* pGCMCtx64=
new gcm_ctx_64k;
230 UINT8 tmpBlock[8192];
234 gcm_init_64k(pGCMCtx64,keybuff,128);
236 for(
UINT32 i =0;i<runs;i++)
237 ::gcm_encrypt_64k(pGCMCtx64, nonce ,12, oneBlock,lenBlock,NULL,0,encBlock,tag);
241 double bytes=(double)(runs*lenBlock);
242 double thetime=(double)
diff64(end,start);
243 printf(
"Time for %u run of 64k encypt of %u bytes: %s [ms] (%f bytes/s)\n",runs,lenBlock,tmpBlock,bytes/thetime*1000.0);
247 printf(
"Test finished!\n");
249 memset(tmpBlock,1,8192);
250 if(gcm_decrypt_4k(pGCMCtx,nonce,12,encBlock,lenBlock,tag,16,NULL,0,tmpBlock)==0||memcmp(oneBlock,tmpBlock,lenBlock)!=0)
251 printf(
"Check failed!\n");
253 printf(
"Check success!\n");
255 printf(
"Check finished!\n");
const UINT8 DATARETENTION_ENTITY_MIDDLE_MIX
const UINT8 DATARETENTION_ENTITY_LAST_MIX
const UINT8 DATARETENTION_ENTITY_FIRST_MIX
SINT32 getcurrentTimeMillis(UINT64 &u64Time)
Gets the current Systemtime in milli seconds.
SINT32 getRandom(UINT32 *val)
Gets 32 random bits.
UINT32 diff64(const UINT64 &bigop, const UINT64 &smallop)
void print64(UINT8 *buff, UINT64 num)
SINT32 encryptPKCS1(const UINT8 *from, UINT32 fromlen, UINT8 *to, UINT32 *len)
Encrypts one block of plain text using PKCS1 padding.
SINT32 log(t_dataretentionLogEntry *)
UINT8 * m_nonceBuffForLogEntries
UINT32 m_nLogEntriesPerBlock
~CADataRetentionLogFile()
SINT32 openLog(UINT8 *strLogDir, UINT32 date, CAASymCipher *pPublicKey)
UINT32 m_nCurrentLogEntriesInBlock
UINT32 m_nCurrentBlockNumber
UINT32 m_nBytesPerLogEntry
static SINT32 doCheckAndPerformanceTest()
SINT32 writeHeader(CAASymCipher *pPublicKey)
static CACmdLnOptions * getOptions()
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.