Keep vanetza-idf in obu-firmware, so a plain clone builds the firmware
obu-firmware builds against the vanetza-idf C-ITS library, which until now came from the colleague's microbu-esp32c5 tree beside the repository and was not tracked here, so a clone of this repository could not build the firmware it ships. The library alone is now part of obu-firmware, as obu-firmware/external/vanetza-idf: their external/vanetza-idf at commit cf4b99f, unchanged (9775 files; see its PROVENANCE.md). CMake takes it from there by default; -DVANETZA_IDF_DIR still points the build elsewhere. The rest of the colleague's tree (their own VAM firmware, PKI tooling, station-link Python tools, the V2X2MAP bridge) stays out of this repository and gitignored; nothing is pushed to their repository. NOTES.md, docs/06, TODO.md and the pcap verifier's usage line point at the new location.
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
#ifndef BACKEND_HPP_ZMRDTY2O
|
||||
#define BACKEND_HPP_ZMRDTY2O
|
||||
|
||||
#include <vanetza/common/byte_buffer.hpp>
|
||||
#include <vanetza/common/factory.hpp>
|
||||
#include <vanetza/security/ecdsa256.hpp>
|
||||
#include <vanetza/security/hash_algorithm.hpp>
|
||||
#include <vanetza/security/private_key.hpp>
|
||||
#include <vanetza/security/public_key.hpp>
|
||||
#include <vanetza/security/signature.hpp>
|
||||
#include <boost/optional/optional.hpp>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace vanetza
|
||||
{
|
||||
namespace security
|
||||
{
|
||||
|
||||
/**
|
||||
* Interface to cryptographic features
|
||||
*/
|
||||
class Backend
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief calculate signature for given data and private key
|
||||
*
|
||||
* \param private_key Secret private key
|
||||
* \param data buffer with plaintext data
|
||||
* \return calculated signature
|
||||
*/
|
||||
virtual EcdsaSignature sign_data(const ecdsa256::PrivateKey& private_key, const ByteBuffer& data) = 0;
|
||||
|
||||
/**
|
||||
* \brief calculate signature for given digest and private key
|
||||
*
|
||||
* \param private_key secret private key
|
||||
* \param digest hash value of data
|
||||
* \return calculated signature
|
||||
*/
|
||||
virtual Signature sign_digest(const PrivateKey&, const ByteBuffer& digest) = 0;
|
||||
|
||||
/**
|
||||
* \brief try to verify data using public key and signature
|
||||
*
|
||||
* \param public_key Public key
|
||||
* \param data plaintext
|
||||
* \param sig signature of data
|
||||
* \return true if the data could be verified
|
||||
*/
|
||||
virtual bool verify_data(const ecdsa256::PublicKey& public_key, const ByteBuffer& data, const EcdsaSignature& sig) = 0;
|
||||
|
||||
/**
|
||||
* \brief try to verify digest using public key and signature
|
||||
*
|
||||
* \param public_key public key
|
||||
* \param digest hash value of data
|
||||
* \param sig signature of data
|
||||
* \return true if data could be verified
|
||||
*/
|
||||
virtual bool verify_digest(const PublicKey& public_key, const ByteBuffer& digest, const Signature& sig) = 0;
|
||||
|
||||
/**
|
||||
* \brief decompress a possibly compressed elliptic curve point
|
||||
*
|
||||
* \param ecc_point elliptic curve point
|
||||
* \return uncompressed point
|
||||
*/
|
||||
virtual boost::optional<Uncompressed> decompress_point(const EccPoint& ecc_point) = 0;
|
||||
|
||||
/**
|
||||
* \brief calculate hash value of data
|
||||
*
|
||||
* \param algo hash algorithm
|
||||
* \param data buffer with data
|
||||
* \return buffer containing calculated hash value
|
||||
*/
|
||||
virtual ByteBuffer calculate_hash(HashAlgorithm algo, const ByteBuffer& data) = 0;
|
||||
|
||||
/**
|
||||
* \brief generate a private key and the corresponding public key
|
||||
* \return generated key pair
|
||||
*/
|
||||
virtual ecdsa256::KeyPair generate_key_pair() = 0;
|
||||
|
||||
virtual ~Backend() = default;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief get factory containing builtin backend implementations
|
||||
*
|
||||
* Included set of backends depends on CMake build configuration.
|
||||
* At least the "Null" backend is always included.
|
||||
* \return factory
|
||||
*/
|
||||
const Factory<Backend>& builtin_backends();
|
||||
|
||||
/**
|
||||
* \brief create a backend instance
|
||||
*
|
||||
* A backend named "default" is guaranteed not to return a nullptr.
|
||||
* However, it might be a dummy backend.
|
||||
*
|
||||
* \param name identifying name of backend implementation
|
||||
* \param factory build backend registered by name from this factory
|
||||
* \return backend instance (if available) or nullptr
|
||||
*/
|
||||
std::unique_ptr<Backend> create_backend(const std::string& name, const Factory<Backend>& = builtin_backends());
|
||||
|
||||
/**
|
||||
* \brief create a backend instance
|
||||
*
|
||||
* Will never return a nullptr but throw an exception if backend is unavailable.
|
||||
*
|
||||
* \param name identifying name of backend implementation
|
||||
* \throws runtime_error if backend is unavailable
|
||||
* \return backend instance
|
||||
*/
|
||||
std::unique_ptr<Backend> create_backend_or_throw(const std::string& name);
|
||||
|
||||
} // namespace security
|
||||
} // namespace vanetza
|
||||
|
||||
#endif /* BACKEND_HPP_ZMRDTY2O */
|
||||
|
||||
Reference in New Issue
Block a user