From 4c8fdf71733c7ea14d5ee47306cc45e781d27b30 Mon Sep 17 00:00:00 2001 From: weidai Date: Wed, 30 Jul 2003 00:28:54 +0000 Subject: add XTEA and BTEA git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@119 57ff6487-cd31-0410-9ec3-f628ee90f5f0 --- datatest.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'datatest.cpp') diff --git a/datatest.cpp b/datatest.cpp index a104ae5..80d7e06 100644 --- a/datatest.cpp +++ b/datatest.cpp @@ -61,6 +61,18 @@ public: *reinterpret_cast(pValue) = atoi(value.c_str()); else if (valueType == typeid(Integer)) *reinterpret_cast(pValue) = Integer((std::string(value) + "h").c_str()); + else if (valueType == typeid(ConstByteArrayParameter)) + { + m_temp.resize(0); + StringSource(value, true, new HexDecoder(new StringSink(m_temp))); + reinterpret_cast(pValue)->Assign((const byte *)m_temp.data(), m_temp.size(), true); + } + else if (valueType == typeid(const byte *)) + { + m_temp.resize(0); + StringSource(value, true, new HexDecoder(new StringSink(m_temp))); + *reinterpret_cast(pValue) = (const byte *)m_temp.data(); + } else throw ValueTypeMismatch(name, typeid(std::string), valueType); @@ -69,6 +81,7 @@ public: private: const TestData &m_data; + mutable std::string m_temp; }; const std::string & GetRequiredDatum(const TestData &data, const char *name) @@ -243,14 +256,15 @@ void TestSymmetricCipher(TestData &v) std::string test = GetRequiredDatum(v, "Test"); std::string key = GetDecodedDatum(v, "Key"); - std::string iv = GetDecodedDatum(v, "IV"); std::string ciphertext = GetDecodedDatum(v, "Ciphertext"); std::string plaintext = GetDecodedDatum(v, "Plaintext"); + TestDataNameValuePairs pairs(v); + if (test == "Encrypt") { std::auto_ptr encryptor(ObjectFactoryRegistry::Registry().CreateObject(name.c_str())); - encryptor->SetKeyWithIV((const byte *)key.data(), key.size(), (const byte *)iv.data()); + encryptor->SetKey((const byte *)key.data(), key.size(), pairs); std::string encrypted; StringSource ss(plaintext, true, new StreamTransformationFilter(*encryptor, new StringSink(encrypted), StreamTransformationFilter::NO_PADDING)); if (encrypted != ciphertext) @@ -259,7 +273,7 @@ void TestSymmetricCipher(TestData &v) else if (test == "Decrypt") { std::auto_ptr decryptor(ObjectFactoryRegistry::Registry().CreateObject(name.c_str())); - decryptor->SetKeyWithIV((const byte *)key.data(), key.size(), (const byte *)iv.data()); + decryptor->SetKey((const byte *)key.data(), key.size(), pairs); std::string decrypted; StringSource ss(ciphertext, true, new StreamTransformationFilter(*decryptor, new StringSink(decrypted), StreamTransformationFilter::NO_PADDING)); if (decrypted != plaintext) -- cgit v1.2.1