summaryrefslogtreecommitdiff
path: root/chachapoly.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2019-01-28 22:42:34 -0500
committerJeffrey Walton <noloader@gmail.com>2019-01-28 22:42:34 -0500
commita4f6da8d304401c209a0e2ea89ef5377707d0b22 (patch)
tree52e3ac6c322f3d8a02e25e5744f676a52dcaca2d /chachapoly.cpp
parent281831c08a4af049f1de649d6561f4213b050c0a (diff)
downloadcryptopp-git-a4f6da8d304401c209a0e2ea89ef5377707d0b22.tar.gz
Update documentation
Diffstat (limited to 'chachapoly.cpp')
-rw-r--r--chachapoly.cpp15
1 files changed, 5 insertions, 10 deletions
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);
}