obu-firmware builds against vanetza-idf from microbu-esp32c5/external, but that tree was gitignored, so a clone of this repository could not build the firmware it ships. It is now committed here as ordinary files in its own folder, microbu-esp32c5/: the colleague's commit cf4b99f plus the V2X2MAP bridge's signature verification (--trust) used on the bench. Nothing is fetched from or pushed to the colleague's repository; this repository and its remotes carry everything. The folder's own .gitignore keeps build output, downloaded components and private key material out, as it did there; the committed file set is identical to that repository's tracked files. The ESP32-C5 is still flashed from obu-firmware/, which only takes vanetza-idf from microbu-esp32c5/, so the two stay separate folders. FLASHING.md says how to take a newer version of the colleague's tree (copy it over the folder, rebuild, test, commit).
77 lines
2.4 KiB
C++
77 lines
2.4 KiB
C++
#ifndef BACKEND_CRYPTOPP_HPP_JQWA9MLZ
|
|
#define BACKEND_CRYPTOPP_HPP_JQWA9MLZ
|
|
|
|
#include <vanetza/security/backend.hpp>
|
|
#include <cryptopp/eccrypto.h>
|
|
#include <cryptopp/osrng.h>
|
|
#include <cryptopp/sha.h>
|
|
|
|
namespace vanetza
|
|
{
|
|
namespace security
|
|
{
|
|
|
|
class BackendCryptoPP : public Backend
|
|
{
|
|
public:
|
|
using Ecdsa256 = CryptoPP::ECDSA<CryptoPP::ECP, CryptoPP::SHA256>;
|
|
using Ecdsa384 = CryptoPP::ECDSA<CryptoPP::ECP, CryptoPP::SHA384>;
|
|
|
|
static constexpr auto backend_name = "CryptoPP";
|
|
|
|
BackendCryptoPP();
|
|
|
|
/// \see Backend::sign_data
|
|
EcdsaSignature sign_data(const ecdsa256::PrivateKey& private_key, const ByteBuffer& data_buffer) override;
|
|
|
|
/// \see Backend::sign_digest
|
|
Signature sign_digest(const PrivateKey&, const ByteBuffer& digest) override;
|
|
|
|
/// \see Backend::verify_data
|
|
bool verify_data(const ecdsa256::PublicKey& public_key, const ByteBuffer& data, const EcdsaSignature& sig) override;
|
|
|
|
/// \see Backend::verify_digest
|
|
bool verify_digest(const PublicKey&, const ByteBuffer& digest, const Signature&) override;
|
|
|
|
/// \see Backend::decompress_point
|
|
boost::optional<Uncompressed> decompress_point(const EccPoint& ecc_point) override;
|
|
|
|
/// \see Backend::calculate_hash
|
|
ByteBuffer calculate_hash(HashAlgorithm, const ByteBuffer&) override;
|
|
|
|
/// \see Backend::generate_key_pair
|
|
ecdsa256::KeyPair generate_key_pair() override;
|
|
|
|
private:
|
|
/// internal sign method using crypto++ private key
|
|
EcdsaSignature sign_data(const Ecdsa256::PrivateKey& key, const ByteBuffer& data);
|
|
|
|
/// internal verify method using crypto++ public key
|
|
bool verify_data(const Ecdsa256::PublicKey& key, const ByteBuffer& data, const ByteBuffer& sig);
|
|
|
|
/// create private key
|
|
Ecdsa256::PrivateKey generate_private_key();
|
|
|
|
/// derive public key from private key
|
|
Ecdsa256::PublicKey generate_public_key(const Ecdsa256::PrivateKey&);
|
|
|
|
/// adapt generic public key to internal structure
|
|
Ecdsa256::PublicKey internal_public_key(const ecdsa256::PublicKey&);
|
|
|
|
/// adapt generic private key to internal structure
|
|
Ecdsa256::PrivateKey internal_private_key(const ecdsa256::PrivateKey&);
|
|
|
|
CryptoPP::AutoSeededRandomPool m_prng;
|
|
};
|
|
|
|
namespace cryptopp
|
|
{
|
|
/// Derive the public key from a private key (pub = priv * G), on the key's own curve.
|
|
PublicKey derive_public_key(const PrivateKey& private_key);
|
|
} // namespace cryptopp
|
|
|
|
} // namespace security
|
|
} // namespace vanetza
|
|
|
|
#endif /* BACKEND_CRYPTOPP_HPP_JQWA9MLZ */
|