1#include <vanetza/security/openssl_wrapper.hpp>
2#include <vanetza/security/public_key.hpp>
3#include <vanetza/security/signature.hpp>
5#include <openssl/bio.h>
7#include <openssl/err.h>
8#include <openssl/evp.h>
24static const char* reason_error_string(
Exception::code_type err)
26 const char* msg = ERR_reason_error_string(err);
27 return msg ? msg :
"unknown reason";
30static const char* library_error_string(
Exception::code_type err)
32 const char* msg = ERR_lib_error_string(err);
33 return msg ? msg :
"unknown library";
45Exception::Exception(
const std::string& msg) :
46 std::runtime_error(msg),
47 m_error(ERR_get_error())
51Exception::Exception(code_type err,
const std::string& msg) :
52 std::runtime_error(msg),
59 return reason_error_string(m_error);
64 return library_error_string(m_error);
69 check(bignum !=
nullptr);
72BigNumber::BigNumber(
const uint8_t* arr, std::size_t len) : bignum(BN_bin2bn(arr, len,
nullptr))
74 check(bignum !=
nullptr);
79 BN_clear_free(bignum);
84 check(ctx !=
nullptr);
94Point::Point(
const EC_GROUP* group) : point(EC_POINT_new(group))
96 check(point !=
nullptr);
101 std::swap(point, other.point);
106 std::swap(point, other.point);
112 EC_POINT_free(point);
115Group::Group(
int nid) : group(EC_GROUP_new_by_curve_name(nid))
117 check(group !=
nullptr);
122 EC_GROUP_clear_free(group);
125Signature::Signature(ECDSA_SIG* sig) : signature(sig)
131 Signature(convert_for_signing(ecdsa.R), ecdsa.s)
140Signature::Signature(
const ByteBuffer& r,
const ByteBuffer& s) :
141 signature(ECDSA_SIG_new())
145 BIGNUM* bn_r = BN_bin2bn(r.data(), r.size(),
nullptr);
146 BIGNUM* bn_s = BN_bin2bn(s.data(), s.size(),
nullptr);
147 if (!ECDSA_SIG_set0(signature, bn_r, bn_s)) {
156 std::swap(signature, other.signature);
161 std::swap(signature, other.signature);
167 ECDSA_SIG_free(signature);
170Key::Key() : eckey(EC_KEY_new())
175Key::Key(
int nid) : eckey(EC_KEY_new_by_curve_name(nid))
180Key::Key(EC_KEY* key) : eckey(key)
184Key::Key(
Key&& other) : eckey(
nullptr)
186 std::swap(eckey, other.eckey);
191 std::swap(eckey, other.eckey);
200Bio::Bio(BIO* bio) : bio(bio)
204Bio::Bio(
Bio&& other) : bio(
nullptr)
206 std::swap(bio, other.bio);
211 std::swap(bio, other.bio);
220EvpKey::EvpKey(EVP_PKEY* pkey) : pkey(pkey)
226 std::swap(pkey, other.pkey);
231 std::swap(pkey, other.pkey);
EcdsaSignature specified in TS 103 097 v1.2.1, section 4.2.9.