Bluetooth: Crypto: Fix naming of params
The naming and documentation of the parameters was inconsistent with
their actual meaning and the implementation - enc_data and plaintext
were swapped.
Also, the parameter names in the file aes_ccm.c were completely
different from the ones in the header. Since all functions in the
header file are consistent in their parameter naming, I chose to make
the implementation follow the header and not the other way around.
Signed-off-by: René Beckmann <rene.beckmann@grandcentrix.net>
diff --git a/include/bluetooth/crypto.h b/include/bluetooth/crypto.h
index e529504..f321054 100644
--- a/include/bluetooth/crypto.h
+++ b/include/bluetooth/crypto.h
@@ -102,19 +102,19 @@
*
* @param key 128 bit MS byte first key
* @param nonce 13 byte MS byte first nonce
- * @param enc_data Buffer to place encrypted data in
+ * @param plaintext Plaintext buffer to encrypt
* @param len Length of the encrypted data
* @param aad Additional input data
* @param aad_len Additional input data length
- * @param plaintext Plaintext buffer to encrypt
+ * @param enc_data Buffer to place encrypted data in
* @param mic_size Size of the trailing MIC (in bytes)
*
* @retval 0 Successfully encrypted the data.
* @retval -EINVAL Invalid parameters.
*/
-int bt_ccm_encrypt(const uint8_t key[16], uint8_t nonce[13], const uint8_t *enc_data,
- size_t len, const uint8_t *aad, size_t aad_len,
- uint8_t *plaintext, size_t mic_size);
+int bt_ccm_encrypt(const uint8_t key[16], uint8_t nonce[13],
+ const uint8_t *plaintext, size_t len, const uint8_t *aad,
+ size_t aad_len, uint8_t *enc_data, size_t mic_size);
#ifdef __cplusplus
}
diff --git a/subsys/bluetooth/host/aes_ccm.c b/subsys/bluetooth/host/aes_ccm.c
index 29bafba..7e7e153 100644
--- a/subsys/bluetooth/host/aes_ccm.c
+++ b/subsys/bluetooth/host/aes_ccm.c
@@ -186,9 +186,9 @@
return 0;
}
-int bt_ccm_decrypt(const uint8_t key[16], uint8_t nonce[13], const uint8_t *enc_msg,
- size_t msg_len, const uint8_t *aad, size_t aad_len,
- uint8_t *out_msg, size_t mic_size)
+int bt_ccm_decrypt(const uint8_t key[16], uint8_t nonce[13],
+ const uint8_t *enc_data, size_t len, const uint8_t *aad,
+ size_t aad_len, uint8_t *plaintext, size_t mic_size)
{
uint8_t mic[16];
@@ -196,26 +196,26 @@
return -EINVAL;
}
- ccm_crypt(key, nonce, enc_msg, out_msg, msg_len);
+ ccm_crypt(key, nonce, enc_data, plaintext, len);
- ccm_auth(key, nonce, out_msg, msg_len, aad, aad_len, mic, mic_size);
+ ccm_auth(key, nonce, plaintext, len, aad, aad_len, mic, mic_size);
- if (memcmp(mic, enc_msg + msg_len, mic_size)) {
+ if (memcmp(mic, enc_data + len, mic_size)) {
return -EBADMSG;
}
return 0;
}
-int bt_ccm_encrypt(const uint8_t key[16], uint8_t nonce[13], const uint8_t *msg,
- size_t msg_len, const uint8_t *aad, size_t aad_len,
- uint8_t *out_msg, size_t mic_size)
+int bt_ccm_encrypt(const uint8_t key[16], uint8_t nonce[13],
+ const uint8_t *plaintext, size_t len, const uint8_t *aad,
+ size_t aad_len, uint8_t *enc_data, size_t mic_size)
{
- uint8_t *mic = out_msg + msg_len;
+ uint8_t *mic = enc_data + len;
BT_DBG("key %s", bt_hex(key, 16));
BT_DBG("nonce %s", bt_hex(nonce, 13));
- BT_DBG("msg (len %zu) %s", msg_len, bt_hex(msg, msg_len));
+ BT_DBG("msg (len %zu) %s", len, bt_hex(plaintext, len));
BT_DBG("aad_len %zu mic_size %zu", aad_len, mic_size);
/* Unsupported AAD size */
@@ -223,9 +223,9 @@
return -EINVAL;
}
- ccm_auth(key, nonce, out_msg, msg_len, aad, aad_len, mic, mic_size);
+ ccm_auth(key, nonce, enc_data, len, aad, aad_len, mic, mic_size);
- ccm_crypt(key, nonce, msg, out_msg, msg_len);
+ ccm_crypt(key, nonce, plaintext, enc_data, len);
return 0;
}