8 #include <botan/cmac.h>
17 const bool top_carry =
static_cast<bool>((in[0] & 0x80) != 0);
22 for(
size_t i = out.size(); i != 0; --i)
24 uint8_t temp = out[i-1];
25 out[i-1] = (temp << 1) | carry;
34 out[out.size()-1] ^= 0x1B;
37 out[out.size()-1] ^= 0x87;
40 out[out.size()-2] ^= 0x4;
41 out[out.size()-1] ^= 0x25;
44 out[out.size()-2] ^= 0x1;
45 out[out.size()-1] ^= 0x25;
58 void CMAC::add_data(
const uint8_t input[],
size_t length)
64 m_cipher->encrypt(m_state);
70 m_cipher->encrypt(m_state);
74 copy_mem(m_buffer.data(), input, length);
83 void CMAC::final_result(uint8_t mac[])
85 xor_buf(m_state, m_buffer, m_position);
93 m_state[m_position] ^= 0x80;
97 m_cipher->encrypt(m_state);
110 void CMAC::key_schedule(
const uint8_t key[],
size_t length)
113 m_cipher->set_key(key, length);
114 m_cipher->encrypt(m_B);
137 return "CMAC(" + m_cipher->name() +
")";
145 return new CMAC(m_cipher->clone());
153 if(m_cipher->block_size() != 8 && m_cipher->block_size() != 16 &&
154 m_cipher->block_size() != 32 && m_cipher->block_size() != 64)
158 " bit cipher " + m_cipher->name());
void xor_buf(T out[], const T in[], size_t length)
std::string name() const override
size_t output_length() const override
std::string to_string(const BER_Object &obj)
std::vector< T, secure_allocator< T >> secure_vector
MessageAuthenticationCode * clone() const override
void copy_mem(T *out, const T *in, size_t n)
static secure_vector< uint8_t > poly_double(const secure_vector< uint8_t > &in)
CMAC(BlockCipher *cipher)
size_t buffer_insert(std::vector< T, Alloc > &buf, size_t buf_offset, const T input[], size_t input_length)
void zeroise(std::vector< T, Alloc > &vec)