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.
92 lines
2.1 KiB
C++
92 lines
2.1 KiB
C++
#include <vanetza/security/exception.hpp>
|
|
#include <vanetza/security/v2/encryption_parameter.hpp>
|
|
#include <vanetza/security/v2/public_key.hpp>
|
|
#include <boost/variant/apply_visitor.hpp>
|
|
#include <boost/variant/static_visitor.hpp>
|
|
|
|
namespace vanetza
|
|
{
|
|
namespace security
|
|
{
|
|
namespace v2
|
|
{
|
|
|
|
SymmetricAlgorithm get_type(const EncryptionParameter& param)
|
|
{
|
|
struct Encryption_visitor : public boost::static_visitor<SymmetricAlgorithm>
|
|
{
|
|
SymmetricAlgorithm operator()(const Nonce&)
|
|
{
|
|
return SymmetricAlgorithm::AES128_CCM;
|
|
}
|
|
};
|
|
|
|
Encryption_visitor visit;
|
|
return boost::apply_visitor(visit, param);
|
|
}
|
|
|
|
void serialize(OutputArchive& ar, const EncryptionParameter& param)
|
|
{
|
|
struct Encryption_visitor : public boost::static_visitor<>
|
|
{
|
|
Encryption_visitor(OutputArchive& ar) :
|
|
m_archive(ar)
|
|
{
|
|
}
|
|
|
|
void operator()(const Nonce& nonce)
|
|
{
|
|
for (auto& byte : nonce) {
|
|
m_archive << byte;
|
|
}
|
|
}
|
|
|
|
OutputArchive& m_archive;
|
|
};
|
|
|
|
SymmetricAlgorithm algo = get_type(param);
|
|
serialize(ar, algo);
|
|
Encryption_visitor visit(ar);
|
|
boost::apply_visitor(visit, param);
|
|
}
|
|
|
|
size_t get_size(const EncryptionParameter& param)
|
|
{
|
|
size_t size = sizeof(SymmetricAlgorithm);
|
|
struct Encryption_visitor : public boost::static_visitor<size_t>
|
|
{
|
|
size_t operator()(const Nonce& nonce)
|
|
{
|
|
return nonce.size();
|
|
}
|
|
};
|
|
|
|
Encryption_visitor visit;
|
|
size += boost::apply_visitor(visit, param);
|
|
return size;
|
|
}
|
|
|
|
size_t deserialize(InputArchive& ar, EncryptionParameter& param)
|
|
{
|
|
SymmetricAlgorithm algo;
|
|
deserialize(ar, algo);
|
|
switch (algo) {
|
|
case SymmetricAlgorithm::AES128_CCM: {
|
|
Nonce nonce;
|
|
for (size_t s = 0; s < nonce.size(); s++) {
|
|
ar >> nonce[s];
|
|
}
|
|
param = nonce;
|
|
break;
|
|
}
|
|
default:
|
|
throw deserialization_error("Unknown Symmetric Algorithm");
|
|
break;
|
|
}
|
|
return get_size(param);
|
|
}
|
|
|
|
} // namespace v2
|
|
} // namespace security
|
|
} // namespace vanetza
|