From: Brian Gix <brian.gix@intel.com>
To: linux-bluetooth@vger.kernel.org
Cc: inga.stotland@intel.com, brian.gix@intel.com,
michal.lowas-rzechonek@silvair.com
Subject: [PATCH BlueZ 2/3] mesh: Normalize Access Key AID naming convention
Date: Tue, 16 Jul 2019 15:56:43 -0700 [thread overview]
Message-ID: <20190716225644.11449-3-brian.gix@intel.com> (raw)
In-Reply-To: <20190716225644.11449-1-brian.gix@intel.com>
---
mesh/crypto.c | 37 ++++++++++++++++++-------------------
mesh/crypto.h | 8 ++++----
mesh/net.h | 4 +---
3 files changed, 23 insertions(+), 26 deletions(-)
diff --git a/mesh/crypto.c b/mesh/crypto.c
index a4679d88e..b1b1fa9a8 100644
--- a/mesh/crypto.c
+++ b/mesh/crypto.c
@@ -429,8 +429,9 @@ bool mesh_crypto_device_nonce(uint32_t seq, uint16_t src,
return true;
}
-bool mesh_crypto_application_encrypt(uint8_t key_id, uint32_t seq, uint16_t src,
- uint16_t dst, uint32_t iv_index,
+bool mesh_crypto_application_encrypt(uint8_t key_aid, uint32_t seq,
+ uint16_t src, uint16_t dst,
+ uint32_t iv_index,
const uint8_t app_key[16],
const uint8_t *aad, uint8_t aad_len,
const uint8_t *msg, uint8_t msg_len,
@@ -440,11 +441,11 @@ bool mesh_crypto_application_encrypt(uint8_t key_id, uint32_t seq, uint16_t src,
uint8_t nonce[13];
bool aszmic = (mic_size == 8) ? true : false;
- if (!key_id && !mesh_crypto_device_nonce(seq, src, dst,
+ if (!key_aid && !mesh_crypto_device_nonce(seq, src, dst,
iv_index, aszmic, nonce))
return false;
- if (key_id && !mesh_crypto_application_nonce(seq, src, dst,
+ if (key_aid && !mesh_crypto_application_nonce(seq, src, dst,
iv_index, aszmic, nonce))
return false;
@@ -453,8 +454,8 @@ bool mesh_crypto_application_encrypt(uint8_t key_id, uint32_t seq, uint16_t src,
out, app_mic, mic_size);
}
-bool mesh_crypto_application_decrypt(uint8_t key_id, uint32_t seq, uint16_t src,
- uint16_t dst, uint32_t iv_index,
+bool mesh_crypto_application_decrypt(uint8_t key_aid, uint32_t seq,
+ uint16_t src, uint16_t dst, uint32_t iv_index,
const uint8_t app_key[16],
const uint8_t *aad, uint8_t aad_len,
const uint8_t *enc_msg, uint8_t enc_msg_len,
@@ -463,11 +464,11 @@ bool mesh_crypto_application_decrypt(uint8_t key_id, uint32_t seq, uint16_t src,
uint8_t nonce[13];
bool aszmic = (mic_size == 8) ? true : false;
- if (!key_id && !mesh_crypto_device_nonce(seq, src, dst,
+ if (!key_aid && !mesh_crypto_device_nonce(seq, src, dst,
iv_index, aszmic, nonce))
return false;
- if (key_id && !mesh_crypto_application_nonce(seq, src, dst,
+ if (key_aid && !mesh_crypto_application_nonce(seq, src, dst,
iv_index, aszmic, nonce))
return false;
@@ -638,7 +639,7 @@ bool mesh_crypto_packet_build(bool ctl, uint8_t ttl,
uint32_t seq,
uint16_t src, uint16_t dst,
uint8_t opcode,
- bool segmented, uint8_t key_id,
+ bool segmented, uint8_t key_aid,
bool szmic, bool relay, uint16_t seqZero,
uint8_t segO, uint8_t segN,
const uint8_t *payload, uint8_t payload_len,
@@ -656,7 +657,7 @@ bool mesh_crypto_packet_build(bool ctl, uint8_t ttl,
if (!ctl) {
hdr = segmented << SEG_HDR_SHIFT;
- hdr |= (key_id & KEY_ID_MASK) << KEY_HDR_SHIFT;
+ hdr |= (key_aid & KEY_ID_MASK) << KEY_HDR_SHIFT;
if (segmented) {
hdr |= szmic << SZMIC_HDR_SHIFT;
hdr |= (seqZero & SEQ_ZERO_MASK) << SEQ_ZERO_HDR_SHIFT;
@@ -700,7 +701,7 @@ bool mesh_crypto_packet_parse(const uint8_t *packet, uint8_t packet_len,
bool *ctl, uint8_t *ttl, uint32_t *seq,
uint16_t *src, uint16_t *dst,
uint32_t *cookie, uint8_t *opcode,
- bool *segmented, uint8_t *key_id,
+ bool *segmented, uint8_t *key_aid,
bool *szmic, bool *relay, uint16_t *seqZero,
uint8_t *segO, uint8_t *segN,
const uint8_t **payload, uint8_t *payload_len)
@@ -769,8 +770,8 @@ bool mesh_crypto_packet_parse(const uint8_t *packet, uint8_t packet_len,
if (cookie)
*cookie = l_get_be32(packet + packet_len - 8);
- if (key_id)
- *key_id = (hdr >> KEY_HDR_SHIFT) & KEY_ID_MASK;
+ if (key_aid)
+ *key_aid = (hdr >> KEY_HDR_SHIFT) & KEY_ID_MASK;
if (is_segmented) {
if (szmic)
@@ -805,7 +806,7 @@ bool mesh_crypto_packet_parse(const uint8_t *packet, uint8_t packet_len,
bool mesh_crypto_payload_encrypt(uint8_t *aad, const uint8_t *payload,
uint8_t *out, uint16_t payload_len,
- uint16_t src, uint16_t dst, uint8_t key_id,
+ uint16_t src, uint16_t dst, uint8_t key_aid,
uint32_t seq_num, uint32_t iv_index,
bool aszmic,
const uint8_t application_key[16])
@@ -815,8 +816,7 @@ bool mesh_crypto_payload_encrypt(uint8_t *aad, const uint8_t *payload,
if (payload_len < 1)
return false;
- /* Key_ID == 0 means the Device Key is being used */
- if (!key_id)
+ if (key_aid == APP_AID_DEV)
application_nonce[0] = 0x02;
/* Seq Num */
@@ -848,7 +848,7 @@ bool mesh_crypto_payload_decrypt(uint8_t *aad, uint16_t aad_len,
const uint8_t *payload, uint16_t payload_len,
bool szmict,
uint16_t src, uint16_t dst,
- uint8_t key_id, uint32_t seq_num,
+ uint8_t key_aid, uint32_t seq_num,
uint32_t iv_index, uint8_t *out,
const uint8_t app_key[16])
{
@@ -859,8 +859,7 @@ bool mesh_crypto_payload_decrypt(uint8_t *aad, uint16_t aad_len,
if (payload_len < 5 || !out)
return false;
- /* Key_ID == 0 means the Device Key is being used */
- if (!key_id)
+ if (key_aid == APP_AID_DEV)
app_nonce[0] = 0x02;
/* Seq Num */
diff --git a/mesh/crypto.h b/mesh/crypto.h
index 3e6815a35..1a73bcaa3 100644
--- a/mesh/crypto.h
+++ b/mesh/crypto.h
@@ -119,7 +119,7 @@ bool mesh_crypto_packet_build(bool ctl, uint8_t ttl,
uint32_t seq,
uint16_t src, uint16_t dst,
uint8_t opcode,
- bool segmented, uint8_t key_id,
+ bool segmented, uint8_t key_aid,
bool szmic, bool relay, uint16_t seqZero,
uint8_t segO, uint8_t segN,
const uint8_t *payload, uint8_t payload_len,
@@ -128,20 +128,20 @@ bool mesh_crypto_packet_parse(const uint8_t *packet, uint8_t packet_len,
bool *ctl, uint8_t *ttl, uint32_t *seq,
uint16_t *src, uint16_t *dst,
uint32_t *cookie, uint8_t *opcode,
- bool *segmented, uint8_t *key_id,
+ bool *segmented, uint8_t *key_aid,
bool *szmic, bool *relay, uint16_t *seqZero,
uint8_t *segO, uint8_t *segN,
const uint8_t **payload, uint8_t *payload_len);
bool mesh_crypto_payload_encrypt(uint8_t *aad, const uint8_t *payload,
uint8_t *out, uint16_t payload_len,
- uint16_t src, uint16_t dst, uint8_t key_id,
+ uint16_t src, uint16_t dst, uint8_t key_aid,
uint32_t seq_num, uint32_t iv_index,
bool aszmic,
const uint8_t application_key[16]);
bool mesh_crypto_payload_decrypt(uint8_t *aad, uint16_t aad_len,
const uint8_t *payload, uint16_t payload_len,
bool szmict,
- uint16_t src, uint16_t dst, uint8_t key_id,
+ uint16_t src, uint16_t dst, uint8_t key_aid,
uint32_t seq_num, uint32_t iv_index,
uint8_t *out,
const uint8_t application_key[16]);
diff --git a/mesh/net.h b/mesh/net.h
index 8848e6df0..7b0733578 100644
--- a/mesh/net.h
+++ b/mesh/net.h
@@ -28,9 +28,7 @@ struct mesh_node;
#define UNUSED_KEY_IDX 0xffff
-#define APP_ID_DEV 0
-#define APP_ID_ANY ((unsigned int) -1)
-#define NET_ID_ANY (APP_ID_ANY - 1)
+#define APP_AID_DEV 0x00
#define CTL 0x80
#define TTL_MASK 0x7f
--
2.14.5
next prev parent reply other threads:[~2019-07-16 22:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-16 22:56 [PATCH BlueZ 0/3] mesh: Propagate/Preserve Net Index for Access Layer Brian Gix
2019-07-16 22:56 ` [PATCH BlueZ 1/3] mesh: Add bound Net Index lookup for App Keys Brian Gix
2019-07-16 22:56 ` Brian Gix [this message]
2019-07-16 22:56 ` [PATCH BlueZ 3/3] mesh: Propagate Net Index up Rx message chain Brian Gix
2019-07-17 8:48 ` Michał Lowas-Rzechonek
2019-07-18 17:07 ` [PATCH BlueZ 0/3] mesh: Propagate/Preserve Net Index for Access Layer Gix, Brian
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190716225644.11449-3-brian.gix@intel.com \
--to=brian.gix@intel.com \
--cc=inga.stotland@intel.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=michal.lowas-rzechonek@silvair.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.