Skip to content

Commit 92c93ef

Browse files
ahmedmoheb-nordiccarlescufi
authored andcommitted
bluetooth: host: crypto: Check input arguments with CHECKIF()
Check input arguments passed to APIs with CHECKIF(). Signed-off-by: Ahmed Moheb <[email protected]>
1 parent 810809f commit 92c93ef

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

subsys/bluetooth/host/crypto.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <zephyr/kernel.h>
1212
#include <zephyr/sys/byteorder.h>
13+
#include <zephyr/sys/check.h>
1314

1415
#include <zephyr/bluetooth/bluetooth.h>
1516
#include <zephyr/bluetooth/hci.h>
@@ -77,6 +78,10 @@ int bt_rand(void *buf, size_t len)
7778
{
7879
int ret;
7980

81+
CHECKIF(buf == NULL || len == 0) {
82+
return -EINVAL;
83+
}
84+
8085
ret = tc_hmac_prng_generate(buf, len, &prng);
8186
if (ret == TC_HMAC_PRNG_RESEED_REQ) {
8287
ret = prng_reseed(&prng);
@@ -96,6 +101,10 @@ int bt_rand(void *buf, size_t len)
96101
#else /* !CONFIG_BT_HOST_CRYPTO_PRNG */
97102
int bt_rand(void *buf, size_t len)
98103
{
104+
CHECKIF(buf == NULL || len == 0) {
105+
return -EINVAL;
106+
}
107+
99108
return bt_hci_le_rand(buf, len);
100109
}
101110
#endif /* CONFIG_BT_HOST_CRYPTO_PRNG */
@@ -106,6 +115,10 @@ int bt_encrypt_le(const uint8_t key[16], const uint8_t plaintext[16],
106115
struct tc_aes_key_sched_struct s;
107116
uint8_t tmp[16];
108117

118+
CHECKIF(key == NULL || plaintext == NULL || enc_data == NULL) {
119+
return -EINVAL;
120+
}
121+
109122
BT_DBG("key %s", bt_hex(key, 16));
110123
BT_DBG("plaintext %s", bt_hex(plaintext, 16));
111124

@@ -133,6 +146,10 @@ int bt_encrypt_be(const uint8_t key[16], const uint8_t plaintext[16],
133146
{
134147
struct tc_aes_key_sched_struct s;
135148

149+
CHECKIF(key == NULL || plaintext == NULL || enc_data == NULL) {
150+
return -EINVAL;
151+
}
152+
136153
BT_DBG("key %s", bt_hex(key, 16));
137154
BT_DBG("plaintext %s", bt_hex(plaintext, 16));
138155

0 commit comments

Comments
 (0)