Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp45631ybi; Tue, 16 Jul 2019 15:57:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqwAIQ5rRvoaOa2TRLi4b0VPu4Jp9uEx3Tl6eaP1FVXNt9FyY6nShvduT1NNcNSM85cC1Ay2 X-Received: by 2002:a65:5082:: with SMTP id r2mr11917240pgp.170.1563317857559; Tue, 16 Jul 2019 15:57:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563317857; cv=none; d=google.com; s=arc-20160816; b=YGQVGFh0luCbCTnUh9Ja4frG05t9hd+Jyab1NMQTKn/kCAWn/btDzHU4LqM9kBo7hm isSu8RUpvaZjGWS/csHf5t4ZBoSdPiatE4b6QWV8aKtezgKcmILR1eC1PcEKT8HR4JS5 zIAQ5+bs/Fz2qaDDYcjXZF7ZZcf47G6dIvrHWsbdOE9T+SRFkexQJR9baXDM+VHwxMiD Q170VsOrquh1/azenbiSAkySqZMe/f/53dxTkxU2/gBrTIsGIJsWLt2aX13qIw1X1P9z 8pd3vqlUGv6ez9whQMdZGq1SNLsIui5z65c1WyQAqF7ljg2JzO/qmtl1WFZEnu60jsmH Vpow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=BNinZgMDafKXvOgxMMulS5s34vhJ4+5QfT+YRZkShjc=; b=s9JRWoW11L5YNAC+DZWSWMh5fgHIyV+QJHw60S9XOG5tVj1lNeAFYlVcOOyyIev8xt kSufrKG/Vx+NkjguWRFwQQyV88LrgboGHe8EKagoCraIcWYu0d+7BxmBKSx6oAjzzs4O VUgq73UHcgdx0nkl2rbPE0wzBP420thT0d+nNsipaS6cNzl5JZRCNoaUkUgzslpARTom u++krYXefjh4iNlKvSgZH2L7UQOn1281k3jIcvQHhMyxZwRmJ4w5qMY7QNKgjjN7G9wR W78RWOzxyTqDldQPkrrsH6oMwEIb8XnqC5FtLo9L626jFSNWcl2hUp1ilIV0E2cWMcfm 7YPA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d4si10964465pgm.357.2019.07.16.15.57.07; Tue, 16 Jul 2019 15:57:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388608AbfGPW4v (ORCPT + 99 others); Tue, 16 Jul 2019 18:56:51 -0400 Received: from mga02.intel.com ([134.134.136.20]:2095 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728414AbfGPW4v (ORCPT ); Tue, 16 Jul 2019 18:56:51 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jul 2019 15:56:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,271,1559545200"; d="scan'208";a="170073273" Received: from bgix-dell-lap.sea.intel.com ([10.251.137.82]) by orsmga003.jf.intel.com with ESMTP; 16 Jul 2019 15:56:50 -0700 From: Brian Gix 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 Message-Id: <20190716225644.11449-3-brian.gix@intel.com> X-Mailer: git-send-email 2.14.5 In-Reply-To: <20190716225644.11449-1-brian.gix@intel.com> References: <20190716225644.11449-1-brian.gix@intel.com> Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org --- 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