aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-08-29 18:14:12 -0400
committerJack Lloyd <[email protected]>2017-08-29 18:14:12 -0400
commit20e2ce7f06f41ba75835593b921ffa8ef993e154 (patch)
tree2a94249dc0d5815df7a56ad3b30e105af0a8add9 /src/lib/pubkey
parent1cc43d2f418508a87c58ee1f27ff8d6d68897207 (diff)
Avoid having variable named m_emsa twice in class hierarchy
In fact the variable was only used if we use deterministic nonces, and just to extract the hash name. So just do that once, and only if we are not using random nonces. Flagged by Sonar
Diffstat (limited to 'src/lib/pubkey')
-rw-r--r--src/lib/pubkey/dsa/dsa.cpp12
-rw-r--r--src/lib/pubkey/ecdsa/ecdsa.cpp12
2 files changed, 16 insertions, 8 deletions
diff --git a/src/lib/pubkey/dsa/dsa.cpp b/src/lib/pubkey/dsa/dsa.cpp
index c419eec97..706722d72 100644
--- a/src/lib/pubkey/dsa/dsa.cpp
+++ b/src/lib/pubkey/dsa/dsa.cpp
@@ -83,9 +83,11 @@ class DSA_Signature_Operation : public PK_Ops::Signature_with_EMSA
m_q(dsa.group_q()),
m_x(dsa.get_x()),
m_powermod_g_p(dsa.group_g(), dsa.group_p()),
- m_mod_q(dsa.group_q()),
- m_emsa(emsa)
+ m_mod_q(dsa.group_q())
{
+#if defined(BOTAN_HAS_RFC6979_GENERATOR)
+ m_rfc6979_hash = hash_for_emsa(emsa);
+#endif
}
size_t max_input_bits() const override { return m_q.bits(); }
@@ -97,7 +99,9 @@ class DSA_Signature_Operation : public PK_Ops::Signature_with_EMSA
const BigInt& m_x;
Fixed_Base_Power_Mod m_powermod_g_p;
Modular_Reducer m_mod_q;
- std::string m_emsa;
+#if defined(BOTAN_HAS_RFC6979_GENERATOR)
+ std::string m_rfc6979_hash;
+#endif
};
secure_vector<uint8_t>
@@ -111,7 +115,7 @@ DSA_Signature_Operation::raw_sign(const uint8_t msg[], size_t msg_len,
#if defined(BOTAN_HAS_RFC6979_GENERATOR)
BOTAN_UNUSED(rng);
- const BigInt k = generate_rfc6979_nonce(m_x, m_q, i, hash_for_emsa(m_emsa));
+ const BigInt k = generate_rfc6979_nonce(m_x, m_q, i, m_rfc6979_hash);
#else
const BigInt k = BigInt::random_integer(rng, 1, m_q);
#endif
diff --git a/src/lib/pubkey/ecdsa/ecdsa.cpp b/src/lib/pubkey/ecdsa/ecdsa.cpp
index 72551c8c7..8b0248770 100644
--- a/src/lib/pubkey/ecdsa/ecdsa.cpp
+++ b/src/lib/pubkey/ecdsa/ecdsa.cpp
@@ -55,9 +55,11 @@ class ECDSA_Signature_Operation : public PK_Ops::Signature_with_EMSA
m_order(ecdsa.domain().get_order()),
m_base_point(ecdsa.domain().get_base_point(), m_order),
m_x(ecdsa.private_value()),
- m_mod_order(m_order),
- m_emsa(emsa)
+ m_mod_order(m_order)
{
+#if defined(BOTAN_HAS_RFC6979_GENERATOR)
+ m_rfc6979_hash = hash_for_emsa(emsa);
+#endif
}
size_t max_input_bits() const override { return m_order.bits(); }
@@ -70,7 +72,9 @@ class ECDSA_Signature_Operation : public PK_Ops::Signature_with_EMSA
Blinded_Point_Multiply m_base_point;
const BigInt& m_x;
Modular_Reducer m_mod_order;
- std::string m_emsa;
+#if defined(BOTAN_HAS_RFC6979_GENERATOR)
+ std::string m_rfc6979_hash;
+#endif
};
secure_vector<uint8_t>
@@ -80,7 +84,7 @@ ECDSA_Signature_Operation::raw_sign(const uint8_t msg[], size_t msg_len,
const BigInt m(msg, msg_len);
#if defined(BOTAN_HAS_RFC6979_GENERATOR)
- const BigInt k = generate_rfc6979_nonce(m_x, m_order, m, hash_for_emsa(m_emsa));
+ const BigInt k = generate_rfc6979_nonce(m_x, m_order, m, m_rfc6979_hash);
#else
const BigInt k = BigInt::random_integer(rng, 1, m_order);
#endif