feat: HMAC-SHA256 signing module with native tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-13 14:20:24 -07:00
parent 74bff0912b
commit 47f3f6afef
4 changed files with 116 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
// firmware/test/test_native/test_hmac.cpp
#include <unity.h>
#include "hmac.h"
void setUp(void) {}
void tearDown(void) {}
void test_hmac_known_vector() {
HString secret = "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20";
HString device = "dc-0042";
HString body = "{\"location_id\":\"retailer-123\",\"records\":[]}";
uint32_t ts = 1712000000;
HString result = hmac_sign(secret, device, ts, body);
TEST_ASSERT_EQUAL_STRING("90f5fa5fdbf7f95e7475791bf5bb90cdef7f16534d9a7d263fc588305bad0525", result.c_str());
}
void test_hmac_different_timestamp_gives_different_sig() {
HString secret = "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20";
HString device = "dc-0042";
HString body = "{}";
HString sig1 = hmac_sign(secret, device, 1712000000, body);
HString sig2 = hmac_sign(secret, device, 1712000001, body);
TEST_ASSERT_NOT_EQUAL(0, sig1.compare(sig2));
}
int main() {
UNITY_BEGIN();
RUN_TEST(test_hmac_known_vector);
RUN_TEST(test_hmac_different_timestamp_gives_different_sig);
return UNITY_END();
}