aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-02-19 12:30:20 -0500
committerJack Lloyd <[email protected]>2018-02-19 12:30:20 -0500
commitb300eb0515b2a392793d887435b8ca44a1de7898 (patch)
tree44e6cdf1710f537a53098dad4e03d9caf6e79643 /src/lib/pubkey
parent4dcff1874ad430269bb7d75818b906b34331d919 (diff)
Small fixes
Diffstat (limited to 'src/lib/pubkey')
-rw-r--r--src/lib/pubkey/dl_algo/dl_algo.cpp14
-rw-r--r--src/lib/pubkey/dl_algo/dl_algo.h20
-rw-r--r--src/lib/pubkey/dl_group/dl_group.cpp1
-rw-r--r--src/lib/pubkey/dl_group/dl_group.h11
-rw-r--r--src/lib/pubkey/dsa/dsa.cpp4
5 files changed, 29 insertions, 21 deletions
diff --git a/src/lib/pubkey/dl_algo/dl_algo.cpp b/src/lib/pubkey/dl_algo/dl_algo.cpp
index c28ccaee0..0ac6bfce5 100644
--- a/src/lib/pubkey/dl_algo/dl_algo.cpp
+++ b/src/lib/pubkey/dl_algo/dl_algo.cpp
@@ -34,12 +34,17 @@ std::vector<uint8_t> DL_Scheme_PublicKey::public_key_bits() const
return DER_Encoder().encode(m_y).get_contents_unlocked();
}
+DL_Scheme_PublicKey::DL_Scheme_PublicKey(const DL_Group& group, const BigInt& y) :
+ m_y(y),
+ m_group(group)
+ {
+ }
+
DL_Scheme_PublicKey::DL_Scheme_PublicKey(const AlgorithmIdentifier& alg_id,
const std::vector<uint8_t>& key_bits,
- DL_Group::Format format)
+ DL_Group::Format format) :
+ m_group(alg_id.get_parameters(), format)
{
- m_group.BER_decode(alg_id.get_parameters(), format);
-
BER_Decoder(key_bits).decode(m_y);
}
@@ -91,7 +96,6 @@ bool DL_Scheme_PrivateKey::check_key(RandomNumberGenerator& rng,
bool strong) const
{
const BigInt& p = group_p();
- const BigInt& g = group_g();
if(m_y < 2 || m_y >= p || m_x < 2 || m_x >= p)
return false;
@@ -101,7 +105,7 @@ bool DL_Scheme_PrivateKey::check_key(RandomNumberGenerator& rng,
if(!strong)
return true;
- if(m_y != power_mod(g, m_x, p))
+ if(m_y != m_group.power_g_p(m_x))
return false;
return true;
diff --git a/src/lib/pubkey/dl_algo/dl_algo.h b/src/lib/pubkey/dl_algo/dl_algo.h
index 9364f4c5d..af01bc217 100644
--- a/src/lib/pubkey/dl_algo/dl_algo.h
+++ b/src/lib/pubkey/dl_algo/dl_algo.h
@@ -69,6 +69,11 @@ class BOTAN_PUBLIC_API(2,0) DL_Scheme_PublicKey : public virtual Public_Key
size_t key_length() const override;
size_t estimated_strength() const override;
+ DL_Scheme_PublicKey& operator=(const DL_Scheme_PublicKey& other) = default;
+
+ protected:
+ DL_Scheme_PublicKey() = default;
+
/**
* Create a public key.
* @param alg_id the X.509 algorithm identifier
@@ -79,14 +84,7 @@ class BOTAN_PUBLIC_API(2,0) DL_Scheme_PublicKey : public virtual Public_Key
const std::vector<uint8_t>& key_bits,
DL_Group::Format group_format);
- DL_Scheme_PublicKey(const DL_Group& group, const BigInt& y) :
- m_y(y), m_group(group)
- {}
-
- DL_Scheme_PublicKey& operator=(const DL_Scheme_PublicKey& other) = default;
-
- protected:
- DL_Scheme_PublicKey() = default;
+ DL_Scheme_PublicKey(const DL_Group& group, const BigInt& y);
/**
* The DL public key
@@ -116,6 +114,9 @@ class BOTAN_PUBLIC_API(2,0) DL_Scheme_PrivateKey : public virtual DL_Scheme_Publ
secure_vector<uint8_t> private_key_bits() const override;
+ DL_Scheme_PrivateKey& operator=(const DL_Scheme_PrivateKey& other) = default;
+
+ protected:
/**
* Create a private key.
* @param alg_id the X.509 algorithm identifier
@@ -126,9 +127,6 @@ class BOTAN_PUBLIC_API(2,0) DL_Scheme_PrivateKey : public virtual DL_Scheme_Publ
const secure_vector<uint8_t>& key_bits,
DL_Group::Format group_format);
- DL_Scheme_PrivateKey& operator=(const DL_Scheme_PrivateKey& other) = default;
-
- protected:
DL_Scheme_PrivateKey() = default;
/**
diff --git a/src/lib/pubkey/dl_group/dl_group.cpp b/src/lib/pubkey/dl_group/dl_group.cpp
index 6d9418241..9eedeccf3 100644
--- a/src/lib/pubkey/dl_group/dl_group.cpp
+++ b/src/lib/pubkey/dl_group/dl_group.cpp
@@ -55,7 +55,6 @@ class DL_Group_Data final
Modular_Reducer m_mod_p;
std::shared_ptr<const Montgomery_Exponentation_State> m_monty;
size_t m_p_bits;
- size_t m_q_bits;
};
//static
diff --git a/src/lib/pubkey/dl_group/dl_group.h b/src/lib/pubkey/dl_group/dl_group.h
index 823c0ba95..2bd79e3dd 100644
--- a/src/lib/pubkey/dl_group/dl_group.h
+++ b/src/lib/pubkey/dl_group/dl_group.h
@@ -105,6 +105,13 @@ class BOTAN_PUBLIC_API(2,0) DL_Group final
DL_Group(const uint8_t ber[], size_t ber_len, Format format);
/**
+ * Decode a BER-encoded DL group param
+ */
+ template<typename Alloc>
+ DL_Group(const std::vector<uint8_t, Alloc>& ber, Format format) :
+ DL_Group(ber.data(), ber.size(), format) {}
+
+ /**
* Get the prime p.
* @return prime p
*/
@@ -181,13 +188,13 @@ class BOTAN_PUBLIC_API(2,0) DL_Group final
* @param ber a vector containing the DER/BER encoded group
* @param format the format of the encoded group
*/
- void BOTAN_DEPRECATED("Use DL_Group(ber, Format)") BER_decode(const std::vector<uint8_t>& ber, Format format);
+ void BER_decode(const std::vector<uint8_t>& ber, Format format);
/**
* Decode a PEM encoded group into this instance.
* @param pem the PEM encoding of the group
*/
- void BOTAN_DEPRECATED("Use DL_Group(std::string)") PEM_decode(const std::string& pem);
+ void PEM_decode(const std::string& pem);
/**
* Return PEM representation of named DL group
diff --git a/src/lib/pubkey/dsa/dsa.cpp b/src/lib/pubkey/dsa/dsa.cpp
index 7b4cbebfb..f1d412013 100644
--- a/src/lib/pubkey/dsa/dsa.cpp
+++ b/src/lib/pubkey/dsa/dsa.cpp
@@ -47,14 +47,14 @@ DSA_PrivateKey::DSA_PrivateKey(RandomNumberGenerator& rng,
else
m_x = x_arg;
- m_y = power_mod(group_g(), m_x, group_p());
+ m_y = m_group.power_g_p(m_x);
}
DSA_PrivateKey::DSA_PrivateKey(const AlgorithmIdentifier& alg_id,
const secure_vector<uint8_t>& key_bits) :
DL_Scheme_PrivateKey(alg_id, key_bits, DL_Group::ANSI_X9_57)
{
- m_y = power_mod(group_g(), m_x, group_p());
+ m_y = m_group.power_g_p(m_x);
}
/*