Prepare for Crypto++ 8.2 release
Fix VS2010 compile on WIndows Vista; Add BytePtr inline functionpull/828/head
parent
c9703ab5ea
commit
7ba4657375
44
datatest.cpp
44
datatest.cpp
|
|
@ -79,6 +79,24 @@ std::string TrimComment(std::string str)
|
||||||
return TrimSpace(str);
|
return TrimSpace(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline const byte* BytePtr(const std::string& str)
|
||||||
|
{
|
||||||
|
// Need c_str() here to ensure valid pointer.
|
||||||
|
// An empty string will have a trailing NULL.
|
||||||
|
return reinterpret_cast<const byte*>(str.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline byte* BytePtr(std::string& str)
|
||||||
|
{
|
||||||
|
CRYPTOPP_ASSERT(str.size() > 0);
|
||||||
|
return reinterpret_cast<byte*>(&str[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline size_t BytePtrSize(const std::string& str)
|
||||||
|
{
|
||||||
|
return str.size();
|
||||||
|
}
|
||||||
|
|
||||||
static void OutputTestData(const TestData &v)
|
static void OutputTestData(const TestData &v)
|
||||||
{
|
{
|
||||||
std::cerr << "\n";
|
std::cerr << "\n";
|
||||||
|
|
@ -208,7 +226,7 @@ void PutDecodedDatumInto(const TestData &data, const char *name, BufferedTransfo
|
||||||
|
|
||||||
while (repeat--)
|
while (repeat--)
|
||||||
{
|
{
|
||||||
q.Put(reinterpret_cast<const byte*>(&s2[0]), s2.size());
|
q.Put(BytePtr(s2), BytePtrSize(s2));
|
||||||
RandomizedTransfer(q, target, false);
|
RandomizedTransfer(q, target, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -265,10 +283,11 @@ public:
|
||||||
*reinterpret_cast<int *>(pValue) = atoi(value.c_str());
|
*reinterpret_cast<int *>(pValue) = atoi(value.c_str());
|
||||||
else if (valueType == typeid(word64))
|
else if (valueType == typeid(word64))
|
||||||
{
|
{
|
||||||
std::string x(value); errno = 0;
|
std::string x(value.empty() ? "0" : value);
|
||||||
const char* beg = &x[0];
|
const char* beg = &x[0];
|
||||||
char* end = &x[0] + value.size();
|
char* end = &x[0] + value.size();
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
*reinterpret_cast<word64*>(pValue) = STRTOUL64(beg, &end, 0);
|
*reinterpret_cast<word64*>(pValue) = STRTOUL64(beg, &end, 0);
|
||||||
if (errno != 0)
|
if (errno != 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -279,7 +298,7 @@ public:
|
||||||
{
|
{
|
||||||
m_temp.clear();
|
m_temp.clear();
|
||||||
PutDecodedDatumInto(m_data, name, StringSink(m_temp).Ref());
|
PutDecodedDatumInto(m_data, name, StringSink(m_temp).Ref());
|
||||||
reinterpret_cast<ConstByteArrayParameter *>(pValue)->Assign(reinterpret_cast<const byte *>(&m_temp[0]), m_temp.size(), false);
|
reinterpret_cast<ConstByteArrayParameter *>(pValue)->Assign(BytePtr(m_temp), BytePtrSize(m_temp), false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw ValueTypeMismatch(name, typeid(std::string), valueType);
|
throw ValueTypeMismatch(name, typeid(std::string), valueType);
|
||||||
|
|
@ -496,8 +515,8 @@ void TestSymmetricCipher(TestData &v, const NameValuePairs &overrideParameters)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
encryptor->SetKey(reinterpret_cast<const byte*>(&key[0]), key.size(), pairs);
|
encryptor->SetKey(BytePtr(key), BytePtrSize(key), pairs);
|
||||||
decryptor->SetKey(reinterpret_cast<const byte*>(&key[0]), key.size(), pairs);
|
decryptor->SetKey(BytePtr(key), BytePtrSize(key), pairs);
|
||||||
}
|
}
|
||||||
|
|
||||||
word64 seek64 = pairs.GetWord64ValueWithDefault("Seek64", 0);
|
word64 seek64 = pairs.GetWord64ValueWithDefault("Seek64", 0);
|
||||||
|
|
@ -547,13 +566,13 @@ void TestSymmetricCipher(TestData &v, const NameValuePairs &overrideParameters)
|
||||||
encrypted.reserve(10000 * plaintext.size());
|
encrypted.reserve(10000 * plaintext.size());
|
||||||
for (int j=0; j<10000; j++)
|
for (int j=0; j<10000; j++)
|
||||||
{
|
{
|
||||||
cipher->ProcessString(reinterpret_cast<byte*>(&buf[0]), buf.size());
|
cipher->ProcessString(BytePtr(buf), BytePtrSize(buf));
|
||||||
encrypted.append(buf.begin(), buf.end());
|
encrypted.append(buf.begin(), buf.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
encrypted.erase(0, encrypted.size() - keybuf.size());
|
encrypted.erase(0, encrypted.size() - keybuf.size());
|
||||||
xorbuf(reinterpret_cast<byte*>(&keybuf[0]), reinterpret_cast<const byte*>(&encrypted[0]), keybuf.size());
|
xorbuf(BytePtr(keybuf), BytePtr(encrypted), BytePtrSize(keybuf));
|
||||||
cipher->SetKey(reinterpret_cast<const byte*>(&keybuf[0]), keybuf.size());
|
cipher->SetKey(BytePtr(keybuf), BytePtrSize(keybuf));
|
||||||
}
|
}
|
||||||
|
|
||||||
encrypted.assign(buf.begin(), buf.end());
|
encrypted.assign(buf.begin(), buf.end());
|
||||||
|
|
@ -641,8 +660,8 @@ void TestAuthenticatedSymmetricCipher(TestData &v, const NameValuePairs &overrid
|
||||||
member_ptr<AuthenticatedSymmetricCipher> encryptor, decryptor;
|
member_ptr<AuthenticatedSymmetricCipher> encryptor, decryptor;
|
||||||
encryptor.reset(ObjectFactoryRegistry<AuthenticatedSymmetricCipher, ENCRYPTION>::Registry().CreateObject(name.c_str()));
|
encryptor.reset(ObjectFactoryRegistry<AuthenticatedSymmetricCipher, ENCRYPTION>::Registry().CreateObject(name.c_str()));
|
||||||
decryptor.reset(ObjectFactoryRegistry<AuthenticatedSymmetricCipher, DECRYPTION>::Registry().CreateObject(name.c_str()));
|
decryptor.reset(ObjectFactoryRegistry<AuthenticatedSymmetricCipher, DECRYPTION>::Registry().CreateObject(name.c_str()));
|
||||||
encryptor->SetKey(reinterpret_cast<const byte*>(&key[0]), key.size(), pairs);
|
encryptor->SetKey(BytePtr(key), BytePtrSize(key), pairs);
|
||||||
decryptor->SetKey(reinterpret_cast<const byte*>(&key[0]), key.size(), pairs);
|
decryptor->SetKey(BytePtr(key), BytePtrSize(key), pairs);
|
||||||
|
|
||||||
// Code coverage
|
// Code coverage
|
||||||
(void)encryptor->AlgorithmName();
|
(void)encryptor->AlgorithmName();
|
||||||
|
|
@ -736,7 +755,7 @@ void TestDigestOrMAC(TestData &v, bool testDigest)
|
||||||
mac.reset(ObjectFactoryRegistry<MessageAuthenticationCode>::Registry().CreateObject(name.c_str()));
|
mac.reset(ObjectFactoryRegistry<MessageAuthenticationCode>::Registry().CreateObject(name.c_str()));
|
||||||
pHash = mac.get();
|
pHash = mac.get();
|
||||||
std::string key = GetDecodedDatum(v, "Key");
|
std::string key = GetDecodedDatum(v, "Key");
|
||||||
mac->SetKey(reinterpret_cast<const byte *>(&key[0]), key.size(), pairs);
|
mac->SetKey(BytePtr(key), BytePtrSize(key), pairs);
|
||||||
|
|
||||||
// Code coverage
|
// Code coverage
|
||||||
(void)mac->AlgorithmName();
|
(void)mac->AlgorithmName();
|
||||||
|
|
@ -779,8 +798,7 @@ void TestKeyDerivationFunction(TestData &v)
|
||||||
kdf.reset(ObjectFactoryRegistry<KeyDerivationFunction>::Registry().CreateObject(name.c_str()));
|
kdf.reset(ObjectFactoryRegistry<KeyDerivationFunction>::Registry().CreateObject(name.c_str()));
|
||||||
|
|
||||||
std::string calculated; calculated.resize(expected.size());
|
std::string calculated; calculated.resize(expected.size());
|
||||||
kdf->DeriveKey(reinterpret_cast<byte*>(&calculated[0]), calculated.size(),
|
kdf->DeriveKey(BytePtr(calculated), BytePtrSize(calculated), BytePtr(secret), BytePtrSize(secret), pairs);
|
||||||
reinterpret_cast<const byte*>(&secret[0]), secret.size(), pairs);
|
|
||||||
|
|
||||||
if(calculated != expected)
|
if(calculated != expected)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue