mirror of
https://github.com/rvtr/ctr_eFuse.git
synced 2025-11-02 00:11:04 -04:00
serial -> deviceId に置換
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_eFuse@99 ff987cc8-cf2f-4642-8568-d52cce064691
This commit is contained in:
parent
b5a1aaea14
commit
742bb88c8b
@ -163,16 +163,25 @@ int cr_generate_id_initialize( u8 err[CR_ID_BUF_SIZE] )
|
||||
|
||||
|
||||
// generate_id関数のファイナライズ
|
||||
int cr_generate_id_finalize( void )
|
||||
int cr_generate_id_finalize( u8 err[CR_ID_BUF_SIZE] )
|
||||
{
|
||||
int ret_code = CR_GENID_SUCCESS;
|
||||
|
||||
// init for error info
|
||||
InitErrorInfo();
|
||||
|
||||
// HSM
|
||||
#ifdef USE_HSM
|
||||
ret_code = hsm_finalize();
|
||||
if ( ret_code != CR_GENID_SUCCESS )
|
||||
{
|
||||
return CR_GENID_FAILED;
|
||||
CR_ERR_BUFFER *cr_err_buf = (CR_ERR_BUFFER *)id_buf;
|
||||
memset( cr_err_buf, 0, sizeof( CR_ERR_BUFFER ) );
|
||||
cr_err_buf->errorCode = ret_code;
|
||||
GetErrorInfo( cr_err_buf->callStack, &cr_err_buf->recordSize );
|
||||
#ifdef DEBUG_PRINT
|
||||
printf( "error(%d), CALL_STACK : %s\n", (int)cr_err_buf->errorCode, cr_err_buf->callStack );
|
||||
#endif
|
||||
}
|
||||
#endif // USE_HSM
|
||||
|
||||
@ -180,7 +189,7 @@ int cr_generate_id_finalize( void )
|
||||
} // cr_generate_id_finalize
|
||||
|
||||
// generate_id 関数
|
||||
int cr_generate_id( u32 serial[CR_NUM_OF_SERIAL], u8 id_buf[CR_ID_BUF_SIZE], u8 bondingOption )
|
||||
int cr_generate_id( u32 deviceId[CR_NUM_OF_DEVICEID], u8 id_buf[CR_ID_BUF_SIZE], u8 bondingOption )
|
||||
{
|
||||
int i;
|
||||
int ret_code = CR_GENID_SUCCESS;
|
||||
@ -230,18 +239,18 @@ int cr_generate_id( u32 serial[CR_NUM_OF_SERIAL], u8 id_buf[CR_ID_BUF_SIZE], u8
|
||||
cr_id_buf->bondingOption = bondingOption;
|
||||
|
||||
//--------------------------------------------------------------
|
||||
// serialNo.セット
|
||||
// deviceId セット
|
||||
//--------------------------------------------------------------
|
||||
for( i = 0 ; i < CR_NUM_OF_SERIAL ; i++ ) {
|
||||
cr_id_buf->serial[i] = serial[i]; /* serial[0] => ec priv key */
|
||||
for( i = 0 ; i < CR_NUM_OF_DEVICEID ; i++ ) {
|
||||
cr_id_buf->deviceId[i] = deviceId[i]; /* deviceId[0] => ec priv key */
|
||||
}
|
||||
|
||||
#ifdef DEBUG_PRINT
|
||||
if( cr_print_flag ) {
|
||||
printf("serialNo:\n");
|
||||
printf(" 0x%08x\n", (unsigned int)serial[0] );
|
||||
printf(" 0x%08x%08x\n", (unsigned int)serial[2], (unsigned int)serial[1] );
|
||||
printf(" 0x%08x%08x\n", (unsigned int)serial[4], (unsigned int)serial[3] );
|
||||
printf("deviceId:\n");
|
||||
printf(" 0x%08x\n", (unsigned int)deviceId[0] );
|
||||
printf(" 0x%08x%08x\n", (unsigned int)deviceId[2], (unsigned int)deviceId[1] );
|
||||
printf(" 0x%08x%08x\n", (unsigned int)deviceId[4], (unsigned int)deviceId[3] );
|
||||
printf("\n");
|
||||
}
|
||||
#endif /* DEBUG_PRINT */
|
||||
@ -292,7 +301,7 @@ int cr_generate_id( u32 serial[CR_NUM_OF_SERIAL], u8 id_buf[CR_ID_BUF_SIZE], u8
|
||||
// デバイス証明書生成 + 署名の付与 + 証明書期限セット
|
||||
//--------------------------------------------------------------
|
||||
ret_code = GenerateCTRDeviceCert( deviceKeyPair,
|
||||
cr_id_buf->serial[0],
|
||||
cr_id_buf->deviceId[0],
|
||||
cr_id_buf->bondingOption,
|
||||
cr_id_buf->deviceCertSign,
|
||||
&cr_id_buf->expiryDate );
|
||||
@ -316,7 +325,7 @@ int cr_generate_id( u32 serial[CR_NUM_OF_SERIAL], u8 id_buf[CR_ID_BUF_SIZE], u8
|
||||
//--------------------------------------------------------------
|
||||
DEBUG_PRINT_ARRAY( "RAW eFuseID:", (const char *)id_buf, CR_ID_BUF_SIZE );
|
||||
#ifdef DEBUG_EFUSE_ID_OUTPUT_FILE
|
||||
DebugFileOutput( serial[ 0 ], "raw", id_buf, CR_ID_BUF_SIZE );
|
||||
DebugFileOutput( deviceId[ 0 ], "raw", id_buf, CR_ID_BUF_SIZE );
|
||||
#endif // DEBUG_EFUSE_ID_OUTPUT_FILE
|
||||
|
||||
//--------------------------------------------------------------
|
||||
@ -330,7 +339,7 @@ int cr_generate_id( u32 serial[CR_NUM_OF_SERIAL], u8 id_buf[CR_ID_BUF_SIZE], u8
|
||||
|
||||
DEBUG_PRINT_ARRAY( "ENC eFuseID:", (const char *)id_buf, CR_ID_BUF_SIZE );
|
||||
#ifdef DEBUG_EFUSE_ID_OUTPUT_FILE
|
||||
DebugFileOutput( serial[ 0 ], "enc", id_buf, CR_ID_BUF_SIZE );
|
||||
DebugFileOutput( deviceId[ 0 ], "enc", id_buf, CR_ID_BUF_SIZE );
|
||||
#endif // DEBUG_EFUSE_ID_OUTPUT_FILE
|
||||
|
||||
//--------------------------------------------------------------
|
||||
@ -346,7 +355,7 @@ end:
|
||||
memset( cr_err_buf, 0, sizeof( CR_ERR_BUFFER ) );
|
||||
cr_err_buf->totalCount = generatingCount;
|
||||
cr_err_buf->magic_number = 0x01234567;
|
||||
cr_err_buf->serial0 = serial[0];
|
||||
cr_err_buf->deviceId0 = deviceId[0];
|
||||
cr_err_buf->errorCode = ret_code;
|
||||
GetErrorInfo( cr_err_buf->callStack, &cr_err_buf->recordSize );
|
||||
cr_err_buf->bondingOption = bondingOption;
|
||||
|
||||
@ -128,13 +128,13 @@ typedef unsigned long u32;
|
||||
typedef unsigned long long u64;
|
||||
|
||||
#define CR_ID_BUF_SIZE (2048/8)
|
||||
#define CR_NUM_OF_SERIAL 5
|
||||
#define CR_NUM_OF_DEVICEID 5
|
||||
|
||||
/*
|
||||
serial と 実際のID との関係は、下記のようになっています。
|
||||
ID0 = serial[ 0 ]
|
||||
ID1 = serial[ 1 ] | ( serial[ 2 ] << 32 )
|
||||
ID2 = serial[ 3 ] | ( serial[ 4 ] << 32 )
|
||||
deviceId と 実際のID との関係は、下記のようになっています。
|
||||
ID0 = deviceId[ 0 ]
|
||||
ID1 = deviceId[ 1 ] | ( deviceId[ 2 ] << 32 )
|
||||
ID2 = deviceId[ 3 ] | ( deviceId[ 4 ] << 32 )
|
||||
*/
|
||||
|
||||
// Nintendo ID Žd—l
|
||||
@ -146,7 +146,7 @@ typedef unsigned long long u64;
|
||||
#define CR_ID2_MASK 0xFFFFFFFFFFFFFFFFll // 64bit
|
||||
|
||||
extern int cr_generate_id_initialize( u8 err[CR_ID_BUF_SIZE] );
|
||||
extern int cr_generate_id( u32 serial[CR_NUM_OF_SERIAL], u8 id[CR_ID_BUF_SIZE], u8 bondingOption );
|
||||
extern int cr_generate_id( u32 deviceId[CR_NUM_OF_DEVICEID], u8 id[CR_ID_BUF_SIZE], u8 bondingOption );
|
||||
extern int cr_generate_id_finalize( u8 err[CR_ID_BUF_SIZE] );
|
||||
|
||||
extern int cr_print_flag;
|
||||
|
||||
@ -177,7 +177,7 @@ extern "C" {
|
||||
|
||||
typedef struct {
|
||||
u32 magic_number; /* 0x00 - 0x03 = 0xdeadb00f 確定!*/
|
||||
u32 serial[CR_NUM_OF_SERIAL]; /* 0x04 - 0x07 32bit device ID
|
||||
u32 deviceId[CR_NUM_OF_DEVICEID]; /* 0x04 - 0x07 32bit device ID
|
||||
(32bit。1固定カウントアップ。)
|
||||
(本ID+randomの先頭0x1C bytesを組み合わせて、デバイス秘密鍵とする。)
|
||||
0x08 - 0x0F 64bit CTR番号 seed
|
||||
@ -208,7 +208,7 @@ typedef struct {
|
||||
typedef struct {
|
||||
u64 totalCount; /* 0x00 - 0x07 */
|
||||
u32 magic_number; /* 0x08 - 0x0b 0x01234567 確定!*/
|
||||
u32 serial0; /* 0x0c - 0x0f */
|
||||
u32 deviceId0; /* 0x0c - 0x0f */
|
||||
s32 errorCode; /* 0x10 - 0x13 */
|
||||
u8 bondingOption; // TORIAEZU
|
||||
u8 recordSize; // コールスタックの記録サイズ
|
||||
|
||||
46
main.c
46
main.c
@ -168,7 +168,7 @@ static double gettimeofday_sec(void)
|
||||
|
||||
int main(int ac, char *argv[])
|
||||
{
|
||||
u32 serial[CR_NUM_OF_SERIAL];
|
||||
u32 deviceId[CR_NUM_OF_DEVICEID];
|
||||
u8 id[CR_ID_BUF_SIZE]; /* 256byte(2048bit) */
|
||||
int ret_code;
|
||||
int c;
|
||||
@ -244,15 +244,15 @@ int main(int ac, char *argv[])
|
||||
fprintf(stderr,"counter2 overflow : %08x%08x\n", (unsigned int)( counter2 >> 32 ), (unsigned int)counter2 );
|
||||
}
|
||||
|
||||
serial[0] = counter0;
|
||||
serial[1] = (u32)(counter1 & 0xffffffff);
|
||||
serial[2] = (u32)((counter1 >> 32) & 0xffffffff);
|
||||
serial[3] = (u32)(counter2 & 0xffffffff);
|
||||
serial[4] = (u32)((counter2 >> 32) & 0xffffffff);
|
||||
deviceId[0] = counter0;
|
||||
deviceId[1] = (u32)(counter1 & 0xffffffff);
|
||||
deviceId[2] = (u32)((counter1 >> 32) & 0xffffffff);
|
||||
deviceId[3] = (u32)(counter2 & 0xffffffff);
|
||||
deviceId[4] = (u32)((counter2 >> 32) & 0xffffffff);
|
||||
|
||||
|
||||
time_start = gettimeofday_sec();
|
||||
ret_code = cr_generate_id( serial, id, T_BONDING_OPTION );
|
||||
ret_code = cr_generate_id( deviceId, id, T_BONDING_OPTION );
|
||||
if( ret_code != 0 ) {
|
||||
fprintf(stderr,"generate_id failed\n");
|
||||
}
|
||||
@ -267,9 +267,9 @@ int main(int ac, char *argv[])
|
||||
{
|
||||
c = getch();
|
||||
if( 'p' == c ) {
|
||||
printf("ID[0] = 0x%08x\n", (unsigned int)serial[0]);
|
||||
printf("ID[1] = 0x%08x%08x\n", (unsigned int)serial[2], (unsigned int)serial[1] );
|
||||
printf("ID[2] = 0x%08x%08x\n", (unsigned int)serial[4], (unsigned int)serial[3] );
|
||||
printf("ID[0] = 0x%08x\n", (unsigned int)deviceId[0]);
|
||||
printf("ID[1] = 0x%08x%08x\n", (unsigned int)deviceId[2], (unsigned int)deviceId[1] );
|
||||
printf("ID[2] = 0x%08x%08x\n", (unsigned int)deviceId[4], (unsigned int)deviceId[3] );
|
||||
printf("time av. = %8.8f sec\n", (double)(time_total/(long double)time_count));
|
||||
cr_print_flag = 1;
|
||||
}
|
||||
@ -284,17 +284,17 @@ int main(int ac, char *argv[])
|
||||
}
|
||||
}
|
||||
else if( ac == 3 ) {
|
||||
if( 0 == str_to_u32(&serial[0], argv[1]) && 0 == str_to_u32(&serial[1], argv[2]) ) {
|
||||
printf("ID[0] = 0x%08x\n", (unsigned int)serial[0]);
|
||||
printf("ID[1] = 0x%08x%08x\n", (unsigned int)serial[2], (unsigned int)serial[1] );
|
||||
printf("ID[2] = 0x%08x%08x\n", (unsigned int)serial[4], (unsigned int)serial[3] );
|
||||
if( 0 == str_to_u32(&deviceId[0], argv[1]) && 0 == str_to_u32(&deviceId[1], argv[2]) ) {
|
||||
printf("ID[0] = 0x%08x\n", (unsigned int)deviceId[0]);
|
||||
printf("ID[1] = 0x%08x%08x\n", (unsigned int)deviceId[2], (unsigned int)deviceId[1] );
|
||||
printf("ID[2] = 0x%08x%08x\n", (unsigned int)deviceId[4], (unsigned int)deviceId[3] );
|
||||
|
||||
time_start = gettimeofday_sec();
|
||||
cr_print_flag = 1;
|
||||
if( 0 != cr_generate_id( serial, id, T_BONDING_OPTION ) )
|
||||
if( 0 != cr_generate_id( deviceId, id, T_BONDING_OPTION ) )
|
||||
{
|
||||
fprintf(stderr,"cr_generate_id failed s1=0x%08x s2_lo=0x%08x s2_hi=0x%08x\n",
|
||||
(int)serial[0], (int)serial[1], (int)serial[2]);
|
||||
(int)deviceId[0], (int)deviceId[1], (int)deviceId[2]);
|
||||
}
|
||||
else {
|
||||
time_end = gettimeofday_sec();
|
||||
@ -310,20 +310,20 @@ int main(int ac, char *argv[])
|
||||
|
||||
}
|
||||
else if( ac == 4 ) {
|
||||
if( 0 == str_to_u32(&serial[0], argv[1]) && 0 == str_to_u32(&serial[1], argv[2]) ) {
|
||||
printf("ID[0] = 0x%08x\n", (unsigned int)serial[0]);
|
||||
printf("ID[1] = 0x%08x%08x\n", (unsigned int)serial[2], (unsigned int)serial[1] );
|
||||
printf("ID[2] = 0x%08x%08x\n", (unsigned int)serial[4], (unsigned int)serial[3] );
|
||||
if( 0 == str_to_u32(&deviceId[0], argv[1]) && 0 == str_to_u32(&deviceId[1], argv[2]) ) {
|
||||
printf("ID[0] = 0x%08x\n", (unsigned int)deviceId[0]);
|
||||
printf("ID[1] = 0x%08x%08x\n", (unsigned int)deviceId[2], (unsigned int)deviceId[1] );
|
||||
printf("ID[2] = 0x%08x%08x\n", (unsigned int)deviceId[4], (unsigned int)deviceId[3] );
|
||||
fp = fopen( argv[3], "wb" );
|
||||
if( fp == NULL ) {
|
||||
fprintf(stderr, "failed to fopen %s\n",argv[3]);
|
||||
}
|
||||
else {
|
||||
time_start = gettimeofday_sec();
|
||||
if( 0 != cr_generate_id( serial, id, T_BONDING_OPTION ) )
|
||||
if( 0 != cr_generate_id( deviceId, id, T_BONDING_OPTION ) )
|
||||
{
|
||||
fprintf(stderr,"cr_generate_id failed s1=0x%08x s2_lo=0x%08x s2_hi=0x%08x\n",
|
||||
(int)serial[0], (int)serial[1], (int)serial[2]);
|
||||
(int)deviceId[0], (int)deviceId[1], (int)deviceId[2]);
|
||||
}
|
||||
else {
|
||||
time_end = gettimeofday_sec();
|
||||
@ -340,7 +340,7 @@ int main(int ac, char *argv[])
|
||||
err_print:
|
||||
fprintf(stderr,"Invalid argument!\n");
|
||||
fprintf(stderr,"Usage: %s\n", argv[0]);
|
||||
fprintf(stderr,"Usage: %s SerialNo.(32bit) filename.dat\n", argv[0]);
|
||||
fprintf(stderr,"Usage: %s deviceId(32bit) filename.dat\n", argv[0]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user