bondingOption -> bonding_option

git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_eFuse@109 ff987cc8-cf2f-4642-8568-d52cce064691
This commit is contained in:
kubodera_yuichi 2009-12-27 23:45:24 +00:00
parent e95cee71fd
commit ea5bc5fbf2
8 changed files with 49 additions and 49 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 bondingOption, u8 *pDevCertSign, u32 *pExpiryDate )
int GenerateCTRDeviceCert( EC_KEY *pECkey, u32 deviceId, u8 bonding_option, u8 *pDevCertSign, u32 *pExpiryDate )
{
int ret_code = CR_GENID_SUCCESS;
CR_DeviceCert deviceCert;
@ -178,8 +178,8 @@ int GenerateCTRDeviceCert( EC_KEY *pECkey, u32 deviceId, u8 bondingOption, u8 *p
// issuerName
memcpy( deviceCert.issuerName,
bondingOption ? issuerNameDev : issuerNameProd,
bondingOption ? strlen( issuerNameDev ) : strlen( issuerNameProd ) );
bonding_option ? issuerNameDev : issuerNameProd,
bonding_option ? strlen( issuerNameDev ) : strlen( issuerNameProd ) );
// keyType 0x00000002 ECC233
deviceCert.keyType[0] = 0x00;
@ -187,8 +187,8 @@ int GenerateCTRDeviceCert( EC_KEY *pECkey, u32 deviceId, u8 bondingOption, u8 *p
deviceCert.keyType[2] = 0x00;
deviceCert.keyType[3] = 0x02;
// subject : CT + deviceID + BondingOption
sprintf( deviceCert.subject, "CT%08X-%02X", (unsigned int)deviceId, bondingOption );
// subject : CT + deviceID + bonding_option
sprintf( deviceCert.subject, "CT%08X-%02X", (unsigned int)deviceId, bonding_option );
// expiryDate +20years
*pExpiryDate += CR_CERT_EXPIRE_SECS; // ID_BUFにも証明書期限をセットする。
@ -212,8 +212,8 @@ int GenerateCTRDeviceCert( EC_KEY *pECkey, u32 deviceId, u8 bondingOption, u8 *p
#else // !USE_HSM
// DERフォーマットのECC鍵を読み込み
{
// bondingOptionによって、鍵を差し替え
const unsigned char *der_priv = bondingOption ? cr_NintendoCTR2_priv_dummy_dev : cr_NintendoCTR2_priv_dummy_prod;
// bonding_option によって、鍵を差し替え
const unsigned char *der_priv = bonding_option ? cr_NintendoCTR2_priv_dummy_dev : cr_NintendoCTR2_priv_dummy_prod;
int priv_len = der_priv[ 8 ] | der_priv[ 9 ] << 8; // KEY長を取り出し
der_priv += 0x10; // ヘッダ部分を除外してKEY実体を指定

View File

@ -141,9 +141,9 @@ extern RSA *d2i_RSA_PUBKEY(RSA **a, const unsigned char **pp, long length);
#endif // USE_HSM
#ifdef ENCRYPT_AES
static int crypto_aes_enc_dec( unsigned char *dst_buf,unsigned char *org_buf, u8 bondingOption );
static int crypto_aes_enc_dec( unsigned char *dst_buf,unsigned char *org_buf, u8 bonding_option );
#else // !ENCRYPT_AES
static int crypto_rsa_enc_dec( unsigned char *dst_buf,unsigned char *org_buf, u8 bondingOption );
static int crypto_rsa_enc_dec( unsigned char *dst_buf,unsigned char *org_buf, u8 bonding_option );
#endif // ENCRYPT_AES
@ -151,14 +151,14 @@ static unsigned char local_buf_1[CR_ID_BUF_SIZE];
static unsigned char local_buf_2[CR_ID_BUF_SIZE];
// ビルドスイッチに従ってAES or RSA で指定バッファを暗号化
int EncryptID( unsigned char *dst_buf, unsigned char *org_buf, u8 bondingOption )
int EncryptID( unsigned char *dst_buf, unsigned char *org_buf, u8 bonding_option )
{
#ifdef ENCRYPT_AES
if( cr_print_flag ) printf( "[AES]\n");
return crypto_aes_enc_dec( dst_buf, org_buf, bondingOption ); // AES
return crypto_aes_enc_dec( dst_buf, org_buf, bonding_option ); // AES
#else // !ENCRYPT_AES
if( cr_print_flag ) printf( "[RSA]\n");
return crypto_rsa_enc_dec( dst_buf, org_buf, bondingOption ); // RSA pubKey enc
return crypto_rsa_enc_dec( dst_buf, org_buf, bonding_option ); // RSA pubKey enc
#endif // ENCRYPT_AES
}
@ -167,13 +167,13 @@ int EncryptID( unsigned char *dst_buf, unsigned char *org_buf, u8 bondingOption
// AES
#ifdef USE_HSM
int crypto_aes_enc_dec( unsigned char *dst_buf, unsigned char *org_buf, u8 bondingOption )
int crypto_aes_enc_dec( unsigned char *dst_buf, unsigned char *org_buf, u8 bonding_option )
{
int i;
int ret_code = CR_GENID_SUCCESS;
// encrypt
ret_code = hsm_aes_encrypt( local_buf_1, org_buf, CR_ID_BUF_SIZE, bondingOption );
ret_code = hsm_aes_encrypt( local_buf_1, org_buf, CR_ID_BUF_SIZE, bonding_option );
if ( ret_code != CR_GENID_SUCCESS )
{
SetErrorInfo( __FUNCTION__, __LINE__ );
@ -181,7 +181,7 @@ int crypto_aes_enc_dec( unsigned char *dst_buf, unsigned char *org_buf, u8 bondi
}
// decyrpt
ret_code = hsm_aes_decrypt( local_buf_2, local_buf_1, CR_ID_BUF_SIZE, bondingOption );
ret_code = hsm_aes_decrypt( local_buf_2, local_buf_1, CR_ID_BUF_SIZE, bonding_option );
if ( ret_code != CR_GENID_SUCCESS )
{
SetErrorInfo( __FUNCTION__, __LINE__ );
@ -206,15 +206,15 @@ int crypto_aes_enc_dec( unsigned char *dst_buf, unsigned char *org_buf, u8 bondi
#else // !USE_HSM
int crypto_aes_enc_dec( unsigned char *dst_buf, unsigned char *org_buf, u8 bondingOption )
int crypto_aes_enc_dec( unsigned char *dst_buf, unsigned char *org_buf, u8 bonding_option )
{
int i;
AES_KEY aesEncKey;
AES_KEY aesDecKey;
u8 temp_iv[16];
// 鍵データ取り出し。ヘッダ部分0x10を除去。
char *pAesKey = (char *)( bondingOption ? cr_eFuse_aesKey_dev : cr_eFuse_aesKey_prod ) + 0x10;
char *pIV = (char *)( bondingOption ? cr_eFuse_iv_dev : cr_eFuse_iv_prod ) + 0x10;
char *pAesKey = (char *)( bonding_option ? cr_eFuse_aesKey_dev : cr_eFuse_aesKey_prod ) + 0x10;
char *pIV = (char *)( bonding_option ? cr_eFuse_iv_dev : cr_eFuse_iv_prod ) + 0x10;
memset( local_buf_1, 0, CR_ID_BUF_SIZE );
memset( local_buf_2, 0, CR_ID_BUF_SIZE );
@ -259,13 +259,13 @@ int crypto_aes_enc_dec( unsigned char *dst_buf, unsigned char *org_buf, u8 bondi
// RSA
#ifdef USE_HSM
int crypto_rsa_enc_dec( unsigned char *dst_buf,unsigned char *org_buf, u8 bondingOption )
int crypto_rsa_enc_dec( unsigned char *dst_buf,unsigned char *org_buf, u8 bonding_option )
{
int i;
int ret_code = CR_GENID_SUCCESS;
// encrypt
ret_code = hsm_rsa_encrypt( local_buf_1, org_buf, CR_ID_BUF_SIZE, bondingOption );
ret_code = hsm_rsa_encrypt( local_buf_1, org_buf, CR_ID_BUF_SIZE, bonding_option );
if ( ret_code != CR_GENID_SUCCESS )
{
SetErrorInfo( __FUNCTION__, __LINE__ );
@ -273,7 +273,7 @@ int crypto_rsa_enc_dec( unsigned char *dst_buf,unsigned char *org_buf, u8 bondin
}
// decyrpt
ret_code = hsm_rsa_decrypt( local_buf_2, local_buf_1, CR_ID_BUF_SIZE, bondingOption );
ret_code = hsm_rsa_decrypt( local_buf_2, local_buf_1, CR_ID_BUF_SIZE, bonding_option );
if ( ret_code != CR_GENID_SUCCESS )
{
SetErrorInfo( __FUNCTION__, __LINE__ );
@ -298,7 +298,7 @@ int crypto_rsa_enc_dec( unsigned char *dst_buf,unsigned char *org_buf, u8 bondin
#else // USE_HSM
int crypto_rsa_enc_dec( unsigned char *dst_buf,unsigned char *org_buf, u8 bondingOption )
int crypto_rsa_enc_dec( unsigned char *dst_buf,unsigned char *org_buf, u8 bonding_option )
{
int ret_code = CR_GENID_SUCCESS;
int rsa_outlen = 0;
@ -310,9 +310,9 @@ int crypto_rsa_enc_dec( unsigned char *dst_buf,unsigned char *org_buf, u8 bondin
// DERフォーマットのRSA鍵を読み込み
{
// bondingOptionによって、鍵を差し替え
const unsigned char *der_priv = bondingOption ? cr_eFuse_privKey_dev : cr_eFuse_privKey_prod;
const unsigned char *der_pub = bondingOption ? cr_eFuse_pubKey_dev : cr_eFuse_pubKey_prod;
// bonding_option によって、鍵を差し替え
const unsigned char *der_priv = bonding_option ? cr_eFuse_privKey_dev : cr_eFuse_privKey_prod;
const unsigned char *der_pub = bonding_option ? cr_eFuse_pubKey_dev : cr_eFuse_pubKey_prod;
int priv_len = der_priv[ 8 ] | der_priv[ 9 ] << 8; // KEY長を取り出し
int pub_len = der_pub [ 8 ] | der_pub [ 9 ] << 8; // 同上
der_priv += 0x10; // ヘッダ部分を除外してKEY実体を指定

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 bondingOption )
int cr_generate_id( u32 deviceId[CR_NUM_OF_DEVICEID], u8 id_buf[CR_ID_BUF_SIZE], u8 bonding_option )
{
int i;
int ret_code = CR_GENID_SUCCESS;
@ -236,7 +236,7 @@ int cr_generate_id( u32 deviceId[CR_NUM_OF_DEVICEID], u8 id_buf[CR_ID_BUF_SIZE],
//--------------------------------------------------------------
// 引数のボンディングオプションをセット
//--------------------------------------------------------------
cr_id_buf->bondingOption = bondingOption;
cr_id_buf->bonding_option = bonding_option;
//--------------------------------------------------------------
// deviceId セット
@ -302,7 +302,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->bondingOption,
cr_id_buf->bonding_option,
cr_id_buf->deviceCertSign,
&cr_id_buf->expiryDate );
if ( ret_code != CR_GENID_SUCCESS ) {
@ -331,7 +331,7 @@ int cr_generate_id( u32 deviceId[CR_NUM_OF_DEVICEID], u8 id_buf[CR_ID_BUF_SIZE],
//--------------------------------------------------------------
// FuseIDバッファ全体をAES or RSAで暗号化
//--------------------------------------------------------------
ret_code = EncryptID( id_buf, id_buf, bondingOption );
ret_code = EncryptID( id_buf, id_buf, bonding_option );
if( ret_code != CR_GENID_SUCCESS ) {
SetErrorInfo( __FUNCTION__, __LINE__ );
goto end;
@ -358,7 +358,7 @@ end:
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;
cr_err_buf->bonding_option = bonding_option;
#ifdef DEBUG_PRINT
printf( "CALL_STACK : %s\n", cr_err_buf->callStack );
#endif

View File

@ -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 bondingOption );
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_finalize( u8 err_buf[CR_ID_BUF_SIZE] );
extern int cr_print_flag;

View File

@ -186,7 +186,7 @@ typedef struct {
(64bitフルに使用10x100000000)
*/
u8 version; /* 0x18 = CR_GEN_ID_VERSION = 1 */
u8 bondingOption; /* 0x19 ボンディングオプション */
u8 bonding_option; /* 0x19 ボンディングオプション */
u8 year; /* 0x1A デバイス証明書発行時間 HSMから取得 */
u8 month; /* 0x1B */
u8 mday; /* 0x1C */
@ -203,14 +203,14 @@ typedef struct {
u8 hash[ SHA256_DIGEST_LENGTH ]; /* 0xE0 - 0xFF "0x00-0xDF"領域のSHA256ハッシュ */
} CR_ID_BUFFER; /* 合計256bytes = 2048bit */
// TODO: 仕様FIXする必要あり -> 仮 version
// TORIAEZU Version
#define CALL_STACK_SIZE (234)
typedef struct {
u64 totalCount; /* 0x00 - 0x07 */
u32 magic_number; /* 0x08 - 0x0b 0x01234567 確定!*/
u32 deviceId0; /* 0x0c - 0x0f */
s32 errorCode; /* 0x10 - 0x13 */
u8 bondingOption; // TORIAEZU
u8 bonding_option;
u8 recordSize; // コールスタックの記録サイズ
u8 callStack[ CALL_STACK_SIZE ];
} CR_ERR_BUFFER;
@ -224,8 +224,8 @@ 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 bondingOption, u8 *pDevCertSign, u32 *pExpiryDate );
extern int EncryptID( unsigned char *dst_buf, unsigned char *org_buf, u8 bondingOption );
extern int GenerateCTRDeviceCert( EC_KEY *pECkey, u32 deviceId, 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 );

View File

@ -458,7 +458,7 @@ end:
return ret_code;
} // hsm_aes_load_key
int hsm_aes_encrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, u8 bondingOption )
int hsm_aes_encrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, u8 bonding_option )
{
int ret_code = CR_GENID_SUCCESS;
@ -471,7 +471,7 @@ int hsm_aes_encrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, u
memset( &reply, 0, sizeof( reply ) );
// key set
keyid = bondingOption ? hsmAesKeyidDev : hsmAesKeyidProd;
keyid = bonding_option ? hsmAesKeyidDev : hsmAesKeyidProd;
// iv set
enc_iv.mech = Mech_RijndaelmCBCpNONE;
@ -510,7 +510,7 @@ int hsm_aes_encrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, u
return CR_GENID_SUCCESS;
} // hsm_aes_encrypt
int hsm_aes_decrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, u8 bondingOption )
int hsm_aes_decrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, u8 bonding_option )
{
int ret_code = CR_GENID_SUCCESS;
@ -523,7 +523,7 @@ int hsm_aes_decrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, u
memset( &reply, 0, sizeof( reply ) );
// key set
keyid = bondingOption ? hsmAesKeyidDev : hsmAesKeyidProd;
keyid = bonding_option ? hsmAesKeyidDev : hsmAesKeyidProd;
// iv set
dec_iv.mech = Mech_RijndaelmCBCpNONE;
@ -620,7 +620,7 @@ end:
return ret_code;
} // hsm_rsa_load_keypair
int hsm_rsa_encrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, u8 bondingOption )
int hsm_rsa_encrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, u8 bonding_option )
{
int ret_code = CR_GENID_SUCCESS;
@ -632,7 +632,7 @@ int hsm_rsa_encrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, u
memset( &reply, 0, sizeof( reply ) );
// key set
keyid = bondingOption ? hsmRsaPubkeyidDev : hsmRsaPubkeyidProd;
keyid = bonding_option ? hsmRsaPubkeyidDev : hsmRsaPubkeyidProd;
// encrypt command set
cmd.cmd = Cmd_Encrypt;
@ -666,7 +666,7 @@ int hsm_rsa_encrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, u
return CR_GENID_SUCCESS;
} // hsm_rsa_encrypt
int hsm_rsa_decrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, u8 bondingOption )
int hsm_rsa_decrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, u8 bonding_option )
{
int ret_code = CR_GENID_SUCCESS;
@ -678,7 +678,7 @@ int hsm_rsa_decrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, u
memset( &reply, 0, sizeof( reply ) );
// key set
keyid = bondingOption ? hsmRsaPrivkeyidDev : hsmRsaPrivkeyidProd;
keyid = bonding_option ? hsmRsaPrivkeyidDev : hsmRsaPrivkeyidProd;
// decyrpt command set
cmd.cmd = Cmd_Decrypt;

View File

@ -124,10 +124,10 @@ int hsm_finalize( void );
int hsm_reset_module( void );
int hsm_generate_random( unsigned char *buf, int bytes );
int hsm_get_rtc( time_t *time );
int hsm_aes_encrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, unsigned char bondingOption );
int hsm_aes_decrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, unsigned char bondingOption );
int hsm_rsa_encrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, unsigned char bondingOption );
int hsm_rsa_decrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, unsigned char bondingOption );
int hsm_aes_encrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, unsigned char bonding_option );
int hsm_aes_decrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, unsigned char bonding_option );
int hsm_rsa_encrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, unsigned char bonding_option );
int hsm_rsa_decrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, unsigned char bonding_option );
#ifdef __cplusplus
}

2
main.c
View File

@ -16,7 +16,7 @@
#include "cr_generate_id.h"
#define T_BONDING_OPTION 0 // TORIAEZU bondingOption = 0
#define T_BONDING_OPTION 0 // TORIAEZU : bonding_option = 0
// extern const int isDummyPrivateKey;