mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/crypto: Check block size for CCM operations
This commit is contained in:
parent
238ebe3d37
commit
3382a089a8
@ -169,6 +169,7 @@ int cipher_encrypt_ccm(cipher_t *cipher,
|
||||
|
||||
/* Create B0, encrypt it (X1) and use it as mac_iv */
|
||||
block_size = cipher_get_block_size(cipher);
|
||||
assert(block_size == CCM_BLOCK_SIZE);
|
||||
if (ccm_create_mac_iv(cipher, auth_data_len, mac_length, length_encoding,
|
||||
nonce, nonce_len, input_len, mac_iv) < 0) {
|
||||
return CCM_ERR_INVALID_DATA_LENGTH;
|
||||
@ -236,6 +237,7 @@ int cipher_decrypt_ccm(cipher_t *cipher,
|
||||
/* Compute first stream block */
|
||||
nonce_counter[0] = length_encoding - 1;
|
||||
block_size = cipher_get_block_size(cipher);
|
||||
assert(block_size == CCM_BLOCK_SIZE);
|
||||
memcpy(&nonce_counter[1], nonce, min(nonce_len,
|
||||
(size_t)15 - length_encoding));
|
||||
len = cipher_encrypt_ctr(cipher, nonce_counter, block_size, zero_block,
|
||||
|
@ -37,6 +37,12 @@ extern "C" {
|
||||
#define CCM_ERR_INVALID_MAC_LENGTH (-5)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @brief Block size required for the cipher. CCM is only defined for 128 bit ciphers.
|
||||
*/
|
||||
#define CCM_BLOCK_SIZE 16
|
||||
|
||||
|
||||
/**
|
||||
* @brief Encrypt and authenticate data of arbitrary length in ccm mode.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user