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