Files
MicrOBU/microbu-esp32c5/external/vanetza-idf/vanetza/security/hashed_id.cpp
T
Ashin Walpola 0e9525162d Keep the colleague's microbu-esp32c5 tree in this repository
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).
2026-09-23 17:46:40 +02:00

81 lines
1.7 KiB
C++

#include <vanetza/security/hashed_id.hpp>
#include <boost/functional/hash.hpp>
#include <algorithm>
#include <cassert>
#include <iomanip>
#include <sstream>
namespace vanetza
{
namespace security
{
HashedId3 truncate(const HashedId8& in)
{
HashedId3 out;
assert(out.size() <= in.size());
std::copy_n(in.rbegin(), out.size(), out.rbegin());
return out;
}
HashedId8 create_hashed_id8(const Sha256Digest& digest)
{
HashedId8 hashed;
std::copy(digest.end() - 8, digest.end(), hashed.data());
return hashed;
}
HashedId8 create_hashed_id8(const Sha384Digest& digest)
{
HashedId8 hashed;
std::copy(digest.end() - 8, digest.end(), hashed.data());
return hashed;
}
std::string to_string(const vanetza::security::HashedId3& digest)
{
std::stringstream ss;
ss << std::hex << std::setfill('0');
for (uint8_t octet : digest)
{
ss << std::setw(2) << static_cast<unsigned>(octet);
}
return ss.str();
}
std::string to_string(const vanetza::security::HashedId8& digest)
{
std::stringstream ss;
ss << std::hex << std::setfill('0');
for (uint8_t octet : digest)
{
ss << std::setw(2) << static_cast<unsigned>(octet);
}
return ss.str();
}
} // namespace security
} // namespace vanetza
namespace std
{
size_t hash<vanetza::security::HashedId3>::operator()(const vanetza::security::HashedId3& hid3) const
{
size_t seed = 0;
for (uint8_t octet : hid3) {
boost::hash_combine(seed, octet);
}
return seed;
}
size_t hash<vanetza::security::HashedId8>::operator()(const vanetza::security::HashedId8& hid8) const
{
size_t seed = 0;
for (uint8_t octet : hid8) {
boost::hash_combine(seed, octet);
}
return seed;
}
} // namespace std