From c87fe94ec10f684dedafa76703a28408dcdccece Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= <gaetan.harter@fu-berlin.de>
Date: Mon, 12 Nov 2018 18:33:02 +0100
Subject: [PATCH] crypto/modes/ccm: update api to const input buffers

Input buffers are not modified, so can be declared const arguments.
---
 sys/crypto/modes/ccm.c                        | 17 +++++++++-------
 sys/include/crypto/modes/ccm.h                | 20 +++++++++++--------
 .../tests-crypto/tests-crypto-modes-ccm.c     |  5 +++--
 3 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/sys/crypto/modes/ccm.c b/sys/crypto/modes/ccm.c
index c8818213ca..50ad97008e 100644
--- a/sys/crypto/modes/ccm.c
+++ b/sys/crypto/modes/ccm.c
@@ -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* nonce, size_t nonce_len,
-                       uint8_t* input, size_t input_len,
+                       const uint8_t* nonce, size_t nonce_len,
+                       const uint8_t* input, size_t input_len,
                        uint8_t* output)
 {
     int len = -1;
@@ -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,
-                       uint32_t auth_data_len, uint8_t mac_length,
-                       uint8_t length_encoding, uint8_t* nonce, size_t nonce_len,
-                       uint8_t* input, size_t input_len, uint8_t* plain)
+int cipher_decrypt_ccm(cipher_t* cipher,
+                       const uint8_t* auth_data, uint32_t auth_data_len,
+                       uint8_t mac_length, uint8_t length_encoding,
+                       const uint8_t* nonce, size_t nonce_len,
+                       const uint8_t* input, size_t input_len,
+                       uint8_t* plain)
 {
     int len = -1;
     uint8_t nonce_counter[16] = {0}, mac_iv[16] = {0}, mac[16] = {0},
diff --git a/sys/include/crypto/modes/ccm.h b/sys/include/crypto/modes/ccm.h
index 03ac25a5f1..aacf2f05a8 100644
--- a/sys/include/crypto/modes/ccm.h
+++ b/sys/include/crypto/modes/ccm.h
@@ -57,10 +57,12 @@ extern "C" {
  * @return                 Length of encrypted data on a successful encryption
  * @return                 A negative error code if something went wrong
  */
-int cipher_encrypt_ccm(cipher_t* cipher, uint8_t* auth_data,
-                       uint32_t auth_data_len, uint8_t mac_length,
-                       uint8_t length_encoding, uint8_t* nonce, size_t nonce_len,
-                       uint8_t* input, size_t input_len, uint8_t* output);
+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,
+                       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,
  * @return                 Length of the decrypted data on a successful decryption
  * @return                 A negative error code if something went wrong
  */
-int cipher_decrypt_ccm(cipher_t* cipher, uint8_t* auth_data,
-                       uint32_t auth_data_len, uint8_t mac_length,
-                       uint8_t length_encoding, uint8_t* nonce, size_t nonce_len,
-                       uint8_t* input, size_t input_len, uint8_t* output);
+int cipher_decrypt_ccm(cipher_t* cipher,
+                       const uint8_t* auth_data, uint32_t auth_data_len,
+                       uint8_t mac_length, uint8_t length_encoding,
+                       const uint8_t* nonce, size_t nonce_len,
+                       const uint8_t* input, size_t input_len,
+                       uint8_t* output);
 
 #ifdef __cplusplus
 }
diff --git a/tests/unittests/tests-crypto/tests-crypto-modes-ccm.c b/tests/unittests/tests-crypto/tests-crypto-modes-ccm.c
index c9151d9ef5..a8fcedf175 100644
--- a/tests/unittests/tests-crypto/tests-crypto-modes-ccm.c
+++ b/tests/unittests/tests-crypto/tests-crypto-modes-ccm.c
@@ -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,
-                          uint8_t*, size_t, uint8_t*, size_t, uint8_t*);
+typedef int (*func_ccm_t)(cipher_t*, const uint8_t*, uint32_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,
                          uint8_t *input, size_t input_len, size_t adata_len)
-- 
GitLab