Update documentation

pull/795/head
Jeffrey Walton 2019-01-28 22:42:34 -05:00
parent 281831c08a
commit a4f6da8d30
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
2 changed files with 18 additions and 22 deletions

View File

@ -14,14 +14,14 @@ void ChaCha20Poly1305_Base::RekeyCipherAndMac(const byte *userKey, size_t keylen
AlgorithmParameters block0 = MakeParameters("InitialBlock", (word64)0, true); AlgorithmParameters block0 = MakeParameters("InitialBlock", (word64)0, true);
AccessSymmetricCipher().SetKey(userKey, keylength, CombinedNameValuePairs(params, block0)); 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); SecByteBlock derived(NULLPTR, 32);
AccessSymmetricCipher().ProcessString(derived, derived.size()); AccessSymmetricCipher().ProcessString(derived, derived.size());
// Set the Poly1305 key // Key the Poly1305 MAC
AccessMAC().SetKey(derived, derived.size(), params); AccessMAC().SetKey(derived, derived.size(), params);
// Key Cipher for bulk encryption // Key the ChaCha20 cipher
AlgorithmParameters block1 = MakeParameters("InitialBlock", (word64)1, true); AlgorithmParameters block1 = MakeParameters("InitialBlock", (word64)1, true);
AccessSymmetricCipher().SetKey(userKey, keylength, CombinedNameValuePairs(params, block1)); 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); CRYPTOPP_ASSERT(userKey && userKeyLength == 32);
m_userKey.Assign(userKey, userKeyLength); m_userKey.Assign(userKey, userKeyLength);
RekeyCipherAndMac(userKey, userKeyLength, params); RekeyCipherAndMac(userKey, userKeyLength, params);
} }
void ChaCha20Poly1305_Base::Resync(const byte *iv, size_t len) void ChaCha20Poly1305_Base::Resync(const byte *iv, size_t len)
{ {
CRYPTOPP_ASSERT(iv && len == 12); CRYPTOPP_ASSERT(iv && len == 12);
RekeyCipherAndMac(m_userKey, m_userKey.SizeInBytes(), RekeyCipherAndMac(m_userKey, m_userKey.SizeInBytes(),
MakeParameters(Name::IV(), ConstByteArrayParameter(iv,len))); MakeParameters(Name::IV(), ConstByteArrayParameter(iv,len)));
} }
@ -52,8 +50,7 @@ void ChaCha20Poly1305_Base::AuthenticateLastHeaderBlock()
{ {
// Pad to a multiple of 16 or 0 // Pad to a multiple of 16 or 0
const byte zero[16] = {0}; const byte zero[16] = {0};
size_t rem = m_totalHeaderLength % 16; size_t pad = (16 - (m_totalHeaderLength % 16)) % 16;
size_t pad = rem ? 16 - rem : 0;
AccessMAC().Update(zero, pad); AccessMAC().Update(zero, pad);
} }
@ -61,8 +58,7 @@ void ChaCha20Poly1305_Base::AuthenticateLastConfidentialBlock()
{ {
// Pad to a multiple of 16 or 0 // Pad to a multiple of 16 or 0
const byte zero[16] = {0}; const byte zero[16] = {0};
size_t rem = m_totalMessageLength % 16; size_t pad = (16 - (m_totalMessageLength % 16)) % 16;
size_t pad = rem ? 16 - rem : 0;
AccessMAC().Update(zero, pad); 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+0, m_totalHeaderLength);
PutWord(true, LITTLE_ENDIAN_ORDER, length+8, m_totalMessageLength); PutWord(true, LITTLE_ENDIAN_ORDER, length+8, m_totalMessageLength);
AccessMAC().Update(length, sizeof(length)); AccessMAC().Update(length, sizeof(length));
AccessMAC().TruncatedFinal(mac, macSize); AccessMAC().TruncatedFinal(mac, macSize);
} }

View File

