1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 10:52:44 +01:00

sys/crypto/modes/ccm: accept input_len=0

CCM may be used on messages with no plaintext data.
This commit is contained in:
Francisco Molina 2020-04-09 15:57:57 +02:00
parent 3b5067b5d0
commit 8372286591
No known key found for this signature in database
GPG Key ID: 3E94EAC3DBDEEDA8
2 changed files with 13 additions and 4 deletions

View File

@ -43,6 +43,12 @@ static int ccm_compute_cbc_mac(cipher_t *cipher, const uint8_t iv[16],
block_size = cipher_get_block_size(cipher);
memmove(mac, iv, 16);
offset = 0;
/* no input message */
if(length == 0) {
return 0;
}
do {
uint8_t block_size_input = (length - offset > block_size) ?
block_size : length - offset;

View File

@ -57,10 +57,12 @@ extern "C" {
* @param nonce_len Length of the nonce in octets
* (maximum: 15-length_encoding)
* @param input pointer to input data to encrypt
* @param input_len length of the input data, max 2^32
* @param input_len length of the input data, [0, 2^32]
* @param output pointer to allocated memory for encrypted data. It
* has to be of size data_len + mac_length.
* @return Length of encrypted data on a successful encryption
*
* @return Length of encrypted data on a successful encryption,
* can be 0 if input_len=0 (no plaintext)
* @return A negative error code if something went wrong
*/
int cipher_encrypt_ccm(cipher_t *cipher,
@ -85,11 +87,12 @@ int cipher_encrypt_ccm(cipher_t *cipher,
* @param nonce_len Length of the nonce in octets
* (maximum: 15-length_encoding)
* @param input pointer to input data to decrypt
* @param input_len length of the input data, max 2^32
* @param input_len length of the input data, [0, 2^32]
* @param output pointer to allocated memory for decrypted data. It
* has to be of size data_len - mac_length.
*
* @return Length of the decrypted data on a successful decryption
* @return Length of the decrypted data on a successful decryption,
* can be 0 if only auth_data and MAC is present.
* @return A negative error code if something went wrong
*/
int cipher_decrypt_ccm(cipher_t *cipher,