Skip to content

Commit

Permalink
misc changes
Browse files Browse the repository at this point in the history
  • Loading branch information
weidai11 committed Jul 18, 2003
1 parent b3d4024 commit 5b20081
Show file tree
Hide file tree
Showing 25 changed files with 191 additions and 99 deletions.
4 changes: 3 additions & 1 deletion Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,6 @@ History

5.2 - Merged in changes for 5.01 - 5.0.4
- added support for using encoding parameters and key derivation parameters
with public key encryption (implemented by OAEP and DLIES)
with public key encryption (implemented by OAEP and DL/ECIES)
- added Camellia, SHACAL-2, Two-Track-MAC, Whirlpool, RIPEMD-320,
RIPEMD-128, RIPEMD-256, Base 32 coding
14 changes: 12 additions & 2 deletions algparam.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ByteArrayParameter
unsigned int m_size;
};

class CombinedNameValuePairs : public NameValuePairs
class CRYPTOPP_DLL CombinedNameValuePairs : public NameValuePairs
{
public:
CombinedNameValuePairs(const NameValuePairs &pairs1, const NameValuePairs &pairs2)
Expand Down Expand Up @@ -323,6 +323,12 @@ class AlgorithmParameters : public AlgorithmParametersBase2<T>
return AlgorithmParameters<AlgorithmParameters<PARENT,T>, R>(*this, name, value, m_throwIfNotUsed);
}

template <class R>
AlgorithmParameters<AlgorithmParameters<PARENT,T>, R> operator()(const char *name, const R &value, bool throwIfNotUsed) const
{
return AlgorithmParameters<AlgorithmParameters<PARENT,T>, R>(*this, name, value, throwIfNotUsed);
}

private:
const NameValuePairs & GetParent() const {return m_parent;}
PARENT m_parent;
Expand All @@ -331,7 +337,11 @@ class AlgorithmParameters : public AlgorithmParametersBase2<T>
//! Create an object that implements NameValuePairs for passing parameters
/*! \param throwIfNotUsed if true, the object will throw an exception if the value is not accessed
\note throwIfNotUsed is ignored if using a compiler that does not support std::uncaught_exception(),
such as MSVC 7.0 and earlier. */
such as MSVC 7.0 and earlier.
\note A NameValuePairs object containing an arbitrary number of name value pairs may be constructed by
repeatedly using operator() on the object returned by MakeParameters, for example:
const NameValuePairs &parameters = MakeParameters(name1, value1)(name2, value2)(name3, value3);
*/
template <class T>
AlgorithmParameters<NullNameValuePairs,T> MakeParameters(const char *name, const T &value, bool throwIfNotUsed = true)
{
Expand Down
11 changes: 11 additions & 0 deletions argnames.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ CRYPTOPP_DEFINE_NAME_STRING(OutputStreamPointer) //!< std::ostream *
CRYPTOPP_DEFINE_NAME_STRING(OutputBinaryMode) //!< bool
CRYPTOPP_DEFINE_NAME_STRING(EncodingParameters) //!< ConstByteArrayParameter
CRYPTOPP_DEFINE_NAME_STRING(KeyDerivationParameters) //!< ConstByteArrayParameter
CRYPTOPP_DEFINE_NAME_STRING(Separator) //< ConstByteArrayParameter
CRYPTOPP_DEFINE_NAME_STRING(Terminator) //< ConstByteArrayParameter
CRYPTOPP_DEFINE_NAME_STRING(Uppercase) //< bool
CRYPTOPP_DEFINE_NAME_STRING(GroupSize) //< int
CRYPTOPP_DEFINE_NAME_STRING(Pad) //< bool
CRYPTOPP_DEFINE_NAME_STRING(PaddingByte) //< byte
CRYPTOPP_DEFINE_NAME_STRING(Log2Base) //< int
CRYPTOPP_DEFINE_NAME_STRING(EncodingLookupArray) //< const byte *
CRYPTOPP_DEFINE_NAME_STRING(DecodingLookupArray) //< const byte *
CRYPTOPP_DEFINE_NAME_STRING(InsertLineBreaks) //< bool
CRYPTOPP_DEFINE_NAME_STRING(MaxLineLength) //< int

DOCUMENTED_NAMESPACE_END

Expand Down
16 changes: 8 additions & 8 deletions base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ static const byte s_padding = '=';

void Base64Encoder::IsolatedInitialize(const NameValuePairs &parameters)
{
bool insertLineBreaks = parameters.GetValueWithDefault("InsertLineBreaks", true);
int maxLineLength = parameters.GetIntValueWithDefault("MaxLineLength", 72);
bool insertLineBreaks = parameters.GetValueWithDefault(Name::InsertLineBreaks(), true);
int maxLineLength = parameters.GetIntValueWithDefault(Name::MaxLineLength(), 72);

const char *lineBreak = insertLineBreaks ? "\n" : "";

m_filter->Initialize(CombinedNameValuePairs(
parameters,
MakeParameters("EncodingLookupArray", (const byte *)s_vec)
("PaddingByte", s_padding)
("Log2Base", 6)
("GroupSize", insertLineBreaks ? maxLineLength : 0)
("Separator", ConstByteArrayParameter(lineBreak))
("Terminator", ConstByteArrayParameter(lineBreak))));
MakeParameters(Name::EncodingLookupArray(), &s_vec[0], false)
(Name::PaddingByte(), s_padding)
(Name::GroupSize(), insertLineBreaks ? maxLineLength : 0)
(Name::Separator(), ConstByteArrayParameter(lineBreak))
(Name::Terminator(), ConstByteArrayParameter(lineBreak))
(Name::Log2Base(), 6, true)));
}

