?? testhelix.cpp
字號:
#include "stdafx.h"
#include "stdio.h"
#include "Helix.h"
#include "HelixAPI.h"
int _tmain()
{
CHelixNonce nonce;
CHelix helix;
helix.SetKey(NULL, 0);
BYTE Cipher[10];
CHelixMAC mac;
helix.Encrypt((BYTE*) "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 10, nonce, Cipher, mac);
BYTE PlainText[10];
if (!helix.Decrypt(Cipher, 10, nonce, mac, PlainText))
{
_tprintf(_T("Failed to verify first test vector\n"));
return 1;
}
CHelixNonce nonce2;
nonce2.m_Data[4] = 1;
nonce2.m_Data[8] = 2;
nonce2.m_Data[12] = 3;
CHelix helix2;
helix2.SetKey((BYTE*) "\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\x05\x00\x00\x00\x06\x00\x00\x00\x07\x00\x00\x00", 32);
BYTE Cipher2[32];
CHelixMAC mac2;
helix2.Encrypt((BYTE*) "\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\x05\x00\x00\x00\x06\x00\x00\x00\x07\x00\x00\x00", 32, nonce2, Cipher2, mac2);
BYTE PlainText2[32];
if (!helix2.Decrypt(Cipher2, 32, nonce2, mac2, PlainText2))
{
_tprintf(_T("Failed to verify second test vector\n"));
return 1;
}
CHelixNonce nonce3;
nonce3.m_Data[0] = 0x30;
nonce3.m_Data[1] = 0x31;
nonce3.m_Data[2] = 0x32;
nonce3.m_Data[3] = 0x33;
nonce3.m_Data[4] = 0x34;
nonce3.m_Data[5] = 0x35;
nonce3.m_Data[6] = 0x36;
nonce3.m_Data[7] = 0x37;
nonce3.m_Data[8] = 0x38;
nonce3.m_Data[9] = 0x39;
nonce3.m_Data[10] = 0x61;
nonce3.m_Data[11] = 0x62;
nonce3.m_Data[12] = 0x63;
nonce3.m_Data[13] = 0x64;
nonce3.m_Data[14] = 0x65;
nonce3.m_Data[15] = 0x66;
CHelix helix3;
helix3.SetKey((BYTE*) "\x48\x65\x6c\x69\x78", 5);
BYTE Cipher3[13];
CHelixMAC mac3;
helix3.Encrypt((BYTE*) "\x48\x65\x6c\x6c\x6f\x2c\x20\x77\x6f\x72\x6c\x64\x21", 13, nonce3, Cipher3, mac3);
BYTE PlainText3[13];
if (!helix3.Decrypt(Cipher3, 13, nonce3, mac3, PlainText3))
{
_tprintf(_T("Failed to verify third test vector\n"));
return 1;
}
//Test the in place encryption / decryption
CHelixNonce nonce4;
CHelix helix4;
helix4.SetKey((BYTE*) "", 0);
CHelixMAC mac4;
BYTE Plaintext4[10];
memset(&Plaintext4, 0, sizeof(Plaintext4));
helix4.Encrypt(Plaintext4, 10, nonce4, Plaintext4, mac4);
if (!helix4.Decrypt(Plaintext4, 10, nonce4, mac4, Plaintext4))
{
_tprintf(_T("Failed to verify first fourth test vector\n"));
return 1;
}
CHelixNonce nonce5;
nonce5.m_Data[0] = 0x30;
nonce5.m_Data[1] = 0x31;
nonce5.m_Data[2] = 0x32;
nonce5.m_Data[3] = 0x33;
nonce5.m_Data[4] = 0x34;
nonce5.m_Data[5] = 0x35;
nonce5.m_Data[6] = 0x36;
nonce5.m_Data[7] = 0x37;
nonce5.m_Data[8] = 0x38;
nonce5.m_Data[9] = 0x39;
nonce5.m_Data[10] = 0x61;
nonce5.m_Data[11] = 0x62;
nonce5.m_Data[12] = 0x63;
nonce5.m_Data[13] = 0x64;
nonce5.m_Data[14] = 0x65;
nonce5.m_Data[15] = 0x66;
DWORD dwSize = 1024 * 1024 * 100;
BYTE* pPlainData = new BYTE[dwSize];
for (DWORD i=0; i<dwSize; i++)
pPlainData[i] = (BYTE) i;
CHelix helix5;
helix5.SetKey((BYTE*) "\x48\x65\x6c\x69\x78", 5);
CHelixMAC mac5;
DWORD dwStartTick = GetTickCount();
helix5.Encrypt(pPlainData, dwSize, nonce5, pPlainData, mac5);
DWORD dwTimeTaken = GetTickCount() - dwStartTick;
double fSpeed = dwSize * 1000.0 / dwTimeTaken / 1024 / 1024;
_tprintf(_T("Time taken to encrypt %d bytes was %d milliseconds, speed: %f MB/s\n"), dwSize, dwTimeTaken, fSpeed);
//Try out the DLL interface to Helix
HHELIX hHelix = HelixOpen();
BYTE nonce6[] = "\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x61\x62\x63\x64\x65\x66";
BYTE mac6[16];
memset(mac6, 0, sizeof(mac6));
dwStartTick = GetTickCount();
HelixEncrypt(hHelix, pPlainData, dwSize, nonce6, pPlainData, mac6);
dwTimeTaken = GetTickCount() - dwStartTick;
HelixClose(hHelix);
fSpeed = dwSize * 1000.0 / dwTimeTaken / 1024 / 1024;
_tprintf(_T("Time taken to encrypt %d bytes (using DLL) was %d milliseconds, speed: %f MB/s"), dwSize, dwTimeTaken, fSpeed);
delete [] pPlainData;
CHelixNonce nonce7;
CHelix helix7;
helix7.SetKey(NULL, 0);
BYTE Cipher7[34];
CHelixMAC mac7;
helix7.Encrypt((BYTE*)"\x4e\x1c\x00\x00\x00\x0a\x00\x00\x00\x01\x00\x00\x00\x02\x04\x00\x00\x01\x00\xc0\x00\x01\x00\x80\x04\x0e\x00\x00\x00\x01\x00\xc0\x0a\x4e", 34, nonce7, Cipher7, mac7);
BYTE PlainText7[34];
if (!helix7.Decrypt(Cipher7, 34, nonce7, mac7, PlainText7))
{
_tprintf(_T("Failed to verify test vector which was failing in earlier versions of CHelix"));
return 1;
}
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -