diff mbox series

[v2,04/18] sae: add function sae_set_group

Message ID 20240506003518.320176-5-brandtwjohn@gmail.com (mailing list archive)
State New
Headers show
Series Basic WPA3 support in AP mode | expand

Checks

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

Commit Message

John Brandt May 6, 2024, 12:30 a.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 | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

Comments

Denis Kenzior May 7, 2024, 2:53 p.m. UTC | #1
Hi John,

On 5/5/24 7:30 PM, 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 | 25 ++++++++++++++-----------
>   1 file changed, 14 insertions(+), 11 deletions(-)
> 
> diff --git a/src/sae.c b/src/sae.c
> index bf9fb0ff..4e0b73d8 100644
> --- a/src/sae.c
> +++ b/src/sae.c
> @@ -148,6 +148,18 @@ static void sae_reset_state(struct sae_sm *sm)
>   	sm->pwe = NULL;
>   }
>   
> +static int sae_set_group(struct sae_sm *sm, int group)
> +{
> +	sm->curve = l_ecc_curve_from_ike_group(group);
> +	if (sm->curve == NULL)
> +		return -ENOENT;

Could we avoid side-effects on error by doing something like:

const struct l_ecc_curve *curve = l_ecc_curve_from_ike_group(group);

if (!curve)
	return -ENOENT;

sm->curve = curve;
sm->group = group;
...

> +
> +	sae_debug("Using group %u", group);
> +	sm->group = group;
> +
> +	return 0;
> +}
> +
>   static int sae_choose_next_group(struct sae_sm *sm)
>   {
>   	const unsigned int *ecc_groups = l_ecc_supported_ike_groups();

Regards,
-Denis
diff mbox series

Patch

diff --git a/src/sae.c b/src/sae.c
index bf9fb0ff..4e0b73d8 100644
--- a/src/sae.c
+++ b/src/sae.c
@@ -148,6 +148,18 @@  static void sae_reset_state(struct sae_sm *sm)
 	sm->pwe = NULL;
 }
 
+static int sae_set_group(struct sae_sm *sm, int group)
+{
+	sm->curve = l_ecc_curve_from_ike_group(group);
+	if (sm->curve == NULL)
+		return -ENOENT;
+
+	sae_debug("Using group %u", group);
+	sm->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 +178,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 +192,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)