All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Gix, Brian" <brian.gix@intel.com>
To: "michal.lowas-rzechonek@silvair.com" 
	<michal.lowas-rzechonek@silvair.com>,
	"linux-bluetooth@vger.kernel.org"
	<linux-bluetooth@vger.kernel.org>
Subject: Re: [PATCH BlueZ v3 1/2] mesh: Fixed handling of IVI flag in app layer
Date: Thu, 27 Jun 2019 17:20:36 +0000	[thread overview]
Message-ID: <1561656034.7802.7.camel@intel.com> (raw)
In-Reply-To: <20190627074043.22891-2-michal.lowas-rzechonek@silvair.com>

Patch applied, Thanks.


On Thu, 2019-06-27 at 09:40 +0200, Michał Lowas-Rzechonek wrote:
> Since IV Index is used in application nonces, we need to honor IVI flag
> not only in network layer crypto, but also in application layer.
> 
> This means that if IVI field of incoming packet is different than in
> current IV Index, try to decode *both* net and app layers using IV Index
> decreased by one.
> ---
>  mesh/net-keys.c |  6 ------
>  mesh/net.c      | 17 ++++++++---------
>  2 files changed, 8 insertions(+), 15 deletions(-)
> 
> diff --git a/mesh/net-keys.c b/mesh/net-keys.c
> index 25f4caeb7..5be7e0b58 100644
> --- a/mesh/net-keys.c
> +++ b/mesh/net-keys.c
> @@ -209,12 +209,6 @@ static void decrypt_net_pkt(void *a, void *b)
>  uint32_t net_key_decrypt(uint32_t iv_index, const uint8_t *pkt, size_t len,
>  					uint8_t **plain, size_t *plain_len)
>  {
> -	bool iv_flag = !!(iv_index & 1);
> -	bool iv_pkt = !!(pkt[0] & 0x80);
> -
> -	if (iv_pkt != iv_flag)
> -		iv_index--;
> -
>  	/* If we already successfully decrypted this packet, use cached data */
>  	if (cache_id && cache_len == len && !memcmp(pkt, cache_pkt, len)) {
>  		/* IV Index must match what was used to decrypt */
> diff --git a/mesh/net.c b/mesh/net.c
> index a597b8794..a5693f154 100644
> --- a/mesh/net.c
> +++ b/mesh/net.c
> @@ -2489,8 +2489,13 @@ static void net_rx(void *net_ptr, void *user_data)
>  	size_t out_size;
>  	uint32_t key_id;
>  	int8_t rssi = 0;
> +	bool ivi_net = !!(net->iv_index & 1);
> +	bool ivi_pkt = !!(data->data[0] & 0x80);
>  
> -	key_id = net_key_decrypt(net->iv_index, data->data, data->len,
> +	/* if IVI flag differs, use previous IV Index */
> +	uint32_t iv_index = net->iv_index - (ivi_pkt ^ ivi_net);
> +
> +	key_id = net_key_decrypt(iv_index, data->data, data->len,
>  							&out, &out_size);
>  
>  	if (!key_id)
> @@ -2504,16 +2509,10 @@ static void net_rx(void *net_ptr, void *user_data)
>  		rssi = data->info->rssi;
>  	}
>  
> -	relay_advice = packet_received(net, key_id, net->iv_index,
> +	relay_advice = packet_received(net, key_id, iv_index,
>  							out, out_size, rssi);
>  	if (relay_advice > data->relay_advice) {
> -		bool iv_flag = !!(net->iv_index & 1);
> -		bool iv_pkt = !!(data->data[0] & 0x80);
> -
> -		data->iv_index = net->iv_index;
> -		if (iv_pkt != iv_flag)
> -			data->iv_index--;
> -
> +		data->iv_index = iv_index;
>  		data->relay_advice = relay_advice;
>  		data->key_id = key_id;
>  		data->net = net;

  reply	other threads:[~2019-06-27 17:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-27  7:40 [PATCH BlueZ v3 0/2] mesh: Fix IV Index handling during IV Update Michał Lowas-Rzechonek
2019-06-27  7:40 ` [PATCH BlueZ v3 1/2] mesh: Fixed handling of IVI flag in app layer Michał Lowas-Rzechonek
2019-06-27 17:20   ` Gix, Brian [this message]
2019-06-27  7:40 ` [PATCH BlueZ v3 2/2] mesh: Use current IV Index when relaying Michał Lowas-Rzechonek
2019-06-27  8:25   ` Michał Lowas-Rzechonek
2019-06-27 15:38   ` Gix, Brian
2019-06-27 15:58     ` Michal Lowas-Rzechonek

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=1561656034.7802.7.camel@intel.com \
    --to=brian.gix@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.