1/* 2 * File: RijndaelCBCMAC.h 3 * 4 * Copyright (c) Freescale Semiconductor, Inc. All rights reserved. 5 * See included license file for license details. 6 */ 7#if !defined(_RijndaelCBCMAC_h_) 8#define _RijndaelCBCMAC_h_ 9 10#include "AESKey.h" 11#include <string.h> 12 13/*! 14 * \brief Class to compute CBC-MAC using the AES/Rijndael cipher. 15 * 16 * Currently only supports 128-bit keys and block sizes. 17 */ 18class RijndaelCBCMAC 19{ 20public: 21 enum 22 { 23 BLOCK_SIZE = 16 //!< Number of bytes in one cipher block. 24 }; 25 26 //! The cipher block data type. 27 typedef uint8_t block_t[BLOCK_SIZE]; 28 29public: 30 //! \brief Default constructor. 31 //! 32 //! The key and IV are both set to zero. 33 RijndaelCBCMAC() {} 34 35 //! \brief Constructor. 36 RijndaelCBCMAC(const AESKey<128> & key, const uint8_t * iv=0); 37 38 //! \brief Process data. 39 void update(const uint8_t * data, unsigned length); 40 41 //! \brief Signal that all data has been processed. 42 void finalize(); 43 44 //! \brief Returns a reference to the current MAC value. 45 const block_t & getMAC() const { return m_mac; } 46 47 //! \brief Assignment operator. 48 RijndaelCBCMAC & operator = (const RijndaelCBCMAC & other) 49 { 50 m_key = other.m_key; 51 memcpy(m_mac, other.m_mac, sizeof(m_mac)); 52 return *this; 53 } 54 55protected: 56 AESKey<128> m_key; //!< 128-bit key to use for the CBC-MAC. 57 block_t m_mac; //!< Current message authentication code value. 58 59 void updateOneBlock(const uint8_t * data); 60}; 61 62#endif // _RijndaelCBCMAC_h_ 63