1 /*
2 * Copyright (c) 2023 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 enum bt_mesh_key_type {
8 BT_MESH_KEY_TYPE_ECB,
9 BT_MESH_KEY_TYPE_CCM,
10 BT_MESH_KEY_TYPE_CMAC,
11 BT_MESH_KEY_TYPE_NET,
12 BT_MESH_KEY_TYPE_APP,
13 BT_MESH_KEY_TYPE_DEV
14 };
15
16 #if defined CONFIG_BT_MESH_USES_MBEDTLS_PSA || defined CONFIG_BT_MESH_USES_TFM_PSA
17
18 int bt_mesh_key_import(enum bt_mesh_key_type type, const uint8_t in[16], struct bt_mesh_key *out);
19 int bt_mesh_key_export(uint8_t out[16], const struct bt_mesh_key *in);
20 void bt_mesh_key_assign(struct bt_mesh_key *dst, const struct bt_mesh_key *src);
21 int bt_mesh_key_destroy(const struct bt_mesh_key *key);
22 int bt_mesh_key_compare(const uint8_t raw_key[16], const struct bt_mesh_key *mesh_key);
23
24 #elif defined CONFIG_BT_MESH_USES_TINYCRYPT
25
bt_mesh_key_import(enum bt_mesh_key_type type,const uint8_t in[16],struct bt_mesh_key * out)26 static inline int bt_mesh_key_import(enum bt_mesh_key_type type, const uint8_t in[16],
27 struct bt_mesh_key *out)
28 {
29 memcpy(out, in, 16);
30 return 0;
31 }
32
bt_mesh_key_export(uint8_t out[16],const struct bt_mesh_key * in)33 static inline int bt_mesh_key_export(uint8_t out[16], const struct bt_mesh_key *in)
34 {
35 memcpy(out, in, 16);
36 return 0;
37 }
38
bt_mesh_key_assign(struct bt_mesh_key * dst,const struct bt_mesh_key * src)39 static inline void bt_mesh_key_assign(struct bt_mesh_key *dst, const struct bt_mesh_key *src)
40 {
41 memcpy(dst, src, sizeof(struct bt_mesh_key));
42 }
43
bt_mesh_key_destroy(const struct bt_mesh_key * key)44 static inline int bt_mesh_key_destroy(const struct bt_mesh_key *key)
45 {
46 return 0;
47 }
48
bt_mesh_key_compare(const uint8_t raw_key[16],const struct bt_mesh_key * mesh_key)49 static inline int bt_mesh_key_compare(const uint8_t raw_key[16], const struct bt_mesh_key *mesh_key)
50 {
51 return memcmp(mesh_key, raw_key, 16);
52 }
53
54 #endif
55