aboutsummaryrefslogtreecommitdiffstats
path: root/src/common/dragonfly.c
diff options
context:
space:
mode:
authorJouni Malinen <jouni@codeaurora.org>2019-04-25 17:18:27 (GMT)
committerJouni Malinen <j@w1.fi>2019-04-25 20:49:49 (GMT)
commit6c9543fcb7962e26c2a91c43089abe171d073b44 (patch)
treeb528beed7f6c89252c957bc04d62889910879503 /src/common/dragonfly.c
parent2b84ca4dd96459b661b0ebaf40ec43074fc9f42c (diff)
downloadhostap-6c9543fcb7962e26c2a91c43089abe171d073b44.zip
hostap-6c9543fcb7962e26c2a91c43089abe171d073b44.tar.gz
hostap-6c9543fcb7962e26c2a91c43089abe171d073b44.tar.bz2
Share common SAE and EAP-pwd functionality: random qr/qnr creation
Use a shared helper function to create random qr/qnr values. Signed-off-by: Jouni Malinen <jouni@codeaurora.org>
Diffstat (limited to 'src/common/dragonfly.c')
-rw-r--r--src/common/dragonfly.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/common/dragonfly.c b/src/common/dragonfly.c
index 1e80404..334f492 100644
--- a/src/common/dragonfly.c
+++ b/src/common/dragonfly.c
@@ -10,6 +10,7 @@
#include "utils/includes.h"
#include "utils/common.h"
+#include "crypto/crypto.h"
#include "dragonfly.h"
@@ -25,3 +26,35 @@ int dragonfly_suitable_group(int group, int ecc_only)
(!ecc_only &&
(group == 15 || group == 16 || group == 17 || group == 18));
}
+
+
+int dragonfly_get_random_qr_qnr(const struct crypto_bignum *prime,
+ struct crypto_bignum **qr,
+ struct crypto_bignum **qnr)
+{
+ *qr = *qnr = NULL;
+
+ while (!(*qr) || !(*qnr)) {
+ struct crypto_bignum *tmp;
+ int res;
+
+ tmp = crypto_bignum_init();
+ if (!tmp || crypto_bignum_rand(tmp, prime) < 0)
+ break;
+
+ res = crypto_bignum_legendre(tmp, prime);
+ if (res == 1 && !(*qr))
+ *qr = tmp;
+ else if (res == -1 && !(*qnr))
+ *qnr = tmp;
+ else
+ crypto_bignum_deinit(tmp, 0);
+ }
+
+ if (*qr && *qnr)
+ return 0;
+ crypto_bignum_deinit(*qr, 0);
+ crypto_bignum_deinit(*qnr, 0);
+ *qr = *qnr = NULL;
+ return -1;
+}