5#ifndef CRYPTOPP_IMPORTS
11void CCM_Base::SetKeyWithoutResync(
const byte *userKey,
size_t keylength,
const NameValuePairs ¶ms)
14 blockCipher.
SetKey(userKey, keylength, params);
16 if (blockCipher.
BlockSize() != REQUIRED_BLOCKSIZE)
20 if (m_digestSize % 2 > 0 || m_digestSize < 4 || m_digestSize > 16)
23 m_buffer.Grow(2*REQUIRED_BLOCKSIZE);
27void CCM_Base::Resync(
const byte *iv,
size_t len)
31 m_L = REQUIRED_BLOCKSIZE-1-(int)len;
36 m_buffer[0] =
byte(m_L-1);
37 std::memcpy(m_buffer+1, iv, len);
38 std::memset(m_buffer+1+len, 0, REQUIRED_BLOCKSIZE-1-len);
40 if (m_state >= State_IVSet)
45 m_ctr.
Seek(REQUIRED_BLOCKSIZE);
50void CCM_Base::UncheckedSpecifyDataLengths(
lword headerLength,
lword messageLength,
lword )
52 if (m_state != State_IVSet)
53 throw BadState(
AlgorithmName(),
"SpecifyDataLengths",
"or after State_IVSet");
55 m_aadLength = headerLength;
56 m_messageLength = messageLength;
58 byte *cbcBuffer = CBC_Buffer();
61 cbcBuffer[0] =
byte(64*(headerLength>0) + 8*((m_digestSize-2)/2) + (m_L-1));
62 PutWord<word64>(
true,
BIG_ENDIAN_ORDER, cbcBuffer+REQUIRED_BLOCKSIZE-8, m_messageLength);
63 std::memcpy(cbcBuffer+1, m_buffer+1, REQUIRED_BLOCKSIZE-1-m_L);
70 if (headerLength < ((1<<16) - (1<<8)))
73 m_bufferedDataLength = 2;
75 else if (headerLength < (
W64LIT(1)<<32))
80 m_bufferedDataLength = 6;
87 m_bufferedDataLength = 10;
92size_t CCM_Base::AuthenticateBlocks(
const byte *data,
size_t len)
94 byte *cbcBuffer = CBC_Buffer();
99void CCM_Base::AuthenticateLastHeaderBlock()
101 byte *cbcBuffer = CBC_Buffer();
104 if (m_aadLength != m_totalHeaderLength)
107 if (m_bufferedDataLength > 0)
109 xorbuf(cbcBuffer, m_buffer, m_bufferedDataLength);
111 m_bufferedDataLength = 0;
115void CCM_Base::AuthenticateLastConfidentialBlock()
117 byte *cbcBuffer = CBC_Buffer();
120 if (m_messageLength != m_totalMessageLength)
123 if (m_bufferedDataLength > 0)
125 xorbuf(cbcBuffer, m_buffer, m_bufferedDataLength);
127 m_bufferedDataLength = 0;
131void CCM_Base::AuthenticateLastFooterBlock(
byte *mac,
size_t macSize)
CCM block cipher mode of operation.
void ProcessData(byte *outString, const byte *inString, size_t length)
Apply keystream to data.
void Seek(lword position)
Seeks to a random position in the stream.
void Resynchronize(const byte *iv, int length=-1)
Resynchronize the cipher.
Interface for one direction (encryption or decryption) of a block cipher.
std::string AlgorithmName() const
Provides the name of this algorithm.
void SetCipherWithIV(BlockCipher &cipher, const byte *iv, int feedbackSize=0)
Set external block cipher and IV.
An invalid argument was detected.
Interface for retrieving values given their names.
CRYPTOPP_DLL int GetIntValueWithDefault(const char *name, int defaultValue) const
Get a named value with type int, with default.
virtual void SetKey(const byte *key, size_t length, const NameValuePairs ¶ms=g_nullNameValuePairs)
Sets or reset the key of this object.
unsigned char byte
8-bit unsigned datatype
#define W64LIT(x)
Declare an unsigned word64.
unsigned int word32
32-bit unsigned datatype
unsigned short word16
16-bit unsigned datatype
word64 lword
Large word type.
@ BIG_ENDIAN_ORDER
byte order is big-endian
CRYPTOPP_DLL void xorbuf(byte *buf, const byte *mask, size_t count)
Performs an XOR of a buffer with a mask.
Crypto++ library namespace.
const char * DigestSize()
int, in bytes
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.