Files
km 344f86b07f TAI64N ハードウェア実装追加
- SE050 モノトニックカウンタ使用
- リプレイ防止用タイムスタンプ
- テスト実装済み
2026-03-27 05:26:46 +09:00

69 lines
1.7 KiB
C

/**
* @file se050_tai64n_hw.h
* @brief TAI64N using SE050 Hardware Monotonic Counter
*
* Uses SE050's built-in monotonic counter for replay prevention.
* Object ID: SE05X_OBJ_ID_MONOTONIC_COUNTER (0x7FFF0203)
*/
#ifndef SE050_TAI64N_HW_H
#define SE050_TAI64N_HW_H
#include <stdint.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
#define TAI64N_HW_SIZE 12
#define SE050_MONOTONIC_COUNTER_ID 0x7FFF0203
/* Session handle type (opaque) */
typedef void* se050_session_t;
/* Mock session for testing */
typedef struct {
uint32_t counter;
} mock_session_t;
/**
* @brief Read SE050 monotonic counter and encode as TAI64N
* @param session SE050 session handle
* @param out Output buffer (12 bytes)
* @return 0 on success, -1 on error
*/
int se050_tai64n_hw_now(void *session, uint8_t out[12]);
/**
* @brief Read SE050 monotonic counter only (32-bit)
* @param session SE050 session handle
* @param counter Output counter value
* @return 0 on success, -1 on error
*/
int se050_tai64n_hw_read_counter(void *session, uint32_t *counter);
/**
* @brief Increment SE050 monotonic counter
* @param session SE050 session handle
* @return 0 on success, -1 on error
*/
int se050_tai64n_hw_increment(void *session);
/**
* @brief Check if timestamp is within acceptable window
* @param timestamp Received TAI64N timestamp
* @param current Current TAI64N timestamp
* @param window Acceptable window in seconds
* @return 1 if valid, 0 if expired/replay, -1 on error
*/
int se050_tai64n_hw_check_window(const uint8_t timestamp[12],
const uint8_t current[12],
uint32_t window);
#ifdef __cplusplus
}
#endif
#endif /* SE050_TAI64N_HW_H */