const int *Base64Decoder::GetDecodingLookupArray()
Expand Down
2 changes: 1 addition & 1 deletion base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Base64Encoder : public SimpleProxyFilter
Base64Encoder(BufferedTransformation *attachment = NULL, bool insertLineBreaks = true, int maxLineLength = 72)
: SimpleProxyFilter(new BaseN_Encoder(new Grouper), attachment)
{
IsolatedInitialize(MakeParameters("InsertLineBreaks", insertLineBreaks)("MaxLineLength", maxLineLength));
IsolatedInitialize(MakeParameters(Name::InsertLineBreaks(), insertLineBreaks)(Name::MaxLineLength(), maxLineLength));
}

void IsolatedInitialize(const NameValuePairs &parameters);
Expand Down
20 changes: 10 additions & 10 deletions basecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ NAMESPACE_BEGIN(CryptoPP)

void BaseN_Encoder::IsolatedInitialize(const NameValuePairs &parameters)
{
parameters.GetRequiredParameter("BaseN_Encoder", "EncodingLookupArray", m_alphabet);
parameters.GetRequiredParameter("BaseN_Encoder", Name::EncodingLookupArray(), m_alphabet);

parameters.GetRequiredIntParameter("BaseN_Encoder", "Log2Base", m_bitsPerChar);
parameters.GetRequiredIntParameter("BaseN_Encoder", Name::Log2Base(), m_bitsPerChar);
if (m_bitsPerChar <= 0 || m_bitsPerChar >= 8)
throw InvalidArgument("BaseN_Encoder: Log2Base must be between 1 and 7 inclusive");

byte padding;
bool pad;
if (parameters.GetValue("PaddingByte", padding))
pad = parameters.GetValueWithDefault("Pad", true);
if (parameters.GetValue(Name::PaddingByte(), padding))
pad = parameters.GetValueWithDefault(Name::Pad(), true);
else
pad = false;
m_padding = pad ? padding : -1;
Expand Down Expand Up @@ -105,9 +105,9 @@ unsigned int BaseN_Encoder::Put2(const byte *begin, unsigned int length, int mes

void BaseN_Decoder::IsolatedInitialize(const NameValuePairs &parameters)
{
parameters.GetRequiredParameter("BaseN_Decoder", "DecodingLookupArray", m_lookup);
parameters.GetRequiredParameter("BaseN_Decoder", Name::DecodingLookupArray(), m_lookup);

parameters.GetRequiredIntParameter("BaseN_Decoder", "Log2Base", m_bitsPerChar);
parameters.GetRequiredIntParameter("BaseN_Decoder", Name::Log2Base(), m_bitsPerChar);
if (m_bitsPerChar <= 0 || m_bitsPerChar >= 8)
throw InvalidArgument("BaseN_Decoder: Log2Base must be between 1 and 7 inclusive");

Expand Down Expand Up @@ -189,13 +189,13 @@ void BaseN_Decoder::InitializeDecodingLookupArray(int *lookup, const byte *alpha

void Grouper::IsolatedInitialize(const NameValuePairs &parameters)
{
m_groupSize = parameters.GetIntValueWithDefault("GroupSize", 0);
m_groupSize = parameters.GetIntValueWithDefault(Name::GroupSize(), 0);
ConstByteArrayParameter separator, terminator;
if (m_groupSize)
parameters.GetRequiredParameter("Grouper", "Separator", separator);
parameters.GetRequiredParameter("Grouper", Name::Separator(), separator);
else
parameters.GetValue("Separator", separator);
parameters.GetValue("Terminator", terminator);
parameters.GetValue(Name::Separator(), separator);
parameters.GetValue(Name::Terminator(), terminator);

m_separator.Assign(separator.begin(), separator.size());
m_terminator.Assign(terminator.begin(), terminator.size());
Expand Down
19 changes: 10 additions & 9 deletions basecode.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "filters.h"
#include "algparam.h"
#include "argnames.h"

NAMESPACE_BEGIN(CryptoPP)

Expand All @@ -15,10 +16,10 @@ class CRYPTOPP_DLL BaseN_Encoder : public Unflushable<Filter>
BaseN_Encoder(const byte *alphabet, int log2base, BufferedTransformation *attachment=NULL, int padding=-1)
: Unflushable<Filter>(attachment)
{
IsolatedInitialize(MakeParameters("EncodingLookupArray", alphabet)
("Log2Base", log2base)
("Pad", padding != -1)
("PaddingByte", byte(padding)));
IsolatedInitialize(MakeParameters(Name::EncodingLookupArray(), alphabet)
(Name::Log2Base(), log2base)
(Name::Pad(), padding != -1)
(Name::PaddingByte(), byte(padding)));
}

void IsolatedInitialize(const NameValuePairs &parameters);
Expand All @@ -40,13 +41,13 @@ class CRYPTOPP_DLL BaseN_Decoder : public Unflushable<Filter>
BaseN_Decoder(const int *lookup, int log2base, BufferedTransformation *attachment=NULL)
: Unflushable<Filter>(attachment)
{
IsolatedInitialize(MakeParameters("DecodingLookupArray", lookup)("Log2Base", log2base));
IsolatedInitialize(MakeParameters(Name::DecodingLookupArray(), lookup)(Name::Log2Base(), log2base));
}

void IsolatedInitialize(const NameValuePairs &parameters);
unsigned int Put2(const byte *begin, unsigned int length, int messageEnd, bool blocking);

static void InitializeDecodingLookupArray(int *lookup, const byte *alphabet, unsigned int log2base, bool caseInsensitive);
static void InitializeDecodingLookupArray(int *lookup, const byte *alphabet, unsigned int base, bool caseInsensitive);

private:
const int *m_lookup;
Expand All @@ -64,9 +65,9 @@ class CRYPTOPP_DLL Grouper : public Bufferless<Filter>
Grouper(int groupSize, const std::string &separator, const std::string &terminator, BufferedTransformation *attachment=NULL)
: Bufferless<Filter>(attachment)
{
IsolatedInitialize(MakeParameters("GroupSize", groupSize)
("Separator", ConstByteArrayParameter(separator))
("Terminator", ConstByteArrayParameter(terminator)));
IsolatedInitialize(MakeParameters(Name::GroupSize(), groupSize)
(Name::Separator(), ConstByteArrayParameter(separator))
(Name::Terminator(), ConstByteArrayParameter(terminator)));
}

void IsolatedInitialize(const NameValuePairs &parameters);
Expand Down
38 changes: 19 additions & 19 deletions bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ static const byte *const key=(byte *)"0123456789abcdefghijklmnopqrstuvwxyzABCDEF
static double logtotal = 0;
static unsigned int logcount = 0;

void OutputResultBytes(const char *name, unsigned long length, double timeTaken)
void OutputResultBytes(const char *name, double length, double timeTaken)
{
double mbs = length / timeTaken / (1024*1024);
cout << "<TR><TH>" << name;
cout << "<TD>" << length;
cout << "<TD>" << setprecision(3) << length / (1024*1024);
cout << setiosflags(ios::fixed);
cout << "<TD>" << setprecision(3) << timeTaken;
cout << "<TD>" << setprecision(3) << mbs << endl;
Expand Down Expand Up @@ -120,18 +120,18 @@ void BenchMark(const char *name, BlockTransformation &cipher, double timeTotal)
const int nBlocks = BUF_SIZE / cipher.BlockSize();
clock_t start = clock();

unsigned long i=0, length=BUF_SIZE;
unsigned long i=0, blocks=1;
double timeTaken;
do
{
length *= 2;
for (; i<length; i+=BUF_SIZE)
blocks *= 2;
for (; i<blocks; i++)
cipher.ProcessAndXorMultipleBlocks(buf, NULL, buf, nBlocks);
timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND;
}
while (timeTaken < 2.0/3*timeTotal);

OutputResultBytes(name, length, timeTaken);
OutputResultBytes(name, double(blocks) * BUF_SIZE, timeTaken);
}

void BenchMark(const char *name, StreamTransformation &cipher, double timeTotal)
Expand All @@ -140,18 +140,18 @@ void BenchMark(const char *name, StreamTransformation &cipher, double timeTotal)
SecByteBlock buf(BUF_SIZE);
clock_t start = clock();

unsigned long i=0, length=BUF_SIZE;
unsigned long i=0, blocks=1;
double timeTaken;
do
{
length *= 2;
for (; i<length; i+=BUF_SIZE)
blocks *= 2;
for (; i<blocks; i++)
cipher.ProcessString(buf, BUF_SIZE);
timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND;
}
while (timeTaken < 2.0/3*timeTotal);

OutputResultBytes(name, length, timeTaken);
OutputResultBytes(name, double(blocks) * BUF_SIZE, timeTaken);
}

void BenchMark(const char *name, HashTransformation &hash, double timeTotal)
Expand All @@ -162,18 +162,18 @@ void BenchMark(const char *name, HashTransformation &hash, double timeTotal)
rng.GenerateBlock(buf, BUF_SIZE);
clock_t start = clock();

unsigned long i=0, length=BUF_SIZE;
unsigned long i=0, blocks=1;
double timeTaken;
do
{
length *= 2;
for (; i<length; i+=BUF_SIZE)
blocks *= 2;
for (; i<blocks; i++)
hash.Update(buf, BUF_SIZE);
timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND;
}
while (timeTaken < 2.0/3*timeTotal);

OutputResultBytes(name, length, timeTaken);
OutputResultBytes(name, double(blocks) * BUF_SIZE, timeTaken);
}

void BenchMark(const char *name, BufferedTransformation &bt, double timeTotal)
Expand All @@ -184,18 +184,18 @@ void BenchMark(const char *name, BufferedTransformation &bt, double timeTotal)
rng.GenerateBlock(buf, BUF_SIZE);
clock_t start = clock();

unsigned long i=0, length=BUF_SIZE;
unsigned long i=0, blocks=1;
double timeTaken;
do
{
length *= 2;
for (; i<length; i+=BUF_SIZE)
blocks *= 2;
for (; i<blocks; i++)
bt.Put(buf, BUF_SIZE);
timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND;
}
while (timeTaken < 2.0/3*timeTotal);

OutputResultBytes(name, length, timeTaken);
OutputResultBytes(name, double(blocks) * BUF_SIZE, timeTaken);
}

void BenchMarkEncryption(const char *name, PK_Encryptor &key, double timeTotal, bool pc=false)
Expand Down Expand Up @@ -434,7 +434,7 @@ void BenchMarkAll(double t)
logcount = 0;

cout << "<TABLE border=1><COLGROUP><COL align=left><COL align=right><COL align=right><COL align=right>" << endl;
cout << "<THEAD><TR><TH>Algorithm<TH>Bytes Processed<TH>Time Taken<TH>Megabytes(2^20 bytes)/Second\n<TBODY>" << endl;
cout << "<THEAD><TR><TH>Algorithm<TH>Megabytes(2^20 bytes) Processed<TH>Time Taken<TH>MB/Second\n<TBODY>" << endl;

BenchMarkKeyless<CRC32>("CRC-32", t);
BenchMarkKeyless<Adler32>("Adler-32", t);
Expand Down
4 changes: 2 additions & 2 deletions cryptdll.dsp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions cryptest.dsp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions cryptlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,12 @@ unsigned int BufferedTransformation::TransferMessagesTo2(BufferedTransformation
for (messageCount=0; messageCount < maxMessages && AnyMessages(); messageCount++)
{
unsigned int blockedBytes;
unsigned long transferedBytes;
unsigned long transferredBytes;

while (AnyRetrievable())
{
transferedBytes = ULONG_MAX;
blockedBytes = TransferTo2(target, transferedBytes, channel, blocking);
transferredBytes = ULONG_MAX;
blockedBytes = TransferTo2(target, transferredBytes, channel, blocking);
if (blockedBytes > 0)
return blockedBytes;
}
Expand Down
Loading

0 comments on commit 5b20081

Please sign in to comment.