Crypto++ 8.5 Free C++ class library of cryptographic schemes

eax.cpp
1 // eax.cpp - originally written and placed in the public domain by Wei Dai
2
3 #include "pch.h"
4 #include "eax.h"
5
6 NAMESPACE_BEGIN(CryptoPP)
7
8 void EAX_Base::SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs &params)
9 {
10 AccessMAC().SetKey(userKey, keylength, params);
11 m_buffer.New(2*AccessMAC().TagSize());
12 }
13
14 void EAX_Base::Resync(const byte *iv, size_t len)
15 {
16 MessageAuthenticationCode &mac = AccessMAC();
17 unsigned int blockSize = mac.TagSize();
18
19 memset(m_buffer, 0, blockSize);
20 mac.Update(m_buffer, blockSize);
21 mac.CalculateDigest(m_buffer+blockSize, iv, len);
22
23 m_buffer[blockSize-1] = 1;
24 mac.Update(m_buffer, blockSize);
25
26 m_ctr.SetCipherWithIV(AccessMAC().AccessCipher(), m_buffer+blockSize, blockSize);
27 }
28
29 size_t EAX_Base::AuthenticateBlocks(const byte *data, size_t len)
30 {
31 AccessMAC().Update(data, len);
32 return 0;
33 }
34
35 void EAX_Base::AuthenticateLastHeaderBlock()
36 {
37 CRYPTOPP_ASSERT(m_bufferedDataLength == 0);
38 MessageAuthenticationCode &mac = AccessMAC();
39 const unsigned int blockSize = mac.TagSize();
40
41 mac.Final(m_buffer);
42 xorbuf(m_buffer+blockSize, m_buffer, blockSize);
43
44 memset(m_buffer, 0, blockSize);
45 m_buffer[blockSize-1] = 2;
46 mac.Update(m_buffer, blockSize);
47 }
48
49 void EAX_Base::AuthenticateLastFooterBlock(byte *tag, size_t macSize)
50 {
51 CRYPTOPP_ASSERT(m_bufferedDataLength == 0);
52 MessageAuthenticationCode &mac = AccessMAC();
53 unsigned int blockSize = mac.TagSize();
54
55 mac.TruncatedFinal(m_buffer, macSize);
56 xorbuf(tag, m_buffer, m_buffer+blockSize, macSize);
57 }
58
59 NAMESPACE_END
SimpleKeyingInterface::SetKey
virtual void SetKey(const byte *key, size_t length, const NameValuePairs &params=g_nullNameValuePairs)
Sets or reset the key of this object.
CMAC_Base::Update
void Update(const byte *input, size_t length)
Updates a hash with additional input.
HashTransformation::TruncatedFinal
virtual void TruncatedFinal(byte *digest, size_t digestSize)=0
Computes the hash of the current message.
HashTransformation::CalculateDigest
virtual void CalculateDigest(byte *digest, const byte *input, size_t length)
Updates the hash with additional input and computes the hash of the current message.
Definition: cryptlib.h:1188
CRYPTOPP_ASSERT
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
Definition: trap.h:68
CipherModeBase::SetCipherWithIV
void SetCipherWithIV(BlockCipher &cipher, const byte *iv, int feedbackSize=0)
Set external block cipher and IV.
Definition: modes.h:117
pch.h
Precompiled header file.
HashTransformation::TagSize
unsigned int TagSize() const
Provides the tag size of the hash.
Definition: cryptlib.h:1157
eax.h
EAX block cipher mode of operation.
CryptoPP
Crypto++ library namespace.
xorbuf
CRYPTOPP_DLL void xorbuf(byte *buf, const byte *mask, size_t count)
Performs an XOR of a buffer with a mask.
MessageAuthenticationCode
Interface for message authentication codes.
Definition: cryptlib.h:1298
NameValuePairs
Interface for retrieving values given their names.
Definition: cryptlib.h:321
HashTransformation::Update
virtual void Update(const byte *input, size_t length)=0
Updates a hash with additional input.
HashTransformation::Final
virtual void Final(byte *digest)
Computes the hash of the current message.
Definition: cryptlib.h:1142