summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2019-01-25 23:27:48 -0500
committerJeffrey Walton <noloader@gmail.com>2019-01-25 23:27:48 -0500
commitb9d2310beb4866537fd1c46a4873eb0557adc88f (patch)
tree40936fda904a32e1e6c01d26febe639f9ff9ba4d
parent76bdb328a68119db409e5ce5d8c85f398a333fee (diff)
downloadcryptopp-git-b9d2310beb4866537fd1c46a4873eb0557adc88f.tar.gz
Use ROUNDS constant for ChaChaTLS
-rw-r--r--chacha.cpp13
-rw-r--r--chacha.h9
2 files changed, 9 insertions, 13 deletions
diff --git a/chacha.cpp b/chacha.cpp
index 9d0f357e..321ebbaf 100644
--- a/chacha.cpp
+++ b/chacha.cpp
@@ -384,7 +384,7 @@ void ChaChaTLS_Policy::CipherSetKey(const NameValuePairs &params, const byte *ke
CRYPTOPP_ASSERT(key); CRYPTOPP_ASSERT(length == 32);
// ChaChaTLS is always 20 rounds. Fetch Rounds() to avoid a spurious failure.
- int rounds = params.GetIntValueWithDefault(Name::Rounds(), m_rounds);
+ int rounds = params.GetIntValueWithDefault(Name::Rounds(), ROUNDS);
if (rounds != 20)
throw InvalidRounds(ChaChaTLS::StaticAlgorithmName(), rounds);
@@ -423,12 +423,6 @@ void ChaChaTLS_Policy::CipherResynchronize(byte *keystreamBuffer, const byte *IV
get(m_state[13])(m_state[14])(m_state[15]);
}
-void ChaChaTLS_Policy::CipherResynchronize(byte *keystreamBuffer, word32 initialBlock, const byte *IV, size_t length)
-{
- m_state[16] = initialBlock;
- this->CipherResynchronize(keystreamBuffer, IV, length);
-}
-
void ChaChaTLS_Policy::SeekToIteration(lword iterationCount)
{
// Should we throw here??? If the initial block counter is
@@ -454,14 +448,15 @@ void ChaChaTLS_Policy::OperateKeystream(KeystreamOperation operation,
{
word32 discard=0;
ChaCha_OperateKeystream(operation, m_state, m_state[12], discard,
- m_rounds, output, input, iterationCount);
+ ROUNDS, output, input, iterationCount);
// If this fires it means ChaCha_OperateKeystream generated a counter
// block carry that was discarded. The problem is, the RFC does not
// specify what should happen when the counter block wraps. All we can
// do is inform the user that something bad may happen because we don't
// know what we should do.
- // Also see https://github.com/weidai11/cryptopp/issues/790.
+ // Also see https://github.com/weidai11/cryptopp/issues/790 and
+ // https://mailarchive.ietf.org/arch/msg/cfrg/gsOnTJzcbgG6OqD8Sc0GO5aR_tU
CRYPTOPP_ASSERT(discard==0);
}
diff --git a/chacha.h b/chacha.h
index 9be96253..9551b344 100644
--- a/chacha.h
+++ b/chacha.h
@@ -114,7 +114,6 @@ protected:
void CipherSetKey(const NameValuePairs &params, const byte *key, size_t length);
void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount);
void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length);
- void CipherResynchronize(byte *keystreamBuffer, word32 initialBlock, const byte *IV, size_t length);
bool CipherIsRandomAccess() const {return true;}
void SeekToIteration(lword iterationCount);
unsigned int GetAlignment() const;
@@ -124,7 +123,7 @@ protected:
std::string AlgorithmProvider() const;
FixedSizeAlignedSecBlock<word32, 16+1> m_state;
- CRYPTOPP_CONSTANT(m_rounds = ChaChaTLS_Info::ROUNDS)
+ CRYPTOPP_CONSTANT(ROUNDS = ChaChaTLS_Info::ROUNDS)
};
/// \brief ChaCha-TLS stream cipher
@@ -135,8 +134,10 @@ protected:
/// <tt>TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256</tt>,
/// <tt>TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256</tt>, and
/// <tt>TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256</tt>.
-/// \sa <a href="https://tools.ietf.org/html/rfc8439">ChaCha20 and Poly1305 for
-/// IETF Protocols</a> and <A HREF="https://github.com/weidai11/cryptopp/issues/790">Issue
+/// \sa <a href="https://tools.ietf.org/html/rfc8439">RFC 8439, ChaCha20 and
+/// Poly1305 for IETF Protocols</a>, <A HREF="https://mailarchive.ietf.org/arch/msg/cfrg/gsOnTJzcbgG6OqD8Sc0GO5aR_tU">How
+/// to handle block counter wrap in IETF's ChaCha algorithm?</A> and
+/// <A HREF="https://github.com/weidai11/cryptopp/issues/790">Issue
/// 790, ChaChaTLS results when counter block wraps</A>.
/// \since Crypto++ 8.1
struct ChaChaTLS : public ChaChaTLS_Info, public SymmetricCipherDocumentation