#include #include #include #if defined VANETZA_WITH_OPENSSL #include #endif #if defined VANETZA_WITH_CRYPTOPP #include #include #endif namespace vanetza { namespace security { #if defined VANETZA_WITH_OPENSSL KeyTag create_hmac_tag_openssl(const ByteBuffer& data, const HmacKey& hmacKey) { KeyTag keyTag; std::array tag; unsigned int len = 0; HMAC(EVP_sha256(), hmacKey.data(), static_cast(hmacKey.size()), data.data(), data.size(), tag.data(), &len); std::copy_n(tag.data(), keyTag.size(), keyTag.data()); return keyTag; } #endif #if defined VANETZA_WITH_CRYPTOPP KeyTag create_hmac_tag_cryptopp(const ByteBuffer& data, const HmacKey& hmacKey) { KeyTag keyTag; std::array tag; CryptoPP::HMAC mac(hmacKey.data(), hmacKey.size()); mac.Update(data.data(), data.size()); mac.Final(tag.data()); std::copy_n(tag.data(), keyTag.size(), keyTag.data()); return keyTag; } #endif KeyTag create_hmac_tag(const ByteBuffer& data, const HmacKey& hmacKey) { #if defined VANETZA_WITH_OPENSSL return create_hmac_tag_openssl(data, hmacKey); #elif defined VANETZA_WITH_CRYPTOPP return create_hmac_tag_cryptopp(data, hmacKey); #else # warning "no HMAC implementation available" return KeyTag {}; #endif } } // namespace security } // namespace vanetza