Add Integer Bitops tests (Issue 344)
parent
f197549662
commit
26db40567d
|
|
@ -183,7 +183,7 @@ endif()
|
|||
file(GLOB cryptopp_HEADERS *.h)
|
||||
|
||||
# Test sources. You can use the GNUmakefile to generate the list: `make sources`.
|
||||
file(GLOB cryptopp_SOURCES_TEST test.cpp bench1.cpp bench2.cpp validat1.cpp validat2.cpp validat3.cpp adhoc.cpp datatest.cpp regtest.cpp fipsalgt.cpp dlltest.cpp fipstest.cpp)
|
||||
file(GLOB cryptopp_SOURCES_TEST test.cpp bench1.cpp bench2.cpp validat0.cpp validat1.cpp validat2.cpp validat3.cpp adhoc.cpp datatest.cpp regtest.cpp fipsalgt.cpp dlltest.cpp fipstest.cpp)
|
||||
|
||||
# Library sources. You can use the GNUmakefile to generate the list: `make sources`.
|
||||
file(GLOB cryptopp_SOURCES *.cpp)
|
||||
|
|
|
|||
|
|
@ -278,6 +278,7 @@ ttmac.cpp
|
|||
ttmac.h
|
||||
twofish.cpp
|
||||
twofish.h
|
||||
validat0.cpp
|
||||
validat1.cpp
|
||||
validat2.cpp
|
||||
validat3.cpp
|
||||
|
|
|
|||
|
|
@ -443,7 +443,7 @@ endif
|
|||
OBJS := $(SRCS:.cpp=.o)
|
||||
|
||||
# List test.cpp first to tame C++ static initialization problems.
|
||||
TESTSRCS := adhoc.cpp test.cpp bench1.cpp bench2.cpp validat1.cpp validat2.cpp validat3.cpp datatest.cpp regtest.cpp fipsalgt.cpp dlltest.cpp
|
||||
TESTSRCS := adhoc.cpp test.cpp bench1.cpp bench2.cpp validat0.cpp validat1.cpp validat2.cpp validat3.cpp datatest.cpp regtest.cpp fipsalgt.cpp dlltest.cpp
|
||||
TESTOBJS := $(TESTSRCS:.cpp=.o)
|
||||
LIBOBJS := $(filter-out $(TESTOBJS),$(OBJS))
|
||||
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ SRCS := cryptlib.cpp cpu.cpp integer.cpp $(filter-out cryptlib.cpp cpu.cpp integ
|
|||
OBJS := $(SRCS:.cpp=.o)
|
||||
|
||||
# List test.cpp first to tame C++ static initialization problems.
|
||||
TESTSRCS := adhoc.cpp test.cpp bench1.cpp bench2.cpp validat1.cpp validat2.cpp validat3.cpp datatest.cpp regtest.cpp fipsalgt.cpp dlltest.cpp
|
||||
TESTSRCS := adhoc.cpp test.cpp bench1.cpp bench2.cpp validat0.cpp validat1.cpp validat2.cpp validat3.cpp datatest.cpp regtest.cpp fipsalgt.cpp dlltest.cpp
|
||||
TESTOBJS := $(TESTSRCS:.cpp=.o)
|
||||
LIBOBJS := $(filter-out $(TESTOBJS),$(OBJS))
|
||||
|
||||
|
|
|
|||
|
|
@ -52,9 +52,9 @@ LIB_SRCS = cryptlib.cpp cpu.cpp integer.cpp shacal2.cpp md5.cpp shark.cpp zinfla
|
|||
|
||||
LIB_OBJS = cryptlib.obj cpu.obj integer.obj shacal2.obj md5.obj shark.obj zinflate.obj gf2n.obj salsa.obj xtr.obj oaep.obj rc2.obj default.obj wait.obj wake.obj twofish.obj iterhash.obj adler32.obj algparam.obj marss.obj blowfish.obj ecp.obj strciphr.obj camellia.obj dh2.obj ida.obj zlib.obj elgamal.obj crc.obj dessp.obj tea.obj eax.obj network.obj sha.obj emsa2.obj pkcspad.obj squaretb.obj idea.obj authenc.obj hmac.obj xtrcrypt.obj queue.obj mars.obj rc5.obj md2.obj hrtimer.obj vmac.obj eprecomp.obj hex.obj dsa.obj fips140.obj gzip.obj seal.obj blake2.obj files.obj base32.obj sharkbox.obj safer.obj randpool.obj sosemanuk.obj arc4.obj osrng.obj skipjack.obj seed.obj sha3.obj filters.obj bfinit.obj rabin.obj 3way.obj rw.obj rdtables.obj rsa.obj tftables.obj gost.obj socketft.obj nbtheory.obj panama.obj modes.obj rijndael.obj casts.obj algebra.obj esign.obj gfpcrypt.obj dll.obj ec2n.obj poly1305.obj polynomi.obj blumshub.obj des.obj basecode.obj zdeflate.obj base64.obj rc6.obj gf256.obj mqueue.obj misc.obj pssr.obj channels.obj rng.obj tiger.obj cast.obj square.obj asn.obj chacha.obj whrlpool.obj md4.obj dh.obj ccm.obj mqv.obj tigertab.obj gf2_32.obj cbcmac.obj ttmac.obj luc.obj trdlocal.obj pubkey.obj gcm.obj ripemd.obj keccak.obj eccrypto.obj serpent.obj cmac.obj winpipes.obj
|
||||
|
||||
TEST_SRCS = bench1.cpp bench2.cpp test.cpp validat1.cpp validat2.cpp validat3.cpp datatest.cpp regtest.cpp fipsalgt.cpp dlltest.cpp fipstest.cpp
|
||||
TEST_SRCS = bench1.cpp bench2.cpp test.cpp validat0.cpp validat1.cpp validat2.cpp validat3.cpp datatest.cpp regtest.cpp fipsalgt.cpp dlltest.cpp fipstest.cpp
|
||||
|
||||
TEST_OBJS = bench1.obj bench2.obj test.obj validat1.obj validat2.obj validat3.obj datatest.obj regtest.obj fipsalgt.obj dlltest.obj fipstest.obj
|
||||
TEST_OBJS = bench1.obj bench2.obj test.obj validat0.obj validat1.obj validat2.obj validat3.obj datatest.obj regtest.obj fipsalgt.obj dlltest.obj fipstest.obj
|
||||
|
||||
CXX = cl.exe
|
||||
LD = link.exe
|
||||
|
|
|
|||
|
|
@ -201,6 +201,7 @@
|
|||
<ClCompile Include="fipsalgt.cpp" />
|
||||
<ClCompile Include="regtest.cpp" />
|
||||
<ClCompile Include="test.cpp" />
|
||||
<ClCompile Include="validat0.cpp" />
|
||||
<ClCompile Include="validat1.cpp" />
|
||||
<ClCompile Include="validat2.cpp" />
|
||||
<ClCompile Include="validat3.cpp" />
|
||||
|
|
|
|||
|
|
@ -341,6 +341,9 @@
|
|||
<ClCompile Include="test.cpp">
|
||||
<Filter>Source Code</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="validat0.cpp">
|
||||
<Filter>Source Code</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="validat1.cpp">
|
||||
<Filter>Source Code</Filter>
|
||||
</ClCompile>
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
974
validat1.cpp
974
validat1.cpp
|
|
@ -81,6 +81,8 @@ bool ValidateAll(bool thorough)
|
|||
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_IMPORTS)
|
||||
// http://github.com/weidai11/cryptopp/issues/92
|
||||
pass=TestSecBlock() && pass;
|
||||
// http://github.com/weidai11/cryptopp/issues/336
|
||||
pass=TestIntegerBitops() && pass;
|
||||
// http://github.com/weidai11/cryptopp/issues/64
|
||||
pass=TestPolynomialMod2() && pass;
|
||||
// http://github.com/weidai11/cryptopp/pull/242
|
||||
|
|
@ -334,978 +336,6 @@ bool TestSettings()
|
|||
return pass;
|
||||
}
|
||||
|
||||
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_IMPORTS)
|
||||
bool TestSecBlock()
|
||||
{
|
||||
cout << "\nTesting SecBlock...\n\n";
|
||||
|
||||
bool pass1=true, pass2=true, pass3=true, pass4=true, pass5=true, pass6=true, pass7=true, temp=false;
|
||||
|
||||
//********** Zeroized block **********//
|
||||
|
||||
{
|
||||
// NULL ptr with a size means to create a new SecBlock with all elements zero'd
|
||||
SecByteBlock z1(NULL, 256);
|
||||
temp = true;
|
||||
|
||||
for (size_t i = 0; i < z1.size(); i++)
|
||||
temp &= (z1[i] == 0);
|
||||
|
||||
pass1 &= temp;
|
||||
if (!temp)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " Zeroized byte array" << endl;
|
||||
|
||||
SecBlock<word32> z2(NULL, 256);
|
||||
temp = true;
|
||||
|
||||
for (size_t i = 0; i < z2.size(); i++)
|
||||
temp &= (z2[i] == 0);
|
||||
|
||||
pass1 &= temp;
|
||||
if (!temp)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " Zeroized word32 array" << endl;
|
||||
|
||||
SecBlock<word64> z3(NULL, 256);
|
||||
temp = true;
|
||||
|
||||
for (size_t i = 0; i < z3.size(); i++)
|
||||
temp &= (z3[i] == 0);
|
||||
|
||||
pass1 &= temp;
|
||||
if (!temp)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " Zeroized word64 array" << endl;
|
||||
|
||||
#if defined(CRYPTOPP_WORD128_AVAILABLE)
|
||||
SecBlock<word128> z4(NULL, 256);
|
||||
temp = true;
|
||||
|
||||
for (size_t i = 0; i < z4.size(); i++)
|
||||
temp &= (z4[i] == 0);
|
||||
|
||||
pass1 &= temp;
|
||||
if (!temp)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " Zeroized word128 array" << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
//********** Assign **********//
|
||||
|
||||
try
|
||||
{
|
||||
SecByteBlock a, b;
|
||||
temp = true;
|
||||
|
||||
a.Assign((const byte*)"a", 1);
|
||||
b.Assign((const byte*)"b", 1);
|
||||
|
||||
temp &= (a.SizeInBytes() == 1);
|
||||
temp &= (b.SizeInBytes() == 1);
|
||||
temp &= (a[0] == 'a');
|
||||
temp &= (b[0] == 'b');
|
||||
|
||||
a.Assign((const byte*)"ab", 2);
|
||||
b.Assign((const byte*)"cd", 2);
|
||||
|
||||
temp &= (a.SizeInBytes() == 2);
|
||||
temp &= (b.SizeInBytes() == 2);
|
||||
temp &= (a[0] == 'a' && a[1] == 'b');
|
||||
temp &= (b[0] == 'c' && b[1] == 'd');
|
||||
}
|
||||
catch(const Exception& /*ex*/)
|
||||
{
|
||||
temp = false;
|
||||
}
|
||||
|
||||
pass2 &= temp;
|
||||
if (!temp)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " Assign byte" << endl;
|
||||
|
||||
try
|
||||
{
|
||||
SecBlock<word32> a, b;
|
||||
temp = true;
|
||||
|
||||
word32 one[1] = {1}, two[1] = {2};
|
||||
a.Assign(one, 1);
|
||||
b.Assign(two, 1);
|
||||
|
||||
temp &= (a.SizeInBytes() == 4);
|
||||
temp &= (b.SizeInBytes() == 4);
|
||||
temp &= (a[0] == 1);
|
||||
temp &= (b[0] == 2);
|
||||
|
||||
word32 three[2] = {1,2}, four[2] = {3,4};
|
||||
a.Assign(three, 2);
|
||||
b.Assign(four, 2);
|
||||
|
||||
temp &= (a.SizeInBytes() == 8);
|
||||
temp &= (b.SizeInBytes() == 8);
|
||||
temp &= (a[0] == 1 && a[1] == 2);
|
||||
temp &= (b[0] == 3 && b[1] == 4);
|
||||
}
|
||||
catch(const Exception& /*ex*/)
|
||||
{
|
||||
temp = false;
|
||||
}
|
||||
|
||||
pass2 &= temp;
|
||||
if (!temp)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " Assign word32" << endl;
|
||||
|
||||
try
|
||||
{
|
||||
SecBlock<word64> a, b;
|
||||
temp = true;
|
||||
|
||||
word64 one[1] = {1}, two[1] = {2};
|
||||
a.Assign(one, 1);
|
||||
b.Assign(two, 1);
|
||||
|
||||
temp &= (a.SizeInBytes() == 8);
|
||||
temp &= (b.SizeInBytes() == 8);
|
||||
temp &= (a[0] == 1);
|
||||
temp &= (b[0] == 2);
|
||||
|
||||
word64 three[2] = {1,2}, four[2] = {3,4};
|
||||
a.Assign(three, 2);
|
||||
b.Assign(four, 2);
|
||||
|
||||
temp &= (a.SizeInBytes() == 16);
|
||||
temp &= (b.SizeInBytes() == 16);
|
||||
temp &= (a[0] == 1 && a[1] == 2);
|
||||
temp &= (b[0] == 3 && b[1] == 4);
|
||||
}
|
||||
catch(const Exception& /*ex*/)
|
||||
{
|
||||
temp = false;
|
||||
}
|
||||
|
||||
pass2 &= temp;
|
||||
if (!temp)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " Assign word64" << endl;
|
||||
|
||||
#if defined(CRYPTOPP_WORD128_AVAILABLE)
|
||||
try
|
||||
{
|
||||
SecBlock<word128> a, b;
|
||||
temp = true;
|
||||
|
||||
word128 one[1] = {1}, two[1] = {2};
|
||||
a.Assign(one, 1);
|
||||
b.Assign(two, 1);
|
||||
|
||||
temp &= (a.SizeInBytes() == 16);
|
||||
temp &= (b.SizeInBytes() == 16);
|
||||
temp &= (a[0] == 1);
|
||||
temp &= (b[0] == 2);
|
||||
|
||||
word128 three[2] = {1,2}, four[2] = {3,4};
|
||||
a.Assign(three, 2);
|
||||
b.Assign(four, 2);
|
||||
|
||||
temp &= (a.SizeInBytes() == 32);
|
||||
temp &= (b.SizeInBytes() == 32);
|
||||
temp &= (a[0] == 1 && a[1] == 2);
|
||||
temp &= (b[0] == 3 && b[1] == 4);
|
||||
}
|
||||
catch(const Exception& /*ex*/)
|
||||
{
|
||||
temp = false;
|
||||
}
|
||||
|
||||
pass2 &= temp;
|
||||
if (!temp)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " Assign word128" << endl;
|
||||
#endif
|
||||
|
||||
//********** Append **********//
|
||||
|
||||
try
|
||||
{
|
||||
SecByteBlock a, b;
|
||||
temp = true;
|
||||
|
||||
a.Assign((const byte*)"a", 1);
|
||||
b.Assign((const byte*)"b", 1);
|
||||
|
||||
a += b;
|
||||
temp &= (a.SizeInBytes() == 2);
|
||||
temp &= (a[0] == 'a' && a[1] == 'b');
|
||||
|
||||
a.Assign((const byte*)"ab", 2);
|
||||
b.Assign((const byte*)"cd", 2);
|
||||
|
||||
a += b;
|
||||
temp &= (a.SizeInBytes() == 4);
|
||||
temp &= (a[0] == 'a' && a[1] == 'b' && a[2] == 'c' && a[3] == 'd');
|
||||
|
||||
a.Assign((const byte*)"a", 1);
|
||||
|
||||
a += a;
|
||||
temp &= (a.SizeInBytes() == 2);
|
||||
temp &= (a[0] == 'a' && a[1] == 'a');
|
||||
|
||||
a.Assign((const byte*)"ab", 2);
|
||||
|
||||
a += a;
|
||||
temp &= (a.SizeInBytes() == 4);
|
||||
temp &= (a[0] == 'a' && a[1] == 'b' && a[2] == 'a' && a[3] == 'b');
|
||||
}
|
||||
catch(const Exception& /*ex*/)
|
||||
{
|
||||
temp = false;
|
||||
}
|
||||
|
||||
pass3 &= temp;
|
||||
if (!temp)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " Append byte" << endl;
|
||||
|
||||
try
|
||||
{
|
||||
SecBlock<word32> a, b;
|
||||
temp = true;
|
||||
|
||||
const word32 one[1] = {1}, two[1] = {2};
|
||||
a.Assign(one, 1);
|
||||
b.Assign(two, 1);
|
||||
|
||||
a += b;
|
||||
temp &= (a.SizeInBytes() == 8);
|
||||
temp &= (a[0] == 1 && a[1] == 2);
|
||||
|
||||
const word32 three[2] = {1,2}, four[2] = {3,4};
|
||||
a.Assign(three, 2);
|
||||
b.Assign(four, 2);
|
||||
|
||||
a += b;
|
||||
temp &= (a.SizeInBytes() == 16);
|
||||
temp &= (a[0] == 1 && a[1] == 2 && a[2] == 3 && a[3] == 4);
|
||||
|
||||
a.Assign(one, 1);
|
||||
|
||||
a += a;
|
||||
temp &= (a.SizeInBytes() == 8);
|
||||
temp &= (a[0] == 1 && a[1] == 1);
|
||||
|
||||
a.Assign(three, 2);
|
||||
|
||||
a += a;
|
||||
temp &= (a.SizeInBytes() == 16);
|
||||
temp &= (a[0] == 1 && a[1] == 2 && a[2] == 1 && a[3] == 2);
|
||||
}
|
||||
catch(const Exception& /*ex*/)
|
||||
{
|
||||
temp = false;
|
||||
}
|
||||
|
||||
pass3 &= temp;
|
||||
if (!temp)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " Append word32" << endl;
|
||||
|
||||
try
|
||||
{
|
||||
SecBlock<word64> a, b;
|
||||
temp = true;
|
||||
|
||||
const word64 one[1] = {1}, two[1] = {2};
|
||||
a.Assign(one, 1);
|
||||
b.Assign(two, 1);
|
||||
|
||||
a += b;
|
||||
temp &= (a.SizeInBytes() == 16);
|
||||
temp &= (a[0] == 1 && a[1] == 2);
|
||||
|
||||
const word64 three[2] = {1,2}, four[2] = {3,4};
|
||||
a.Assign(three, 2);
|
||||
b.Assign(four, 2);
|
||||
|
||||
a += b;
|
||||
temp &= (a.SizeInBytes() == 32);
|
||||
temp &= (a[0] == 1 && a[1] == 2 && a[2] == 3 && a[3] == 4);
|
||||
|
||||
a.Assign(one, 1);
|
||||
|
||||
a += a;
|
||||
temp &= (a.SizeInBytes() == 16);
|
||||
temp &= (a[0] == 1 && a[1] == 1);
|
||||
|
||||
a.Assign(three, 2);
|
||||
|
||||
a += a;
|
||||
temp &= (a.SizeInBytes() == 32);
|
||||
temp &= (a[0] == 1 && a[1] == 2 && a[2] == 1 && a[3] == 2);
|
||||
}
|
||||
catch(const Exception& /*ex*/)
|
||||
{
|
||||
temp = false;
|
||||
}
|
||||
|
||||
pass3 &= temp;
|
||||
if (!temp)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " Append word64" << endl;
|
||||
|
||||
#if defined(CRYPTOPP_WORD128_AVAILABLE)
|
||||
try
|
||||
{
|
||||
SecBlock<word128> a, b;
|
||||
temp = true;
|
||||
|
||||
const word128 one[1] = {1}, two[1] = {2};
|
||||
a.Assign(one, 1);
|
||||
b.Assign(two, 1);
|
||||
|
||||
a += b;
|
||||
temp &= (a.SizeInBytes() == 32);
|
||||
temp &= (a[0] == 1 && a[1] == 2);
|
||||
|
||||
const word128 three[2] = {1,2}, four[2] = {3,4};
|
||||
a.Assign(three, 2);
|
||||
b.Assign(four, 2);
|
||||
|
||||
a += b;
|
||||
temp &= (a.SizeInBytes() == 64);
|
||||
temp &= (a[0] == 1 && a[1] == 2 && a[2] == 3 && a[3] == 4);
|
||||
|
||||
a.Assign(one, 1);
|
||||
|
||||
a += a;
|
||||
temp &= (a.SizeInBytes() == 32);
|
||||
temp &= (a[0] == 1 && a[1] == 1);
|
||||
|
||||
a.Assign(three, 2);
|
||||
|
||||
a += a;
|
||||
temp &= (a.SizeInBytes() == 64);
|
||||
temp &= (a[0] == 1 && a[1] == 2 && a[2] == 1 && a[3] == 2);
|
||||
}
|
||||
catch(const Exception& /*ex*/)
|
||||
{
|
||||
temp = false;
|
||||
}
|
||||
|
||||
pass3 &= temp;
|
||||
if (!temp)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " Append word128" << endl;
|
||||
#endif
|
||||
|
||||
//********** Concatenate **********//
|
||||
|
||||
// byte
|
||||
try
|
||||
{
|
||||
SecByteBlock a, b, c;
|
||||
temp = true;
|
||||
|
||||
a.Assign((const byte*)"a", 1);
|
||||
b.Assign((const byte*)"b", 1);
|
||||
|
||||
c = a + b;
|
||||
temp &= (a[0] == 'a');
|
||||
temp &= (b[0] == 'b');
|
||||
temp &= (c.SizeInBytes() == 2);
|
||||
temp &= (c[0] == 'a' && c[1] == 'b');
|
||||
|
||||
a.Assign((const byte*)"ab", 2);
|
||||
b.Assign((const byte*)"cd", 2);
|
||||
|
||||
c = a + b;
|
||||
temp &= (a[0] == 'a' && a[1] == 'b');
|
||||
temp &= (b[0] == 'c' && b[1] == 'd');
|
||||
temp &= (c.SizeInBytes() == 4);
|
||||
temp &= (c[0] == 'a' && c[1] == 'b' && c[2] == 'c' && c[3] == 'd');
|
||||
}
|
||||
catch(const Exception& /*ex*/)
|
||||
{
|
||||
temp = false;
|
||||
}
|
||||
|
||||
pass4 &= temp;
|
||||
if (!temp)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " Concatenate byte" << endl;
|
||||
|
||||
// word32
|
||||
try
|
||||
{
|
||||
SecBlock<word32> a, b, c;
|
||||
temp = true;
|
||||
|
||||
const word32 one[1] = {1}, two[1] = {2};
|
||||
a.Assign(one, 1);
|
||||
b.Assign(two, 1);
|
||||
|
||||
c = a + b;
|
||||
temp &= (a[0] == 1);
|
||||
temp &= (b[0] == 2);
|
||||
temp &= (c.SizeInBytes() == 8);
|
||||
temp &= (c[0] == 1 && c[1] == 2);
|
||||
|
||||
const word32 three[2] = {1,2}, four[2] = {3,4};
|
||||
a.Assign(three, 2);
|
||||
b.Assign(four, 2);
|
||||
|
||||
c = a + b;
|
||||
temp &= (a[0] == 1 && a[1] == 2);
|
||||
temp &= (b[0] == 3 && b[1] == 4);
|
||||
temp &= (c.SizeInBytes() == 16);
|
||||
temp &= (c[0] == 1 && c[1] == 2 && c[2] == 3 && c[3] == 4);
|
||||
}
|
||||
catch(const Exception& /*ex*/)
|
||||
{
|
||||
temp = false;
|
||||
}
|
||||
|
||||
pass4 &= temp;
|
||||
if (!temp)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " Concatenate word32" << endl;
|
||||
|
||||
// word64
|
||||
try
|
||||
{
|
||||
SecBlock<word64> a, b, c;
|
||||
temp = true;
|
||||
|
||||
const word64 one[1] = {1}, two[1] = {2};
|
||||
a.Assign(one, 1);
|
||||
b.Assign(two, 1);
|
||||
|
||||
c = a + b;
|
||||
temp &= (a[0] == 1);
|
||||
temp &= (b[0] == 2);
|
||||
temp &= (c.SizeInBytes() == 16);
|
||||
temp &= (c[0] == 1 && c[1] == 2);
|
||||
|
||||
const word64 three[2] = {1,2}, four[2] = {3,4};
|
||||
a.Assign(three, 2);
|
||||
b.Assign(four, 2);
|
||||
|
||||
c = a + b;
|
||||
temp &= (a[0] == 1 && a[1] == 2);
|
||||
temp &= (b[0] == 3 && b[1] == 4);
|
||||
temp &= (c.SizeInBytes() == 32);
|
||||
temp &= (c[0] == 1 && c[1] == 2 && c[2] == 3 && c[3] == 4);
|
||||
}
|
||||
catch(const Exception& /*ex*/)
|
||||
{
|
||||
temp = false;
|
||||
}
|
||||
|
||||
pass4 &= temp;
|
||||
if (!temp)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " Concatenate word64" << endl;
|
||||
|
||||
#if defined(CRYPTOPP_WORD128_AVAILABLE)
|
||||
try
|
||||
{
|
||||
SecBlock<word128> a, b, c;
|
||||
temp = true;
|
||||
|
||||
const word128 one[1] = {1}, two[1] = {2};
|
||||
a.Assign(one, 1);
|
||||
b.Assign(two, 1);
|
||||
|
||||
c = a + b;
|
||||
temp &= (a[0] == 1);
|
||||
temp &= (b[0] == 2);
|
||||
temp &= (c.SizeInBytes() == 32);
|
||||
temp &= (c[0] == 1 && c[1] == 2);
|
||||
|
||||
const word128 three[2] = {1,2}, four[2] = {3,4};
|
||||
a.Assign(three, 2);
|
||||
b.Assign(four, 2);
|
||||
|
||||
c = a + b;
|
||||
temp &= (a[0] == 1 && a[1] == 2);
|
||||
temp &= (b[0] == 3 && b[1] == 4);
|
||||
temp &= (c.SizeInBytes() == 64);
|
||||
temp &= (c[0] == 1 && c[1] == 2 && c[2] == 3 && c[3] == 4);
|
||||
}
|
||||
catch(const Exception& /*ex*/)
|
||||
{
|
||||
temp = false;
|
||||
}
|
||||
|
||||
pass4 &= temp;
|
||||
if (!temp)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " Concatenate word128" << endl;
|
||||
#endif
|
||||
|
||||
//********** Equality **********//
|
||||
|
||||
// byte
|
||||
try
|
||||
{
|
||||
static const byte str1[] = "abcdefghijklmnopqrstuvwxyz";
|
||||
static const byte str2[] = "zyxwvutsrqponmlkjihgfedcba";
|
||||
static const byte str3[] = "0123456789";
|
||||
|
||||
temp = true;
|
||||
SecByteBlock a,b;
|
||||
|
||||
a.Assign(str1, COUNTOF(str1));
|
||||
b.Assign(str1, COUNTOF(str1));
|
||||
temp &= (a.operator==(b));
|
||||
|
||||
a.Assign(str3, COUNTOF(str3));
|
||||
b.Assign(str3, COUNTOF(str3));
|
||||
temp &= (a == b);
|
||||
|
||||
a.Assign(str1, COUNTOF(str1));
|
||||
b.Assign(str2, COUNTOF(str2));
|
||||
temp &= (a.operator!=(b));
|
||||
|
||||
a.Assign(str1, COUNTOF(str1));
|
||||
b.Assign(str3, COUNTOF(str3));
|
||||
temp &= (a != b);
|
||||
}
|
||||
catch(const Exception& /*ex*/)
|
||||
{
|
||||
temp = false;
|
||||
}
|
||||
|
||||
pass5 &= temp;
|
||||
if (!temp)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " Equality byte" << endl;
|
||||
|
||||
// word32
|
||||
try
|
||||
{
|
||||
static const word32 str1[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
|
||||
static const word32 str2[] = {97,89,83,79,73,71,67,61,59,53,47,43,41,37,31,29,23,19,17,13,11,7,5,3,2};
|
||||
static const word32 str3[] = {0,1,2,3,4,5,6,7,8,9};
|
||||
|
||||
temp = true;
|
||||
SecBlock<word32> a,b;
|
||||
|
||||
a.Assign(str1, COUNTOF(str1));
|
||||
b.Assign(str1, COUNTOF(str1));
|
||||
temp &= (a.operator==(b));
|
||||
|
||||
a.Assign(str3, COUNTOF(str3));
|
||||
b.Assign(str3, COUNTOF(str3));
|
||||
temp &= (a == b);
|
||||
|
||||
a.Assign(str1, COUNTOF(str1));
|
||||
b.Assign(str2, COUNTOF(str2));
|
||||
temp &= (a.operator!=(b));
|
||||
|
||||
a.Assign(str1, COUNTOF(str1));
|
||||
b.Assign(str3, COUNTOF(str3));
|
||||
temp &= (a != b);
|
||||
}
|
||||
catch(const Exception& /*ex*/)
|
||||
{
|
||||
temp = false;
|
||||
}
|
||||
|
||||
pass5 &= temp;
|
||||
if (!temp)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " Equality word32" << endl;
|
||||
|
||||
// word64
|
||||
try
|
||||
{
|
||||
static const word64 str1[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
|
||||
static const word64 str2[] = {97,89,83,79,73,71,67,61,59,53,47,43,41,37,31,29,23,19,17,13,11,7,5,3,2};
|
||||
static const word64 str3[] = {0,1,2,3,4,5,6,7,8,9};
|
||||
|
||||
temp = true;
|
||||
SecBlock<word64> a,b;
|
||||
|
||||
a.Assign(str1, COUNTOF(str1));
|
||||
b.Assign(str1, COUNTOF(str1));
|
||||
temp &= (a.operator==(b));
|
||||
|
||||
a.Assign(str3, COUNTOF(str3));
|
||||
b.Assign(str3, COUNTOF(str3));
|
||||
temp &= (a == b);
|
||||
|
||||
a.Assign(str1, COUNTOF(str1));
|
||||
b.Assign(str2, COUNTOF(str2));
|
||||
temp &= (a.operator!=(b));
|
||||
|
||||
a.Assign(str1, COUNTOF(str1));
|
||||
b.Assign(str3, COUNTOF(str3));
|
||||
temp &= (a != b);
|
||||
}
|
||||
catch(const Exception& /*ex*/)
|
||||
{
|
||||
temp = false;
|
||||
}
|
||||
|
||||
pass5 &= temp;
|
||||
if (!temp)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " Equality word64" << endl;
|
||||
|
||||
#if defined(CRYPTOPP_WORD128_AVAILABLE)
|
||||
// word128
|
||||
try
|
||||
{
|
||||
static const word128 str1[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
|
||||
static const word128 str2[] = {97,89,83,79,73,71,67,61,59,53,47,43,41,37,31,29,23,19,17,13,11,7,5,3,2};
|
||||
static const word128 str3[] = {0,1,2,3,4,5,6,7,8,9};
|
||||
|
||||
temp = true;
|
||||
SecBlock<word128> a,b;
|
||||
|
||||
a.Assign(str1, COUNTOF(str1));
|
||||
b.Assign(str1, COUNTOF(str1));
|
||||
temp &= (a.operator==(b));
|
||||
|
||||
a.Assign(str3, COUNTOF(str3));
|
||||
b.Assign(str3, COUNTOF(str3));
|
||||
temp &= (a == b);
|
||||
|
||||
a.Assign(str1, COUNTOF(str1));
|
||||
b.Assign(str2, COUNTOF(str2));
|
||||
temp &= (a.operator!=(b));
|
||||
|
||||
a.Assign(str1, COUNTOF(str1));
|
||||
b.Assign(str3, COUNTOF(str3));
|
||||
temp &= (a != b);
|
||||
}
|
||||
catch(const Exception& /*ex*/)
|
||||
{
|
||||
temp = false;
|
||||
}
|
||||
|
||||
pass5 &= temp;
|
||||
if (!temp)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " Equality word128" << endl;
|
||||
#endif
|
||||
|
||||
//********** Allocator Size/Overflow **********//
|
||||
|
||||
try
|
||||
{
|
||||
temp = false;
|
||||
|
||||
AllocatorBase<word32> A;
|
||||
const size_t max = A.max_size();
|
||||
SecBlock<word32> t(max+1);
|
||||
}
|
||||
catch(const Exception& /*ex*/)
|
||||
{
|
||||
temp = true;
|
||||
}
|
||||
catch(const std::exception& /*ex*/)
|
||||
{
|
||||
temp = true;
|
||||
}
|
||||
|
||||
pass6 &= temp;
|
||||
if (!temp)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " Overflow word32" << endl;
|
||||
|
||||
try
|
||||
{
|
||||
temp = false;
|
||||
|
||||
AllocatorBase<word64> A;
|
||||
const size_t max = A.max_size();
|
||||
SecBlock<word64> t(max+1);
|
||||
}
|
||||
catch(const Exception& /*ex*/)
|
||||
{
|
||||
temp = true;
|
||||
}
|
||||
catch(const std::exception& /*ex*/)
|
||||
{
|
||||
temp = true;
|
||||
}
|
||||
|
||||
pass6 &= temp;
|
||||
if (!temp)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " Overflow word64" << endl;
|
||||
|
||||
#if defined(CRYPTOPP_WORD128_AVAILABLE)
|
||||
try
|
||||
{
|
||||
temp = false;
|
||||
|
||||
AllocatorBase<word128> A;
|
||||
const size_t max = A.max_size();
|
||||
SecBlock<word128> t(max+1);
|
||||
}
|
||||
catch(const Exception& /*ex*/)
|
||||
{
|
||||
temp = true;
|
||||
}
|
||||
catch(const std::exception& /*ex*/)
|
||||
{
|
||||
temp = true;
|
||||
}
|
||||
|
||||
pass6 &= temp;
|
||||
if (!temp)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " Overflow word128" << endl;
|
||||
#endif
|
||||
|
||||
//********** FixedSizeAllocatorWithCleanup and Grow **********//
|
||||
|
||||
// byte
|
||||
try
|
||||
{
|
||||
static const unsigned int SIZE = 8;
|
||||
SecBlockWithHint<byte, SIZE> block(SIZE);
|
||||
memset(block, 0xaa, block.SizeInBytes());
|
||||
|
||||
temp = true;
|
||||
block.CleanGrow(SIZE*2);
|
||||
temp &= (block.size() == SIZE*2);
|
||||
|
||||
for (size_t i = 0; i < block.size()/2; i++)
|
||||
temp &= (block[i] == 0xaa);
|
||||
for (size_t i = block.size()/2; i < block.size(); i++)
|
||||
temp &= (block[i] == 0);
|
||||
|
||||
block.CleanNew(SIZE*4);
|
||||
temp &= (block.size() == SIZE*4);
|
||||
for (size_t i = 0; i < block.size(); i++)
|
||||
temp &= (block[i] == 0);
|
||||
}
|
||||
catch(const Exception& /*ex*/)
|
||||
{
|
||||
temp = false;
|
||||
}
|
||||
catch(const std::exception& /*ex*/)
|
||||
{
|
||||
temp = false;
|
||||
}
|
||||
|
||||
pass7 &= temp;
|
||||
if (!temp)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " FixedSizeAllocator Grow with byte" << endl;
|
||||
|
||||
// word32
|
||||
try
|
||||
{
|
||||
static const unsigned int SIZE = 8;
|
||||
SecBlockWithHint<word32, SIZE> block(SIZE);
|
||||
memset(block, 0xaa, block.SizeInBytes());
|
||||
|
||||
temp = true;
|
||||
block.CleanGrow(SIZE*2);
|
||||
temp &= (block.size() == SIZE*2);
|
||||
|
||||
for (size_t i = 0; i < block.size()/2; i++)
|
||||
temp &= (block[i] == 0xaaaaaaaa);
|
||||
|
||||
for (size_t i = block.size()/2; i < block.size(); i++)
|
||||
temp &= (block[i] == 0);
|
||||
|
||||
block.CleanNew(SIZE*4);
|
||||
temp &= (block.size() == SIZE*4);
|
||||
for (size_t i = 0; i < block.size(); i++)
|
||||
temp &= (block[i] == 0);
|
||||
}
|
||||
catch(const Exception& /*ex*/)
|
||||
{
|
||||
temp = false;
|
||||
}
|
||||
catch(const std::exception& /*ex*/)
|
||||
{
|
||||
temp = false;
|
||||
}
|
||||
|
||||
pass7 &= temp;
|
||||
if (!temp)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " FixedSizeAllocator Grow with word32" << endl;
|
||||
|
||||
// word64
|
||||
try
|
||||
{
|
||||
static const unsigned int SIZE = 8;
|
||||
SecBlockWithHint<word64, SIZE> block(SIZE);
|
||||
memset(block, 0xaa, block.SizeInBytes());
|
||||
|
||||
temp = true;
|
||||
block.CleanGrow(SIZE*2);
|
||||
temp &= (block.size() == SIZE*2);
|
||||
|
||||
for (size_t i = 0; i < block.size()/2; i++)
|
||||
temp &= (block[i] == W64LIT(0xaaaaaaaaaaaaaaaa));
|
||||
|
||||
for (size_t i = block.size()/2; i < block.size(); i++)
|
||||
temp &= (block[i] == 0);
|
||||
|
||||
block.CleanNew(SIZE*4);
|
||||
temp &= (block.size() == SIZE*4);
|
||||
for (size_t i = 0; i < block.size(); i++)
|
||||
temp &= (block[i] == 0);
|
||||
}
|
||||
catch(const Exception& /*ex*/)
|
||||
{
|
||||
temp = false;
|
||||
}
|
||||
catch(const std::exception& /*ex*/)
|
||||
{
|
||||
temp = false;
|
||||
}
|
||||
|
||||
pass7 &= temp;
|
||||
if (!temp)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " FixedSizeAllocator Grow with word64" << endl;
|
||||
|
||||
#if defined(CRYPTOPP_WORD128_AVAILABLE)
|
||||
// word128
|
||||
try
|
||||
{
|
||||
static const unsigned int SIZE = 8;
|
||||
SecBlock<word128, AllocatorWithCleanup<word128, true> > block(SIZE);
|
||||
memset(block, 0xaa, block.SizeInBytes());
|
||||
|
||||
temp = true;
|
||||
block.CleanGrow(SIZE*2);
|
||||
temp &= (block.size() == SIZE*2);
|
||||
|
||||
for (size_t i = 0; i < block.size()/2; i++)
|
||||
temp &= (block[i] == (((word128)W64LIT(0xaaaaaaaaaaaaaaaa) << 64U) | W64LIT(0xaaaaaaaaaaaaaaaa)));
|
||||
|
||||
for (size_t i = block.size()/2; i < block.size(); i++)
|
||||
temp &= (block[i] == 0);
|
||||
|
||||
block.CleanNew(SIZE*4);
|
||||
temp &= (block.size() == SIZE*4);
|
||||
for (size_t i = 0; i < block.size(); i++)
|
||||
temp &= (block[i] == 0);
|
||||
}
|
||||
catch(const Exception& /*ex*/)
|
||||
{
|
||||
temp = false;
|
||||
}
|
||||
catch(const std::exception& /*ex*/)
|
||||
{
|
||||
temp = false;
|
||||
}
|
||||
|
||||
pass7 &= temp;
|
||||
if (!temp)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " FixedSizeAllocator Grow with word128" << endl;
|
||||
#endif
|
||||
|
||||
return pass1 && pass2 && pass3 && pass4 && pass5 && pass6 && pass7;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_IMPORTS)
|
||||
bool TestHuffmanCodes()
|
||||
{
|
||||
cout << "\nTesting Huffman codes...\n\n";
|
||||
bool pass=true;
|
||||
|
||||
static const size_t nCodes = 30;
|
||||
const unsigned int codeCounts[nCodes] = {
|
||||
1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
static const unsigned int maxCodeBits = nCodes >> 1;
|
||||
unsigned int codeBits[nCodes] = {
|
||||
~0u, ~0u, ~0u, ~0u, ~0u,
|
||||
~0u, ~0u, ~0u, ~0u, ~0u,
|
||||
~0u, ~0u, ~0u, ~0u, ~0u,
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
HuffmanEncoder::GenerateCodeLengths(codeBits, maxCodeBits, codeCounts, nCodes);
|
||||
}
|
||||
catch(const Exception& /*ex*/)
|
||||
{
|
||||
pass=false;
|
||||
}
|
||||
|
||||
if (!pass)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " GenerateCodeLengths" << endl;
|
||||
|
||||
return pass;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool TestOS_RNG()
|
||||
{
|
||||
bool pass = true;
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@ bool ValidateESIGN();
|
|||
#if defined(CRYPTOPP_DEBUG)
|
||||
bool TestSecBlock();
|
||||
bool TestPolynomialMod2();
|
||||
bool TestIntegerBitops();
|
||||
bool TestHuffmanCodes();
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue