Fabcoin Core  0.16.2
P2P Digital Currency
cbcmac.cpp
Go to the documentation of this file.
1 #include "pch.h"
2 
3 #ifndef CRYPTOPP_IMPORTS
4 
5 #include "cbcmac.h"
6 
8 
9 void CBC_MAC_Base::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params)
10 {
11  AccessCipher().SetKey(key, length, params);
12  m_reg.CleanNew(AccessCipher().BlockSize());
13  m_counter = 0;
14 }
15 
16 void CBC_MAC_Base::Update(const byte *input, size_t length)
17 {
18  unsigned int blockSize = AccessCipher().BlockSize();
19 
20  while (m_counter && length)
21  {
22  m_reg[m_counter++] ^= *input++;
23  if (m_counter == blockSize)
24  ProcessBuf();
25  length--;
26  }
27 
28  if (length >= blockSize)
29  {
31  input += (length - leftOver);
32  length = leftOver;
33  }
34 
35  while (length--)
36  {
37  m_reg[m_counter++] ^= *input++;
38  if (m_counter == blockSize)
39  ProcessBuf();
40  }
41 }
42 
44 {
46 
47  if (m_counter)
48  ProcessBuf();
49 
50  memcpy(mac, m_reg, size);
51  memset(m_reg, 0, AccessCipher().BlockSize());
52 }
53 
55 {
57  m_counter = 0;
58 }
59 
61 
62 #endif
void ProcessBuf()
Definition: cbcmac.cpp:54
uint8_t byte
Definition: Common.h:57
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:97
SecByteBlock m_reg
Definition: cbcmac.h:31
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
should not modify block pointers
Definition: cryptlib.h:796
virtual size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const
Encrypt and xor multiple blocks using additional flags.
Definition: cryptlib.cpp:178
Classes for CBC MAC.
void TruncatedFinal(byte *mac, size_t size)
Computes the hash of the current message.
Definition: cbcmac.cpp:43
void ThrowIfInvalidTruncatedSize(size_t size) const
Validates a truncated digest size.
Definition: cryptlib.cpp:416
virtual unsigned int BlockSize() const =0
Provides the block size of the cipher.
void ProcessBlock(const byte *inBlock, byte *outBlock) const
Encrypt or decrypt a block.
Definition: cryptlib.h:758
virtual BlockCipher & AccessCipher()=0
virtual unsigned int BlockSize() const
Provides the block size of the compression function.
Definition: cryptlib.h:981
unsigned int m_counter
Definition: cbcmac.h:32
void Update(const byte *input, size_t length)
Updates a hash with additional input.
Definition: cbcmac.cpp:16
uint8_t const size_t const size
Definition: sha3.h:20
void * memcpy(void *a, const void *b, size_t c)
#define NAMESPACE_END
Definition: config.h:201
Interface for retrieving values given their names.
Definition: cryptlib.h:279