aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNever <[email protected]>2016-12-20 14:24:09 +0100
committerNever <[email protected]>2016-12-20 14:27:47 +0100
commit75e6d9aa7da63cf7dbf81359e350da682c8e4979 (patch)
tree873fd4f31a71a41425da36c157eace3d23306134
parent735282facf31b9ac688fd0724c1a68ca3dcc4107 (diff)
Add missing q == 0 check in DL_Scheme_PublicKey::check_key() as q may not be available in all groups
-rw-r--r--src/lib/pubkey/dl_algo/dl_algo.cpp26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/lib/pubkey/dl_algo/dl_algo.cpp b/src/lib/pubkey/dl_algo/dl_algo.cpp
index 472b979b1..85576e9bf 100644
--- a/src/lib/pubkey/dl_algo/dl_algo.cpp
+++ b/src/lib/pubkey/dl_algo/dl_algo.cpp
@@ -35,8 +35,8 @@ std::vector<byte> DL_Scheme_PublicKey::public_key_bits() const
}
DL_Scheme_PublicKey::DL_Scheme_PublicKey(const AlgorithmIdentifier& alg_id,
- const std::vector<byte>& key_bits,
- DL_Group::Format format)
+ const std::vector<byte>& key_bits,
+ DL_Group::Format format)
{
m_group.BER_decode(alg_id.parameters, format);
@@ -49,8 +49,8 @@ secure_vector<byte> DL_Scheme_PrivateKey::private_key_bits() const
}
DL_Scheme_PrivateKey::DL_Scheme_PrivateKey(const AlgorithmIdentifier& alg_id,
- const secure_vector<byte>& key_bits,
- DL_Group::Format format)
+ const secure_vector<byte>& key_bits,
+ DL_Group::Format format)
{
m_group.BER_decode(alg_id.parameters, format);
@@ -63,12 +63,24 @@ DL_Scheme_PrivateKey::DL_Scheme_PrivateKey(const AlgorithmIdentifier& alg_id,
bool DL_Scheme_PublicKey::check_key(RandomNumberGenerator& rng,
bool strong) const
{
- if(m_y < 2 || m_y >= group_p())
+ const BigInt& p = group_p();
+
+ if(m_y < 2 || m_y >= p)
return false;
if(!m_group.verify_group(rng, strong))
return false;
- if(power_mod(m_y,group_q(),group_p()) != 1)
- return false;
+
+ try
+ {
+ const BigInt& q = group_q();
+ if(power_mod(m_y, q, p) != 1)
+ return false;
+ }
+ catch(const Invalid_State& e)
+ {
+ return true;
+ }
+
return true;
}