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,69 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "se050_tai64n.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 timestamp[TAI64N_SIZE];
|
||||
uint64_t seconds;
|
||||
uint32_t nanoseconds;
|
||||
int passed = 0;
|
||||
|
||||
printf("TAI64N Test Suite\n=================\n\n");
|
||||
|
||||
printf("Test 1: Encode Unix Epoch\n");
|
||||
se050_tai64n_encode(timestamp, 0, 0);
|
||||
print_hex("TAI64N", timestamp, 12);
|
||||
se050_tai64n_decode(&seconds, &nanoseconds, timestamp);
|
||||
printf("Decoded: seconds=%llu, nanoseconds=%u\n",
|
||||
(unsigned long long)seconds, nanoseconds);
|
||||
if (seconds == 0 && nanoseconds == 0) {
|
||||
printf("[PASS]\n\n"); passed++;
|
||||
} else {
|
||||
printf("[FAIL]\n\n");
|
||||
}
|
||||
|
||||
printf("Test 2: Encode Current Time\n");
|
||||
se050_tai64n_now(timestamp);
|
||||
print_hex("TAI64N", timestamp, 12);
|
||||
se050_tai64n_decode(&seconds, &nanoseconds, timestamp);
|
||||
printf("Decoded: seconds=%llu, nanoseconds=%u\n",
|
||||
(unsigned long long)seconds, nanoseconds);
|
||||
printf("[INFO] Computed\n\n"); passed++;
|
||||
|
||||
printf("Test 3: Specific Time\n");
|
||||
se050_tai64n_encode(timestamp, 1609459200, 123456789);
|
||||
print_hex("TAI64N", timestamp, 12);
|
||||
se050_tai64n_decode(&seconds, &nanoseconds, timestamp);
|
||||
printf("Decoded: seconds=%llu, nanoseconds=%u\n",
|
||||
(unsigned long long)seconds, nanoseconds);
|
||||
if (seconds == 1609459200 && nanoseconds == 123456789) {
|
||||
printf("[PASS]\n\n"); passed++;
|
||||
} else {
|
||||
printf("[FAIL]\n\n");
|
||||
}
|
||||
|
||||
printf("Test 4: Window Check\n");
|
||||
se050_tai64n_now(timestamp);
|
||||
int result = se050_tai64n_check_window(timestamp, 60);
|
||||
printf("Window check (60s): %s\n",
|
||||
result == 0 ? "PASS (within window)" :
|
||||
result == -1 ? "FAIL (too old)" : "FAIL (too far future)");
|
||||
if (result == 0) {
|
||||
printf("[PASS]\n\n"); passed++;
|
||||
} else {
|
||||
printf("[FAIL]\n\n");
|
||||
}
|
||||
|
||||
printf("=================\n");
|
||||
printf("Passed: %d/4\n=================\n", passed);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user