Skip to content
Snippets Groups Projects
Unverified Commit c87fe94e authored by Gaëtan Harter's avatar Gaëtan Harter
Browse files

crypto/modes/ccm: update api to const input buffers

Input buffers are not modified, so can be declared const arguments.
parent 9e6782af
No related branches found
No related tags found
No related merge requests found
...@@ -144,10 +144,11 @@ static inline int _fits_in_nbytes(size_t value, uint8_t num_bytes) ...@@ -144,10 +144,11 @@ static inline int _fits_in_nbytes(size_t value, uint8_t num_bytes)
} }
int cipher_encrypt_ccm(cipher_t* cipher, uint8_t* auth_data, uint32_t auth_data_len, int cipher_encrypt_ccm(cipher_t* cipher,
const uint8_t* auth_data, uint32_t auth_data_len,
uint8_t mac_length, uint8_t length_encoding, uint8_t mac_length, uint8_t length_encoding,
uint8_t* nonce, size_t nonce_len, const uint8_t* nonce, size_t nonce_len,
uint8_t* input, size_t input_len, const uint8_t* input, size_t input_len,
uint8_t* output) uint8_t* output)
{ {
int len = -1; int len = -1;
...@@ -207,10 +208,12 @@ int cipher_encrypt_ccm(cipher_t* cipher, uint8_t* auth_data, uint32_t auth_data_ ...@@ -207,10 +208,12 @@ int cipher_encrypt_ccm(cipher_t* cipher, uint8_t* auth_data, uint32_t auth_data_
} }
int cipher_decrypt_ccm(cipher_t* cipher, uint8_t* auth_data, int cipher_decrypt_ccm(cipher_t* cipher,
uint32_t auth_data_len, uint8_t mac_length, const uint8_t* auth_data, uint32_t auth_data_len,
uint8_t length_encoding, uint8_t* nonce, size_t nonce_len, uint8_t mac_length, uint8_t length_encoding,
uint8_t* input, size_t input_len, uint8_t* plain) const uint8_t* nonce, size_t nonce_len,
const uint8_t* input, size_t input_len,
uint8_t* plain)
{ {
int len = -1; int len = -1;
uint8_t nonce_counter[16] = {0}, mac_iv[16] = {0}, mac[16] = {0}, uint8_t nonce_counter[16] = {0}, mac_iv[16] = {0}, mac[16] = {0},
......
...@@ -57,10 +57,12 @@ extern "C" { ...@@ -57,10 +57,12 @@ extern "C" {
* @return Length of encrypted data on a successful encryption * @return Length of encrypted data on a successful encryption
* @return A negative error code if something went wrong * @return A negative error code if something went wrong
*/ */
int cipher_encrypt_ccm(cipher_t* cipher, uint8_t* auth_data, int cipher_encrypt_ccm(cipher_t* cipher,
uint32_t auth_data_len, uint8_t mac_length, const uint8_t* auth_data, uint32_t auth_data_len,
uint8_t length_encoding, uint8_t* nonce, size_t nonce_len, uint8_t mac_length, uint8_t length_encoding,
uint8_t* input, size_t input_len, uint8_t* output); const uint8_t* nonce, size_t nonce_len,
const uint8_t* input, size_t input_len,
uint8_t* output);
/** /**
...@@ -84,10 +86,12 @@ int cipher_encrypt_ccm(cipher_t* cipher, uint8_t* auth_data, ...@@ -84,10 +86,12 @@ int cipher_encrypt_ccm(cipher_t* cipher, uint8_t* auth_data,
* @return Length of the decrypted data on a successful decryption * @return Length of the decrypted data on a successful decryption
* @return A negative error code if something went wrong * @return A negative error code if something went wrong
*/ */
int cipher_decrypt_ccm(cipher_t* cipher, uint8_t* auth_data, int cipher_decrypt_ccm(cipher_t* cipher,
uint32_t auth_data_len, uint8_t mac_length, const uint8_t* auth_data, uint32_t auth_data_len,
uint8_t length_encoding, uint8_t* nonce, size_t nonce_len, uint8_t mac_length, uint8_t length_encoding,
uint8_t* input, size_t input_len, uint8_t* output); const uint8_t* nonce, size_t nonce_len,
const uint8_t* input, size_t input_len,
uint8_t* output);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -190,8 +190,9 @@ static void test_crypto_modes_ccm_decrypt(void) ...@@ -190,8 +190,9 @@ static void test_crypto_modes_ccm_decrypt(void)
} }
typedef int (*func_ccm_t)(cipher_t*, uint8_t*, uint32_t, uint8_t, uint8_t, typedef int (*func_ccm_t)(cipher_t*, const uint8_t*, uint32_t,
uint8_t*, size_t, uint8_t*, size_t, uint8_t*); uint8_t, uint8_t, const uint8_t*, size_t,
const uint8_t*, size_t, uint8_t*);
static int _test_ccm_len(func_ccm_t func, uint8_t len_encoding, static int _test_ccm_len(func_ccm_t func, uint8_t len_encoding,
uint8_t *input, size_t input_len, size_t adata_len) uint8_t *input, size_t input_len, size_t adata_len)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment