Class desfire::cmac_provider
Defined in File cmac_provider.hpp
Class Documentation
-
class cmac_provider
Class tasked with computing CMACs using a crypto implementation.
CMAC codes are actually used only for more modern ciphers, like 3DES and AES128, but in principle can be computed on any crypto implementation. This is used internally by crypto_aes_base and crypto_3k3des_base.
See also
Public Functions
-
inline cmac_provider(std::size_t block_size, std::uint8_t last_byte_xor)
Initialize a new CMAC provider.
You must call initialize_subkeys before compute_cmac can be used.
See also
- Parameters:
block_size – Size of the block used in the crypto object (8 bytes for 3K3DES, 16 for AES128).
last_byte_xor – Used in subkey generation, this is specific to the Desfire implementation. Refer to cmac_keychain::prepare_subkey for more details; the values used are cmac_keychain::xor_byte_3k3des for 3K3DES, and cmac_keychain::xor_byte_aes for AES128.
-
inline cmac_keychain const &keychain() const
Returns the keychain that holds the keys used for computing a CMAC.
See also
-
void initialize_subkeys(crypto &crypto)
Computes the subkeys that will be used for compute_cmac.
You must call this method before using compute_cmac, otherwise the subkeys used in the CMAC will be zero-initialized and this will not only compute an incorrect CMAC, but it will also mangle the initialization vector, invalidating the whole session.
This method is identical to cmac_keychain::initialize_subkeys.
See also
-
mac_t compute_cmac(crypto &crypto, range<std::uint8_t*> iv, range<std::uint8_t const*> data)
Compute a CMAC on the given range of data.
Make sure that the subkeys are initialized with initialize_subkeys before calling. This method performs the following operations:
Pads
data
with80 00 .. 00
.XORs the last block with the appropriate key, depending on whether it was padded or not.
Calls crypto::do_crypto with crypto_operation::mac on the resulting data together with
iv
.The first 8 bytes of the resulting
iv
are the CMAC that is returned.
- Parameters:
crypto – Cryptographic implementation to use for deriving the keys. Make sure that the block size matches to what used in the constructor (i.e. cmac_keychain::block_size).
iv – Initialization vector to use. This method passes the initialization vector to the method crypto::do_crypto, therefore upon exit it is modified accordingly (and should contain the resulting initialization vector state after the cryptographic operation).
data – Data to compute the CMAC on.
- Returns:
A 8-byte message authentication code.
-
inline cmac_provider(std::size_t block_size, std::uint8_t last_byte_xor)