summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2018-01-23 21:15:26 -0500
committerJeffrey Walton <noloader@gmail.com>2018-01-23 21:15:26 -0500
commit01136e2c7be25cc857dbad274329e51bb8144a83 (patch)
treec86bf51c83763dfd3bcb364cb153f979222d2586
parent675575d96039ff840df7519ef9cfdd423a73d7df (diff)
downloadcryptopp-git-01136e2c7be25cc857dbad274329e51bb8144a83.tar.gz
Clear clang-tidy warnings
-rw-r--r--algebra.h2
-rw-r--r--aria.cpp7
-rw-r--r--aria.h7
-rw-r--r--bench2.cpp93
-rw-r--r--blake2.cpp6
5 files changed, 82 insertions, 33 deletions
diff --git a/algebra.h b/algebra.h
index 0c4da2ba..f41b3402 100644
--- a/algebra.h
+++ b/algebra.h
@@ -7,8 +7,8 @@
#define CRYPTOPP_ALGEBRA_H
#include "config.h"
-#include "misc.h"
#include "integer.h"
+#include "misc.h"
NAMESPACE_BEGIN(CryptoPP)
diff --git a/aria.cpp b/aria.cpp
index a53a00c6..922ef309 100644
--- a/aria.cpp
+++ b/aria.cpp
@@ -111,6 +111,9 @@ void ARIA::Base::UncheckedSetKey(const byte *key, unsigned int keylen, const Nam
{
CRYPTOPP_UNUSED(params);
+ m_rk.New(16*17); // round keys
+ m_w.New(4*7); // w0, w1, w2, w3, t and u
+
const byte *mk = key;
byte *rk = m_rk.data();
int Q, q, R, r;
@@ -236,6 +239,10 @@ void ARIA::Base::UncheckedSetKey(const byte *key, unsigned int keylen, const Nam
ARIA_MM(t[0],t[1],t[2],t[3]); ARIA_P(t[0],t[1],t[2],t[3]); ARIA_MM(t[0],t[1],t[2],t[3]);
::memcpy(z, t, 16);
}
+
+ // Silence warnings
+ CRYPTOPP_UNUSED(Q); CRYPTOPP_UNUSED(R);
+ CRYPTOPP_UNUSED(q); CRYPTOPP_UNUSED(r);
}
void ARIA::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
diff --git a/aria.h b/aria.h
index ca3f3b81..ebc44f08 100644
--- a/aria.h
+++ b/aria.h
@@ -50,8 +50,11 @@ public:
private:
// Reference implementation allocates a table of 17 round keys.
- FixedSizeAlignedSecBlock<byte, 16*17> m_rk; // round keys
- FixedSizeAlignedSecBlock<word32, 4*7> m_w; // w0, w1, w2, w3, t and u
+ typedef SecBlock<byte, AllocatorWithCleanup<byte, true> > AlignedByteBlock;
+ typedef SecBlock<word32, AllocatorWithCleanup<word32, true> > AlignedWordBlock;
+
+ AlignedByteBlock m_rk; // round keys
+ AlignedWordBlock m_w; // w0, w1, w2, w3, t and u
unsigned int m_rounds;
};
diff --git a/bench2.cpp b/bench2.cpp
index 2fdf648e..d38391ea 100644
--- a/bench2.cpp
+++ b/bench2.cpp
@@ -31,6 +31,7 @@
#include "oids.h"
#include "randpool.h"
#include "stdcpp.h"
+#include "hrtimer.h"
#if CRYPTOPP_MSC_VERSION
# pragma warning(disable: 4505 4355)
@@ -45,12 +46,18 @@ void BenchMarkEncryption(const char *name, PK_Encryptor &key, double timeTotal,
SecByteBlock plaintext(len), ciphertext(key.CiphertextLength(len));
Test::GlobalRNG().GenerateBlock(plaintext, len);
- unsigned int i;
+ unsigned int i = 0;
double timeTaken;
- const clock_t start = ::clock();
- for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(::clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
+ ThreadUserTimer timer;
+ timer.StartTimer();
+
+ do
+ {
key.Encrypt(Test::GlobalRNG(), plaintext, len, ciphertext);
+ ++i; timeTaken = timer.ElapsedTimeAsDouble();
+ }
+ while (timeTaken < timeTotal);
OutputResultOperations(name, "Encryption", pc, i, timeTaken);
@@ -69,12 +76,18 @@ void BenchMarkDecryption(const char *name, PK_Decryptor &priv, PK_Encryptor &pub
Test::GlobalRNG().GenerateBlock(plaintext, len);
pub.Encrypt(Test::GlobalRNG(), plaintext, len, ciphertext);
- unsigned int i;
+ unsigned int i = 0;
double timeTaken;
- const clock_t start = ::clock();
- for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(::clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
+ ThreadUserTimer timer;
+ timer.StartTimer();
+
+ do
+ {
priv.Decrypt(Test::GlobalRNG(), ciphertext, ciphertext.size(), plaintext);
+ ++i; timeTaken = timer.ElapsedTimeAsDouble();
+ }
+ while (timeTaken < timeTotal);
OutputResultOperations(name, "Decryption", false, i, timeTaken);
}
@@ -85,12 +98,18 @@ void BenchMarkSigning(const char *name, PK_Signer &key, double timeTotal, bool p
AlignedSecByteBlock message(len), signature(key.SignatureLength());
Test::GlobalRNG().GenerateBlock(message, len);
- unsigned int i;
+ unsigned int i = 0;
double timeTaken;
- const clock_t start = ::clock();
- for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(::clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
+ ThreadUserTimer timer;
+ timer.StartTimer();
+
+ do
+ {
(void)key.SignMessage(Test::GlobalRNG(), message, len, signature);
+ ++i; timeTaken = timer.ElapsedTimeAsDouble();
+ }
+ while (timeTaken < timeTotal);
OutputResultOperations(name, "Signature", pc, i, timeTaken);
@@ -108,12 +127,18 @@ void BenchMarkVerification(const char *name, const PK_Signer &priv, PK_Verifier
Test::GlobalRNG().GenerateBlock(message, len);
priv.SignMessage(Test::GlobalRNG(), message, len, signature);
- unsigned int i;
+ unsigned int i = 0;
double timeTaken;
- const clock_t start = ::clock();
- for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(::clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
+ ThreadUserTimer timer;
+ timer.StartTimer();
+
+ do
+ {
(void)pub.VerifyMessage(message, len, signature, signature.size());
+ ++i; timeTaken = timer.ElapsedTimeAsDouble();
+ }
+ while (timeTaken < timeTotal);
OutputResultOperations(name, "Verification", pc, i, timeTaken);
@@ -128,12 +153,18 @@ void BenchMarkKeyGen(const char *name, SimpleKeyAgreementDomain &d, double timeT
{
SecByteBlock priv(d.PrivateKeyLength()), pub(d.PublicKeyLength());
- unsigned int i;
+ unsigned int i = 0;
double timeTaken;
- const clock_t start = ::clock();
- for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(::clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
+ ThreadUserTimer timer;
+ timer.StartTimer();
+
+ do
+ {
d.GenerateKeyPair(Test::GlobalRNG(), priv, pub);
+ ++i; timeTaken = timer.ElapsedTimeAsDouble();
+ }
+ while (timeTaken < timeTotal);
OutputResultOperations(name, "Key-Pair Generation", pc, i, timeTaken);
@@ -148,12 +179,18 @@ void BenchMarkKeyGen(const char *name, AuthenticatedKeyAgreementDomain &d, doubl
{
SecByteBlock priv(d.EphemeralPrivateKeyLength()), pub(d.EphemeralPublicKeyLength());
- unsigned int i;
+ unsigned int i = 0;
double timeTaken;
- const clock_t start = ::clock();
- for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(::clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
+ ThreadUserTimer timer;
+ timer.StartTimer();
+
+ do
+ {
d.GenerateEphemeralKeyPair(Test::GlobalRNG(), priv, pub);
+ ++i; timeTaken = timer.ElapsedTimeAsDouble();
+ }
+ while (timeTaken < timeTotal);
OutputResultOperations(name, "Key-Pair Generation", pc, i, timeTaken);
@@ -172,15 +209,19 @@ void BenchMarkAgreement(const char *name, SimpleKeyAgreementDomain &d, double ti
d.GenerateKeyPair(Test::GlobalRNG(), priv2, pub2);
SecByteBlock val(d.AgreedValueLength());
- unsigned int i;
+ unsigned int i = 0;
double timeTaken;
- const clock_t start = ::clock();
- for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(::clock() - start) / CLOCK_TICKS_PER_SECOND, i+=2)
+ ThreadUserTimer timer;
+ timer.StartTimer();
+
+ do
{
d.Agree(val, priv1, pub2);
d.Agree(val, priv2, pub1);
+ i+=2; timeTaken = timer.ElapsedTimeAsDouble();
}
+ while (timeTaken < timeTotal);
OutputResultOperations(name, "Key Agreement", pc, i, timeTaken);
}
@@ -197,15 +238,19 @@ void BenchMarkAgreement(const char *name, AuthenticatedKeyAgreementDomain &d, do
d.GenerateEphemeralKeyPair(Test::GlobalRNG(), epriv2, epub2);
SecByteBlock val(d.AgreedValueLength());
- unsigned int i;
+ unsigned int i = 0;
double timeTaken;
- const clock_t start = ::clock();
- for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(::clock() - start) / CLOCK_TICKS_PER_SECOND, i+=2)
+ ThreadUserTimer timer;
+ timer.StartTimer();
+
+ do
{
d.Agree(val, spriv1, epriv1, spub2, epub2);
d.Agree(val, spriv2, epriv2, spub1, epub1);
+ i+=2; timeTaken = timer.ElapsedTimeAsDouble();
}
+ while (timeTaken < timeTotal);
OutputResultOperations(name, "Key Agreement", pc, i, timeTaken);
}
diff --git a/blake2.cpp b/blake2.cpp
index 2fcba5f9..0500e7a0 100644
--- a/blake2.cpp
+++ b/blake2.cpp
@@ -248,15 +248,9 @@ void BLAKE2_Base<W, T_64bit>::UncheckedSetKey(const byte *key, unsigned int leng
m_key.resize(0);
}
-#if defined(__COVERITY__)
// Avoid Coverity finding SIZEOF_MISMATCH/suspicious_sizeof
ParameterBlock& block = *m_block.data();
memset(m_block.data(), 0x00, sizeof(ParameterBlock));
-#else
- // Set Head bytes; Tail bytes are set below
- ParameterBlock& block = *m_block.data();
- memset(m_block.data(), 0x00, T_64bit ? 32 : 16);
-#endif
block.keyLength = (byte)length;
block.digestLength = (byte)params.GetIntValueWithDefault(Name::DigestSize(), DIGESTSIZE);