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 */
110
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
EcdsaSignature specified in TS 103 097 v1.2.1, section 4.2.9.
Definition signature.hpp:17