1#include <vanetza/security/backend.hpp>
2#include <vanetza/security/v3/certificate.hpp>
3#include <vanetza/security/v3/hash.hpp>
12ByteBuffer calculate_message_hash(Backend& backend, HashAlgorithm hash_algo,
const ByteBuffer& payload,
const CertificateView& signing_cert)
14 ByteBuffer encoded_cert;
15 if (signing_cert.is_canonical()) {
16 encoded_cert = signing_cert.encode();
18 auto canonical_signing_cert = signing_cert.canonicalize();
19 if (canonical_signing_cert) {
20 encoded_cert = canonical_signing_cert->encode();
24 ByteBuffer data_hash = backend.calculate_hash(hash_algo, payload);
25 ByteBuffer cert_hash = backend.calculate_hash(hash_algo, encoded_cert);
26 ByteBuffer concat_hash;
27 concat_hash.reserve(data_hash.size() + cert_hash.size());
28 concat_hash.insert(concat_hash.end(), data_hash.begin(), data_hash.end());
29 concat_hash.insert(concat_hash.end(), cert_hash.begin(), cert_hash.end());
30 return backend.calculate_hash(hash_algo, concat_hash);
33HashAlgorithm specified_hash_algorithm(KeyType key_type)
36 case KeyType::NistP256:
37 case KeyType::BrainpoolP256r1:
38 return HashAlgorithm::SHA256;
39 case KeyType::BrainpoolP384r1:
40 return HashAlgorithm::SHA384;
42 return HashAlgorithm::Unspecified;