diff options
author | lloyd <[email protected]> | 2010-03-02 19:11:21 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-03-02 19:11:21 +0000 |
commit | 200e88602c2f5d3b09ee6f1caaac3d14da6c8860 (patch) | |
tree | 94d32d044a6ff39ee28c74c48a1b577063739eaa /src/cert | |
parent | 732056d8876b669159b3ade4b9786528a3d2366f (diff) |
Remove ECDSA_Signature encoding/decoding cruft
Diffstat (limited to 'src/cert')
-rw-r--r-- | src/cert/cvc/eac_obj.h | 10 | ||||
-rw-r--r-- | src/cert/cvc/ecdsa_sig.cpp | 48 | ||||
-rw-r--r-- | src/cert/cvc/ecdsa_sig.h | 64 |
3 files changed, 39 insertions, 83 deletions
diff --git a/src/cert/cvc/eac_obj.h b/src/cert/cvc/eac_obj.h index 1c6802d58..82aaee787 100644 --- a/src/cert/cvc/eac_obj.h +++ b/src/cert/cvc/eac_obj.h @@ -66,11 +66,8 @@ EAC1_1_obj<Derived>::make_signature(PK_Signer& signer, RandomNumberGenerator& rng) { // this is the signature as a der sequence - SecureVector<byte> seq_sig = signer.sign_message(tbs_bits, rng); - - ECDSA_Signature sig(decode_seq(seq_sig)); - SecureVector<byte> concat_sig(sig.get_concatenation()); - return concat_sig; + ECDSA_Signature sig(signer.sign_message(tbs_bits, rng)); + return sig.get_concatenation(); } template<typename Derived> @@ -106,8 +103,7 @@ bool EAC1_1_obj<Derived>::check_signature(Public_Key& pub_key) const if(!dynamic_cast<PK_Verifying_wo_MR_Key*>(&pub_key)) return false; - std::auto_ptr<ECDSA_Signature_Encoder> enc(new ECDSA_Signature_Encoder(&m_sig)); - SecureVector<byte> seq_sig = enc->signature_bits(); + SecureVector<byte> seq_sig = m_sig.DER_encode(); SecureVector<byte> to_sign = tbs_data(); PK_Verifying_wo_MR_Key& sig_key = dynamic_cast<PK_Verifying_wo_MR_Key&>(pub_key); diff --git a/src/cert/cvc/ecdsa_sig.cpp b/src/cert/cvc/ecdsa_sig.cpp index f49aa1b09..e003bb369 100644 --- a/src/cert/cvc/ecdsa_sig.cpp +++ b/src/cert/cvc/ecdsa_sig.cpp @@ -1,31 +1,36 @@ +/* +* ECDSA Signature +* (C) 2007 Falko Strenzke, FlexSecure GmbH +* (C) 2008-2010 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ #include <botan/ecdsa_sig.h> -#include <memory> namespace Botan { -ECDSA_Signature::ECDSA_Signature(const BigInt& r, const BigInt& s) - : m_r(r), - m_s(s) - {} - -ECDSA_Signature::ECDSA_Signature(const ECDSA_Signature& other) - : m_r(other.m_r), m_s(other.m_s) - {} - -ECDSA_Signature& ECDSA_Signature::operator=(const ECDSA_Signature& other) +ECDSA_Signature::ECDSA_Signature(const MemoryRegion<byte>& ber) { - m_r = other.m_r; - m_s = other.m_s; - return *this; + BER_Decoder(ber) + .start_cons(SEQUENCE) + .decode(m_r) + .decode(m_s) + .end_cons() + .verify_end(); } -bool operator==(const ECDSA_Signature& lhs, const ECDSA_Signature& rhs) +MemoryVector<byte> ECDSA_Signature::DER_encode() const { - return (lhs.get_r() == rhs.get_r() && lhs.get_s() == rhs.get_s()); + return DER_Encoder() + .start_cons(SEQUENCE) + .encode(get_r()) + .encode(get_s()) + .end_cons() + .get_contents(); } -SecureVector<byte> ECDSA_Signature::get_concatenation() const +MemoryVector<byte> ECDSA_Signature::get_concatenation() const { u32bit enc_len = m_r > m_s ? m_r.bytes() : m_s.bytes(); // use the larger @@ -37,15 +42,6 @@ SecureVector<byte> ECDSA_Signature::get_concatenation() const return result; } -ECDSA_Signature decode_seq(const MemoryRegion<byte>& seq) - { - ECDSA_Signature sig; - - std::auto_ptr<ECDSA_Signature_Decoder> dec(new ECDSA_Signature_Decoder(&sig)); - dec->signature_bits(seq); - return sig; - } - ECDSA_Signature decode_concatenation(const MemoryRegion<byte>& concat) { if(concat.size() % 2 != 0) diff --git a/src/cert/cvc/ecdsa_sig.h b/src/cert/cvc/ecdsa_sig.h index 3e202d703..1397a92b1 100644 --- a/src/cert/cvc/ecdsa_sig.h +++ b/src/cert/cvc/ecdsa_sig.h @@ -1,5 +1,5 @@ /* -* ECDSA +* ECDSA Signature * (C) 2007 Falko Strenzke, FlexSecure GmbH * (C) 2008-2010 Jack Lloyd * @@ -21,9 +21,10 @@ class BOTAN_DLL ECDSA_Signature friend class ECDSA_Signature_Decoder; ECDSA_Signature() {} - ECDSA_Signature(const BigInt& r, const BigInt& s); - ECDSA_Signature(const ECDSA_Signature& other); - ECDSA_Signature& operator=(const ECDSA_Signature& other); + ECDSA_Signature(const BigInt& r, const BigInt& s) : + m_r(r), m_s(s) {} + + ECDSA_Signature(const MemoryRegion<byte>& ber); const BigInt& get_r() const { return m_r; } const BigInt& get_s() const { return m_s; } @@ -31,62 +32,25 @@ class BOTAN_DLL ECDSA_Signature /** * return the r||s */ - SecureVector<byte> get_concatenation() const; - private: - BigInt m_r; - BigInt m_s; - }; + MemoryVector<byte> get_concatenation() const; -/* Equality of ECDSA_Signature */ -bool operator==(const ECDSA_Signature& lhs, const ECDSA_Signature& rhs); -inline bool operator!=(const ECDSA_Signature& lhs, const ECDSA_Signature& rhs) - { - return !(lhs == rhs); - } + MemoryVector<byte> DER_encode() const; -class BOTAN_DLL ECDSA_Signature_Decoder - { - public: - void signature_bits(const MemoryRegion<byte>& bits) + bool operator==(const ECDSA_Signature& other) const { - BER_Decoder(bits) - .start_cons(SEQUENCE) - .decode(m_signature->m_r) - .decode(m_signature->m_s) - .verify_end() - .end_cons(); + return (get_r() == other.get_r() && get_s() == other.get_s()); } - ECDSA_Signature_Decoder(ECDSA_Signature* signature) : - m_signature(signature) - {} - private: - ECDSA_Signature* m_signature; + BigInt m_r; + BigInt m_s; }; -class BOTAN_DLL ECDSA_Signature_Encoder +inline bool operator!=(const ECDSA_Signature& lhs, const ECDSA_Signature& rhs) { - public: - MemoryVector<byte> signature_bits() const - { - return DER_Encoder() - .start_cons(SEQUENCE) - .encode(m_signature->get_r()) - .encode(m_signature->get_s()) - .end_cons() - .get_contents(); - } - - ECDSA_Signature_Encoder(const ECDSA_Signature* signature) : - m_signature(signature) - {} - - private: - const ECDSA_Signature* m_signature; - }; + return !(lhs == rhs); + } -ECDSA_Signature decode_seq(const MemoryRegion<byte>& seq); ECDSA_Signature decode_concatenation(const MemoryRegion<byte>& concatenation); } |