Crypto++ 8.1 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
HashTransformation::TagSize
unsigned int TagSize() const
Provides the tag size of the hash.
Definition: cryptlib.h:1129
MessageAuthenticationCode
Interface for message authentication codes.
Definition: cryptlib.h:1266
SimpleKeyingInterface::SetKey
virtual void SetKey(const byte *key, size_t length, const NameValuePairs &params=g_nullNameValuePairs)
Sets or reset the key of this object.
Definition: cryptlib.cpp:58
CipherModeBase::SetCipherWithIV
void SetCipherWithIV(BlockCipher &cipher, const byte *iv, int feedbackSize=0)
Set external block cipher and IV.
Definition: modes.h:117
HashTransformation::TruncatedFinal
virtual void TruncatedFinal(byte *digest, size_t digestSize)=0
Computes the hash of the current message.
pch.h
Precompiled header file.
CRYPTOPP_ASSERT
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
Definition: trap.h:69
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:1160
xorbuf
void xorbuf(byte *buf, const byte *mask, size_t count)
Performs an XOR of a buffer with a mask.
Definition: misc.cpp:32
eax.h
EAX block cipher mode of operation.
CryptoPP
Crypto++ library namespace.
HashTransformation::Final
virtual void Final(byte *digest)
Computes the hash of the current message.
Definition: cryptlib.h:1114
CMAC_Base::Update
void Update(const byte *input, size_t length)
Updates a hash with additional input.
Definition: cmac.cpp:73
HashTransformation::Update
virtual void Update(const byte *input, size_t length)=0
Updates a hash with additional input.
NameValuePairs
Interface for retrieving values given their names.
Definition: cryptlib.h:293