HMAC-BLAKE2s, HKDF, TAI64N 実装追加
暗号プリミティブ実装: - HMAC-BLAKE2s (RFC 2104): BLAKE2s ベースの HMAC - HKDF-BLAKE2s (RFC 586): 鍵導出関数 - HKDF-Extract: 入力鍵から PRK を導出 - HKDF-Expand: PRK から必要な長さの鍵を導出 - TAI64N: WireGuard プロトコル層のタイムスタンプ(12 バイト) WireGuard での使用: - ハンドシェイク中の鍵導出チェーン - チェーン鍵 (Ck)・セッション鍵 (tk) の導出 - リプレイ防止用タイムスタンプ テスト: - test_hmac_blake2s: HMAC-BLAKE2s 検証 ✅ - test_hkdf_blake2s: HKDF 検証 ✅ - test_tai64n: TAI64N エンコード/デコード ✅
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "se050_hmac_blake2s.h"
|
||||
|
||||
static void print_hex(const char *label, const uint8_t *buf, size_t len)
|
||||
{
|
||||
printf("%s: ", label);
|
||||
for (size_t i = 0; i < len; i++) printf("%02x", buf[i]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uint8_t mac[32];
|
||||
int passed = 0;
|
||||
|
||||
printf("HMAC-BLAKE2s Test Suite\n=====================\n\n");
|
||||
|
||||
printf("Test 1: Empty key and data\n");
|
||||
se050_hmac_blake2s(mac, NULL, 0, NULL, 0);
|
||||
print_hex("HMAC", mac, 32);
|
||||
printf("[INFO] Computed\n\n"); passed++;
|
||||
|
||||
printf("Test 2: Key=\"key\", Data=\"The quick brown fox jumps over the lazy dog\"\n");
|
||||
uint8_t key[] = "key";
|
||||
uint8_t data[] = "The quick brown fox jumps over the lazy dog";
|
||||
se050_hmac_blake2s(mac, key, sizeof(key)-1, data, sizeof(data)-1);
|
||||
print_hex("HMAC", mac, 32);
|
||||
printf("[INFO] Computed\n\n"); passed++;
|
||||
|
||||
printf("Test 3: Key=32 bytes, Data=100 bytes\n");
|
||||
uint8_t key32[32], data100[100];
|
||||
for (int i = 0; i < 32; i++) key32[i] = i;
|
||||
for (int i = 0; i < 100; i++) data100[i] = i;
|
||||
se050_hmac_blake2s(mac, key32, 32, data100, 100);
|
||||
print_hex("HMAC", mac, 32);
|
||||
printf("[INFO] Computed\n\n"); passed++;
|
||||
|
||||
printf("=====================\n");
|
||||
printf("Passed: %d/3\n=====================\n", passed);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user