Vanetza
Loading...
Searching...
No Matches
openssl_wrapper.hpp
1
#ifndef OPENSSL_WRAPPER_HPP_GUFJGICT
2
#define OPENSSL_WRAPPER_HPP_GUFJGICT
3
4
#include <vanetza/common/byte_buffer.hpp>
5
#include <boost/core/noncopyable.hpp>
6
#include <openssl/bn.h>
7
#include <openssl/ecdsa.h>
8
#include <openssl/err.h>
9
#include <array>
10
#include <cstdint>
11
#include <stdexcept>
12
13
namespace
vanetza
14
{
15
namespace
security
16
{
17
18
// forward declaration
19
struct
EcdsaSignature;
20
struct
Signature
;
21
22
namespace
openssl
23
{
24
25
/**
26
* Check valid condition
27
* \param valid If false stored OpenSSL error will be thrown
28
*/
29
void
check(
bool
valid);
30
31
32
class
Exception
:
public
std::runtime_error
33
{
34
public
:
35
using
code_type =
decltype
(ERR_get_error());
36
37
Exception
();
38
explicit
Exception
(code_type err);
39
};
40
41
42
class
BigNumber
:
private
boost::noncopyable
43
{
44
public
:
45
BigNumber
();
46
~BigNumber
();
47
48
BigNumber
(
const
ByteBuffer& buf) :
49
BigNumber
(buf.data(), buf.size())
50
{
51
}
52
53
template
<std::
size_t
N>
54
BigNumber
(
const
std::array<uint8_t, N>& bin) :
55
BigNumber
(bin.data(), bin.size())
56
{
57
}
58
59
operator
BIGNUM*() {
return
bignum; }
60
BIGNUM* move();
61
62
private
:
63
BigNumber
(
const
uint8_t*, std::size_t);
64
65
BIGNUM* bignum;
66
};
67
68
69
class
BigNumberContext
:
private
boost::noncopyable
70
{
71
public
:
72
BigNumberContext
();
73
~BigNumberContext
();
74
75
operator
BN_CTX*() {
return
ctx; }
76
77
private
:
78
BN_CTX* ctx;
79
};
80
81
82
class
Group
:
private
boost::noncopyable
83
{
84
public
:
85
explicit
Group
(
int
nid);
86
~Group
();
87
88
operator
EC_GROUP*() {
return
group; }
89
90
private
:
91
EC_GROUP* group;
92
};
93
94
95
class
Point
:
private
boost::noncopyable
96
{
97
public
:
98
explicit
Point
(
const
EC_GROUP* group);
99
Point
(
Point
&&);
100
Point
& operator=(
Point
&&);
101
~Point
();
102
103
operator
EC_POINT*() {
return
point; }
104
105
private
:
106
EC_POINT* point;
107
};
108
109
110
class
Signature
:
private
boost::noncopyable
111
{
112
public
:
113
explicit
Signature
(ECDSA_SIG* sig);
114
explicit
Signature
(
const
EcdsaSignature
& sig);
115
explicit
Signature
(
const
security::Signature
& sig);
116
Signature
(
Signature
&&);
117
Signature
& operator=(
Signature
&&);
118
~Signature
();
119
120
operator
const
ECDSA_SIG*() {
return
signature; }
121
const
ECDSA_SIG* operator->()
const
{
return
signature; }
122
ECDSA_SIG* operator->() {
return
signature; }
123
operator
bool() {
return
signature !=
nullptr
; }
124
125
private
:
126
Signature
(
const
ByteBuffer& r,
const
ByteBuffer& s);
127
128
ECDSA_SIG* signature;
129
};
130
131
132
class
Key
133
{
134
public
:
135
Key
();
136
explicit
Key
(
int
nid);
137
// non-copyable
138
Key
(
const
Key
&) =
delete
;
139
Key
& operator=(
const
Key
&) =
delete
;
140
// but movable
141
Key
(
Key
&&);
142
Key
& operator=(
Key
&&);
143
~Key
();
144
145
operator
EC_KEY*() {
return
eckey; }
146
147
private
:
148
EC_KEY* eckey;
149
};
150
151
}
// namespace openssl
152
}
// namespace security
153
}
// namespace vanetza
154
155
#endif
/* OPENSSL_WRAPPER_HPP_GUFJGICT */
156
vanetza::security::openssl::BigNumberContext
Definition:
openssl_wrapper.hpp:70
vanetza::security::openssl::BigNumber
Definition:
openssl_wrapper.hpp:43
vanetza::security::openssl::Exception
Definition:
openssl_wrapper.hpp:33
vanetza::security::openssl::Group
Definition:
openssl_wrapper.hpp:83
vanetza::security::openssl::Key
Definition:
openssl_wrapper.hpp:133
vanetza::security::openssl::Point
Definition:
openssl_wrapper.hpp:96
vanetza::security::openssl::Signature
Definition:
openssl_wrapper.hpp:111
Signature
Definition:
Signature.h:33
vanetza::security::EcdsaSignature
EcdsaSignature specified in TS 103 097 v1.2.1, section 4.2.9.
Definition:
signature.hpp:17
vanetza::security::Signature
Definition:
signature.hpp:38
vanetza
security
openssl_wrapper.hpp
Generated on Thu Nov 30 2023 12:03:35 for Vanetza by
1.9.6