diff options
author | lloyd <[email protected]> | 2010-03-13 19:31:27 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-03-13 19:31:27 +0000 |
commit | 634f3d27f7faad1dc558821382f71ecc2194637d (patch) | |
tree | dd4e626a4ac3ff5c928460b9e133007023d3321c /src/pubkey | |
parent | 1fe724175fdad94d724d401c46b5187f5f539136 (diff) | |
parent | 72a154f3d7eef286b42a116232f8b7be88ccb6d6 (diff) |
propagate from branch 'net.randombit.botan' (head aabb4c3bc2207ceac1920573293b95d138a185df)
to branch 'net.randombit.botan.c++0x' (head 179172dd6952f15f832855f4ec0ac48cb1e08188)
Diffstat (limited to 'src/pubkey')
-rw-r--r-- | src/pubkey/ecdsa/ecdsa.cpp | 12 | ||||
-rw-r--r-- | src/pubkey/ecdsa/ecdsa.h | 2 | ||||
-rw-r--r-- | src/pubkey/gost_3410/gost_3410.cpp | 4 | ||||
-rw-r--r-- | src/pubkey/gost_3410/gost_3410.h | 4 |
4 files changed, 12 insertions, 10 deletions
diff --git a/src/pubkey/ecdsa/ecdsa.cpp b/src/pubkey/ecdsa/ecdsa.cpp index afca6cc73..40ae7c3b9 100644 --- a/src/pubkey/ecdsa/ecdsa.cpp +++ b/src/pubkey/ecdsa/ecdsa.cpp @@ -14,7 +14,8 @@ namespace Botan { ECDSA_Signature_Operation::ECDSA_Signature_Operation(const ECDSA_PrivateKey& ecdsa) : base_point(ecdsa.domain().get_base_point()), order(ecdsa.domain().get_order()), - x(ecdsa.private_value()) + x(ecdsa.private_value()), + mod_order(order) { } @@ -30,17 +31,15 @@ ECDSA_Signature_Operation::sign(const byte msg[], u32bit msg_len, while(k >= order) k.randomize(rng, order.bits() - 1); - BigInt e(msg, msg_len); + BigInt m(msg, msg_len); PointGFp k_times_P = base_point * k; - BigInt r = k_times_P.get_affine_x() % order; + BigInt r = mod_order.reduce(k_times_P.get_affine_x()); if(r == 0) throw Internal_Error("ECDSA_Signature_Operation: r was zero"); - BigInt k_inv = inverse_mod(k, order); - - BigInt s = (((r * x) + e) * k_inv) % order; + BigInt s = mod_order.multiply(inverse_mod(k, order), mul_add(x, r, m)); SecureVector<byte> output(2*order.bytes()); r.binary_encode(output + (output.size() / 2 - r.bytes())); @@ -72,6 +71,7 @@ bool ECDSA_Verification_Operation::verify(const byte msg[], u32bit msg_len, BigInt w = inverse_mod(s, order); PointGFp R = w * (e * base_point + r * public_point); + if(R.is_zero()) return false; diff --git a/src/pubkey/ecdsa/ecdsa.h b/src/pubkey/ecdsa/ecdsa.h index e20a234fc..cb4893002 100644 --- a/src/pubkey/ecdsa/ecdsa.h +++ b/src/pubkey/ecdsa/ecdsa.h @@ -11,6 +11,7 @@ #define BOTAN_ECDSA_KEY_H__ #include <botan/ecc_key.h> +#include <botan/reducer.h> #include <botan/pk_ops.h> namespace Botan { @@ -102,6 +103,7 @@ class BOTAN_DLL ECDSA_Signature_Operation : public PK_Ops::Signature const PointGFp& base_point; const BigInt& order; const BigInt& x; + Modular_Reducer mod_order; }; class BOTAN_DLL ECDSA_Verification_Operation : public PK_Ops::Verification diff --git a/src/pubkey/gost_3410/gost_3410.cpp b/src/pubkey/gost_3410/gost_3410.cpp index c5cc1ddbd..0ba55cdd9 100644 --- a/src/pubkey/gost_3410/gost_3410.cpp +++ b/src/pubkey/gost_3410/gost_3410.cpp @@ -79,7 +79,7 @@ GOST_3410_Signature_Operation::GOST_3410_Signature_Operation( SecureVector<byte> GOST_3410_Signature_Operation::sign(const byte msg[], u32bit msg_len, - RandomNumberGenerator& rng) const + RandomNumberGenerator& rng) { BigInt k; do @@ -117,7 +117,7 @@ GOST_3410_Verification_Operation::GOST_3410_Verification_Operation(const GOST_34 } bool GOST_3410_Verification_Operation::verify(const byte msg[], u32bit msg_len, - const byte sig[], u32bit sig_len) const + const byte sig[], u32bit sig_len) { if(sig_len != order.bytes()*2) return false; diff --git a/src/pubkey/gost_3410/gost_3410.h b/src/pubkey/gost_3410/gost_3410.h index ffdbc6e19..36fa2912d 100644 --- a/src/pubkey/gost_3410/gost_3410.h +++ b/src/pubkey/gost_3410/gost_3410.h @@ -106,7 +106,7 @@ class BOTAN_DLL GOST_3410_Signature_Operation : public PK_Ops::Signature u32bit max_input_bits() const { return order.bits(); } SecureVector<byte> sign(const byte msg[], u32bit msg_len, - RandomNumberGenerator& rng) const; + RandomNumberGenerator& rng); private: const PointGFp& base_point; @@ -126,7 +126,7 @@ class BOTAN_DLL GOST_3410_Verification_Operation : public PK_Ops::Verification bool with_recovery() const { return false; } bool verify(const byte msg[], u32bit msg_len, - const byte sig[], u32bit sig_len) const; + const byte sig[], u32bit sig_len); private: const PointGFp& base_point; const PointGFp& public_point; |