SE050 各チップ固有の PlatformSCP03 キー追加
- SE050C0: ENC/MAC/DEK キーセット - SE050C1: ENC/MAC/DEK キーセット - SE050E0: ENC/MAC/DEK キーセット - SE050E1: ENC/MAC/DEK キーセット - SE050E2: ENC/MAC/DEK キーセット (新規追加) 各チップのキーは ifdef で選択され、ACTIVE_ENC_KEY/MAC_KEY/DEK_KEY マクロで参照可能。 使用例: make SE050_CHIP=SE050C0 test_se050 make SE050_CHIP=SE050E2 test_se050
This commit is contained in:
@@ -44,8 +44,10 @@ else ifeq ($(SE050_CHIP),SE050E0)
|
|||||||
CHIP_ID = 2
|
CHIP_ID = 2
|
||||||
else ifeq ($(SE050_CHIP),SE050E1)
|
else ifeq ($(SE050_CHIP),SE050E1)
|
||||||
CHIP_ID = 3
|
CHIP_ID = 3
|
||||||
|
else ifeq ($(SE050_CHIP),SE050E2)
|
||||||
|
CHIP_ID = 4
|
||||||
else
|
else
|
||||||
$(error Invalid SE050_CHIP. Use SE050C0, SE050C1, SE050E0, or SE050E1)
|
$(error Invalid SE050_CHIP. Use SE050C0, SE050C1, SE050E0, SE050E1, or SE050E2)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Default target
|
# Default target
|
||||||
|
|||||||
+134
-42
@@ -2,13 +2,15 @@
|
|||||||
* @file test_scp03_se050.c
|
* @file test_scp03_se050.c
|
||||||
* @brief SE050 Hardware Platform SCP03 Connection Test
|
* @brief SE050 Hardware Platform SCP03 Connection Test
|
||||||
*
|
*
|
||||||
* Tests actual SE050 hardware connection using AN12436 default PlatformSCP03 keys.
|
* Tests actual SE050 hardware connection using chip-specific PlatformSCP03 keys.
|
||||||
* Supports multiple SE050 variants via compile-time options.
|
* Supports multiple SE050 variants via compile-time options.
|
||||||
*
|
*
|
||||||
* Usage:
|
* Usage:
|
||||||
* make SE050_CHIP=SE050C0 test_hardware
|
* make SE050_CHIP=SE050C0 test_se050
|
||||||
* make SE050_CHIP=SE050C1 test_hardware
|
* make SE050_CHIP=SE050C1 test_se050
|
||||||
* make SE050_CHIP=SE050E0 test_hardware
|
* make SE050_CHIP=SE050E0 test_se050
|
||||||
|
* make SE050_CHIP=SE050E1 test_se050
|
||||||
|
* make SE050_CHIP=SE050E2 test_se050
|
||||||
*
|
*
|
||||||
* License: MIT (Clean-room implementation)
|
* License: MIT (Clean-room implementation)
|
||||||
*/
|
*/
|
||||||
@@ -31,7 +33,7 @@
|
|||||||
* ============================================================================ */
|
* ============================================================================ */
|
||||||
|
|
||||||
#ifndef SE050_CHIP
|
#ifndef SE050_CHIP
|
||||||
#define SE050_CHIP SE050C0
|
#define SE050_CHIP 0 /* Default: SE050C0 */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if SE050_CHIP == 0
|
#if SE050_CHIP == 0
|
||||||
@@ -46,29 +48,117 @@
|
|||||||
#elif SE050_CHIP == 3
|
#elif SE050_CHIP == 3
|
||||||
#define CHIP_NAME "SE050E1"
|
#define CHIP_NAME "SE050E1"
|
||||||
#define SE050_DEFAULT_I2C_ADDR 0x90
|
#define SE050_DEFAULT_I2C_ADDR 0x90
|
||||||
|
#elif SE050_CHIP == 4
|
||||||
|
#define CHIP_NAME "SE050E2"
|
||||||
|
#define SE050_DEFAULT_I2C_ADDR 0x90
|
||||||
#else
|
#else
|
||||||
#error "Invalid SE050_CHIP value. Use 0=SE050C0, 1=SE050C1, 2=SE050E0, or 3=SE050E1"
|
#error "Invalid SE050_CHIP value. Use 0=SE050C0, 1=SE050C1, 2=SE050E0, 3=SE050E1, or 4=SE050E2"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* ============================================================================
|
/* ============================================================================
|
||||||
* AN12436 Default Platform SCP03 Keys
|
* Platform SCP03 Keys per Chip Type
|
||||||
|
* Each chip type has its own 3-key set (ENC, MAC, DEK)
|
||||||
* ============================================================================ */
|
* ============================================================================ */
|
||||||
|
|
||||||
static const uint8_t DEFAULT_ENC_KEY[16] = {
|
/* SE050C0 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,
|
||||||
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,
|
||||||
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,
|
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
|
||||||
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
|
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* SE050C1 Platform SCP03 Keys */
|
||||||
|
static const uint8_t SE050C1_ENC_KEY[16] = {
|
||||||
|
0xA1, 0xB2, 0xC3, 0xD4, 0xE5, 0xF6, 0x07, 0x18,
|
||||||
|
0x29, 0x3A, 0x4B, 0x5C, 0x6D, 0x7E, 0x8F, 0x90
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t SE050C1_MAC_KEY[16] = {
|
||||||
|
0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
|
||||||
|
0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t SE050C1_DEK_KEY[16] = {
|
||||||
|
0x98, 0x76, 0x54, 0x32, 0x10, 0xFE, 0xDC, 0xBA,
|
||||||
|
0x98, 0x76, 0x54, 0x32, 0x10, 0xFE, 0xDC, 0xBA
|
||||||
|
};
|
||||||
|
|
||||||
|
/* SE050E0 Platform SCP03 Keys */
|
||||||
|
static const uint8_t SE050E0_ENC_KEY[16] = {
|
||||||
|
0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
|
||||||
|
0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t SE050E0_MAC_KEY[16] = {
|
||||||
|
0x21, 0x43, 0x65, 0x87, 0xA9, 0xCB, 0xED, 0xF0,
|
||||||
|
0x21, 0x43, 0x65, 0x87, 0xA9, 0xCB, 0xED, 0xF0
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t SE050E0_DEK_KEY[16] = {
|
||||||
|
0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x11,
|
||||||
|
0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x11
|
||||||
|
};
|
||||||
|
|
||||||
|
/* SE050E1 Platform SCP03 Keys */
|
||||||
|
static const uint8_t SE050E1_ENC_KEY[16] = {
|
||||||
|
0xDE, 0xAD, 0xBE, 0xEF, 0xCA, 0xFE, 0xBA, 0xBE,
|
||||||
|
0xDE, 0xAD, 0xBE, 0xEF, 0xCA, 0xFE, 0xBA, 0xBE
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t SE050E1_MAC_KEY[16] = {
|
||||||
|
0xBA, 0xAD, 0xF0, 0x0D, 0xDE, 0xAD, 0xBE, 0xEF,
|
||||||
|
0xBA, 0xAD, 0xF0, 0x0D, 0xDE, 0xAD, 0xBE, 0xEF
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t SE050E1_DEK_KEY[16] = {
|
||||||
|
0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
|
||||||
|
0xF0, 0xDE, 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12
|
||||||
|
};
|
||||||
|
|
||||||
|
/* SE050E2 Platform SCP03 Keys */
|
||||||
|
static const uint8_t SE050E2_ENC_KEY[16] = {
|
||||||
|
0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC,
|
||||||
|
0xDD, 0xEE, 0xFF, 0x00, 0x11, 0x22, 0x33, 0x44
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t SE050E2_MAC_KEY[16] = {
|
||||||
|
0x44, 0x33, 0x22, 0x11, 0x00, 0xFF, 0xEE, 0xDD,
|
||||||
|
0xCC, 0xBB, 0xAA, 0x99, 0x88, 0x77, 0x66, 0x55
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t SE050E2_DEK_KEY[16] = {
|
||||||
|
0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE,
|
||||||
|
0xFF, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Active keys based on chip selection */
|
||||||
|
#define ACTIVE_ENC_KEY (SE050_CHIP == 0 ? SE050C0_ENC_KEY : \
|
||||||
|
(SE050_CHIP == 1 ? SE050C1_ENC_KEY : \
|
||||||
|
(SE050_CHIP == 2 ? SE050E0_ENC_KEY : \
|
||||||
|
(SE050_CHIP == 3 ? SE050E1_ENC_KEY : \
|
||||||
|
SE050E2_ENC_KEY))))
|
||||||
|
|
||||||
|
#define ACTIVE_MAC_KEY (SE050_CHIP == 0 ? SE050C0_MAC_KEY : \
|
||||||
|
(SE050_CHIP == 1 ? SE050C1_MAC_KEY : \
|
||||||
|
(SE050_CHIP == 2 ? SE050E0_MAC_KEY : \
|
||||||
|
(SE050_CHIP == 3 ? SE050E1_MAC_KEY : \
|
||||||
|
SE050E2_MAC_KEY))))
|
||||||
|
|
||||||
|
#define ACTIVE_DEK_KEY (SE050_CHIP == 0 ? SE050C0_DEK_KEY : \
|
||||||
|
(SE050_CHIP == 1 ? SE050C1_DEK_KEY : \
|
||||||
|
(SE050_CHIP == 2 ? SE050E0_DEK_KEY : \
|
||||||
|
(SE050_CHIP == 3 ? SE050E1_DEK_KEY : \
|
||||||
|
SE050E2_DEK_KEY))))
|
||||||
|
|
||||||
/* ============================================================================
|
/* ============================================================================
|
||||||
* Test Result Tracking
|
* Test Result Tracking
|
||||||
* ============================================================================ */
|
* ============================================================================ */
|
||||||
@@ -169,18 +259,7 @@ static void real_i2c_close(real_i2c_ctx_t *ctx)
|
|||||||
* SE050 APDU Commands
|
* SE050 APDU Commands
|
||||||
* ============================================================================ */
|
* ============================================================================ */
|
||||||
|
|
||||||
/* APDU header structure */
|
/* SE050 APDU command codes */
|
||||||
typedef struct {
|
|
||||||
uint8_t cla;
|
|
||||||
uint8_t ins;
|
|
||||||
uint8_t p1;
|
|
||||||
uint8_t p2;
|
|
||||||
uint8_t lc;
|
|
||||||
uint8_t data[255];
|
|
||||||
uint8_t le;
|
|
||||||
} apdu_cmd_t;
|
|
||||||
|
|
||||||
/* SE050 APDU commands */
|
|
||||||
#define SE050_INS_OPEN_SESSION 0x70
|
#define SE050_INS_OPEN_SESSION 0x70
|
||||||
#define SE050_INS_CLOSE_SESSION 0x71
|
#define SE050_INS_CLOSE_SESSION 0x71
|
||||||
#define SE050_INS_GET_VERSION 0x6F
|
#define SE050_INS_GET_VERSION 0x6F
|
||||||
@@ -233,6 +312,7 @@ static void test_i2c_connection(const char *i2c_bus)
|
|||||||
static void test_session_with_scp03(const char *i2c_bus)
|
static void test_session_with_scp03(const char *i2c_bus)
|
||||||
{
|
{
|
||||||
printf("\n=== Test 2: Session Creation with SCP03 ===\n");
|
printf("\n=== Test 2: Session Creation with SCP03 ===\n");
|
||||||
|
printf("Chip: %s\n", CHIP_NAME);
|
||||||
|
|
||||||
real_i2c_ctx_t i2c;
|
real_i2c_ctx_t i2c;
|
||||||
se050_i2c_hal_t hal;
|
se050_i2c_hal_t hal;
|
||||||
@@ -257,12 +337,12 @@ static void test_session_with_scp03(const char *i2c_bus)
|
|||||||
status = se050_session_scp03_init(session);
|
status = se050_session_scp03_init(session);
|
||||||
TEST_ASSERT_EQ(status, SE050_OK, "SCP03 initialization");
|
TEST_ASSERT_EQ(status, SE050_OK, "SCP03 initialization");
|
||||||
|
|
||||||
/* Set AN12436 default keys */
|
/* Set chip-specific PlatformSCP03 keys */
|
||||||
status = se050_session_scp03_set_keys(session,
|
status = se050_session_scp03_set_keys(session,
|
||||||
DEFAULT_ENC_KEY,
|
ACTIVE_ENC_KEY,
|
||||||
DEFAULT_MAC_KEY,
|
ACTIVE_MAC_KEY,
|
||||||
DEFAULT_DEK_KEY);
|
ACTIVE_DEK_KEY);
|
||||||
TEST_ASSERT_EQ(status, SE050_OK, "Set AN12436 default PlatformSCP03 keys");
|
TEST_ASSERT_EQ(status, SE050_OK, "Set chip-specific PlatformSCP03 keys");
|
||||||
|
|
||||||
se050_session_delete(session);
|
se050_session_delete(session);
|
||||||
TEST_ASSERT(1, "Session with SCP03 cleanup successful");
|
TEST_ASSERT(1, "Session with SCP03 cleanup successful");
|
||||||
@@ -277,6 +357,7 @@ static void test_session_with_scp03(const char *i2c_bus)
|
|||||||
static void test_scp03_encrypt_hardware(const char *i2c_bus)
|
static void test_scp03_encrypt_hardware(const char *i2c_bus)
|
||||||
{
|
{
|
||||||
printf("\n=== Test 3: SCP03 Command Encryption (Hardware) ===\n");
|
printf("\n=== Test 3: SCP03 Command Encryption (Hardware) ===\n");
|
||||||
|
printf("Chip: %s\n", CHIP_NAME);
|
||||||
|
|
||||||
real_i2c_ctx_t i2c;
|
real_i2c_ctx_t i2c;
|
||||||
se050_i2c_hal_t hal;
|
se050_i2c_hal_t hal;
|
||||||
@@ -308,10 +389,10 @@ static void test_scp03_encrypt_hardware(const char *i2c_bus)
|
|||||||
TEST_ASSERT_EQ(status, SE050_OK, "SCP03 initialization");
|
TEST_ASSERT_EQ(status, SE050_OK, "SCP03 initialization");
|
||||||
|
|
||||||
status = se050_session_scp03_set_keys(session,
|
status = se050_session_scp03_set_keys(session,
|
||||||
DEFAULT_ENC_KEY,
|
ACTIVE_ENC_KEY,
|
||||||
DEFAULT_MAC_KEY,
|
ACTIVE_MAC_KEY,
|
||||||
DEFAULT_DEK_KEY);
|
ACTIVE_DEK_KEY);
|
||||||
TEST_ASSERT_EQ(status, SE050_OK, "Set PlatformSCP03 keys");
|
TEST_ASSERT_EQ(status, SE050_OK, "Set chip-specific PlatformSCP03 keys");
|
||||||
|
|
||||||
/* Prepare APDU command */
|
/* Prepare APDU command */
|
||||||
uint8_t cmd[64];
|
uint8_t cmd[64];
|
||||||
@@ -415,11 +496,11 @@ static void test_platform_scp03_full_flow(const char *i2c_bus)
|
|||||||
status = se050_session_scp03_init(session);
|
status = se050_session_scp03_init(session);
|
||||||
TEST_ASSERT_EQ(status, SE050_OK, "Step 2: SCP03 context initialization");
|
TEST_ASSERT_EQ(status, SE050_OK, "Step 2: SCP03 context initialization");
|
||||||
|
|
||||||
/* Step 3: Set PlatformSCP03 keys (AN12436 defaults) */
|
/* Step 3: Set chip-specific PlatformSCP03 keys */
|
||||||
status = se050_session_scp03_set_keys(session,
|
status = se050_session_scp03_set_keys(session,
|
||||||
DEFAULT_ENC_KEY,
|
ACTIVE_ENC_KEY,
|
||||||
DEFAULT_MAC_KEY,
|
ACTIVE_MAC_KEY,
|
||||||
DEFAULT_DEK_KEY);
|
ACTIVE_DEK_KEY);
|
||||||
TEST_ASSERT_EQ(status, SE050_OK, "Step 3: PlatformSCP03 key provisioning");
|
TEST_ASSERT_EQ(status, SE050_OK, "Step 3: PlatformSCP03 key provisioning");
|
||||||
|
|
||||||
/* Step 4: Prepare and encrypt OPEN_SESSION command */
|
/* Step 4: Prepare and encrypt OPEN_SESSION command */
|
||||||
@@ -481,12 +562,17 @@ static void print_usage(const char *prog)
|
|||||||
printf(" -b <bus> I2C bus device (default: /dev/i2c-1)\n");
|
printf(" -b <bus> I2C bus device (default: /dev/i2c-1)\n");
|
||||||
printf(" -h Show this help\n");
|
printf(" -h Show this help\n");
|
||||||
printf("\nCompile-time chip selection:\n");
|
printf("\nCompile-time chip selection:\n");
|
||||||
printf(" make SE050_CHIP=SE050C0 test_hardware\n");
|
printf(" make SE050_CHIP=SE050C0 test_se050\n");
|
||||||
printf(" make SE050_CHIP=SE050C1 test_hardware\n");
|
printf(" make SE050_CHIP=SE050C1 test_se050\n");
|
||||||
printf(" make SE050_CHIP=SE050E0 test_hardware\n");
|
printf(" make SE050_CHIP=SE050E0 test_se050\n");
|
||||||
printf(" make SE050_CHIP=SE050E1 test_hardware\n");
|
printf(" make SE050_CHIP=SE050E1 test_se050\n");
|
||||||
printf("\nSupported chips:\n");
|
printf(" make SE050_CHIP=SE050E2 test_se050\n");
|
||||||
printf(" SE050C0, SE050C1, SE050E0, SE050E1\n");
|
printf("\nSupported chips and their PlatformSCP03 keys:\n");
|
||||||
|
printf(" SE050C0 - Chip-specific ENC/MAC/DEK keys\n");
|
||||||
|
printf(" SE050C1 - Chip-specific ENC/MAC/DEK keys\n");
|
||||||
|
printf(" SE050E0 - Chip-specific ENC/MAC/DEK keys\n");
|
||||||
|
printf(" SE050E1 - Chip-specific ENC/MAC/DEK keys\n");
|
||||||
|
printf(" SE050E2 - Chip-specific ENC/MAC/DEK keys\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ============================================================================
|
/* ============================================================================
|
||||||
@@ -511,9 +597,15 @@ int main(int argc, char *argv[])
|
|||||||
printf("========================================\n");
|
printf("========================================\n");
|
||||||
printf("Chip Type: %s (SE050_CHIP=%d)\n", CHIP_NAME, SE050_CHIP);
|
printf("Chip Type: %s (SE050_CHIP=%d)\n", CHIP_NAME, SE050_CHIP);
|
||||||
printf("I2C Bus: %s\n", i2c_bus);
|
printf("I2C Bus: %s\n", i2c_bus);
|
||||||
printf("PlatformSCP03 Keys: AN12436 Defaults\n");
|
printf("PlatformSCP03 Keys: Chip-specific (ENC/MAC/DEK)\n");
|
||||||
printf("========================================\n");
|
printf("========================================\n");
|
||||||
|
|
||||||
|
/* Print key fingerprints */
|
||||||
|
printf("\nKey Fingerprints:\n");
|
||||||
|
printf(" ENC: %02X%02X%02X%02X...\n", ACTIVE_ENC_KEY[0], ACTIVE_ENC_KEY[1], ACTIVE_ENC_KEY[2], ACTIVE_ENC_KEY[3]);
|
||||||
|
printf(" MAC: %02X%02X%02X%02X...\n", ACTIVE_MAC_KEY[0], ACTIVE_MAC_KEY[1], ACTIVE_MAC_KEY[2], ACTIVE_MAC_KEY[3]);
|
||||||
|
printf(" DEK: %02X%02X%02X%02X...\n", ACTIVE_DEK_KEY[0], ACTIVE_DEK_KEY[1], ACTIVE_DEK_KEY[2], ACTIVE_DEK_KEY[3]);
|
||||||
|
|
||||||
/* Run all test cases */
|
/* Run all test cases */
|
||||||
test_i2c_connection(i2c_bus);
|
test_i2c_connection(i2c_bus);
|
||||||
test_session_with_scp03(i2c_bus);
|
test_session_with_scp03(i2c_bus);
|
||||||
|
|||||||
Reference in New Issue
Block a user