From 3caa9be3e5c028ed47532c0c3d984c9f43186685 Mon Sep 17 00:00:00 2001 From: hashlag <90853356+hashlag@users.noreply.github.com> Date: Thu, 21 Aug 2025 23:50:53 +0300 Subject: [PATCH] Add LongKeyTest for HMAC --- ChaosTests/HmacTests.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ChaosTests/HmacTests.cpp b/ChaosTests/HmacTests.cpp index 1965310..39ca936 100644 --- a/ChaosTests/HmacTests.cpp +++ b/ChaosTests/HmacTests.cpp @@ -50,3 +50,25 @@ TEST(HmacTests, RFCTest) ASSERT_EQ("56be34521d144c88dbb8c733f0e8b3f6", hmacMd5.Finish().ToHexString()); } } + +TEST(HmacTests, LongKeyTest) +{ + struct Helper + { + std::string operator()(const char * key, const char * data) const + { + Hmac hmac(key, key + strlen(key)); + hmac.Update(data, data + strlen(data)); + return hmac.Finish().ToHexString(); + } + }; + + Helper hmacMd5; + + { + const char * key = "Passages from the Life of a Philosopher (1864), ch. 8 \"Of the Analytical Engine\""; + const char * data = "As soon as an Analytical Engine exists, it will necessarily guide the future course of the science."; + + ASSERT_EQ("99459b85e800f3e5eab24e1c945794f8", hmacMd5(key, data)); + } +}