summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2017-05-04 19:11:24 -0400
committerJeffrey Walton <noloader@gmail.com>2017-05-04 19:11:24 -0400
commit5c1de7b5a5676a136e00eb2c2a8fcc18aded5bb9 (patch)
treec88d146217f3f3d22b71b8c395824f25152dfe2b
parent9614307ab7f4a4a420b665ac6c798d80c96cdaad (diff)
downloadcryptopp-git-5c1de7b5a5676a136e00eb2c2a8fcc18aded5bb9.tar.gz
Add variable block size support to test and benchmarks
CRYPTOPP_COVERAGE was added at 9614307ab7f4a4a4 to increase code coverage support. This commit enables additional validation routines when CRYPTOPP_COVERAGE is in effect.
-rw-r--r--TestVectors/Readme.txt6
-rw-r--r--bench1.cpp11
-rw-r--r--datatest.cpp26
-rw-r--r--regtest2.cpp2
-rw-r--r--test.cpp9
-rw-r--r--validat0.cpp10
-rw-r--r--validat1.cpp4
-rw-r--r--validat2.cpp2
-rw-r--r--validate.h2
9 files changed, 40 insertions, 32 deletions
diff --git a/TestVectors/Readme.txt b/TestVectors/Readme.txt
index 281055f8..df33ee84 100644
--- a/TestVectors/Readme.txt
+++ b/TestVectors/Readme.txt
@@ -57,6 +57,7 @@ PublicElement - the public element when KeyFormat=Component
PrivateExponent - the private exponent when KeyFormat=Component
Message - encoded string, message to be signed or verified
Signature - encoded string, signature to be verified or compared with
+BlockSize - encoded string, block size for vaiable block ciphers
Plaintext - encoded string
Ciphertext - encoded string
Header - encoded string
@@ -79,7 +80,8 @@ Verify - signature/digest/MAC verification should pass
VerifyTruncated - truncated digest/MAC verification should pass
NotVerify - signature/digest/MAC verification should not pass
DeterministicSign - sign message using given seed, and the resulting
- signature should be equal to the given signature
+ signature should equal the given signature
+Encrypt - plaintext encrypts to ciphertext
+EncryptBlockSize - plaintext encrypts to ciphertext under a key and blocksize
DecryptMatch - ciphertext decrypts to plaintext
-
(more to come here)
diff --git a/bench1.cpp b/bench1.cpp
index 4c5de739..f360dad8 100644
--- a/bench1.cpp
+++ b/bench1.cpp
@@ -271,7 +271,6 @@ void BenchMarkKeying(SimpleKeyingInterface &c, size_t keyLength, const NameValue
template <class T_FactoryOutput, class T_Interface>
void BenchMarkByName2(const char *factoryName, size_t keyLength = 0, const char *displayName=NULLPTR, const NameValuePairs &params = g_nullNameValuePairs)
{
- CRYPTOPP_UNUSED(params);
std::string name(factoryName ? factoryName : "");
member_ptr<T_FactoryOutput> obj(ObjectFactoryRegistry<T_FactoryOutput>::Registry().CreateObject(name.c_str()));
@@ -283,9 +282,10 @@ void BenchMarkByName2(const char *factoryName, size_t keyLength = 0, const char
else if (keyLength)
name += " (" + IntToString(keyLength * 8) + "-bit key)";
- obj->SetKey(defaultKey, keyLength, CombinedNameValuePairs(params, MakeParameters(Name::IV(), ConstByteArrayParameter(defaultKey, obj->IVSize()), false)));
+ const int blockSize = params.GetIntValueWithDefault(Name::BlockSize(), 0);
+ obj->SetKey(defaultKey, keyLength, CombinedNameValuePairs(params, MakeParameters(Name::IV(), ConstByteArrayParameter(defaultKey, blockSize ? blockSize : obj->IVSize()), false)));
BenchMark(name.c_str(), *static_cast<T_Interface *>(obj.get()), g_allocatedTime);
- BenchMarkKeying(*obj, keyLength, CombinedNameValuePairs(params, MakeParameters(Name::IV(), ConstByteArrayParameter(defaultKey, obj->IVSize()), false)));
+ BenchMarkKeying(*obj, keyLength, CombinedNameValuePairs(params, MakeParameters(Name::IV(), ConstByteArrayParameter(defaultKey, blockSize ? blockSize : obj->IVSize()), false)));
}
template <class T_FactoryOutput>
@@ -559,6 +559,11 @@ void Benchmark2(double t, double hertz)
BenchMarkByName<SymmetricCipher>("CAST-128/CTR");
BenchMarkByName<SymmetricCipher>("SKIPJACK/CTR");
BenchMarkByName<SymmetricCipher>("SEED/CTR", 0, "SEED/CTR (1/2 K table)");
+// BenchMarkByName<SymmetricCipher>("Kalyna/CTR", 16, "Kalyna-128(128)", MakeParameters(Name::BlockSize(), 16));
+// BenchMarkByName<SymmetricCipher>("Kalyna/CTR", 32, "Kalyna-256(128)", MakeParameters(Name::BlockSize(), 16));
+// BenchMarkByName<SymmetricCipher>("Kalyna/CTR", 32, "Kalyna-256(256)", MakeParameters(Name::BlockSize(), 32));
+// BenchMarkByName<SymmetricCipher>("Kalyna/CTR", 64, "Kalyna-512(256)", MakeParameters(Name::BlockSize(), 32));
+// BenchMarkByName<SymmetricCipher>("Kalyna/CTR", 64, "Kalyna-512(512)", MakeParameters(Name::BlockSize(), 64));
}
std::cout << "\n<TBODY style=\"background: yellow;\">";
diff --git a/datatest.cpp b/datatest.cpp
index 90c6a1df..94a45149 100644
--- a/datatest.cpp
+++ b/datatest.cpp
@@ -363,7 +363,7 @@ void TestSymmetricCipher(TestData &v, const NameValuePairs &overrideParameters)
TestDataNameValuePairs testDataPairs(v);
CombinedNameValuePairs pairs(overrideParameters, testDataPairs);
- if (test == "Encrypt" || test == "EncryptXorDigest" || test == "Resync" || test == "EncryptionMCT" || test == "DecryptionMCT")
+ if (test == "Encrypt" || test == "EncryptBlockSize" || test == "EncryptXorDigest" || test == "Resync" || test == "EncryptionMCT" || test == "DecryptionMCT")
{
static member_ptr<SymmetricCipher> encryptor, decryptor;
static std::string lastName;
@@ -375,8 +375,12 @@ void TestSymmetricCipher(TestData &v, const NameValuePairs &overrideParameters)
lastName = name;
}
+ int blockSize = 0;
+ if (test == "EncryptBlockSize" && !pairs.GetValue(Name::BlockSize(), blockSize))
+ SignalTestFailure();
+
ConstByteArrayParameter iv;
- if (pairs.GetValue(Name::IV(), iv) && iv.size() != encryptor->IVSize())
+ if (pairs.GetValue(Name::IV(), iv) && iv.size() != encryptor->IVSize() && iv.size() != blockSize)
SignalTestFailure();
if (test == "Resync")
@@ -427,7 +431,7 @@ void TestSymmetricCipher(TestData &v, const NameValuePairs &overrideParameters)
ciphertext = GetDecodedDatum(v, test == "EncryptionMCT" ? "Ciphertext" : "Plaintext");
if (encrypted != ciphertext)
{
- std::cout << "incorrectly encrypted: ";
+ std::cout << "\nincorrectly encrypted: ";
StringSource xx(encrypted, false, new HexEncoder(new FileSink(std::cout)));
xx.Pump(256); xx.Flush(false);
std::cout << "\n";
@@ -459,7 +463,7 @@ void TestSymmetricCipher(TestData &v, const NameValuePairs &overrideParameters)
}
if (test != "EncryptXorDigest" ? encrypted != ciphertext : xorDigest != ciphertextXorDigest)
{
- std::cout << "incorrectly encrypted: ";
+ std::cout << "\nincorrectly encrypted: ";
StringSource xx(encrypted, false, new HexEncoder(new FileSink(std::cout)));
xx.Pump(2048); xx.Flush(false);
std::cout << "\n";
@@ -471,7 +475,7 @@ void TestSymmetricCipher(TestData &v, const NameValuePairs &overrideParameters)
decFilter.MessageEnd();
if (decrypted != plaintext)
{
- std::cout << "incorrectly decrypted: ";
+ std::cout << "\nincorrectly decrypted: ";
StringSource xx(decrypted, false, new HexEncoder(new FileSink(std::cout)));
xx.Pump(256); xx.Flush(false);
std::cout << "\n";
@@ -480,7 +484,7 @@ void TestSymmetricCipher(TestData &v, const NameValuePairs &overrideParameters)
}
else
{
- std::cout << "unexpected test name\n";
+ std::cout << "\nunexpected test name\n";
SignalTestError();
}
}
@@ -538,7 +542,7 @@ void TestAuthenticatedSymmetricCipher(TestData &v, const NameValuePairs &overrid
if (test == "Encrypt" && encrypted != ciphertext+mac)
{
- std::cout << "incorrectly encrypted: ";
+ std::cout << "\nincorrectly encrypted: ";
StringSource xx(encrypted, false, new HexEncoder(new FileSink(std::cout)));
xx.Pump(2048); xx.Flush(false);
std::cout << "\n";
@@ -546,7 +550,7 @@ void TestAuthenticatedSymmetricCipher(TestData &v, const NameValuePairs &overrid
}
if (test == "Encrypt" && decrypted != plaintext)
{
- std::cout << "incorrectly decrypted: ";
+ std::cout << "\nincorrectly decrypted: ";
StringSource xx(decrypted, false, new HexEncoder(new FileSink(std::cout)));
xx.Pump(256); xx.Flush(false);
std::cout << "\n";
@@ -555,18 +559,18 @@ void TestAuthenticatedSymmetricCipher(TestData &v, const NameValuePairs &overrid
if (ciphertext.size()+mac.size()-plaintext.size() != asc1->DigestSize())
{
- std::cout << "bad MAC size\n";
+ std::cout << "\nbad MAC size\n";
SignalTestFailure();
}
if (df.GetLastResult() != (test == "Encrypt"))
{
- std::cout << "MAC incorrectly verified\n";
+ std::cout << "\nMAC incorrectly verified\n";
SignalTestFailure();
}
}
else
{
- std::cout << "unexpected test name\n";
+ std::cout << "\nunexpected test name\n";
SignalTestError();
}
}
diff --git a/regtest2.cpp b/regtest2.cpp
index 72cbe909..6a37226e 100644
--- a/regtest2.cpp
+++ b/regtest2.cpp
@@ -134,6 +134,8 @@ void RegisterFactories2()
RegisterSymmetricCipherDefaultFactories<CTR_Mode<Blowfish> >();
RegisterSymmetricCipherDefaultFactories<ECB_Mode<SEED> >();
RegisterSymmetricCipherDefaultFactories<CTR_Mode<SEED> >();
+// RegisterSymmetricCipherDefaultFactories<ECB_Mode<Kalyna> >(); // Test Vectors
+// RegisterSymmetricCipherDefaultFactories<CTR_Mode<Kalyna> >(); // Benchmarks
RegisterDefaultFactoryFor<KeyDerivationFunction, HKDF<SHA1> >();
RegisterDefaultFactoryFor<KeyDerivationFunction, HKDF<SHA256> >();
diff --git a/test.cpp b/test.cpp
index 72fda0d7..714f70c6 100644
--- a/test.cpp
+++ b/test.cpp
@@ -25,7 +25,6 @@
#include "stdcpp.h"
#include "ossig.h"
#include "trap.h"
-#include "aria.h"
#include "validate.h"
#include "bench.h"
@@ -181,10 +180,6 @@ int CRYPTOPP_API main(int argc, char *argv[])
_CrtSetDbgFlag( tempflag );
#endif
-#if defined(__MWERKS__) && defined(macintosh)
- argc = ccommand(&argv);
-#endif
-
try
{
RegisterFactories(Test::All);
@@ -462,7 +457,7 @@ int CRYPTOPP_API main(int argc, char *argv[])
std::cout << "\nstd::exception caught: " << e.what() << std::endl;
return -2;
}
-} // End main()
+} // main()
void FIPS140_GenerateRandomFiles()
{
@@ -994,7 +989,7 @@ bool Validate(int alg, bool thorough, const char *seedInput)
case 78: result = Test::ValidateHashDRBG(); break;
case 79: result = Test::ValidateHmacDRBG(); break;
-#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_IMPORTS)
+#if (defined(CRYPTOPP_DEBUG) || defined(CRYPTOPP_COVERAGE)) && !defined(CRYPTOPP_IMPORTS)
// http://github.com/weidai11/cryptopp/issues/92
case 9999: result = Test::TestSecBlock(); break;
// http://github.com/weidai11/cryptopp/issues/64
diff --git a/validat0.cpp b/validat0.cpp
index 933f78ef..fd533df7 100644
--- a/validat0.cpp
+++ b/validat0.cpp
@@ -24,7 +24,7 @@
NAMESPACE_BEGIN(CryptoPP)
NAMESPACE_BEGIN(Test)
-#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_IMPORTS)
+#if (defined(CRYPTOPP_DEBUG) || defined(CRYPTOPP_COVERAGE)) && !defined(CRYPTOPP_IMPORTS)
bool TestRounding()
{
std::cout << "\nTesting RoundUpToMultipleOf/RoundDownToMultipleOf...\n\n";
@@ -470,7 +470,7 @@ bool TestRounding()
}
#endif
-#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_IMPORTS)
+#if (defined(CRYPTOPP_DEBUG) || defined(CRYPTOPP_COVERAGE)) && !defined(CRYPTOPP_IMPORTS)
struct ASN1_TestTuple
{
int disposition;
@@ -721,7 +721,7 @@ bool TestASN1Parse()
}
#endif
-#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_IMPORTS)
+#if (defined(CRYPTOPP_DEBUG) || defined(CRYPTOPP_COVERAGE)) && !defined(CRYPTOPP_IMPORTS)
bool TestSecBlock()
{
std::cout << "\nTesting SecBlock...\n\n";
@@ -1685,7 +1685,7 @@ bool TestSecBlock()
}
#endif
-#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_IMPORTS)
+#if (defined(CRYPTOPP_DEBUG) || defined(CRYPTOPP_COVERAGE)) && !defined(CRYPTOPP_IMPORTS)
bool TestHuffmanCodes()
{
std::cout << "\nTesting Huffman codes...\n\n";
@@ -1723,7 +1723,7 @@ bool TestHuffmanCodes()
}
#endif
-#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_IMPORTS)
+#if (defined(CRYPTOPP_DEBUG) || defined(CRYPTOPP_COVERAGE)) && !defined(CRYPTOPP_IMPORTS)
bool TestIntegerBitops()
{
std::cout << "\nTesting Integer bitops...\n\n";
diff --git a/validat1.cpp b/validat1.cpp
index 5b6c5bc0..be82172b 100644
--- a/validat1.cpp
+++ b/validat1.cpp
@@ -78,7 +78,7 @@ bool ValidateAll(bool thorough)
pass=TestRDSEED() && pass;
#endif
-#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_IMPORTS)
+#if (defined(CRYPTOPP_DEBUG) || defined(CRYPTOPP_COVERAGE)) && !defined(CRYPTOPP_IMPORTS)
// http://github.com/weidai11/cryptopp/issues/92
pass=TestSecBlock() && pass;
// http://github.com/weidai11/cryptopp/issues/336
@@ -229,7 +229,7 @@ bool TestSettings()
pass = false;
}
-#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_IMPORTS)
+#if (defined(CRYPTOPP_DEBUG) || defined(CRYPTOPP_COVERAGE)) && !defined(CRYPTOPP_IMPORTS)
// App and library versions, http://github.com/weidai11/cryptopp/issues/371
const int v1 = LibraryVersion();
const int v2 = HeaderVersion();
diff --git a/validat2.cpp b/validat2.cpp
index 1c039001..287d9b0f 100644
--- a/validat2.cpp
+++ b/validat2.cpp
@@ -793,7 +793,7 @@ bool ValidateBlumGoldwasser()
}
*/
-#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_IMPORTS)
+#if (defined(CRYPTOPP_DEBUG) || defined(CRYPTOPP_COVERAGE)) && !defined(CRYPTOPP_IMPORTS)
// Issue 64: "PolynomialMod2::operator<<=", http://github.com/weidai11/cryptopp/issues/64
bool TestPolynomialMod2()
{
diff --git a/validate.h b/validate.h
index b9e8a029..094aaf96 100644
--- a/validate.h
+++ b/validate.h
@@ -107,7 +107,7 @@ bool ValidateESIGN();
bool ValidateHashDRBG();
bool ValidateHmacDRBG();
-#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_IMPORTS)
+#if (defined(CRYPTOPP_DEBUG) || defined(CRYPTOPP_COVERAGE)) && !defined(CRYPTOPP_IMPORTS)
// http://github.com/weidai11/cryptopp/issues/92
bool TestSecBlock();
// http://github.com/weidai11/cryptopp/issues/64