aboutsummaryrefslogtreecommitdiffstats
path: root/lib/cert/cvc/ecdsa_sig.h
blob: 1c3b506cbbde7a3f197dfe2e47afb0fae7407a3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* ECDSA Signature
* (C) 2007 Falko Strenzke, FlexSecure GmbH
* (C) 2008-2010 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/

#ifndef BOTAN_ECDSA_SIGNATURE_H__
#define BOTAN_ECDSA_SIGNATURE_H__

#include <botan/bigint.h>
#include <botan/der_enc.h>
#include <botan/ber_dec.h>

namespace Botan {

/**
* Class representing an ECDSA signature
*/
class BOTAN_DLL ECDSA_Signature
   {
   public:
      friend class ECDSA_Signature_Decoder;

      ECDSA_Signature() {}
      ECDSA_Signature(const BigInt& r, const BigInt& s) :
         m_r(r), m_s(s) {}

      ECDSA_Signature(const std::vector<byte>& ber);

      const BigInt& get_r() const { return m_r; }
      const BigInt& get_s() const { return m_s; }

      /**
      * return the r||s
      */
      std::vector<byte> get_concatenation() const;

      std::vector<byte> DER_encode() const;

      bool operator==(const ECDSA_Signature& other) const
         {
         return (get_r() == other.get_r() && get_s() == other.get_s());
         }

   private:
      BigInt m_r;
      BigInt m_s;
   };

inline bool operator!=(const ECDSA_Signature& lhs, const ECDSA_Signature& rhs)
   {
   return !(lhs == rhs);
   }

ECDSA_Signature decode_concatenation(const std::vector<byte>& concatenation);

}

#endif