Botan 1.10.17
ecdsa_sig.cpp
Go to the documentation of this file.
1/*
2* ECDSA Signature
3* (C) 2007 Falko Strenzke, FlexSecure GmbH
4* (C) 2008-2010 Jack Lloyd
5*
6* Distributed under the terms of the Botan license
7*/
8
9#include <botan/ecdsa_sig.h>
10
11namespace Botan {
12
14 {
15 BER_Decoder(ber)
16 .start_cons(SEQUENCE)
17 .decode(m_r)
18 .decode(m_s)
19 .end_cons()
20 .verify_end();
21 }
22
32
34 {
35 // use the larger
36 const size_t enc_len = m_r > m_s ? m_r.bytes() : m_s.bytes();
37
38 SecureVector<byte> sv_r = BigInt::encode_1363(m_r, enc_len);
39 SecureVector<byte> sv_s = BigInt::encode_1363(m_s, enc_len);
40
41 SecureVector<byte> result(sv_r);
42 result += sv_s;
43 return result;
44 }
45
47 {
48 if(concat.size() % 2 != 0)
49 throw Invalid_Argument("Erroneous length of signature");
50
51 const size_t rs_len = concat.size() / 2;
52
53 BigInt r = BigInt::decode(&concat[0], rs_len);
54 BigInt s = BigInt::decode(&concat[rs_len], rs_len);
55
56 return ECDSA_Signature(r, s);
57 }
58
59}
BER_Decoder(DataSource &)
Definition ber_dec.cpp:264
static SecureVector< byte > encode_1363(const BigInt &n, size_t bytes)
Definition big_code.cpp:78
static BigInt decode(const byte buf[], size_t length, Base base=Binary)
Definition big_code.cpp:102
DER_Encoder & start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
Definition der_enc.cpp:135
SecureVector< byte > get_contents()
Definition der_enc.cpp:122
DER_Encoder & end_cons()
Definition der_enc.cpp:145
DER_Encoder & encode(bool b)
Definition der_enc.cpp:209
const BigInt & get_r() const
Definition ecdsa_sig.h:32
MemoryVector< byte > get_concatenation() const
Definition ecdsa_sig.cpp:33
const BigInt & get_s() const
Definition ecdsa_sig.h:33
MemoryVector< byte > DER_encode() const
Definition ecdsa_sig.cpp:23
size_t size() const
Definition secmem.h:29
std::invalid_argument Invalid_Argument
Definition exceptn.h:20
@ SEQUENCE
Definition asn1_int.h:35
ECDSA_Signature decode_concatenation(const MemoryRegion< byte > &concat)
Definition ecdsa_sig.cpp:46