diff --git a/cr_deviceCert.c b/cr_deviceCert.c index 14ac3a8..43e0cba 100644 --- a/cr_deviceCert.c +++ b/cr_deviceCert.c @@ -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 } diff --git a/cr_generate_id.c b/cr_generate_id.c index 232225c..f7c0779 100644 --- a/cr_generate_id.c +++ b/cr_generate_id.c @@ -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 ); diff --git a/cr_generate_id.h b/cr_generate_id.h index 883d7a7..b296efe 100644 --- a/cr_generate_id.h +++ b/cr_generate_id.h @@ -131,10 +131,10 @@ typedef unsigned long long u64; #define CR_NUM_OF_DEVICEID 5 /* - deviceId ۂID Ƃ̊֌ẂAL̂悤ɂȂĂ܂B - ID0 = deviceId[ 0 ] - ID1 = deviceId[ 1 ] | ( deviceId[ 2 ] << 32 ) - ID2 = deviceId[ 3 ] | ( deviceId[ 4 ] << 32 ) + device_id ۂID Ƃ̊֌ẂAL̂悤ɂȂĂ܂B + ID0 = device_id[ 0 ] + ID1 = device_id[ 1 ] | ( device_id[ 2 ] << 32 ) + ID2 = device_id[ 3 ] | ( device_id[ 4 ] << 32 ) */ // Nintendo ID dl @@ -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; diff --git a/cr_generate_id_private.h b/cr_generate_id_private.h index c37cf1f..fa53abd 100644 --- a/cr_generate_id_private.h +++ b/cr_generate_id_private.h @@ -176,8 +176,8 @@ extern "C" { #define CR_GENID_ERROR_RSA_VERIFY (-16) typedef struct { - u32 magic_number; /* 0x00 - 0x03 = 0xdeadb00f mI*/ - u32 deviceId[CR_NUM_OF_DEVICEID]; /* 0x04 - 0x07 32bit device ID + u32 magic_number; /* 0x00 - 0x03 = 0xdeadb00f mI*/ + u32 device_id[CR_NUM_OF_DEVICEID]; /* 0x04 - 0x07 32bit device ID (32bitB1ŒJEgAbvBj ({ID{random̐擪0x1C bytesgݍ킹āAfoCX閧ƂB) 0x08 - 0x0F 64bit CTRԍ seed @@ -208,7 +208,7 @@ typedef struct { typedef struct { u64 totalCount; /* 0x00 - 0x07 */ u32 magic_number; /* 0x08 - 0x0b 0x01234567 mI*/ - u32 deviceId0; /* 0x0c - 0x0f */ + u32 device_id0; /* 0x0c - 0x0f */ s32 errorCode; /* 0x10 - 0x13 */ u8 bonding_option; u8 recordSize; // R[X^bN̋L^TCY @@ -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 } diff --git a/main.c b/main.c index be75e8a..1a21d2d 100644 --- a/main.c +++ b/main.c @@ -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]); }