1#ifndef OPENSSL_WRAPPER_HPP_GUFJGICT
2#define OPENSSL_WRAPPER_HPP_GUFJGICT
4#include <vanetza/common/byte_buffer.hpp>
5#include <boost/core/noncopyable.hpp>
7#include <openssl/err.h>
25
26
27
28void check(
bool valid);
34 using code_type =
decltype(ERR_get_error());
37 explicit Exception(code_type err);
38 explicit Exception(
const std::string& msg);
39 explicit Exception(code_type,
const std::string& msg);
40 ~Exception() override =
default;
42 code_type error_code()
const {
return m_error; }
43 const char* reason()
const;
44 const char* library()
const;
47 code_type m_error = 0;
57 BigNumber(
const ByteBuffer& buf) :
62 template<std::size_t N>
63 BigNumber(
const std::array<uint8_t, N>& bin) :
68 operator BIGNUM*() {
return bignum; }
71 BigNumber(
const uint8_t*, std::size_t);
83 operator BN_CTX*() {
return ctx; }
90class Group :
private boost::noncopyable
93 explicit Group(
int nid);
96 operator EC_GROUP*() {
return group; }
103class Point :
private boost::noncopyable
106 explicit Point(
const EC_GROUP* group);
111 operator EC_POINT*() {
return point; }
121 explicit Signature(ECDSA_SIG* sig);
123 explicit Signature(
const security::
Signature& sig);
128 operator
const ECDSA_SIG*() {
return signature; }
129 const ECDSA_SIG* operator->()
const {
return signature; }
130 ECDSA_SIG* operator->() {
return signature; }
131 operator
bool() {
return signature !=
nullptr; }
134 Signature(
const ByteBuffer& r,
const ByteBuffer& s);
136 ECDSA_SIG* signature;
144 explicit Key(
int nid);
145 explicit Key(EC_KEY* key);
147 Key(
const Key&) =
delete;
148 Key& operator=(
const Key&) =
delete;
154 operator EC_KEY*() {
return eckey; }
155 operator
bool()
const {
return eckey !=
nullptr; }
162class Bio :
private boost::noncopyable
165 explicit Bio(BIO* bio);
170 operator BIO*() {
return bio; }
171 operator
bool()
const {
return bio !=
nullptr; }
181 explicit EvpKey(EVP_PKEY* pkey);
186 operator EVP_PKEY*() {
return pkey; }
187 operator
bool()
const {
return pkey !=
nullptr; }
Backend implementation based on OpenSSL.
std::array< uint8_t, 32 > calculate_sha256_digest(const ByteBuffer &data) const
calculate SHA256 digest of data buffer
bool verify_data(const ecdsa256::PublicKey &public_key, const ByteBuffer &data, const EcdsaSignature &sig) override
bool verify_digest(const PublicKey &, const ByteBuffer &digest, const Signature &) override
std::array< uint8_t, 48 > calculate_sha384_digest(const ByteBuffer &data) const
calculate SHA384 digest of data buffer
openssl::Key internal_public_key(const ecdsa256::PublicKey &) const
convert to internal format of public key
openssl::Point internal_ec_point(const PublicKey &) const
convert to internal format of an EC point
ecdsa256::KeyPair generate_key_pair() override
Signature sign_digest(const PrivateKey &, const ByteBuffer &digest) override
EcdsaSignature sign_data(const ecdsa256::PrivateKey &private_key, const ByteBuffer &data_buffer) override
boost::optional< Uncompressed > decompress_point(const EccPoint &ecc_point) override
openssl::Key internal_private_key(const ecdsa256::PrivateKey &) const
convert to internal format of private key
ByteBuffer calculate_hash(HashAlgorithm, const ByteBuffer &) override
calculate hash value of data
Compressed_Lsb_Y_0 specified in TS 103 097 v1.2.1 in section 4.2.5.
Compressed_Lsb_Y_1 specified in TS 103 097 v1.2.1 in section 4.2.5.
EcdsaSignature specified in TS 103 097 v1.2.1, section 4.2.9.
Uncompressed specified in TS 103 097 v1.2.1 in section 4.2.5.
X_Coordinate_Only specified in TS 103 097 v1.2.1 in section 4.2.5.