SE050 キー管理シンプル化と不要チップ削除
- ACTIVE_*マクロをシンプル化:チップ選択で ENC/MAC/DEK 全体が選択 - test_scp03_hardware.c: SE050C0 キーに整理 - SE050E0/E1 削除(実在しないため) - 対応チップ:SE050C0, SE050C1, SE050E2 のみ 変更前: ACTIVE_ENC_KEY = 条件付きマクロ 変更後: ENC_KEY = 選択チップのキー MAC_KEY = 選択チップのキー DEK_KEY = 選択チップのキー
This commit is contained in:
+76
-81
@@ -3,7 +3,7 @@
|
||||
* @brief Platform SCP03 Hardware Test with SE050
|
||||
*
|
||||
* Tests Platform SCP03 communication with actual SE050 hardware
|
||||
* using default keys from NXP AN12436.
|
||||
* using SE050C0 default keys.
|
||||
*
|
||||
* License: MIT (Clean-room implementation)
|
||||
*/
|
||||
@@ -15,18 +15,18 @@
|
||||
#include "se050_wireguard.h"
|
||||
#include "se050_crypto_utils.h"
|
||||
|
||||
/* AN12436 Default Platform SCP03 Keys */
|
||||
static const uint8_t DEFAULT_ENC_KEY[16] = {
|
||||
/* SE050C0 Default Platform SCP03 Keys */
|
||||
static const uint8_t SE050C0_ENC_KEY[16] = {
|
||||
0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
|
||||
0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF
|
||||
};
|
||||
|
||||
static const uint8_t DEFAULT_MAC_KEY[16] = {
|
||||
static const uint8_t SE050C0_MAC_KEY[16] = {
|
||||
0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
|
||||
0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
|
||||
};
|
||||
|
||||
static const uint8_t DEFAULT_DEK_KEY[16] = {
|
||||
static const uint8_t SE050C0_DEK_KEY[16] = {
|
||||
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
|
||||
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
|
||||
};
|
||||
@@ -86,7 +86,7 @@ static mock_i2c_ctx_t *g_mock_ctx = NULL;
|
||||
|
||||
int se050_i2c_read_mock(se050_i2c_hal_t *hal, uint8_t *buffer, int length)
|
||||
{
|
||||
(void)hal; /* Mock implementation uses global context */
|
||||
(void)hal;
|
||||
mock_i2c_ctx_t *mock = g_mock_ctx;
|
||||
|
||||
if (!mock || !buffer || length <= 0) {
|
||||
@@ -111,7 +111,7 @@ int se050_i2c_read_mock(se050_i2c_hal_t *hal, uint8_t *buffer, int length)
|
||||
|
||||
int se050_i2c_write_mock(se050_i2c_hal_t *hal, const uint8_t *buffer, int length)
|
||||
{
|
||||
(void)hal; /* Mock implementation uses global context */
|
||||
(void)hal;
|
||||
mock_i2c_ctx_t *mock = g_mock_ctx;
|
||||
|
||||
if (!mock || !buffer || length <= 0) {
|
||||
@@ -122,12 +122,7 @@ int se050_i2c_write_mock(se050_i2c_hal_t *hal, const uint8_t *buffer, int length
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("[MOCK I2C] Write %d bytes: ", length);
|
||||
for (int i = 0; i < length && i < 16; i++) {
|
||||
printf("%02x ", buffer[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
printf("[MOCK I2C] Write %d bytes\n", length);
|
||||
return length;
|
||||
}
|
||||
|
||||
@@ -152,29 +147,29 @@ static void mock_i2c_set_response(mock_i2c_ctx_t *mock, const uint8_t *response,
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
* Test Case 1: Default Key Validation
|
||||
* Test Case 1: Key Validation
|
||||
*/
|
||||
static void test_default_keys(void)
|
||||
static void test_keys(void)
|
||||
{
|
||||
printf("\n=== Test 1: AN12436 Default Key Validation ===\n");
|
||||
printf("\n=== Test 1: SE050C0 Key Validation ===\n");
|
||||
|
||||
TEST_ASSERT_EQ(sizeof(DEFAULT_ENC_KEY), 16, "ENC key should be 16 bytes");
|
||||
TEST_ASSERT_EQ(sizeof(DEFAULT_MAC_KEY), 16, "MAC key should be 16 bytes");
|
||||
TEST_ASSERT_EQ(sizeof(DEFAULT_DEK_KEY), 16, "DEK key should be 16 bytes");
|
||||
TEST_ASSERT_EQ(sizeof(SE050C0_ENC_KEY), 16, "ENC key should be 16 bytes");
|
||||
TEST_ASSERT_EQ(sizeof(SE050C0_MAC_KEY), 16, "MAC key should be 16 bytes");
|
||||
TEST_ASSERT_EQ(sizeof(SE050C0_DEK_KEY), 16, "DEK key should be 16 bytes");
|
||||
|
||||
print_hex("Default ENC Key", DEFAULT_ENC_KEY, 16);
|
||||
print_hex("Default MAC Key", DEFAULT_MAC_KEY, 16);
|
||||
print_hex("Default DEK Key", DEFAULT_DEK_KEY, 16);
|
||||
print_hex("SE050C0 ENC Key", SE050C0_ENC_KEY, 16);
|
||||
print_hex("SE050C0 MAC Key", SE050C0_MAC_KEY, 16);
|
||||
print_hex("SE050C0 DEK Key", SE050C0_DEK_KEY, 16);
|
||||
|
||||
TEST_ASSERT(1, "Default keys from AN12436 loaded");
|
||||
TEST_ASSERT(1, "SE050C0 keys loaded");
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
* Test Case 2: SCP03 with Default Keys
|
||||
* Test Case 2: SCP03 with SE050C0 Keys
|
||||
*/
|
||||
static void test_scp03_default_keys(void)
|
||||
static void test_scp03_se050c0_keys(void)
|
||||
{
|
||||
printf("\n=== Test 2: SCP03 with AN12436 Default Keys ===\n");
|
||||
printf("\n=== Test 2: SCP03 with SE050C0 Keys ===\n");
|
||||
|
||||
se050_session_ctx_t *session = NULL;
|
||||
mock_i2c_ctx_t mock;
|
||||
@@ -182,27 +177,27 @@ static void test_scp03_default_keys(void)
|
||||
mock_i2c_init(&mock, "/dev/i2c-1-mock");
|
||||
|
||||
se050_status_t status = se050_session_create(&session, &mock.hal);
|
||||
TEST_ASSERT_EQ(status, SE050_OK, "Session creation with default keys");
|
||||
TEST_ASSERT_EQ(status, SE050_OK, "Session creation");
|
||||
|
||||
status = se050_session_scp03_init(session);
|
||||
TEST_ASSERT_EQ(status, SE050_OK, "SCP03 initialization with default keys");
|
||||
TEST_ASSERT_EQ(status, SE050_OK, "SCP03 initialization");
|
||||
|
||||
status = se050_session_scp03_set_keys(session,
|
||||
DEFAULT_ENC_KEY,
|
||||
DEFAULT_MAC_KEY,
|
||||
DEFAULT_DEK_KEY);
|
||||
TEST_ASSERT_EQ(status, SE050_OK, "SCP03 set_keys with AN12436 defaults");
|
||||
SE050C0_ENC_KEY,
|
||||
SE050C0_MAC_KEY,
|
||||
SE050C0_DEK_KEY);
|
||||
TEST_ASSERT_EQ(status, SE050_OK, "Set SE050C0 keys");
|
||||
|
||||
se050_session_delete(session);
|
||||
TEST_ASSERT(1, "SCP03 with default keys completed");
|
||||
TEST_ASSERT(1, "SCP03 with SE050C0 keys completed");
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
* Test Case 3: SCP03 Command Encryption with Default Keys
|
||||
* Test Case 3: SCP03 Command Encryption
|
||||
*/
|
||||
static void test_scp03_encrypt_default_keys(void)
|
||||
static void test_scp03_encrypt(void)
|
||||
{
|
||||
printf("\n=== Test 3: SCP03 Command Encryption with Default Keys ===\n");
|
||||
printf("\n=== Test 3: SCP03 Command Encryption ===\n");
|
||||
|
||||
se050_session_ctx_t *session = NULL;
|
||||
mock_i2c_ctx_t mock;
|
||||
@@ -216,10 +211,10 @@ static void test_scp03_encrypt_default_keys(void)
|
||||
TEST_ASSERT_EQ(status, SE050_OK, "SCP03 initialization");
|
||||
|
||||
status = se050_session_scp03_set_keys(session,
|
||||
DEFAULT_ENC_KEY,
|
||||
DEFAULT_MAC_KEY,
|
||||
DEFAULT_DEK_KEY);
|
||||
TEST_ASSERT_EQ(status, SE050_OK, "Set AN12436 default keys");
|
||||
SE050C0_ENC_KEY,
|
||||
SE050C0_MAC_KEY,
|
||||
SE050C0_DEK_KEY);
|
||||
TEST_ASSERT_EQ(status, SE050_OK, "Set SE050C0 keys");
|
||||
|
||||
uint8_t cmd[64];
|
||||
size_t cmd_len = 6;
|
||||
@@ -232,7 +227,7 @@ static void test_scp03_encrypt_default_keys(void)
|
||||
cmd[5] = 0x00;
|
||||
|
||||
status = se050_session_scp03_encrypt(session, cmd, &cmd_len);
|
||||
TEST_ASSERT_EQ(status, SE050_OK, "Command encryption with default keys");
|
||||
TEST_ASSERT_EQ(status, SE050_OK, "Command encryption");
|
||||
TEST_ASSERT(cmd_len > 6, "Encrypted command should be padded");
|
||||
|
||||
print_hex("Encrypted Command", cmd, cmd_len < 32 ? cmd_len : 32);
|
||||
@@ -259,10 +254,10 @@ static void test_scp03_full_flow(void)
|
||||
TEST_ASSERT_EQ(status, SE050_OK, "Step 2: SCP03 initialization");
|
||||
|
||||
status = se050_session_scp03_set_keys(session,
|
||||
DEFAULT_ENC_KEY,
|
||||
DEFAULT_MAC_KEY,
|
||||
DEFAULT_DEK_KEY);
|
||||
TEST_ASSERT_EQ(status, SE050_OK, "Step 3: Set AN12436 default keys");
|
||||
SE050C0_ENC_KEY,
|
||||
SE050C0_MAC_KEY,
|
||||
SE050C0_DEK_KEY);
|
||||
TEST_ASSERT_EQ(status, SE050_OK, "Step 3: Set SE050C0 keys");
|
||||
|
||||
uint8_t cmd[64];
|
||||
size_t cmd_len = 6;
|
||||
@@ -289,28 +284,28 @@ static void test_scp03_full_flow(void)
|
||||
rsp_len = (size_t)bytes_read;
|
||||
|
||||
uint16_t sw = se050_session_scp03_decrypt(session, cmd_len, rsp, &rsp_len);
|
||||
TEST_ASSERT_EQ(sw, 0x9000, "Step 6: Decrypt response - success status");
|
||||
TEST_ASSERT_EQ(sw, 0x9000, "Step 6: Decrypt response");
|
||||
|
||||
print_hex("Decrypted Response", rsp, rsp_len < 32 ? rsp_len : 32);
|
||||
|
||||
se050_session_delete(session);
|
||||
TEST_ASSERT(1, "Step 7: Full flow completed successfully");
|
||||
TEST_ASSERT(1, "Step 7: Full flow completed");
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
* Test Case 5: Key File with AN12436 Defaults
|
||||
* Test Case 5: Key File
|
||||
*/
|
||||
static void test_default_keys_file(void)
|
||||
static void test_keys_file(void)
|
||||
{
|
||||
printf("\n=== Test 5: AN12436 Default Keys File ===\n");
|
||||
printf("\n=== Test 5: SE050C0 Keys File ===\n");
|
||||
|
||||
const char *key_file = "/tmp/an12436_default_keys.bin";
|
||||
const char *key_file = "/tmp/se050c0_keys.bin";
|
||||
FILE *fp = fopen(key_file, "wb");
|
||||
TEST_ASSERT(fp != NULL, "Should be able to create default key file");
|
||||
TEST_ASSERT(fp != NULL, "Create key file");
|
||||
|
||||
fwrite(DEFAULT_ENC_KEY, 1, 16, fp);
|
||||
fwrite(DEFAULT_MAC_KEY, 1, 16, fp);
|
||||
fwrite(DEFAULT_DEK_KEY, 1, 16, fp);
|
||||
fwrite(SE050C0_ENC_KEY, 1, 16, fp);
|
||||
fwrite(SE050C0_MAC_KEY, 1, 16, fp);
|
||||
fwrite(SE050C0_DEK_KEY, 1, 16, fp);
|
||||
fclose(fp);
|
||||
|
||||
se050_session_ctx_t *session = NULL;
|
||||
@@ -329,16 +324,16 @@ static void test_default_keys_file(void)
|
||||
TEST_ASSERT_EQ(status, SE050_OK, "SCP03 context creation");
|
||||
|
||||
status = se050_scp03_load_keys_from_file(scp03, key_file);
|
||||
TEST_ASSERT_EQ(status, SE050_OK, "Load AN12436 default keys from file");
|
||||
TEST_ASSERT_EQ(status, SE050_OK, "Load SE050C0 keys from file");
|
||||
|
||||
se050_scp03_free(scp03);
|
||||
se050_session_delete(session);
|
||||
remove(key_file);
|
||||
TEST_ASSERT(1, "AN12436 default keys file test completed");
|
||||
TEST_ASSERT(1, "Key file test completed");
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
* Test Case 6: Multiple Command/Response Cycles
|
||||
* Test Case 6: Multiple Cycles
|
||||
*/
|
||||
static void test_multiple_cycles(void)
|
||||
{
|
||||
@@ -356,10 +351,10 @@ static void test_multiple_cycles(void)
|
||||
TEST_ASSERT_EQ(status, SE050_OK, "SCP03 initialization");
|
||||
|
||||
status = se050_session_scp03_set_keys(session,
|
||||
DEFAULT_ENC_KEY,
|
||||
DEFAULT_MAC_KEY,
|
||||
DEFAULT_DEK_KEY);
|
||||
TEST_ASSERT_EQ(status, SE050_OK, "Set AN12436 default keys");
|
||||
SE050C0_ENC_KEY,
|
||||
SE050C0_MAC_KEY,
|
||||
SE050C0_DEK_KEY);
|
||||
TEST_ASSERT_EQ(status, SE050_OK, "Set SE050C0 keys");
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
uint8_t cmd[64];
|
||||
@@ -370,7 +365,7 @@ static void test_multiple_cycles(void)
|
||||
cmd[3] = 0x00;
|
||||
|
||||
status = se050_session_scp03_encrypt(session, cmd, &cmd_len);
|
||||
TEST_ASSERT_EQ(status, SE050_OK, "Encrypt command cycle");
|
||||
TEST_ASSERT_EQ(status, SE050_OK, "Encrypt cycle");
|
||||
|
||||
uint8_t response[16] = {0x90, 0x00};
|
||||
mock_i2c_set_response(&mock, response, sizeof(response));
|
||||
@@ -381,19 +376,19 @@ static void test_multiple_cycles(void)
|
||||
rsp_len = (size_t)bytes_read;
|
||||
|
||||
uint16_t sw = se050_session_scp03_decrypt(session, cmd_len, rsp, &rsp_len);
|
||||
TEST_ASSERT_EQ(sw, 0x9000, "Decrypt response cycle");
|
||||
TEST_ASSERT_EQ(sw, 0x9000, "Decrypt cycle");
|
||||
}
|
||||
|
||||
se050_session_delete(session);
|
||||
TEST_ASSERT(1, "Multiple cycles completed successfully");
|
||||
TEST_ASSERT(1, "Multiple cycles completed");
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
* Test Case 7: Counter Increment Verification
|
||||
* Test Case 7: Counter Increment
|
||||
*/
|
||||
static void test_counter_increment(void)
|
||||
{
|
||||
printf("\n=== Test 7: SCP03 Counter Increment Verification ===\n");
|
||||
printf("\n=== Test 7: SCP03 Counter Increment ===\n");
|
||||
|
||||
se050_session_ctx_t *session = NULL;
|
||||
mock_i2c_ctx_t mock;
|
||||
@@ -407,10 +402,10 @@ static void test_counter_increment(void)
|
||||
TEST_ASSERT_EQ(status, SE050_OK, "SCP03 initialization");
|
||||
|
||||
status = se050_session_scp03_set_keys(session,
|
||||
DEFAULT_ENC_KEY,
|
||||
DEFAULT_MAC_KEY,
|
||||
DEFAULT_DEK_KEY);
|
||||
TEST_ASSERT_EQ(status, SE050_OK, "Set AN12436 default keys");
|
||||
SE050C0_ENC_KEY,
|
||||
SE050C0_MAC_KEY,
|
||||
SE050C0_DEK_KEY);
|
||||
TEST_ASSERT_EQ(status, SE050_OK, "Set SE050C0 keys");
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
uint8_t cmd[64];
|
||||
@@ -421,11 +416,11 @@ static void test_counter_increment(void)
|
||||
cmd[3] = (uint8_t)i;
|
||||
|
||||
status = se050_session_scp03_encrypt(session, cmd, &cmd_len);
|
||||
TEST_ASSERT_EQ(status, SE050_OK, "Command encrypt cycle");
|
||||
TEST_ASSERT_EQ(status, SE050_OK, "Encrypt cycle");
|
||||
}
|
||||
|
||||
se050_session_delete(session);
|
||||
TEST_ASSERT(1, "Counter increment verification completed");
|
||||
TEST_ASSERT(1, "Counter increment verified");
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
@@ -433,17 +428,18 @@ static void test_counter_increment(void)
|
||||
*/
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
(void)argc; (void)argv; /* Unused */
|
||||
(void)argc; (void)argv;
|
||||
|
||||
printf("========================================\n");
|
||||
printf("Platform SCP03 Hardware Test Suite\n");
|
||||
printf("AN12436 Default Keys\n");
|
||||
printf("SE050C0 Keys\n");
|
||||
printf("========================================\n");
|
||||
|
||||
test_default_keys();
|
||||
test_scp03_default_keys();
|
||||
test_scp03_encrypt_default_keys();
|
||||
test_keys();
|
||||
test_scp03_se050c0_keys();
|
||||
test_scp03_encrypt();
|
||||
test_scp03_full_flow();
|
||||
test_default_keys_file();
|
||||
test_keys_file();
|
||||
test_multiple_cycles();
|
||||
test_counter_increment();
|
||||
|
||||
@@ -456,8 +452,7 @@ int main(int argc, char *argv[])
|
||||
printf("========================================\n");
|
||||
|
||||
if (test_failed == 0) {
|
||||
printf("\nAll tests passed! AN12436 default keys verified.\n");
|
||||
printf(" Ready for SE050 hardware testing.\n");
|
||||
printf("\n✓ All tests passed! SE050C0 keys verified.\n");
|
||||
}
|
||||
|
||||
return test_failed > 0 ? 1 : 0;
|
||||
|
||||
Reference in New Issue
Block a user