1#include <vanetza/security/openssl_wrapper.hpp>
2#include <vanetza/security/public_key.hpp>
3#include <vanetza/security/signature.hpp>
20Exception::Exception() : Exception(ERR_get_error())
24Exception::Exception(code_type err) :
25 std::runtime_error(ERR_reason_error_string(err))
29BigNumber::BigNumber() : bignum(BN_new())
31 check(bignum !=
nullptr);
34BigNumber::BigNumber(
const uint8_t* arr, std::size_t len) : BigNumber()
36 BN_bin2bn(arr, len, bignum);
39BIGNUM* BigNumber::move()
41 BIGNUM* ptr =
nullptr;
42 std::swap(ptr, bignum);
46BigNumber::~BigNumber()
49 BN_clear_free(bignum);
53BigNumberContext::BigNumberContext() : ctx(BN_CTX_new())
55 check(ctx !=
nullptr);
59BigNumberContext::~BigNumberContext()
65Point::Point(
const EC_GROUP* group) : point(EC_POINT_new(group))
67 check(point !=
nullptr);
70Point::Point(Point&& other) : point(nullptr)
72 std::swap(point, other.point);
75Point& Point::operator=(Point&& other)
77 std::swap(point, other.point);
86Group::Group(
int nid) : group(EC_GROUP_new_by_curve_name(nid))
88 check(group !=
nullptr);
93 EC_GROUP_clear_free(group);
96Signature::Signature(ECDSA_SIG* sig) : signature(sig)
101Signature::Signature(
const EcdsaSignature& ecdsa) :
102 Signature(convert_for_signing(ecdsa.R), ecdsa.s)
106Signature::Signature(
const security::Signature& sig) :
111Signature::Signature(
const ByteBuffer& r,
const ByteBuffer& s) :
112 signature(ECDSA_SIG_new())
115#if OPENSSL_API_COMPAT < 0x10100000L
116 BN_bin2bn(r.data(), r.size(), signature->r);
117 BN_bin2bn(s.data(), s.size(), signature->s);
119 BigNumber bn_r { r };
120 BigNumber bn_s { s };
122 ECDSA_SIG_set0(signature, bn_r.move(), bn_s.move());
126Signature::Signature(
Signature&& other) : signature(nullptr)
128 std::swap(signature, other.signature);
133 std::swap(signature, other.signature);
137Signature::~Signature()
139 ECDSA_SIG_free(signature);
142Key::Key() : eckey(EC_KEY_new())
147Key::Key(
int nid) : eckey(EC_KEY_new_by_curve_name(nid))
152Key::Key(Key&& other) : eckey(nullptr)
154 std::swap(eckey, other.eckey);
157Key& Key::operator=(Key&& other)
159 std::swap(eckey, other.eckey);