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