Security Scol plugin
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
6NAMESPACE_BEGIN(CryptoPP)
7
8void 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
14void 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
29size_t EAX_Base::AuthenticateBlocks(const byte *data, size_t len)
30{
31 AccessMAC().Update(data, len);
32 return 0;
33}
34
35void 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
49void 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
59NAMESPACE_END
void Update(const byte *input, size_t length)
Updates a hash with additional input.
Definition cmac.cpp:94
void SetCipherWithIV(BlockCipher &cipher, const byte *iv, int feedbackSize=0)
Set external block cipher and IV.
Definition modes.h:117
virtual void TruncatedFinal(byte *digest, size_t digestSize)=0
Computes the hash of the current message.
virtual void Final(byte *digest)
Computes the hash of the current message.
Definition cryptlib.h:1142
virtual void Update(const byte *input, size_t length)=0
Updates a hash with additional input.
unsigned int TagSize() const
Definition cryptlib.h:1157
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
Interface for message authentication codes.
Definition cryptlib.h:1299
Interface for retrieving values given their names.
Definition cryptlib.h:322
void New(size_type newSize)
Change size without preserving contents.
Definition secblock.h:1126
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
EAX block cipher mode of operation.
Precompiled header file.