Template Function desfire::kdf_an10922(cmac_keychain const&, crypto&, mlab::bin_data&, std::array<std::uint8_t, NBlocks>)
Defined in File kdf.hpp
Function Documentation
-
template<std::size_t BlockSize, std::size_t NBlocks>
key_body<BlockSize * NBlocks> desfire::kdf_an10922(cmac_keychain const &keychain, crypto &crypto, mlab::bin_data &diversify_input, std::array<std::uint8_t, NBlocks> data_prepend_const) Generalized version of AN10922 key diversification protocol.
The KDF protocol described in AN10922 essentially works always in the same way.
A max of
(2 * block_size - 1)
diversification data is in the input.Prepend a constant to it.
Prepare data according to the CMAC procedure (cmac_keychain::prepare_cmac_data). This consists of padding with
80 00 .. 00
up to2 * block_size
, and XORing the last block with the appropriately derived key.The resulting data is passed through the CMAC in crypto::do_crypto
The last block of encrypted data (which constitutes a CMAC) is used as diversified key.
The procedure above is repeated with different constants for all the blocks that constitute a key, i.e. for three in 3K3DES, two in 2K3DES, one in AES128, and, well, theoretically generalizes to one for DES.
This function abstracts the whole procedure for the given number of blocks and block size. Does not set the version of the key, the caller is responsible for that.
- Template Parameters:
BlockSize – Size of the cipher block in bytes. 8 for DES-derives, 16 for AES128.
NBlocks – Number of blocks constituting a key. 1 for AES128, 1 for DES, 2 for 2K3DES, 3 for 3K3DES.
- Parameters:
keychain – Keychain object holding the subkeys for CMAC operations. Its cmac_keychain::block_size must match the template parameter
BlockSize
.crypto – Cryptographic object on which the CMAC operation will be run.
diversify_input – Diversification input. At most
2 * BlockSize - 1
bytes wil be used. It will be modified by the operation.data_prepend_const – Constants to prepend to each block process. These are specific to AN10922.
- Returns:
A diversified key of length
BlockSize * NBlocks
.