diff mbox series

[03/11] sae: add function sae_set_group

Message ID 20240421125050.6649-4-brandtwjohn@gmail.com (mailing list archive)
State New
Headers show
Series Basic SAE support for AP mode | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
prestwoj/iwd-ci-gitlint success GitLint

Commit Message

John Brandt April 21, 2024, 12:50 p.m. UTC
Refactor code by adding function sae_set_group. This will make the next
commits easier where basic SAE support for APs is added.
---
 src/sae.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

Comments

James Prestwood April 24, 2024, 12:05 p.m. UTC | #1
Hi John,

On 4/21/24 5:50 AM, John Brandt wrote:
> Refactor code by adding function sae_set_group. This will make the next
> commits easier where basic SAE support for APs is added.
> ---
>   src/sae.c | 23 ++++++++++++-----------
>   1 file changed, 12 insertions(+), 11 deletions(-)
>
> diff --git a/src/sae.c b/src/sae.c
> index bf9fb0ff..c133386f 100644
> --- a/src/sae.c
> +++ b/src/sae.c
> @@ -148,6 +148,16 @@ static void sae_reset_state(struct sae_sm *sm)
>   	sm->pwe = NULL;
>   }
>   
> +static int sae_set_group(struct sae_sm *sm, int group)
> +{
> +	sae_debug("Using group %u", group);
> +
> +	sm->group = group;
> +	sm->curve = l_ecc_curve_from_ike_group(group);
We need to check if the group was supported. For this set it doesn't 
matter since your only using the static set of groups, but patch 5 uses 
the raw frame which may be a bogus/unsupported group number.
> +
> +	return 0;
> +}
> +
>   static int sae_choose_next_group(struct sae_sm *sm)
>   {
>   	const unsigned int *ecc_groups = l_ecc_supported_ike_groups();
> @@ -166,9 +176,7 @@ static int sae_choose_next_group(struct sae_sm *sm)
>   		sae_debug("Forcing default SAE group 19");
>   
>   		sm->group_retry++;
> -		sm->group = 19;
> -
> -		goto get_curve;
> +		return sae_set_group(sm, 19);
>   	}
>   
>   	do {
> @@ -182,14 +190,7 @@ static int sae_choose_next_group(struct sae_sm *sm)
>   	if (reset)
>   		sae_reset_state(sm);
>   
> -	sm->group = ecc_groups[sm->group_retry];
> -
> -get_curve:
> -	sae_debug("Using group %u", sm->group);
> -
> -	sm->curve = l_ecc_curve_from_ike_group(sm->group);
> -
> -	return 0;
> +	return sae_set_group(sm, ecc_groups[sm->group_retry]);
>   }
>   
>   static int sae_valid_group(struct sae_sm *sm, unsigned int group)
diff mbox series

Patch

diff --git a/src/sae.c b/src/sae.c
index bf9fb0ff..c133386f 100644
--- a/src/sae.c
+++ b/src/sae.c
@@ -148,6 +148,16 @@  static void sae_reset_state(struct sae_sm *sm)
 	sm->pwe = NULL;
 }
 
+static int sae_set_group(struct sae_sm *sm, int group)
+{
+	sae_debug("Using group %u", group);
+
+	sm->group = group;
+	sm->curve = l_ecc_curve_from_ike_group(group);
+
+	return 0;
+}
+
 static int sae_choose_next_group(struct sae_sm *sm)
 {
 	const unsigned int *ecc_groups = l_ecc_supported_ike_groups();
@@ -166,9 +176,7 @@  static int sae_choose_next_group(struct sae_sm *sm)
 		sae_debug("Forcing default SAE group 19");
 
 		sm->group_retry++;
-		sm->group = 19;
-
-		goto get_curve;
+		return sae_set_group(sm, 19);
 	}
 
 	do {
@@ -182,14 +190,7 @@  static int sae_choose_next_group(struct sae_sm *sm)
 	if (reset)
 		sae_reset_state(sm);
 
-	sm->group = ecc_groups[sm->group_retry];
-
-get_curve:
-	sae_debug("Using group %u", sm->group);
-
-	sm->curve = l_ecc_curve_from_ike_group(sm->group);
-
-	return 0;
+	return sae_set_group(sm, ecc_groups[sm->group_retry]);
 }
 
 static int sae_valid_group(struct sae_sm *sm, unsigned int group)