From 200e88602c2f5d3b09ee6f1caaac3d14da6c8860 Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 2 Mar 2010 19:11:21 +0000 Subject: Remove ECDSA_Signature encoding/decoding cruft --- src/cert/cvc/eac_obj.h | 10 +++----- src/cert/cvc/ecdsa_sig.cpp | 48 ++++++++++++++++------------------ src/cert/cvc/ecdsa_sig.h | 64 ++++++++++------------------------------------ 3 files changed, 39 insertions(+), 83 deletions(-) (limited to 'src/cert/cvc') 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::make_signature(PK_Signer& signer, RandomNumberGenerator& rng) { // this is the signature as a der sequence - SecureVector seq_sig = signer.sign_message(tbs_bits, rng); - - ECDSA_Signature sig(decode_seq(seq_sig)); - SecureVector concat_sig(sig.get_concatenation()); - return concat_sig; + ECDSA_Signature sig(signer.sign_message(tbs_bits, rng)); + return sig.get_concatenation(); } template @@ -106,8 +103,7 @@ bool EAC1_1_obj::check_signature(Public_Key& pub_key) const if(!dynamic_cast(&pub_key)) return false; - std::auto_ptr enc(new ECDSA_Signature_Encoder(&m_sig)); - SecureVector seq_sig = enc->signature_bits(); + SecureVector seq_sig = m_sig.DER_encode(); SecureVector to_sign = tbs_data(); PK_Verifying_wo_MR_Key& sig_key = dynamic_cast(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 -#include 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& 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 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 ECDSA_Signature::get_concatenation() const +MemoryVector 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 ECDSA_Signature::get_concatenation() const return result; } -ECDSA_Signature decode_seq(const MemoryRegion& seq) - { - ECDSA_Signature sig; - - std::auto_ptr dec(new ECDSA_Signature_Decoder(&sig)); - dec->signature_bits(seq); - return sig; - } - ECDSA_Signature decode_concatenation(const MemoryRegion& 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& 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 get_concatenation() const; - private: - BigInt m_r; - BigInt m_s; - }; + MemoryVector 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 DER_encode() const; -class BOTAN_DLL ECDSA_Signature_Decoder - { - public: - void signature_bits(const MemoryRegion& 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 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& seq); ECDSA_Signature decode_concatenation(const MemoryRegion& concatenation); } -- cgit v1.2.3