summaryrefslogtreecommitdiff
path: root/cryptlib.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2018-01-24 20:04:16 -0500
committerJeffrey Walton <noloader@gmail.com>2018-01-24 20:04:16 -0500
commit51db9eb436e92f18f4fabf312206f2fe17b5f367 (patch)
tree3a17019da4c473df2edc1e5ba1662d507308ccfa /cryptlib.cpp
parente546b2af8587cabd25c744a8fb3d5aca8f0259a1 (diff)
downloadcryptopp-git-51db9eb436e92f18f4fabf312206f2fe17b5f367.tar.gz
Clear clang-tidy warnings
Diffstat (limited to 'cryptlib.cpp')
-rw-r--r--cryptlib.cpp161
1 files changed, 98 insertions, 63 deletions
diff --git a/cryptlib.cpp b/cryptlib.cpp
index 6750ad59..f7525d80 100644
--- a/cryptlib.cpp
+++ b/cryptlib.cpp
@@ -95,22 +95,25 @@ void SimpleKeyingInterface::ThrowIfInvalidIV(const byte *iv)
throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": this object cannot use a null IV");
}
-size_t SimpleKeyingInterface::ThrowIfInvalidIVLength(int size)
-{
- if (size < 0)
- return (size_t)IVSize();
- else if ((size_t)size < MinIVLength())
- throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": IV length " + IntToString(size) + " is less than the minimum of " + IntToString(MinIVLength()));
- else if ((size_t)size > MaxIVLength())
- throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": IV length " + IntToString(size) + " exceeds the maximum of " + IntToString(MaxIVLength()));
+size_t SimpleKeyingInterface::ThrowIfInvalidIVLength(int length)
+{
+ size_t size = 0;
+ if (length < 0)
+ size = static_cast<size_t>(IVSize());
+ else if ((size_t)length < MinIVLength())
+ throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": IV length " + IntToString(length) + " is less than the minimum of " + IntToString(MinIVLength()));
+ else if ((size_t)length > MaxIVLength())
+ throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": IV length " + IntToString(length) + " exceeds the maximum of " + IntToString(MaxIVLength()));
else
- return (size_t)size;
+ size = static_cast<size_t>(length);
+
+ return size;
}
const byte * SimpleKeyingInterface::GetIVAndThrowIfInvalid(const NameValuePairs &params, size_t &size)
{
ConstByteArrayParameter ivWithLength;
- const byte *iv;
+ const byte *iv = NULLPTR;
bool found = false;
try {found = params.GetValue(Name::IV(), ivWithLength);}
@@ -121,25 +124,24 @@ const byte * SimpleKeyingInterface::GetIVAndThrowIfInvalid(const NameValuePairs
iv = ivWithLength.begin();
ThrowIfInvalidIV(iv);
size = ThrowIfInvalidIVLength(static_cast<int>(ivWithLength.size()));
- return iv;
}
else if (params.GetValue(Name::IV(), iv))
{
ThrowIfInvalidIV(iv);
- size = IVSize();
- return iv;
+ size = static_cast<size_t>(IVSize());
}
else
{
ThrowIfResynchronizable();
size = 0;
- return NULLPTR;
}
+
+ return iv;
}
-void SimpleKeyingInterface::GetNextIV(RandomNumberGenerator &rng, byte *IV)
+void SimpleKeyingInterface::GetNextIV(RandomNumberGenerator &rng, byte *iv)
{
- rng.GenerateBlock(IV, IVSize());
+ rng.GenerateBlock(iv, IVSize());
}
size_t BlockTransformation::AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const
@@ -227,11 +229,11 @@ size_t StreamTransformation::ProcessLastBlock(byte *outString, size_t outLength,
{
outLength = inLength; // squash unused warning
ProcessData(outString, inString, inLength);
- return outLength;
}
else if (inLength != 0)
throw NotImplemented(AlgorithmName() + ": this object doesn't support a special last block");
- return 0;
+
+ return outLength;
}
void AuthenticatedSymmetricCipher::SpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength)
@@ -381,12 +383,12 @@ RandomNumberGenerator & NullRNG()
return s_nullRNG;
}
-bool HashTransformation::TruncatedVerify(const byte *digestIn, size_t digestLength)
+bool HashTransformation::TruncatedVerify(const byte *digest, size_t digestLength)
{
ThrowIfInvalidTruncatedSize(digestLength);
- SecByteBlock digest(digestLength);
- TruncatedFinal(digest, digestLength);
- return VerifyBufsEqual(digest, digestIn, digestLength);
+ SecByteBlock calculated(digestLength);
+ TruncatedFinal(calculated, digestLength);
+ return VerifyBufsEqual(calculated, digest, digestLength);
}
void HashTransformation::ThrowIfInvalidTruncatedSize(size_t size) const
@@ -431,150 +433,183 @@ bool BufferedTransformation::MessageSeriesEnd(int propagation, bool blocking)
byte * BufferedTransformation::ChannelCreatePutSpace(const std::string &channel, size_t &size)
{
+ byte* space = NULLPTR;
if (channel.empty())
- return CreatePutSpace(size);
+ space = CreatePutSpace(size);
else
throw NoChannelSupport(AlgorithmName());
+ return space;
}
-size_t BufferedTransformation::ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking)
+size_t BufferedTransformation::ChannelPut2(const std::string &channel, const byte *inString, size_t length, int messageEnd, bool blocking)
{
+ size_t size = 0;
if (channel.empty())
- return Put2(begin, length, messageEnd, blocking);
+ size = Put2(inString, length, messageEnd, blocking);
else
throw NoChannelSupport(AlgorithmName());
+ return size;
}
-size_t BufferedTransformation::ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking)
+size_t BufferedTransformation::ChannelPutModifiable2(const std::string &channel, byte *inString, size_t length, int messageEnd, bool blocking)
{
+ size_t size = 0;
if (channel.empty())
- return PutModifiable2(begin, length, messageEnd, blocking);
+ size = PutModifiable2(inString, length, messageEnd, blocking);
else
- return ChannelPut2(channel, begin, length, messageEnd, blocking);
+ size = ChannelPut2(channel, inString, length, messageEnd, blocking);
+ return size;
}
-bool BufferedTransformation::ChannelFlush(const std::string &channel, bool completeFlush, int propagation, bool blocking)
+bool BufferedTransformation::ChannelFlush(const std::string &channel, bool hardFlush, int propagation, bool blocking)
{
+ bool result = 0;
if (channel.empty())
- return Flush(completeFlush, propagation, blocking);
+ result = Flush(hardFlush, propagation, blocking);
else
throw NoChannelSupport(AlgorithmName());
+ return result;
}
bool BufferedTransformation::ChannelMessageSeriesEnd(const std::string &channel, int propagation, bool blocking)
{
+ bool result = false;
if (channel.empty())
- return MessageSeriesEnd(propagation, blocking);
+ result = MessageSeriesEnd(propagation, blocking);
else
throw NoChannelSupport(AlgorithmName());
+ return result;
}
lword BufferedTransformation::MaxRetrievable() const
{
+ lword size = 0;
if (AttachedTransformation())
- return AttachedTransformation()->MaxRetrievable();
+ size = AttachedTransformation()->MaxRetrievable();
else
- return CopyTo(TheBitBucket());
+ size = CopyTo(TheBitBucket());
+ return size;
}
bool BufferedTransformation::AnyRetrievable() const
{
+ bool result = false;
if (AttachedTransformation())
- return AttachedTransformation()->AnyRetrievable();
+ result = AttachedTransformation()->AnyRetrievable();
else
{
byte b;
- return Peek(b) != 0;
+ result = Peek(b) != 0;
}
+ return result;
}
size_t BufferedTransformation::Get(byte &outByte)
{
+ size_t size = 0;
if (AttachedTransformation())
- return AttachedTransformation()->Get(outByte);
+ size = AttachedTransformation()->Get(outByte);
else
- return Get(&outByte, 1);
+ size = Get(&outByte, 1);
+ return size;
}
size_t BufferedTransformation::Get(byte *outString, size_t getMax)
{
+ size_t size = 0;
if (AttachedTransformation())
- return AttachedTransformation()->Get(outString, getMax);
+ size = AttachedTransformation()->Get(outString, getMax);
else
{
ArraySink arraySink(outString, getMax);
- return (size_t)TransferTo(arraySink, getMax);
+ size = (size_t)TransferTo(arraySink, getMax);
}
+ return size;
}
size_t BufferedTransformation::Peek(byte &outByte) const
{
+ size_t size = 0;
if (AttachedTransformation())
- return AttachedTransformation()->Peek(outByte);
+ size = AttachedTransformation()->Peek(outByte);
else
- return Peek(&outByte, 1);
+ size = Peek(&outByte, 1);
+ return size;
}
size_t BufferedTransformation::Peek(byte *outString, size_t peekMax) const
{
+ size_t size = 0;
if (AttachedTransformation())
- return AttachedTransformation()->Peek(outString, peekMax);
+ size = AttachedTransformation()->Peek(outString, peekMax);
else
{
ArraySink arraySink(outString, peekMax);
- return (size_t)CopyTo(arraySink, peekMax);
+ size = (size_t)CopyTo(arraySink, peekMax);
}
+ return size;
}
lword BufferedTransformation::Skip(lword skipMax)
{
+ lword size = 0;
if (AttachedTransformation())
- return AttachedTransformation()->Skip(skipMax);
+ size = AttachedTransformation()->Skip(skipMax);
else
- return TransferTo(TheBitBucket(), skipMax);
+ size = TransferTo(TheBitBucket(), skipMax);
+ return size;
}
lword BufferedTransformation::TotalBytesRetrievable() const
{
+ lword size = 0;
if (AttachedTransformation())
- return AttachedTransformation()->TotalBytesRetrievable();
+ size = AttachedTransformation()->TotalBytesRetrievable();
else
- return MaxRetrievable();
+ size = MaxRetrievable();
+ return size;
}
unsigned int BufferedTransformation::NumberOfMessages() const
{
+ unsigned int size = 0;
if (AttachedTransformation())
- return AttachedTransformation()->NumberOfMessages();
+ size = AttachedTransformation()->NumberOfMessages();
else
- return CopyMessagesTo(TheBitBucket());
+ size = CopyMessagesTo(TheBitBucket());
+ return size;
}
bool BufferedTransformation::AnyMessages() const
{
+ bool result = false;
if (AttachedTransformation())
- return AttachedTransformation()->AnyMessages();
+ result = AttachedTransformation()->AnyMessages();
else
- return NumberOfMessages() != 0;
+ result = NumberOfMessages() != 0;
+ return result;
}
bool BufferedTransformation::GetNextMessage()
{
+ bool result = false;
if (AttachedTransformation())
- return AttachedTransformation()->GetNextMessage();
+ result = AttachedTransformation()->GetNextMessage();
else
{
CRYPTOPP_ASSERT(!AnyMessages());
- return false;
}
+ return result;
}
unsigned int BufferedTransformation::SkipMessages(unsigned int count)
{
+ unsigned int size = 0;
if (AttachedTransformation())
- return AttachedTransformation()->SkipMessages(count);
+ size = AttachedTransformation()->SkipMessages(count);
else
- return TransferMessagesTo(TheBitBucket(), count);
+ size = TransferMessagesTo(TheBitBucket(), count);
+ return size;
}
size_t BufferedTransformation::TransferMessagesTo2(BufferedTransformation &target, unsigned int &messageCount, const std::string &channel, bool blocking)
@@ -609,10 +644,10 @@ size_t BufferedTransformation::TransferMessagesTo2(BufferedTransformation &targe
unsigned int BufferedTransformation::CopyMessagesTo(BufferedTransformation &target, unsigned int count, const std::string &channel) const
{
+ unsigned int size = 0;
if (AttachedTransformation())
- return AttachedTransformation()->CopyMessagesTo(target, count, channel);
- else
- return 0;
+ size = AttachedTransformation()->CopyMessagesTo(target, count, channel);
+ return size;
}
void BufferedTransformation::SkipAll()
@@ -745,12 +780,12 @@ size_t BufferedTransformation::GetWord32(word32 &value, ByteOrder order)
return (size_t)Skip(PeekWord32(value, order));
}
-void BufferedTransformation::Attach(BufferedTransformation *newOut)
+void BufferedTransformation::Attach(BufferedTransformation *newAttachment)
{
if (AttachedTransformation() && AttachedTransformation()->Attachable())
- AttachedTransformation()->Attach(newOut);
+ AttachedTransformation()->Attach(newAttachment);
else
- Detach(newOut);
+ Detach(newAttachment);
}
void GeneratableCryptoMaterial::GenerateRandomWithKeySize(RandomNumberGenerator &rng, unsigned int keySize)
@@ -879,10 +914,10 @@ bool PK_Verifier::Verify(PK_MessageAccumulator *messageAccumulator) const
return VerifyAndRestart(*m);
}
-bool PK_Verifier::VerifyMessage(const byte *message, size_t messageLen, const byte *signature, size_t signatureLength) const
+bool PK_Verifier::VerifyMessage(const byte *message, size_t messageLen, const byte *signature, size_t signatureLen) const
{
member_ptr<PK_MessageAccumulator> m(NewVerificationAccumulator());
- InputSignature(*m, signature, signatureLength);
+ InputSignature(*m, signature, signatureLen);
m->Update(message, messageLen);
return VerifyAndRestart(*m);
}