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 ¶ms, 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 ¶ms, 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 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: /// TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, /// TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, and /// TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256. -/// \sa ChaCha20 and Poly1305 for -/// IETF Protocols and Issue +/// \sa RFC 8439, ChaCha20 and +/// Poly1305 for IETF Protocols, How +/// to handle block counter wrap in IETF's ChaCha algorithm? and +/// Issue /// 790, ChaChaTLS results when counter block wraps. /// \since Crypto++ 8.1 struct ChaChaTLS : public ChaChaTLS_Info, public SymmetricCipherDocumentation