Vanetza
Loading...
Searching...
No Matches
hmac.cpp
1#include <vanetza/security/hmac.hpp>
2#include <cryptopp/osrng.h>
3#include <cryptopp/hmac.h>
4#include <cryptopp/sha.h>
5
6namespace vanetza
7{
8namespace security
9{
10
11KeyTag create_hmac_tag(const ByteBuffer& data, const HmacKey& hmacKey)
12{
13 KeyTag keyTag;
14
15 // Calculate tag.
16 CryptoPP::HMAC<CryptoPP::SHA256> mac(hmacKey.data(), hmacKey.size());
17 unsigned char tag[hmacKey.size()];
18 mac.Update(data.data(), data.size());
19 mac.Final(tag);
20
21 // Tag is truncated to leftmost 128 bits.
22 std::copy_n(tag, keyTag.size(), keyTag.data());
23 return keyTag;
24}
25
26} // namespace security
27} // namespace vanetza