Fabcoin Core  0.16.2
P2P Digital Currency
eax.cpp
Go to the documentation of this file.
1 // eax.cpp - written and placed in the public domain by Wei Dai
2 
3 #include "pch.h"
4 #include "eax.h"
5 
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 {
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 
36 {
39  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 {
53  unsigned int blockSize = mac.TagSize();
54 
55  mac.TruncatedFinal(m_buffer, macSize);
56  xorbuf(tag, m_buffer, m_buffer+blockSize, macSize);
57 }
58 
Interface for message authentication codes.
Definition: cryptlib.h:1111
uint8_t byte
Definition: Common.h:57
void SetCipherWithIV(BlockCipher &cipher, const byte *iv, int feedbackSize=0)
Definition: modes.h:65
virtual void TruncatedFinal(byte *digest, size_t digestSize)=0
Computes the hash of the current message.
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
AlignedSecByteBlock m_buffer
Definition: authenc.h:61
unsigned int TagSize() const
Provides the tag size of the hash.
Definition: cryptlib.h:975
EAX block cipher base implementation.
Definition: eax.h:19
size_t AuthenticateBlocks(const byte *data, size_t len)
Definition: eax.cpp:29
unsigned int m_bufferedDataLength
Definition: authenc.h:59
void SetKey(const byte *userKey, size_t keylength, const NameValuePairs &params)
Sets or reset the key of this object.
Definition: authenc.cpp:48
void Resync(const byte *iv, size_t len)
Definition: eax.cpp:14
#define CRYPTOPP_ASSERT(exp)
Definition: trap.h:92
void xorbuf(byte *buf, const byte *mask, size_t count)
Performs an XOR of a buffer with a mask.
Definition: misc.cpp:28
virtual CMAC_Base & AccessMAC()=0
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:1003
EAX block cipher mode of operation.
CTR_Mode_ExternalCipher::Encryption m_ctr
Definition: eax.h:67
#define NAMESPACE_END
Definition: config.h:201
virtual void Final(byte *digest)
Computes the hash of the current message.
Definition: cryptlib.h:960
void AuthenticateLastHeaderBlock()
Definition: eax.cpp:35
uint8_t const * data
Definition: sha3.h:19
void Update(const byte *input, size_t length)
Updates a hash with additional input.
Definition: cmac.cpp:58
virtual void Update(const byte *input, size_t length)=0
Updates a hash with additional input.
void AuthenticateLastFooterBlock(byte *mac, size_t macSize)
Definition: eax.cpp:49
Interface for retrieving values given their names.
Definition: cryptlib.h:279