Vanetza
Loading...
Searching...
No Matches
backend.hpp
1#ifndef BACKEND_HPP_ZMRDTY2O
2#define BACKEND_HPP_ZMRDTY2O
3
4#include <vanetza/common/byte_buffer.hpp>
5#include <vanetza/common/factory.hpp>
6#include <vanetza/security/ecdsa256.hpp>
7#include <vanetza/security/hash_algorithm.hpp>
8#include <vanetza/security/private_key.hpp>
9#include <vanetza/security/public_key.hpp>
10#include <vanetza/security/signature.hpp>
11#include <boost/optional/optional.hpp>
12#include <memory>
13#include <string>
14
15namespace vanetza
16{
17namespace security
18{
19
20/**
21 * Interface to cryptographic features
22 */
24{
25public:
26 /**
27 * \brief calculate signature for given data and private key
28 *
29 * \param private_key Secret private key
30 * \param data buffer with plaintext data
31 * \return calculated signature
32 */
33 virtual EcdsaSignature sign_data(const ecdsa256::PrivateKey& private_key, const ByteBuffer& data) = 0;
34
35 /**
36 * \brief calculate signature for given digest and private key
37 *
38 * \param private_key secret private key
39 * \param digest hash value of data
40 * \return calculated signature
41 */
42 virtual Signature sign_digest(const PrivateKey&, const ByteBuffer& digest) = 0;
43
44 /**
45 * \brief try to verify data using public key and signature
46 *
47 * \param public_key Public key
48 * \param data plaintext
49 * \param sig signature of data
50 * \return true if the data could be verified
51 */
52 virtual bool verify_data(const ecdsa256::PublicKey& public_key, const ByteBuffer& data, const EcdsaSignature& sig) = 0;
53
54 /**
55 * \brief try to verify digest using public key and signature
56 *
57 * \param public_key public key
58 * \param digest hash value of data
59 * \param sig signature of data
60 * \return true if data could be verified
61 */
62 virtual bool verify_digest(const PublicKey& public_key, const ByteBuffer& digest, const Signature& sig) = 0;
63
64 /**
65 * \brief decompress a possibly compressed elliptic curve point
66 *
67 * \param ecc_point elliptic curve point
68 * \return uncompressed point
69 */
70 virtual boost::optional<Uncompressed> decompress_point(const EccPoint& ecc_point) = 0;
71
72 /**
73 * \brief calculate hash value of data
74 *
75 * \param algo hash algorithm
76 * \param data buffer with data
77 * \return buffer containing calculated hash value
78 */
79 virtual ByteBuffer calculate_hash(HashAlgorithm algo, const ByteBuffer& data) = 0;
80
81 /**
82 * \brief generate a private key and the corresponding public key
83 * \return generated key pair
84 */
85 virtual ecdsa256::KeyPair generate_key_pair() = 0;
86
87 virtual ~Backend() = default;
88};
89
90/**
91 * \brief get factory containing builtin backend implementations
92 *
93 * Included set of backends depends on CMake build configuration.
94 * At least the "Null" backend is always included.
95 * \return factory
96 */
97const Factory<Backend>& builtin_backends();
98
99/**
100 * \brief create a backend instance
101 *
102 * A backend named "default" is guaranteed not to return a nullptr.
103 * However, it might be a dummy backend.
104 *
105 * \param name identifying name of backend implementation
106 * \param factory build backend registered by name from this factory
107 * \return backend instance (if available) or nullptr
108 */
109std::unique_ptr<Backend> create_backend(const std::string& name, const Factory<Backend>& = builtin_backends());
110
111/**
112 * \brief create a backend instance
113 *
114 * Will never return a nullptr but throw an exception if backend is unavailable.
115 *
116 * \param name identifying name of backend implementation
117 * \throws runtime_error if backend is unavailable
118 * \return backend instance
119 */
120std::unique_ptr<Backend> create_backend_or_throw(const std::string& name);
121
122} // namespace security
123} // namespace vanetza
124
125#endif /* BACKEND_HPP_ZMRDTY2O */
ChunckPacket is a packet consisting of several memory chunks.
ByteBufferConvertible & operator[](OsiLayer ol)
ChunkPacket & merge(ChunkPacket &packet, OsiLayer from, OsiLayer to)
std::size_t size() const
const ByteBufferConvertible & layer(OsiLayer ol) const
const ByteBufferConvertible & operator[](OsiLayer ol) const
ByteBufferConvertible & layer(OsiLayer ol)
std::size_t size(OsiLayer from, OsiLayer to) const
ChunkPacket extract(OsiLayer from, OsiLayer to)
std::size_t size(OsiLayer from, OsiLayer to) const
buffer_const_range operator[](OsiLayer layer) const
std::size_t size() const
void set_boundary(OsiLayer, unsigned bytes)
const ByteBuffer & buffer() const
CohesivePacket(const ByteBuffer &buffer, OsiLayer layer)
void trim(OsiLayer from, unsigned bytes)
std::size_t size(OsiLayer single_layer) const
value_type operator[](size_type) const
Definition byte_view.cpp:48
byte_view_range(ByteBuffer &&)
Definition byte_view.cpp:37
byte_view_range(const ByteBuffer::const_iterator &, const ByteBuffer::const_iterator &)
Definition byte_view.cpp:27
ByteBuffer::const_pointer data() const
Definition byte_view.cpp:42
void encode(units::Duration)
Definition lifetime.cpp:45
units::Duration decode() const
Definition lifetime.cpp:59
bool after(const Timestamp &other) const
Definition timestamp.cpp:76
bool before(const Timestamp &other) const
Definition timestamp.cpp:71
virtual ecdsa256::KeyPair generate_key_pair()=0
generate a private key and the corresponding public key
virtual boost::optional< Uncompressed > decompress_point(const EccPoint &ecc_point)=0
decompress a possibly compressed elliptic curve point
virtual Signature sign_digest(const PrivateKey &, const ByteBuffer &digest)=0
calculate signature for given digest and private key
virtual EcdsaSignature sign_data(const ecdsa256::PrivateKey &private_key, const ByteBuffer &data)=0
calculate signature for given data and private key
virtual bool verify_data(const ecdsa256::PublicKey &public_key, const ByteBuffer &data, const EcdsaSignature &sig)=0
try to verify data using public key and signature
virtual bool verify_digest(const PublicKey &public_key, const ByteBuffer &digest, const Signature &sig)=0
try to verify digest using public key and signature
virtual ByteBuffer calculate_hash(HashAlgorithm algo, const ByteBuffer &data)=0
calculate hash value of data
static CertificateValidity valid()
Create CertificateValidity signalling a valid certificate This method is equivalent to default constr...
CertificateValidity(CertificateInvalidReason reason)
CertificateInvalidReason reason() const
Get reason for certificate invalidity This call is only safe if reason is available,...
IntX specified in TS 103 097 v1.2.1, section 4.2.1.
Definition int_x.hpp:21
static DecapConfirm from(VerifyConfirm &&verify_confirm, const SecuredMessageView &msg_view)
Input data for decapsulating a secured message.
EcdsaSignature specified in TS 103 097 v1.2.1, section 4.2.9.
Definition signature.hpp:17
Uncompressed specified in TS 103 097 v1.2.1 in section 4.2.5.
Definition ecc_point.hpp:36
described in TS 103 097 v1.2.1 (2015-06), section 6.1
void add_permission(ItsAid aid, const ByteBuffer &ssp)
const ValidityRestriction * get_restriction(ValidityRestrictionType type) const
const SubjectAttribute * get_attribute(SubjectAttributeType type) const
void remove_attribute(SubjectAttributeType type)
const validity_restriction_type< T > * get_restriction() const
const subject_attribute_type< T > * get_attribute() const
void remove_restriction(ValidityRestrictionType type)
Payload specified in TS 103 097 v1.2.1, section 5.2.
Definition payload.hpp:28
SecuredMessage as specified in TS 103 097 v1.2.1, section 5.1.
HeaderField * header_field(HeaderFieldType)
const TrailerField * trailer_field(TrailerFieldType type) const
const HeaderField * header_field(HeaderFieldType type) const
TrailerField * trailer_field(TrailerFieldType)
described in TS 103 097 v1.2.1, section 6.2
ThreeDLocation specified in TS 103 097 v1.2.1, section 4.2.19.
Definition region.hpp:21
Time64WithStandardDeviation specified in TS 103 097 v1.2.1, section 4.2.16.
resolve type for matching HeaderFieldType
resolve type for matching TrailerFieldType