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.
103 lines
2.7 KiB
C++
103 lines
2.7 KiB
C++
#include <vanetza/security/ecc_point.hpp>
|
|
#include <vanetza/security/ecdsa256.hpp>
|
|
#include <vanetza/security/public_key.hpp>
|
|
#include <boost/variant/apply_visitor.hpp>
|
|
#include <boost/variant/static_visitor.hpp>
|
|
#include <stdexcept>
|
|
|
|
namespace vanetza
|
|
{
|
|
namespace security
|
|
{
|
|
|
|
class EccPointVisitor : public boost::static_visitor<ByteBuffer>
|
|
{
|
|
public:
|
|
template<typename T>
|
|
ByteBuffer operator()(const T& point)
|
|
{
|
|
return point.x;
|
|
}
|
|
};
|
|
|
|
ByteBuffer convert_for_signing(const EccPoint& ecc_point)
|
|
{
|
|
EccPointVisitor visit;
|
|
return boost::apply_visitor(visit, ecc_point);
|
|
}
|
|
|
|
class EccPointLengthVisitor : public boost::static_visitor<std::size_t>
|
|
{
|
|
public:
|
|
std::size_t operator()(const X_Coordinate_Only& x_only) const
|
|
{
|
|
return x_only.x.size();
|
|
}
|
|
|
|
std::size_t operator()(const Compressed_Lsb_Y_0& y0) const
|
|
{
|
|
return y0.x.size();
|
|
}
|
|
|
|
std::size_t operator()(const Compressed_Lsb_Y_1& y1) const
|
|
{
|
|
return y1.x.size();
|
|
}
|
|
|
|
std::size_t operator()(const Uncompressed& unc) const
|
|
{
|
|
return unc.x.size() + unc.y.size();
|
|
}
|
|
};
|
|
|
|
std::size_t get_length(const EccPoint& point)
|
|
{
|
|
EccPointLengthVisitor visitor;
|
|
return boost::apply_visitor(visitor, point);
|
|
}
|
|
|
|
EccPoint compress_public_key(const PublicKey& public_key)
|
|
{
|
|
switch (public_key.compression)
|
|
{
|
|
case KeyCompression::NoCompression:
|
|
if (!public_key.y.empty() && public_key.y.back() & 0x01) {
|
|
return Compressed_Lsb_Y_1 {public_key.x };
|
|
} else {
|
|
return Compressed_Lsb_Y_0 {public_key.x };
|
|
}
|
|
case KeyCompression::Y0:
|
|
return Compressed_Lsb_Y_0 {public_key.x };
|
|
case KeyCompression::Y1:
|
|
return Compressed_Lsb_Y_1 {public_key.x };
|
|
default:
|
|
return Compressed_Lsb_Y_0 {};
|
|
}
|
|
}
|
|
|
|
EccPoint make_ecc_point(const PublicKey& public_key)
|
|
{
|
|
switch (public_key.compression)
|
|
{
|
|
case KeyCompression::NoCompression:
|
|
return Uncompressed { public_key.x, public_key.y };
|
|
case KeyCompression::Y0:
|
|
return Compressed_Lsb_Y_0 { public_key.x };
|
|
case KeyCompression::Y1:
|
|
return Compressed_Lsb_Y_1 { public_key.x };
|
|
}
|
|
throw std::invalid_argument("public key has an unknown point compression");
|
|
}
|
|
|
|
EccPoint compress_public_key(const ecdsa256::PublicKey& public_key)
|
|
{
|
|
if (!public_key.y.empty() && public_key.y.back() & 0x01) {
|
|
return Compressed_Lsb_Y_1 { ByteBuffer { public_key.x.begin(), public_key.x.end() } };
|
|
} else {
|
|
return Compressed_Lsb_Y_0 { ByteBuffer { public_key.x.begin(), public_key.x.end() } };
|
|
}
|
|
}
|
|
|
|
} // namespace security
|
|
} // namespace vanetza
|