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
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 /// \see Backend::generate_key_pair
43 ecdsa256::KeyPair generate_key_pair() override;
44
45private:
46 /// internal sign method using crypto++ private key
47 EcdsaSignature sign_data(const Ecdsa256::PrivateKey& key, const ByteBuffer& data);
48
49 /// internal verify method using crypto++ public key
50 bool verify_data(const Ecdsa256::PublicKey& key, const ByteBuffer& data, const ByteBuffer& sig);
51
52 /// create private key
54
55 /// derive public key from private key
56 Ecdsa256::PublicKey generate_public_key(const Ecdsa256::PrivateKey&);
57
58 /// adapt generic public key to internal structure
60
61 /// adapt generic private key to internal structure
63
64 CryptoPP::AutoSeededRandomPool m_prng;
65};
66
67namespace cryptopp
68{
69/// Derive the public key from a private key (pub = priv * G), on the key's own curve.
70PublicKey derive_public_key(const PrivateKey& private_key);
71} // namespace cryptopp
72
73} // namespace security
74} // namespace vanetza
75
76#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
ecdsa256::KeyPair generate_key_pair() override
bool verify_data(const Ecdsa256::PublicKey &key, const ByteBuffer &data, const ByteBuffer &sig)
internal verify method using crypto++ public key
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 &key, const ByteBuffer &data)
internal sign method using crypto++ private key
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::PrivateKey internal_private_key(const ecdsa256::PrivateKey &)
adapt generic private key to internal structure
Compressed_Lsb_Y_0 specified in TS 103 097 v1.2.1 in section 4.2.5.
Definition ecc_point.hpp:24
Compressed_Lsb_Y_1 specified in TS 103 097 v1.2.1 in section 4.2.5.
Definition ecc_point.hpp:30
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
X_Coordinate_Only specified in TS 103 097 v1.2.1 in section 4.2.5.
Definition ecc_point.hpp:18