deviceId -> device_id

git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_eFuse@110 ff987cc8-cf2f-4642-8568-d52cce064691
This commit is contained in:
kubodera_yuichi 2009-12-27 23:53:10 +00:00
parent ea5bc5fbf2
commit 7b7b78c56c
5 changed files with 52 additions and 52 deletions

View File

@ -155,7 +155,7 @@ static void BN2BinWithPadding( BIGNUM *pBn, u8 *pDst, int dstLen );
// create CTR Device cert
int GenerateCTRDeviceCert( EC_KEY *pECkey, u32 deviceId, u8 bonding_option, u8 *pDevCertSign, u32 *pExpiryDate )
int GenerateCTRDeviceCert( EC_KEY *pECkey, u32 device_id, u8 bonding_option, u8 *pDevCertSign, u32 *pExpiryDate )
{
int ret_code = CR_GENID_SUCCESS;
CR_DeviceCert deviceCert;
@ -187,8 +187,8 @@ int GenerateCTRDeviceCert( EC_KEY *pECkey, u32 deviceId, u8 bonding_option, u8 *
deviceCert.keyType[2] = 0x00;
deviceCert.keyType[3] = 0x02;
// subject : CT + deviceID + bonding_option
sprintf( deviceCert.subject, "CT%08X-%02X", (unsigned int)deviceId, bonding_option );
// subject : CT + device_id + bonding_option
sprintf( deviceCert.subject, "CT%08X-%02X", (unsigned int)device_id, bonding_option );
// expiryDate +20years
*pExpiryDate += CR_CERT_EXPIRE_SECS; // ID_BUFにも証明書期限をセットする。
@ -275,8 +275,8 @@ int GenerateCTRDeviceCert( EC_KEY *pECkey, u32 deviceId, u8 bonding_option, u8 *
memcpy( pDevCertSign, &deviceCert.eccSignature, 60 );
if( sig ) ECDSA_SIG_free( sig );
#ifdef DEBUG_DEVICE_CERT_OUTPUT_FILE
DebugFileOutput( deviceId, "dgst", sha256buf, 233/8 );
DebugFileOutput( deviceId, "sign", ecdsasig, signLen );
DebugFileOutput( device_id, "dgst", sha256buf, 233/8 );
DebugFileOutput( device_id, "sign", ecdsasig, signLen );
#endif // DEBUG_DEVICE_CERT_OUTPUT_FILE
}
#endif // USE_HSM
@ -306,7 +306,7 @@ int GenerateCTRDeviceCert( EC_KEY *pECkey, u32 deviceId, u8 bonding_option, u8 *
DEBUG_PRINT_ARRAY( "padding1:", (const char *)deviceCert.padding1, sizeof(deviceCert.padding1) );
#ifdef DEBUG_DEVICE_CERT_OUTPUT_FILE
DebugFileOutput( deviceId, "crt", (const u8 *)&deviceCert, sizeof(CR_DeviceCert) );
DebugFileOutput( device_id, "crt", (const u8 *)&deviceCert, sizeof(CR_DeviceCert) );
#endif // DEBUG_DEVICE_CERT_OUTPUT_FILE
}

View File

@ -189,7 +189,7 @@ int cr_generate_id_finalize( u8 err_buf[CR_ID_BUF_SIZE] )
} // cr_generate_id_finalize
// generate_id 関数
int cr_generate_id( u32 deviceId[CR_NUM_OF_DEVICEID], u8 id_buf[CR_ID_BUF_SIZE], u8 bonding_option )
int cr_generate_id( u32 device_id[CR_NUM_OF_DEVICEID], u8 id_buf[CR_ID_BUF_SIZE], u8 bonding_option )
{
int i;
int ret_code = CR_GENID_SUCCESS;
@ -239,18 +239,18 @@ int cr_generate_id( u32 deviceId[CR_NUM_OF_DEVICEID], u8 id_buf[CR_ID_BUF_SIZE],
cr_id_buf->bonding_option = bonding_option;
//--------------------------------------------------------------
// deviceId セット
// device_id セット
//--------------------------------------------------------------
for( i = 0 ; i < CR_NUM_OF_DEVICEID ; i++ ) {
cr_id_buf->deviceId[i] = deviceId[i]; /* deviceId[0] => ec priv key */
cr_id_buf->device_id[i] = device_id[i]; /* device_id[0] => ec priv key */
}
#ifdef DEBUG_PRINT
if( cr_print_flag ) {
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("device_id:\n");
printf(" 0x%08x\n", (unsigned int)device_id[0] );
printf(" 0x%08x%08x\n", (unsigned int)device_id[2], (unsigned int)device_id[1] );
printf(" 0x%08x%08x\n", (unsigned int)device_id[4], (unsigned int)device_id[3] );
printf("\n");
}
#endif /* DEBUG_PRINT */
@ -301,7 +301,7 @@ int cr_generate_id( u32 deviceId[CR_NUM_OF_DEVICEID], u8 id_buf[CR_ID_BUF_SIZE],
// デバイス証明書生成 + 署名の付与 + 証明書期限セット
//--------------------------------------------------------------
ret_code = GenerateCTRDeviceCert( deviceKeyPair,
cr_id_buf->deviceId[0],
cr_id_buf->device_id[0],
cr_id_buf->bonding_option,
cr_id_buf->deviceCertSign,
&cr_id_buf->expiryDate );
@ -325,7 +325,7 @@ int cr_generate_id( u32 deviceId[CR_NUM_OF_DEVICEID], u8 id_buf[CR_ID_BUF_SIZE],
//--------------------------------------------------------------
DEBUG_PRINT_ARRAY( "RAW eFuseID:", (const char *)id_buf, CR_ID_BUF_SIZE );
#ifdef DEBUG_EFUSE_ID_OUTPUT_FILE
DebugFileOutput( deviceId[ 0 ], "raw", id_buf, CR_ID_BUF_SIZE );
DebugFileOutput( device_id[ 0 ], "raw", id_buf, CR_ID_BUF_SIZE );
#endif // DEBUG_EFUSE_ID_OUTPUT_FILE
//--------------------------------------------------------------
@ -339,7 +339,7 @@ int cr_generate_id( u32 deviceId[CR_NUM_OF_DEVICEID], u8 id_buf[CR_ID_BUF_SIZE],
DEBUG_PRINT_ARRAY( "ENC eFuseID:", (const char *)id_buf, CR_ID_BUF_SIZE );
#ifdef DEBUG_EFUSE_ID_OUTPUT_FILE
DebugFileOutput( deviceId[ 0 ], "enc", id_buf, CR_ID_BUF_SIZE );
DebugFileOutput( device_id[ 0 ], "enc", id_buf, CR_ID_BUF_SIZE );
#endif // DEBUG_EFUSE_ID_OUTPUT_FILE
//--------------------------------------------------------------
@ -355,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->deviceId0 = deviceId[0];
cr_err_buf->device_id0 = device_id[0];
cr_err_buf->errorCode = ret_code;
GetErrorInfo( cr_err_buf->callStack, &cr_err_buf->recordSize );
cr_err_buf->bonding_option = bonding_option;
@ -394,14 +394,14 @@ void DebugPrintArray( char *pStr, const u8 *pData, int length )
}
#endif
void DebugFileOutput( u32 deviceId, char *pSuffix, const u8 *pSrc, int length )
void DebugFileOutput( u32 device_id, char *pSuffix, const u8 *pSrc, int length )
{
if ( cr_print_flag )
{
// 証明書の書き込みテスト
FILE *fp;
char fn[256];
sprintf( fn, "output/0x%08x.%s", (unsigned int)deviceId, pSuffix );
sprintf( fn, "output/0x%08x.%s", (unsigned int)device_id, pSuffix );
fp = fopen( fn, "wb" );
fwrite( pSrc, length, 1, fp );
fclose( fp );

View File

@ -131,10 +131,10 @@ typedef unsigned long long u64;
#define CR_NUM_OF_DEVICEID 5
/*
deviceId ID
ID0 = deviceId[ 0 ]
ID1 = deviceId[ 1 ] | ( deviceId[ 2 ] << 32 )
ID2 = deviceId[ 3 ] | ( deviceId[ 4 ] << 32 )
device_id ID
ID0 = device_id[ 0 ]
ID1 = device_id[ 1 ] | ( device_id[ 2 ] << 32 )
ID2 = device_id[ 3 ] | ( device_id[ 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_buf[CR_ID_BUF_SIZE] );
extern int cr_generate_id( u32 deviceId[CR_NUM_OF_DEVICEID], u8 id[CR_ID_BUF_SIZE], u8 bonding_option );
extern int cr_generate_id( u32 device_id[CR_NUM_OF_DEVICEID], u8 id[CR_ID_BUF_SIZE], u8 bonding_option );
extern int cr_generate_id_finalize( u8 err_buf[CR_ID_BUF_SIZE] );
extern int cr_print_flag;

View File

@ -176,8 +176,8 @@ extern "C" {
#define CR_GENID_ERROR_RSA_VERIFY (-16)
typedef struct {
u32 magic_number; /* 0x00 - 0x03 = 0xdeadb00f Šmè<E28099>I*/
u32 deviceId[CR_NUM_OF_DEVICEID]; /* 0x04 - 0x07 32bit device ID
u32 magic_number; /* 0x00 - 0x03 = 0xdeadb00f Šmè<E28099>I*/
u32 device_id[CR_NUM_OF_DEVICEID]; /* 0x04 - 0x07 32bit device ID
(32bit1
(IDrandomの先頭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 deviceId0; /* 0x0c - 0x0f */
u32 device_id0; /* 0x0c - 0x0f */
s32 errorCode; /* 0x10 - 0x13 */
u8 bonding_option;
u8 recordSize; // コールスタックの記録サイズ
@ -224,10 +224,10 @@ extern void SetErrorInfo( const char *funcName, u32 line );
extern void GetErrorInfo( char *stack, u8 *size );
extern int TestECDSA( EC_KEY *pECkey );
extern int GenerateCTRDeviceCert( EC_KEY *pECkey, u32 deviceId, u8 bonding_option, u8 *pDevCertSign, u32 *pExpiryDate );
extern int GenerateCTRDeviceCert( EC_KEY *pECkey, u32 device_id, u8 bonding_option, u8 *pDevCertSign, u32 *pExpiryDate );
extern int EncryptID( unsigned char *dst_buf, unsigned char *org_buf, u8 bonding_option );
extern void DebugPrintArray( char *pStr, const u8 *pData, int length );
extern void DebugFileOutput( u32 deviceId, char *pSuffix, const u8 *pSrc, int length );
extern void DebugFileOutput( u32 device_id, char *pSuffix, const u8 *pSrc, int length );
#ifdef __cplusplus
}

46
main.c
View File

@ -168,7 +168,7 @@ static double gettimeofday_sec(void)
int main(int ac, char *argv[])
{
u32 deviceId[CR_NUM_OF_DEVICEID];
u32 device_id[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 );
}
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);
device_id[0] = counter0;
device_id[1] = (u32)(counter1 & 0xffffffff);
device_id[2] = (u32)((counter1 >> 32) & 0xffffffff);
device_id[3] = (u32)(counter2 & 0xffffffff);
device_id[4] = (u32)((counter2 >> 32) & 0xffffffff);
time_start = gettimeofday_sec();
ret_code = cr_generate_id( deviceId, id, T_BONDING_OPTION );
ret_code = cr_generate_id( device_id, 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)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("ID[0] = 0x%08x\n", (unsigned int)device_id[0]);
printf("ID[1] = 0x%08x%08x\n", (unsigned int)device_id[2], (unsigned int)device_id[1] );
printf("ID[2] = 0x%08x%08x\n", (unsigned int)device_id[4], (unsigned int)device_id[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(&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] );
if( 0 == str_to_u32(&device_id[0], argv[1]) && 0 == str_to_u32(&device_id[1], argv[2]) ) {
printf("ID[0] = 0x%08x\n", (unsigned int)device_id[0]);
printf("ID[1] = 0x%08x%08x\n", (unsigned int)device_id[2], (unsigned int)device_id[1] );
printf("ID[2] = 0x%08x%08x\n", (unsigned int)device_id[4], (unsigned int)device_id[3] );
time_start = gettimeofday_sec();
cr_print_flag = 1;
if( 0 != cr_generate_id( deviceId, id, T_BONDING_OPTION ) )
if( 0 != cr_generate_id( device_id, id, T_BONDING_OPTION ) )
{
fprintf(stderr,"cr_generate_id failed s1=0x%08x s2_lo=0x%08x s2_hi=0x%08x\n",
(int)deviceId[0], (int)deviceId[1], (int)deviceId[2]);
(int)device_id[0], (int)device_id[1], (int)device_id[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(&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] );
if( 0 == str_to_u32(&device_id[0], argv[1]) && 0 == str_to_u32(&device_id[1], argv[2]) ) {
printf("ID[0] = 0x%08x\n", (unsigned int)device_id[0]);
printf("ID[1] = 0x%08x%08x\n", (unsigned int)device_id[2], (unsigned int)device_id[1] );
printf("ID[2] = 0x%08x%08x\n", (unsigned int)device_id[4], (unsigned int)device_id[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( deviceId, id, T_BONDING_OPTION ) )
if( 0 != cr_generate_id( device_id, id, T_BONDING_OPTION ) )
{
fprintf(stderr,"cr_generate_id failed s1=0x%08x s2_lo=0x%08x s2_hi=0x%08x\n",
(int)deviceId[0], (int)deviceId[1], (int)deviceId[2]);
(int)device_id[0], (int)device_id[1], (int)device_id[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 deviceId(32bit) filename.dat\n", argv[0]);
fprintf(stderr,"Usage: %s device_id(32bit) filename.dat\n", argv[0]);
}