Wireless Daemon for Linux
 help / color / mirror / Atom feed
From: James Prestwood <prestwoj@gmail.com>
To: John Brandt <brandtwjohn@gmail.com>, iwd@lists.linux.dev
Subject: Re: [PATCH 04/11] sae: refactor and add function sae_calculate_keys
Date: Wed, 24 Apr 2024 05:06:05 -0700	[thread overview]
Message-ID: <21968340-08b2-420f-95e2-7b6e6ccacb6a@gmail.com> (raw)
In-Reply-To: <20240421125050.6649-5-brandtwjohn@gmail.com>

Hi John,

On 4/21/24 5:50 AM, John Brandt wrote:
> Refactor code by moving code to the new function sae_calculate_keys.
> This will make it easier in the next commits to add SAE support for AP
> mode.
> ---
>   src/sae.c | 83 +++++++++++++++++++++++++++++++------------------------
>   1 file changed, 47 insertions(+), 36 deletions(-)
>
> diff --git a/src/sae.c b/src/sae.c
> index c133386f..314fc28f 100644
> --- a/src/sae.c
> +++ b/src/sae.c
> @@ -683,10 +683,9 @@ static bool sae_send_confirm(struct sae_sm *sm)
>   	return true;
>   }
>   
> -static int sae_process_commit(struct sae_sm *sm, const uint8_t *from,
> -					const uint8_t *frame, size_t len)
> +
> +static int sae_calculate_keys(struct sae_sm *sm)
>   {
> -	uint8_t *ptr = (uint8_t *) frame;
>   	unsigned int nbytes = l_ecc_curve_get_scalar_bytes(sm->curve);
>   	enum l_checksum_type hash =
>   		crypto_sae_hash_from_ecc_prime_len(sm->sae_type, nbytes);
> @@ -702,39 +701,6 @@ static int sae_process_commit(struct sae_sm *sm, const uint8_t *from,
>   	struct l_ecc_scalar *tmp_scalar;
>   	struct l_ecc_scalar *order;
>   
> -	ptr += 2;
> -
> -	sm->p_scalar = l_ecc_scalar_new(sm->curve, ptr, nbytes);
> -	if (!sm->p_scalar) {
> -		l_error("Server sent invalid P_Scalar during commit");
> -		return sae_reject(sm, SAE_STATE_COMMITTED,
> -				MMPDU_STATUS_CODE_UNSUPP_FINITE_CYCLIC_GROUP);
> -	}
> -
> -	ptr += nbytes;
> -
> -	sm->p_element = l_ecc_point_from_data(sm->curve, L_ECC_POINT_TYPE_FULL,
> -						ptr, nbytes * 2);
> -	if (!sm->p_element) {
> -		l_error("Server sent invalid P_Element during commit");
> -		return sae_reject(sm, SAE_STATE_COMMITTED,
> -				MMPDU_STATUS_CODE_UNSUPP_FINITE_CYCLIC_GROUP);
> -	}
> -
> -	/*
> -	 * If they match those sent as part of the protocol instance's own
> -	 * SAE Commit message, the frame shall be silently discarded (because
> -	 * it is evidence of a reflection attack) and the t0 (retransmission)
> -	 * timer shall be set.
> -	 */
> -	if (l_ecc_scalars_are_equal(sm->p_scalar, sm->scalar) ||
> -			l_ecc_points_are_equal(sm->p_element, sm->element)) {
> -		l_warn("peer scalar or element matched own, discarding frame");
> -		return -ENOMSG;
> -	}
> -
> -	sm->sc++;
> -
>   	/*
>   	 * K = scalar-op(rand, (element-op(scalar-op(peer-commit-scalar, PWE),
>   	 *			PEER-COMMIT-ELEMENT)))
> @@ -823,6 +789,51 @@ static int sae_process_commit(struct sae_sm *sm, const uint8_t *from,
>   	/* don't set the handshakes pmkid until confirm is verified */
>   	memcpy(sm->pmkid, tmp, 16);
>   
> +	return 0;
> +}
> +
> +
> +static int sae_process_commit(struct sae_sm *sm, const uint8_t *from,
> +					const uint8_t *frame, size_t len)
> +{
> +	uint8_t *ptr = (uint8_t *) frame;
> +	unsigned int nbytes = l_ecc_curve_get_scalar_bytes(sm->curve);
> +
> +	ptr += 2;
> +
> +	sm->p_scalar = l_ecc_scalar_new(sm->curve, ptr, nbytes);
> +	if (!sm->p_scalar) {
> +		l_error("Server sent invalid P_Scalar during commit");
> +		return sae_reject(sm, SAE_STATE_COMMITTED,
> +				MMPDU_STATUS_CODE_UNSUPP_FINITE_CYCLIC_GROUP);
> +	}
> +
> +	ptr += nbytes;
> +
> +	sm->p_element = l_ecc_point_from_data(sm->curve, L_ECC_POINT_TYPE_FULL,
> +						ptr, nbytes * 2);
> +	if (!sm->p_element) {
> +		l_error("Server sent invalid P_Element during commit");
> +		return sae_reject(sm, SAE_STATE_COMMITTED,
> +				MMPDU_STATUS_CODE_UNSUPP_FINITE_CYCLIC_GROUP);
> +	}
> +
> +	/*
> +	 * If they match those sent as part of the protocol instance's own
> +	 * SAE Commit message, the frame shall be silently discarded (because
> +	 * it is evidence of a reflection attack) and the t0 (retransmission)
> +	 * timer shall be set.
> +	 */
> +	if (l_ecc_scalars_are_equal(sm->p_scalar, sm->scalar) ||
> +			l_ecc_points_are_equal(sm->p_element, sm->element)) {
> +		l_warn("peer scalar or element matched own, discarding frame");
> +		return -ENOMSG;
> +	}
> +
> +	sm->sc++;
> +
> +	sae_calculate_keys(sm);
No return check here. Its likely an impossible scenario (getting the 
x-value) but for consistency might as well check.
> +
>   	if (!sae_send_confirm(sm))
>   		return -EPROTO;
>   

  reply	other threads:[~2024-04-24 12:06 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-21 12:50 [PATCH 00/11] Basic SAE support for AP mode John Brandt
2024-04-21 12:50 ` [PATCH 01/11] ap: ability to advertise PSK and SAE John Brandt
2024-04-21 12:50 ` [PATCH 02/11] ap: accept PSK/SAE in auth depending on config John Brandt
2024-04-24 12:05   ` James Prestwood
2024-04-21 12:50 ` [PATCH 03/11] sae: add function sae_set_group John Brandt
2024-04-24 12:05   ` James Prestwood
2024-04-21 12:50 ` [PATCH 04/11] sae: refactor and add function sae_calculate_keys John Brandt
2024-04-24 12:06   ` James Prestwood [this message]
2024-04-21 12:50 ` [PATCH 05/11] sae: make sae_process_commit callable in AP mode John Brandt
2024-04-24 12:08   ` James Prestwood
2024-04-21 12:50 ` [PATCH 06/11] sae: verify offered group " John Brandt
2024-04-21 12:50 ` [PATCH 07/11] sae: support reception of Confirm frame by AP John Brandt
2024-04-24 12:08   ` James Prestwood
2024-04-21 12:50 ` [PATCH 08/11] ap: add support to handle SAE authentication John Brandt
2024-04-24 12:06   ` James Prestwood
2024-04-21 12:50 ` [PATCH 09/11] ap: enable start of 4-way HS after SAE John Brandt
2024-04-21 12:50 ` [PATCH 10/11] eapol: support PTK derivation with SHA256 John Brandt
2024-04-21 12:50 ` [PATCH 11/11] eapol: encrypt key data for AKM-defined ciphers John Brandt
2024-04-22 13:52 ` [PATCH 00/11] Basic SAE support for AP mode James Prestwood
2024-04-24 12:07   ` James Prestwood
2024-04-29  0:04     ` John Brandt
2024-04-29 12:00       ` James Prestwood
2024-04-30 23:27         ` KeithG

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=21968340-08b2-420f-95e2-7b6e6ccacb6a@gmail.com \
    --to=prestwoj@gmail.com \
    --cc=brandtwjohn@gmail.com \
    --cc=iwd@lists.linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox