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/ecdsa_signature.hpp>
8#include <vanetza/security/hash_algorithm.hpp>
9#include <vanetza/security/private_key.hpp>
10#include <vanetza/security/public_key.hpp>
11#include <vanetza/security/signature.hpp>
12#include <boost/optional/optional.hpp>
13#include <memory>
14#include <string>
15
16namespace vanetza
17{
18namespace security
19{
20
21/**
22 * Interface to cryptographic features
23 */
25{
26public:
27 /**
28 * \brief calculate signature for given data and private key
29 *
30 * \param private_key Secret private key
31 * \param data buffer with plaintext data
32 * \return calculated signature
33 */
34 virtual EcdsaSignature sign_data(const ecdsa256::PrivateKey& private_key, const ByteBuffer& data) = 0;
35
36 /**
37 * \brief calculate signature for given digest and private key
38 *
39 * \param private_key secret private key
40 * \param digest hash value of data
41 * \return calculated signature
42 */
43 virtual Signature sign_digest(const PrivateKey&, const ByteBuffer& digest) = 0;
44
45 /**
46 * \brief try to verify data using public key and signature
47 *
48 * \param public_key Public key
49 * \param data plaintext
50 * \param sig signature of data
51 * \return true if the data could be verified
52 */
53 virtual bool verify_data(const ecdsa256::PublicKey& public_key, const ByteBuffer& data, const EcdsaSignature& sig) = 0;
54
55 /**
56 * \brief try to verify digest using public key and signature
57 *
58 * \param public_key public key
59 * \param digest hash value of data
60 * \param sig signature of data
61 * \return true if data could be verified
62 */
63 virtual bool verify_digest(const PublicKey& public_key, const ByteBuffer& digest, const Signature& sig) = 0;
64
65 /**
66 * \brief decompress a possibly compressed elliptic curve point
67 *
68 * \param ecc_point elliptic curve point
69 * \return uncompressed point
70 */
71 virtual boost::optional<Uncompressed> decompress_point(const EccPoint& ecc_point) = 0;
72
73 /**
74 * \brief calculate hash value of data
75 *
76 * \param algo hash algorithm
77 * \param data buffer with data
78 * \return buffer containing calculated hash value
79 */
80 virtual ByteBuffer calculate_hash(HashAlgorithm algo, const ByteBuffer& data) = 0;
81
82 virtual ~Backend() = default;
83};
84
85/**
86 * \brief get factory containing builtin backend implementations
87 *
88 * Included set of backends depends on CMake build configuration.
89 * At least the "Null" backend is always included.
90 * \return factory
91 */
92const Factory<Backend>& builtin_backends();
93
94/**
95 * \brief create a backend instance
96 *
97 * A backend named "default" is guaranteed not to return a nullptr.
98 * However, it might be a dummy backend.
99 *
100 * \param name identifying name of backend implementation
101 * \param factory build backend registered by name from this factory
102 * \return backend instance (if available) or nullptr
103 */
104std::unique_ptr<Backend> create_backend(const std::string& name, const Factory<Backend>& = builtin_backends());
105
106} // namespace security
107} // namespace vanetza
108
109#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 boost::optional< Uncompressed > decompress_point(const EccPoint &ecc_point)=0
decompress a possibly compressed elliptic curve point
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