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:
km
2026-03-26 21:03:27 +09:00
parent b83394f37b
commit c892e6ca01
11 changed files with 695 additions and 3 deletions
+9 -1
View File
@@ -11,10 +11,17 @@
#include "se050_wireguard.h"
#include "se050_crypto_utils.h"
#include "se050_mem_protect.h"
#include "se050_x25519_sw.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Function prototypes for software tests */
static int test_sw_keypair_generation(void);
static int test_sw_ecdh_symmetry(void);
static int test_sw_public_key_derivation(void);
static int test_sw_key_zeroization(void);
/* X25519 test vectors from RFC 7748 */
static const uint8_t RFC7748_SK_1[32] = {
0xa5, 0x46, 0xe3, 0x6b, 0xf0, 0x52, 0x7c, 0x9d,
@@ -492,7 +499,8 @@ static int test_sw_public_key_derivation(void)
se050_x25519_sw_clamp(derived);
uint8_t direct_public[32];
x25519_sw(direct_public, derived, (const uint8_t*)"basepoint");
se050_x25519_sw_derive_public_key(direct_public, derived);
se050_x25519_sw_clamp(direct_public);
if (!buffers_equal(public_key, direct_public, 32)) {
printf("[FAIL] Public key mismatch\n");