@ -3,12 +3,13 @@
/// \file chachapoly.h /// \file chachapoly.h
/// \brief ChaCha20/Poly1305-TLS AEAD cipher /// \brief ChaCha20/Poly1305-TLS AEAD cipher
/// \details ChaCha20Poly1305 is an authenticated encryption cipher that combines /// \details ChaCha20Poly1305 is an authenticated encryption scheme that combines
/// ChaCha20TLS and Poly1305TLS. The cipher uses the IETF versions of ChaCha and /// ChaCha20TLS and Poly1305TLS. The scheme is defined in RFC 8439, section 2.8,
/// Poly1305 because it is defined in RFC 8439, section 2.8, AEAD_CHACHA20_POLY1305 /// AEAD_CHACHA20_POLY1305 construction, and uses the IETF versions of ChaCha
/// construction. /// and Poly1305.
/// \sa <A HREF="http://tools.ietf.org/html/rfc8439">RFC 8439, ChaCha20 and Poly1305 /// \sa <A HREF="http://tools.ietf.org/html/rfc8439">RFC 8439, ChaCha20 and Poly1305
/// for IETF Protocols</A>. /// for IETF Protocols</A>.
/// \since Crypto++ 8.1
#ifndef CRYPTOPP_CHACHA_POLY1305_H #ifndef CRYPTOPP_CHACHA_POLY1305_H
#define CRYPTOPP_CHACHA_POLY1305_H #define CRYPTOPP_CHACHA_POLY1305_H
@ -119,10 +120,10 @@ protected:
}; };
/// \brief ChaCha20Poly1305 cipher final implementation /// \brief ChaCha20Poly1305 cipher final implementation
/// \details ChaCha20Poly1305 is an authenticated encryption cipher that combines /// \details ChaCha20Poly1305 is an authenticated encryption scheme that combines
/// ChaCha20TLS and Poly1305TLS. The cipher uses the IETF versions of ChaCha and /// ChaCha20TLS and Poly1305TLS. The scheme is defined in RFC 8439, section 2.8,
/// Poly1305 because it is defined in RFC 8439, section 2.8, AEAD_CHACHA20_POLY1305 /// AEAD_CHACHA20_POLY1305 construction, and uses the IETF versions of ChaCha
/// construction. /// and Poly1305.
/// \sa <A HREF="http://tools.ietf.org/html/rfc8439">RFC 8439, ChaCha20 and Poly1305 /// \sa <A HREF="http://tools.ietf.org/html/rfc8439">RFC 8439, ChaCha20 and Poly1305
/// for IETF Protocols</A>. /// for IETF Protocols</A>.
/// \since Crypto++ 8.1 /// \since Crypto++ 8.1
@ -151,10 +152,10 @@ private:
}; };
/// \brief ChaCha20Poly1305-TLS cipher mode of operation /// \brief ChaCha20Poly1305-TLS cipher mode of operation
/// \details ChaCha20Poly1305 is an authenticated encryption cipher that combines /// \details ChaCha20Poly1305 is an authenticated encryption scheme that combines
/// ChaCha20TLS and Poly1305TLS. The cipher uses the IETF versions of ChaCha and /// ChaCha20TLS and Poly1305TLS. The scheme is defined in RFC 8439, section 2.8,
/// Poly1305 because it is defined in RFC 8439, section 2.8, AEAD_CHACHA20_POLY1305 /// AEAD_CHACHA20_POLY1305 construction, and uses the IETF versions of ChaCha
/// construction. /// and Poly1305.
/// \sa <A HREF="http://tools.ietf.org/html/rfc8439">RFC 8439, ChaCha20 and Poly1305 /// \sa <A HREF="http://tools.ietf.org/html/rfc8439">RFC 8439, ChaCha20 and Poly1305
/// for IETF Protocols</A>. /// for IETF Protocols</A>.
/// \since Crypto++ 8.1 /// \since Crypto++ 8.1