Vanetza
Loading...
Searching...
No Matches
backend_cryptopp.hpp
1#ifndef BACKEND_CRYPTOPP_HPP_JQWA9MLZ
2#define BACKEND_CRYPTOPP_HPP_JQWA9MLZ
3
4#include <vanetza/security/backend.hpp>
5#include <cryptopp/eccrypto.h>
6#include <cryptopp/osrng.h>
7#include <cryptopp/sha.h>
8
9namespace vanetza
10{
11namespace security
12{
13
14class BackendCryptoPP : public Backend
15{
16public:
17 using Ecdsa256 = CryptoPP::ECDSA<CryptoPP::ECP, CryptoPP::SHA256>;
18 using Ecdsa384 = CryptoPP::ECDSA<CryptoPP::ECP, CryptoPP::SHA384>;
19
20 static constexpr auto backend_name = "CryptoPP";
21
22 BackendCryptoPP();
23
24 /// \see Backend::sign_data
25 EcdsaSignature sign_data(const ecdsa256::PrivateKey& private_key, const ByteBuffer& data_buffer) override;
26
27 /// \see Backend::sign_digest
28 Signature sign_digest(const PrivateKey&, const ByteBuffer& digest) override;
29
30 /// \see Backend::verify_data
31 bool verify_data(const ecdsa256::PublicKey& public_key, const ByteBuffer& data, const EcdsaSignature& sig) override;
32
33 /// \see Backend::verify_digest
34 bool verify_digest(const PublicKey&, const ByteBuffer& digest, const Signature&) override;
35
36 /// \see Backend::decompress_point
37 boost::optional<Uncompressed> decompress_point(const EccPoint& ecc_point) override;
38
39 /// \see Backend::calculate_hash
40 ByteBuffer calculate_hash(HashAlgorithm, const ByteBuffer&) override;
41
42 /**
43 * \brief generate a private key and the corresponding public key
44 * \return generated key pair
45 */
47
48private:
49 /// internal sign method using crypto++ private key
50 EcdsaSignature sign_data(const Ecdsa256::PrivateKey& key, const ByteBuffer& data);
51
52 /// internal verify method using crypto++ public key
53 bool verify_data(const Ecdsa256::PublicKey& key, const ByteBuffer& data, const ByteBuffer& sig);
54
55 /// create private key
56 Ecdsa256::PrivateKey generate_private_key();
57
58 /// derive public key from private key
59 Ecdsa256::PublicKey generate_public_key(const Ecdsa256::PrivateKey&);
60
61 /// adapt generic public key to internal structure
62 Ecdsa256::PublicKey internal_public_key(const ecdsa256::PublicKey&);
63
64 /// adapt generic private key to internal structure
65 Ecdsa256::PrivateKey internal_private_key(const ecdsa256::PrivateKey&);
66
67 CryptoPP::AutoSeededRandomPool m_prng;
68};
69
70} // namespace security
71} // namespace vanetza
72
73#endif /* BACKEND_CRYPTOPP_HPP_JQWA9MLZ */
Ecdsa256::PrivateKey generate_private_key()
create private key
Ecdsa256::PublicKey internal_public_key(const ecdsa256::PublicKey &)
adapt generic public key to internal structure
ByteBuffer calculate_hash(HashAlgorithm, const ByteBuffer &) override
boost::optional< Uncompressed > decompress_point(const EccPoint &ecc_point) override
Ecdsa256::PublicKey generate_public_key(const Ecdsa256::PrivateKey &)
derive public key from private key
bool verify_data(const ecdsa256::PublicKey &public_key, const ByteBuffer &data, const EcdsaSignature &sig) override
Signature sign_digest(const PrivateKey &, const ByteBuffer &digest) override
EcdsaSignature sign_data(const ecdsa256::PrivateKey &private_key, const ByteBuffer &data_buffer) override
bool verify_digest(const PublicKey &, const ByteBuffer &digest, const Signature &) override
ecdsa256::KeyPair generate_key_pair()
generate a private key and the corresponding public key
Ecdsa256::PrivateKey internal_private_key(const ecdsa256::PrivateKey &)
adapt generic private key to internal structure
EcdsaSignature specified in TS 103 097 v1.2.1, section 4.2.9.
Definition signature.hpp:17