aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey/dl_group
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-02-23 12:31:03 -0500
committerJack Lloyd <[email protected]>2018-02-23 12:31:03 -0500
commit8d9f83f87e146be428ad7d0684496f12cf34d4c8 (patch)
tree49873a798b00cf8f4714483df047553cca560d4a /src/lib/pubkey/dl_group
parentedf30c4474a161dba6abd16f86fa01917294839f (diff)
Add DL_Group functions to verify elements
Diffstat (limited to 'src/lib/pubkey/dl_group')
-rw-r--r--src/lib/pubkey/dl_group/dl_group.cpp30
-rw-r--r--src/lib/pubkey/dl_group/dl_group.h17
2 files changed, 46 insertions, 1 deletions
diff --git a/src/lib/pubkey/dl_group/dl_group.cpp b/src/lib/pubkey/dl_group/dl_group.cpp
index c96dea677..7d2ad15e9 100644
--- a/src/lib/pubkey/dl_group/dl_group.cpp
+++ b/src/lib/pubkey/dl_group/dl_group.cpp
@@ -292,6 +292,36 @@ const DL_Group_Data& DL_Group::data() const
throw Invalid_State("DL_Group uninitialized");
}
+bool DL_Group::verify_public_element(const BigInt& y) const
+ {
+ const BigInt& p = get_p();
+ const BigInt& q = get_q();
+
+ if(y <= 1 || y >= p)
+ return false;
+
+ if(q.is_zero() == false)
+ {
+ if(power_mod(y, q, p) != 1)
+ return false;
+ }
+
+ return true;
+ }
+
+bool DL_Group::verify_element_pair(const BigInt& y, const BigInt& x) const
+ {
+ const BigInt& p = get_p();
+
+ if(y <= 1 || y >= p || x <= 1 || x >= p)
+ return false;
+
+ if(y != power_g_p(x))
+ return false;
+
+ return true;
+ }
+
/*
* Verify the parameters
*/
diff --git a/src/lib/pubkey/dl_group/dl_group.h b/src/lib/pubkey/dl_group/dl_group.h
index 2bd79e3dd..b9a7bb992 100644
--- a/src/lib/pubkey/dl_group/dl_group.h
+++ b/src/lib/pubkey/dl_group/dl_group.h
@@ -135,7 +135,22 @@ class BOTAN_PUBLIC_API(2,0) DL_Group final
* @param strong whether to perform stronger by lengthier tests
* @return true if the object is consistent, false otherwise
*/
- bool verify_group(RandomNumberGenerator& rng, bool strong) const;
+ bool verify_group(RandomNumberGenerator& rng, bool strong = true) const;
+
+ /**
+ * Verify a public element, ie check if y = g^x for some x.
+ *
+ * This is not a perfect test. It verifies that 1 < y < p and (if q is set)
+ * that y is in the subgroup of size q.
+ */
+ bool verify_public_element(const BigInt& y) const;
+
+ /**
+ * Verify a pair of elements y = g^x
+ *
+ * This verifies that 1 < x,y < p and that y=g^x mod p
+ */
+ bool verify_element_pair(const BigInt& y, const BigInt& x) const;
/**
* Encode this group into a string using PEM encoding.