9 #if CRYPTOPP_MSC_VERSION 10 # pragma warning(disable: 4244) 23 void ChaCha20Poly1305_Base::RekeyCipherAndMac(
const byte *userKey,
size_t keylength,
const NameValuePairs ¶ms)
31 AccessSymmetricCipher().ProcessString(derived, derived.size());
34 AccessMAC().
SetKey(derived, derived.size(), params);
41 void ChaCha20Poly1305_Base::SetKeyWithoutResync(
const byte *userKey,
size_t userKeyLength,
const NameValuePairs ¶ms)
44 m_userKey.
Assign(userKey, userKeyLength);
55 CRYPTOPP_UNUSED(params);
58 void ChaCha20Poly1305_Base::Resync(
const byte *iv,
size_t len)
61 RekeyCipherAndMac(m_userKey, m_userKey.
SizeInBytes(),
65 size_t ChaCha20Poly1305_Base::AuthenticateBlocks(
const byte *data,
size_t len)
67 AccessMAC().
Update(data, len);
71 void ChaCha20Poly1305_Base::AuthenticateLastHeaderBlock()
74 const byte zero[16] = {0};
75 size_t pad = (16U - (m_totalHeaderLength % 16)) % 16;
76 AccessMAC().
Update(zero, pad);
79 void ChaCha20Poly1305_Base::AuthenticateLastConfidentialBlock()
82 const byte zero[16] = {0};
83 size_t pad = (16U - (m_totalMessageLength % 16)) % 16;
84 AccessMAC().
Update(zero, pad);
87 void ChaCha20Poly1305_Base::AuthenticateLastFooterBlock(byte *mac,
size_t macSize)
89 CRYPTOPP_ALIGN_DATA(8) byte length[2*sizeof(word64)];
91 PutWord(true, LITTLE_ENDIAN_ORDER, length+8, m_totalMessageLength);
92 AccessMAC().
Update(length, sizeof(length));
94 m_state = State_KeySet;
105 bool ChaCha20Poly1305_Base::DecryptAndVerify(byte *message,
const byte *mac,
size_t macLength,
const byte *iv,
int ivLength,
const byte *aad,
size_t aadLength,
const byte *ciphertext,
size_t ciphertextLength)
121 void XChaCha20Poly1305_Base::RekeyCipherAndMac(
const byte *userKey,
size_t keylength,
const NameValuePairs ¶ms)
129 AccessSymmetricCipher().ProcessString(derived, derived.
size());
132 AccessMAC().
SetKey(derived, derived.
size(), params);
139 void XChaCha20Poly1305_Base::SetKeyWithoutResync(
const byte *userKey,
size_t userKeyLength,
const NameValuePairs ¶ms)
142 m_userKey.
Assign(userKey, userKeyLength);
153 CRYPTOPP_UNUSED(params);
156 void XChaCha20Poly1305_Base::Resync(
const byte *iv,
size_t len)
159 RekeyCipherAndMac(m_userKey, m_userKey.
SizeInBytes(),
163 size_t XChaCha20Poly1305_Base::AuthenticateBlocks(
const byte *data,
size_t len)
165 AccessMAC().
Update(data, len);
169 void XChaCha20Poly1305_Base::AuthenticateLastHeaderBlock()
172 const byte zero[16] = {0};
173 size_t pad = (16 - (m_totalHeaderLength % 16)) % 16;
174 AccessMAC().
Update(zero, pad);
177 void XChaCha20Poly1305_Base::AuthenticateLastConfidentialBlock()
180 const byte zero[16] = {0};
181 size_t pad = (16 - (m_totalMessageLength % 16)) % 16;
182 AccessMAC().
Update(zero, pad);
185 void XChaCha20Poly1305_Base::AuthenticateLastFooterBlock(byte *mac,
size_t macSize)
187 CRYPTOPP_ALIGN_DATA(8) byte length[2*
sizeof(word64)];
190 AccessMAC().
Update(length,
sizeof(length));
192 m_state = State_KeySet;
Used to pass byte array input as part of a NameValuePairs object.
Classes for working with NameValuePairs.
ChaCha20/Poly1305-TLS AEAD scheme.
Utility functions for the Crypto++ library.
virtual void SetKey(const byte *key, size_t length, const NameValuePairs ¶ms=g_nullNameValuePairs)
Sets or reset the key of this object.
virtual void EncryptAndAuthenticate(byte *ciphertext, byte *mac, size_t macSize, const byte *iv, int ivLength, const byte *aad, size_t aadLength, const byte *message, size_t messageLength)
Encrypts and calculates a MAC in one call.
size_type SizeInBytes() const
Provides the number of bytes in the SecBlock.
void PutWord(bool assumeAligned, ByteOrder order, byte *block, T value, const byte *xorBlock=NULL)
Access a block of memory.
void Resynchronize(const byte *iv, int length=-1)
Resynchronize with an IV.
virtual bool DecryptAndVerify(byte *message, const byte *mac, size_t macSize, const byte *iv, int ivLength, const byte *aad, size_t aadLength, const byte *ciphertext, size_t ciphertextLength)
Decrypts and verifies a MAC in one call.
virtual bool DecryptAndVerify(byte *message, const byte *mac, size_t macSize, const byte *iv, int ivLength, const byte *aad, size_t aadLength, const byte *ciphertext, size_t ciphertextLength)
Decrypts and verifies a MAC in one call.
Combines two sets of NameValuePairs.
byte order is little-endian
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
void Assign(const T *ptr, size_type len)
Set contents and size from an array.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
const char * IV()
ConstByteArrayParameter, also accepts const byte * for backwards compatibility.
void Update(const byte *input, size_t length)
Updates a hash with additional input.
An object that implements NameValuePairs.
ChaCha20Poly1305 cipher base implementation.
Crypto++ library namespace.
void TruncatedFinal(byte *mac, size_t macSize)
Computes the hash of the current message.
size_type size() const
Provides the count of elements in the SecBlock.
virtual void EncryptAndAuthenticate(byte *ciphertext, byte *mac, size_t macSize, const byte *iv, int ivLength, const byte *aad, size_t aadLength, const byte *message, size_t messageLength)
Encrypts and calculates a MAC in one call.
Interface for retrieving values given their names.