diff options
Diffstat (limited to 'src/cert/cvc/ecdsa_sig.cpp')
-rw-r--r-- | src/cert/cvc/ecdsa_sig.cpp | 50 |
1 files changed, 23 insertions, 27 deletions
diff --git a/src/cert/cvc/ecdsa_sig.cpp b/src/cert/cvc/ecdsa_sig.cpp index 1a60f7aa8..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 const& 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> const 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,16 +42,7 @@ SecureVector<byte> const ECDSA_Signature::get_concatenation() const return result; } -ECDSA_Signature const decode_seq(MemoryRegion<byte> const& seq) - { - ECDSA_Signature sig; - - std::unique_ptr<ECDSA_Signature_Decoder> dec(new ECDSA_Signature_Decoder(&sig)); - dec->signature_bits(seq); - return sig; - } - -ECDSA_Signature const decode_concatenation(MemoryRegion<byte> const& concat) +ECDSA_Signature decode_concatenation(const MemoryRegion<byte>& concat) { if(concat.size() % 2 != 0) throw Invalid_Argument("Erroneous length of signature"); |