]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
SAE: Clean up exponent calculation for PWE
authorJouni Malinen <j@w1.fi>
Sun, 6 Jan 2013 16:56:46 +0000 (18:56 +0200)
committerJouni Malinen <j@w1.fi>
Sat, 12 Jan 2013 15:51:54 +0000 (17:51 +0200)
Signed-hostap: Jouni Malinen <j@w1.fi>

src/common/sae.c

index 911c95740eee829ae15fbbd2a695878432819e8d..6aed89c42b9479fb83593094da2f483a318f6ab6 100644 (file)
@@ -229,25 +229,23 @@ static int sae_test_pwd_seed_ffc(struct sae_data *sae, const u8 *pwd_seed,
                 */
                exp[0] = 2;
                b = crypto_bignum_init_set(exp, sizeof(exp));
-               if (a == NULL || b == NULL)
-                       res = -1;
-               else
-                       res = crypto_bignum_exptmod(a, b, sae->prime, pwe);
        } else {
-               struct crypto_bignum *tmp;
-
+               /* Calculate exponent: (p-1)/r */
                exp[0] = 1;
                b = crypto_bignum_init_set(exp, sizeof(exp));
-               tmp = crypto_bignum_init();
-               if (a == NULL || b == NULL || tmp == NULL ||
-                   crypto_bignum_sub(sae->prime, b, tmp) < 0 ||
-                   crypto_bignum_div(tmp, sae->order, b) < 0)
-                       res = -1;
-               else
-                       res = crypto_bignum_exptmod(a, b, sae->prime, pwe);
-               crypto_bignum_deinit(tmp, 0);
+               if (b == NULL ||
+                   crypto_bignum_sub(sae->prime, b, b) < 0 ||
+                   crypto_bignum_div(b, sae->order, b) < 0) {
+                       crypto_bignum_deinit(b, 0);
+                       b = NULL;
+               }
        }
 
+       if (a == NULL || b == NULL)
+               res = -1;
+       else
+               res = crypto_bignum_exptmod(a, b, sae->prime, pwe);
+
        crypto_bignum_deinit(a, 0);
        crypto_bignum_deinit(b, 0);