diff options
Diffstat (limited to 'src/lib/pubkey/dsa/dsa.cpp')
-rw-r--r-- | src/lib/pubkey/dsa/dsa.cpp | 92 |
1 files changed, 46 insertions, 46 deletions
diff --git a/src/lib/pubkey/dsa/dsa.cpp b/src/lib/pubkey/dsa/dsa.cpp index ec0830533..63b7bd07e 100644 --- a/src/lib/pubkey/dsa/dsa.cpp +++ b/src/lib/pubkey/dsa/dsa.cpp @@ -20,8 +20,8 @@ namespace Botan { */ DSA_PublicKey::DSA_PublicKey(const DL_Group& grp, const BigInt& y1) { - group = grp; - y = y1; + m_group = grp; + m_y = y1; } /* @@ -31,13 +31,13 @@ DSA_PrivateKey::DSA_PrivateKey(RandomNumberGenerator& rng, const DL_Group& grp, const BigInt& x_arg) { - group = grp; - x = x_arg; + m_group = grp; + m_x = x_arg; - if(x == 0) - x = BigInt::random_integer(rng, 2, group_q() - 1); + if(m_x == 0) + m_x = BigInt::random_integer(rng, 2, group_q() - 1); - y = power_mod(group_g(), x, group_p()); + m_y = power_mod(group_g(), m_x, group_p()); if(x_arg == 0) gen_check(rng); @@ -50,7 +50,7 @@ DSA_PrivateKey::DSA_PrivateKey(const AlgorithmIdentifier& alg_id, RandomNumberGenerator& rng) : DL_Scheme_PrivateKey(alg_id, key_bits, DL_Group::ANSI_X9_57) { - y = power_mod(group_g(), x, group_p()); + m_y = power_mod(group_g(), m_x, group_p()); load_check(rng); } @@ -60,7 +60,7 @@ DSA_PrivateKey::DSA_PrivateKey(const AlgorithmIdentifier& alg_id, */ bool DSA_PrivateKey::check_key(RandomNumberGenerator& rng, bool strong) const { - if(!DL_Scheme_PrivateKey::check_key(rng, strong) || x >= group_q()) + if(!DL_Scheme_PrivateKey::check_key(rng, strong) || m_x >= group_q()) return false; if(!strong) @@ -80,25 +80,25 @@ class DSA_Signature_Operation : public PK_Ops::Signature_with_EMSA typedef DSA_PrivateKey Key_Type; DSA_Signature_Operation(const DSA_PrivateKey& dsa, const std::string& emsa) : PK_Ops::Signature_with_EMSA(emsa), - q(dsa.group_q()), - x(dsa.get_x()), - powermod_g_p(dsa.group_g(), dsa.group_p()), - mod_q(dsa.group_q()), + 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_hash(hash_for_deterministic_signature(emsa)) { } size_t message_parts() const override { return 2; } - size_t message_part_size() const override { return q.bytes(); } - size_t max_input_bits() const override { return q.bits(); } + size_t message_part_size() const override { return m_q.bytes(); } + size_t max_input_bits() const override { return m_q.bits(); } secure_vector<byte> raw_sign(const byte msg[], size_t msg_len, RandomNumberGenerator& rng) override; private: - const BigInt& q; - const BigInt& x; - Fixed_Base_Power_Mod powermod_g_p; - Modular_Reducer mod_q; + const BigInt& m_q; + const BigInt& m_x; + Fixed_Base_Power_Mod m_powermod_g_p; + Modular_Reducer m_mod_q; std::string m_hash; }; @@ -108,23 +108,23 @@ DSA_Signature_Operation::raw_sign(const byte msg[], size_t msg_len, { BigInt i(msg, msg_len); - while(i >= q) - i -= q; + while(i >= m_q) + i -= m_q; - const BigInt k = generate_rfc6979_nonce(x, q, i, m_hash); + const BigInt k = generate_rfc6979_nonce(m_x, m_q, i, m_hash); auto future_r = std::async(std::launch::async, - [&]() { return mod_q.reduce(powermod_g_p(k)); }); + [&]() { return m_mod_q.reduce(m_powermod_g_p(k)); }); - BigInt s = inverse_mod(k, q); + BigInt s = inverse_mod(k, m_q); const BigInt r = future_r.get(); - s = mod_q.multiply(s, mul_add(x, r, i)); + s = m_mod_q.multiply(s, mul_add(m_x, r, i)); // With overwhelming probability, a bug rather than actual zero r/s BOTAN_ASSERT(s != 0, "invalid s"); BOTAN_ASSERT(r != 0, "invalid r"); - secure_vector<byte> output(2*q.bytes()); + secure_vector<byte> output(2*m_q.bytes()); r.binary_encode(&output[output.size() / 2 - r.bytes()]); s.binary_encode(&output[output.size() - s.bytes()]); return output; @@ -140,54 +140,54 @@ class DSA_Verification_Operation : public PK_Ops::Verification_with_EMSA DSA_Verification_Operation(const DSA_PublicKey& dsa, const std::string& emsa) : PK_Ops::Verification_with_EMSA(emsa), - q(dsa.group_q()), y(dsa.get_y()) + m_q(dsa.group_q()), m_y(dsa.get_y()) { - powermod_g_p = Fixed_Base_Power_Mod(dsa.group_g(), dsa.group_p()); - powermod_y_p = Fixed_Base_Power_Mod(y, dsa.group_p()); - mod_p = Modular_Reducer(dsa.group_p()); - mod_q = Modular_Reducer(dsa.group_q()); + m_powermod_g_p = Fixed_Base_Power_Mod(dsa.group_g(), dsa.group_p()); + m_powermod_y_p = Fixed_Base_Power_Mod(m_y, dsa.group_p()); + m_mod_p = Modular_Reducer(dsa.group_p()); + m_mod_q = Modular_Reducer(dsa.group_q()); } size_t message_parts() const override { return 2; } - size_t message_part_size() const override { return q.bytes(); } - size_t max_input_bits() const override { return q.bits(); } + size_t message_part_size() const override { return m_q.bytes(); } + size_t max_input_bits() const override { return m_q.bits(); } bool with_recovery() const override { return false; } bool verify(const byte msg[], size_t msg_len, const byte sig[], size_t sig_len) override; private: - const BigInt& q; - const BigInt& y; + const BigInt& m_q; + const BigInt& m_y; - Fixed_Base_Power_Mod powermod_g_p, powermod_y_p; - Modular_Reducer mod_p, mod_q; + Fixed_Base_Power_Mod m_powermod_g_p, m_powermod_y_p; + Modular_Reducer m_mod_p, m_mod_q; }; bool DSA_Verification_Operation::verify(const byte msg[], size_t msg_len, const byte sig[], size_t sig_len) { - if(sig_len != 2*q.bytes() || msg_len > q.bytes()) + if(sig_len != 2*m_q.bytes() || msg_len > m_q.bytes()) return false; - BigInt r(sig, q.bytes()); - BigInt s(sig + q.bytes(), q.bytes()); + BigInt r(sig, m_q.bytes()); + BigInt s(sig + m_q.bytes(), m_q.bytes()); BigInt i(msg, msg_len); - if(r <= 0 || r >= q || s <= 0 || s >= q) + if(r <= 0 || r >= m_q || s <= 0 || s >= m_q) return false; - s = inverse_mod(s, q); + s = inverse_mod(s, m_q); auto future_s_i = std::async(std::launch::async, - [&]() { return powermod_g_p(mod_q.multiply(s, i)); }); + [&]() { return m_powermod_g_p(m_mod_q.multiply(s, i)); }); - BigInt s_r = powermod_y_p(mod_q.multiply(s, r)); + BigInt s_r = m_powermod_y_p(m_mod_q.multiply(s, r)); BigInt s_i = future_s_i.get(); - s = mod_p.multiply(s_i, s_r); + s = m_mod_p.multiply(s_i, s_r); - return (mod_q.reduce(s) == r); + return (m_mod_q.reduce(s) == r); } BOTAN_REGISTER_PK_SIGNATURE_OP("DSA", DSA_Signature_Operation); |