diff --git a/chachapoly.cpp b/chachapoly.cpp
index ee49b4e6..6d4d395e 100644
--- a/chachapoly.cpp
+++ b/chachapoly.cpp
@@ -14,14 +14,14 @@ void ChaCha20Poly1305_Base::RekeyCipherAndMac(const byte *userKey, size_t keylen
AlgorithmParameters block0 = MakeParameters("InitialBlock", (word64)0, true);
AccessSymmetricCipher().SetKey(userKey, keylength, CombinedNameValuePairs(params, block0));
- // Only the head 256-bits are used to key the MAC
+ // Only the first 256-bits are used to key the MAC
SecByteBlock derived(NULLPTR, 32);
AccessSymmetricCipher().ProcessString(derived, derived.size());
- // Set the Poly1305 key
+ // Key the Poly1305 MAC
AccessMAC().SetKey(derived, derived.size(), params);
- // Key Cipher for bulk encryption
+ // Key the ChaCha20 cipher
AlgorithmParameters block1 = MakeParameters("InitialBlock", (word64)1, true);
AccessSymmetricCipher().SetKey(userKey, keylength, CombinedNameValuePairs(params, block1));
}
@@ -30,14 +30,12 @@ void ChaCha20Poly1305_Base::SetKeyWithoutResync(const byte *userKey, size_t user
{
CRYPTOPP_ASSERT(userKey && userKeyLength == 32);
m_userKey.Assign(userKey, userKeyLength);
-
RekeyCipherAndMac(userKey, userKeyLength, params);
}
void ChaCha20Poly1305_Base::Resync(const byte *iv, size_t len)
{
CRYPTOPP_ASSERT(iv && len == 12);
-
RekeyCipherAndMac(m_userKey, m_userKey.SizeInBytes(),
MakeParameters(Name::IV(), ConstByteArrayParameter(iv,len)));
}
@@ -52,8 +50,7 @@ void ChaCha20Poly1305_Base::AuthenticateLastHeaderBlock()
{
// Pad to a multiple of 16 or 0
const byte zero[16] = {0};
- size_t rem = m_totalHeaderLength % 16;
- size_t pad = rem ? 16 - rem : 0;
+ size_t pad = (16 - (m_totalHeaderLength % 16)) % 16;
AccessMAC().Update(zero, pad);
}
@@ -61,8 +58,7 @@ void ChaCha20Poly1305_Base::AuthenticateLastConfidentialBlock()
{
// Pad to a multiple of 16 or 0
const byte zero[16] = {0};
- size_t rem = m_totalMessageLength % 16;
- size_t pad = rem ? 16 - rem : 0;
+ size_t pad = (16 - (m_totalMessageLength % 16)) % 16;
AccessMAC().Update(zero, pad);
}
@@ -72,7 +68,6 @@ void ChaCha20Poly1305_Base::AuthenticateLastFooterBlock(byte *mac, size_t macSiz
PutWord(true, LITTLE_ENDIAN_ORDER, length+0, m_totalHeaderLength);
PutWord(true, LITTLE_ENDIAN_ORDER, length+8, m_totalMessageLength);
AccessMAC().Update(length, sizeof(length));
-
AccessMAC().TruncatedFinal(mac, macSize);
}
diff --git a/chachapoly.h b/chachapoly.h
index 0c03e392..fc3f4481 100644
--- a/chachapoly.h
+++ b/chachapoly.h
@@ -3,12 +3,13 @@
/// \file chachapoly.h
/// \brief ChaCha20/Poly1305-TLS AEAD cipher
-/// \details ChaCha20Poly1305 is an authenticated encryption cipher that combines
-/// ChaCha20TLS and Poly1305TLS. The cipher uses the IETF versions of ChaCha and
-/// Poly1305 because it is defined in RFC 8439, section 2.8, AEAD_CHACHA20_POLY1305
-/// construction.
+/// \details ChaCha20Poly1305 is an authenticated encryption scheme that combines
+/// ChaCha20TLS and Poly1305TLS. The scheme is defined in RFC 8439, section 2.8,
+/// AEAD_CHACHA20_POLY1305 construction, and uses the IETF versions of ChaCha
+/// and Poly1305.
/// \sa RFC 8439, ChaCha20 and Poly1305
/// for IETF Protocols.
+/// \since Crypto++ 8.1
#ifndef CRYPTOPP_CHACHA_POLY1305_H
#define CRYPTOPP_CHACHA_POLY1305_H
@@ -119,10 +120,10 @@ protected:
};
/// \brief ChaCha20Poly1305 cipher final implementation
-/// \details ChaCha20Poly1305 is an authenticated encryption cipher that combines
-/// ChaCha20TLS and Poly1305TLS. The cipher uses the IETF versions of ChaCha and
-/// Poly1305 because it is defined in RFC 8439, section 2.8, AEAD_CHACHA20_POLY1305
-/// construction.
+/// \details ChaCha20Poly1305 is an authenticated encryption scheme that combines
+/// ChaCha20TLS and Poly1305TLS. The scheme is defined in RFC 8439, section 2.8,
+/// AEAD_CHACHA20_POLY1305 construction, and uses the IETF versions of ChaCha
+/// and Poly1305.
/// \sa RFC 8439, ChaCha20 and Poly1305
/// for IETF Protocols.
/// \since Crypto++ 8.1
@@ -151,10 +152,10 @@ private:
};
/// \brief ChaCha20Poly1305-TLS cipher mode of operation
-/// \details ChaCha20Poly1305 is an authenticated encryption cipher that combines
-/// ChaCha20TLS and Poly1305TLS. The cipher uses the IETF versions of ChaCha and
-/// Poly1305 because it is defined in RFC 8439, section 2.8, AEAD_CHACHA20_POLY1305
-/// construction.
+/// \details ChaCha20Poly1305 is an authenticated encryption scheme that combines
+/// ChaCha20TLS and Poly1305TLS. The scheme is defined in RFC 8439, section 2.8,
+/// AEAD_CHACHA20_POLY1305 construction, and uses the IETF versions of ChaCha
+/// and Poly1305.
/// \sa RFC 8439, ChaCha20 and Poly1305
/// for IETF Protocols.
/// \since Crypto++ 8.1