mirror of
https://github.com/rvtr/ctr_eFuse.git
synced 2025-11-02 00:11:04 -04:00
・エラーコードの整理。
・TODOの追加。 git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_eFuse@82 ff987cc8-cf2f-4642-8568-d52cce064691
This commit is contained in:
parent
acb6127092
commit
b2e6de4d10
@ -161,12 +161,12 @@ int GenerateCTRDeviceCert( EC_KEY *pECkey, u32 deviceId, u8 bondingOption, u8 *p
|
|||||||
CR_DeviceCert deviceCert;
|
CR_DeviceCert deviceCert;
|
||||||
EC_KEY *NintendoCTR2 = NULL;
|
EC_KEY *NintendoCTR2 = NULL;
|
||||||
|
|
||||||
|
#ifdef DEBUG_PRINT
|
||||||
if ( sizeof( CR_DeviceCert ) > 384 )
|
if ( sizeof( CR_DeviceCert ) > 384 )
|
||||||
{
|
{
|
||||||
ret_code = CR_GENID_ERROR_CERT_BUF_SIZE;
|
printf( "CR_DeviceCert size error. %d\n", sizeof(CR_DeviceCert) );
|
||||||
SetErrorInfo( __FUNCTION__, __LINE__ );
|
|
||||||
goto end;
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
memset( &deviceCert, 0, sizeof(deviceCert) );
|
memset( &deviceCert, 0, sizeof(deviceCert) );
|
||||||
|
|
||||||
@ -262,7 +262,7 @@ int GenerateCTRDeviceCert( EC_KEY *pECkey, u32 deviceId, u8 bondingOption, u8 *p
|
|||||||
// DERデコードして、r と s を eccSignature にセット
|
// DERデコードして、r と s を eccSignature にセット
|
||||||
sig = d2i_ECDSA_SIG( NULL, &pECDSAsig, signLen );
|
sig = d2i_ECDSA_SIG( NULL, &pECDSAsig, signLen );
|
||||||
if( sig == NULL ) {
|
if( sig == NULL ) {
|
||||||
ret_code = CR_GENID_ERROR_ECDSA_DECODE;
|
ret_code = CR_GENID_ERROR_ECDSA_DEC;
|
||||||
SetErrorInfo( __FUNCTION__, __LINE__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -189,17 +189,14 @@ int cr_generate_id( u32 serial[CR_NUM_OF_SERIAL], u8 id_buf[CR_ID_BUF_SIZE], u8
|
|||||||
InitErrorInfo();
|
InitErrorInfo();
|
||||||
generatingCount++;
|
generatingCount++;
|
||||||
|
|
||||||
|
#ifdef DEBUG_PRINT
|
||||||
if( sizeof(CR_ID_BUFFER) != 256 ) {
|
if( sizeof(CR_ID_BUFFER) != 256 ) {
|
||||||
ret_code = CR_GENID_ERROR_ID_BUF_SIZE;
|
printf( "CR_ID_BUFFER size error. %d\n", sizeof(CR_ID_BUFFER) );
|
||||||
SetErrorInfo( __FUNCTION__, __LINE__ );
|
|
||||||
goto end;
|
|
||||||
}
|
}
|
||||||
|
if( sizeof(CR_ERR_BUFFER) != 256 ) {
|
||||||
if( sizeof(CR_ERR_BUFFER) > 256 ) {
|
printf( "CR_ERR_BUFFER size error. %d\n", sizeof(CR_ERR_BUFFER) );
|
||||||
ret_code = CR_GENID_ERROR_ERR_BUF_SIZE;
|
|
||||||
SetErrorInfo( __FUNCTION__, __LINE__ );
|
|
||||||
goto end;
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// ダイジェストアルゴリズムを追加する
|
// ダイジェストアルゴリズムを追加する
|
||||||
OpenSSL_add_all_digests();
|
OpenSSL_add_all_digests();
|
||||||
|
|||||||
@ -114,40 +114,29 @@
|
|||||||
|
|
||||||
// 成功
|
// 成功
|
||||||
#define CR_GENID_SUCCESS ( 0)
|
#define CR_GENID_SUCCESS ( 0)
|
||||||
|
#define CR_GENID_FAILED ( 1)
|
||||||
#define CR_GENID_INITIALIZE_OK (1000)
|
#define CR_GENID_INITIALIZE_OK (1000)
|
||||||
#define CR_GENID_FINALIZE_OK (1001)
|
#define CR_GENID_FINALIZE_OK (1001)
|
||||||
|
|
||||||
//---------------------------------------------------
|
//---------------------------------------------------
|
||||||
// OpenSSLの処理結果によるエラーコード
|
// OpenSSLの処理結果によるエラーコード
|
||||||
//---------------------------------------------------
|
//---------------------------------------------------
|
||||||
// TODO : 種類毎にソートする必要あり
|
#define CR_GENID_ERROR_BN_NEW ( -1)
|
||||||
#define CR_GENID_ERROR_RSA_ENC ( -1)
|
#define CR_GENID_ERROR_ECC_KEY_NEW ( -2)
|
||||||
#define CR_GENID_ERROR_RSA_DEC ( -2)
|
#define CR_GENID_ERROR_ECC_GENERATE_PRIVATE_KEY ( -3)
|
||||||
#define CR_GENID_ERROR_RSA_VERIFY ( -3)
|
#define CR_GENID_ERROR_ECC_GENERATE_PUBLIC_KEY ( -4)
|
||||||
#define CR_GENID_ERROR_ECDSA_SIGN ( -4)
|
#define CR_GENID_ERROR_ECC_READ_PRIVATE_KEY ( -5)
|
||||||
#define CR_GENID_ERROR_ECDSA_VERIFY ( -5)
|
#define CR_GENID_ERROR_ECDSA_SIGN ( -6)
|
||||||
#define CR_GENID_ERROR_SET_MEM_FUNCTIONS ( -6)
|
#define CR_GENID_ERROR_ECDSA_DEC ( -7)
|
||||||
#define CR_GENID_ERROR_RSA_LOAD_PARAM ( -7)
|
#define CR_GENID_ERROR_ECDSA_VERIFY ( -8)
|
||||||
#define CR_GENID_ERROR_EC_GENERATE_PRIVATE_KEY ( -8)
|
#define CR_GENID_ERROR_AES_ENC ( -9)
|
||||||
#define CR_GENID_ERROR_EC_GENERATE_PUBLIC_KEY ( -9)
|
#define CR_GENID_ERROR_AES_DEC (-10)
|
||||||
#define CR_GENID_ERROR_RSA_READ_PRIVATE_KEY (-10)
|
#define CR_GENID_ERROR_AES_VERIFY (-11)
|
||||||
#define CR_GENID_ERROR_RSA_READ_PUBLIC_KEY (-11)
|
#define CR_GENID_ERROR_RSA_READ_PRIVATE_KEY (-12)
|
||||||
#define CR_GENID_ERROR_BN_NEW_0 (-12)
|
#define CR_GENID_ERROR_RSA_READ_PUBLIC_KEY (-13)
|
||||||
#define CR_GENID_ERROR_BN_NEW_1 (-13)
|
#define CR_GENID_ERROR_RSA_ENC (-14)
|
||||||
#define CR_GENID_ERROR_BN_NEW_2 (-14)
|
#define CR_GENID_ERROR_RSA_DEC (-15)
|
||||||
#define CR_GENID_ERROR_BN_CTX_NEW (-15)
|
#define CR_GENID_ERROR_RSA_VERIFY (-16)
|
||||||
#define CR_GENID_ERROR_EC_POINT_NEW (-16)
|
|
||||||
#define CR_GENID_ERROR_EC_KEY_NEW_0 (-17)
|
|
||||||
#define CR_GENID_ERROR_EC_KEY_NEW_1 (-18)
|
|
||||||
#define CR_GENID_ERROR_ID_BUF_SIZE (-19)
|
|
||||||
#define CR_GENID_ERROR_ERR_BUF_SIZE (-20)
|
|
||||||
#define CR_GENID_ERROR_PRIVKEY_SCRAMBLE (-21)
|
|
||||||
#define CR_GENID_ERROR_AES_ENC (-22)
|
|
||||||
#define CR_GENID_ERROR_AES_DEC (-23)
|
|
||||||
#define CR_GENID_ERROR_AES_VERIFY (-24)
|
|
||||||
#define CR_GENID_ERROR_CERT_BUF_SIZE (-25)
|
|
||||||
#define CR_GENID_ERROR_ECC_READ_PRIVATE_KEY (-26)
|
|
||||||
#define CR_GENID_ERROR_ECDSA_DECODE (-27)
|
|
||||||
|
|
||||||
//---------------------------------------------------
|
//---------------------------------------------------
|
||||||
// HSMの処理結果によるエラーコード
|
// HSMの処理結果によるエラーコード
|
||||||
|
|||||||
@ -155,6 +155,8 @@ int hsm_initialize( void )
|
|||||||
{
|
{
|
||||||
int ret_code = CR_GENID_SUCCESS;
|
int ret_code = CR_GENID_SUCCESS;
|
||||||
|
|
||||||
|
// TODO: HSMリセットを入れる。
|
||||||
|
|
||||||
// init HSM
|
// init HSM
|
||||||
ret_code = NFastApp_InitEx( &hsmHandle, NULL, NULL );
|
ret_code = NFastApp_InitEx( &hsmHandle, NULL, NULL );
|
||||||
if ( ret_code != CR_GENID_SUCCESS )
|
if ( ret_code != CR_GENID_SUCCESS )
|
||||||
@ -232,6 +234,7 @@ int hsm_initialize( void )
|
|||||||
|
|
||||||
void hsm_finalize( void )
|
void hsm_finalize( void )
|
||||||
{
|
{
|
||||||
|
// TODO: エラーハンドリングする。
|
||||||
NFKM_freeinfo( hsmHandle, &hsmWorld, NULL );
|
NFKM_freeinfo( hsmHandle, &hsmWorld, NULL );
|
||||||
NFastApp_Disconnect( hsmConnection, NULL );
|
NFastApp_Disconnect( hsmConnection, NULL );
|
||||||
NFastApp_Finish( hsmHandle, NULL );
|
NFastApp_Finish( hsmHandle, NULL );
|
||||||
|
|||||||
@ -138,7 +138,7 @@ int GenarateECCKeyPair( EC_KEY **ppECkey, u8 *pECPrivkey )
|
|||||||
if( *ppECkey == NULL )
|
if( *ppECkey == NULL )
|
||||||
{
|
{
|
||||||
SetErrorInfo( __FUNCTION__, __LINE__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return CR_GENID_ERROR_EC_KEY_NEW_1;
|
return CR_GENID_ERROR_ECC_KEY_NEW;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 秘密鍵生成
|
// 秘密鍵生成
|
||||||
@ -146,7 +146,7 @@ int GenarateECCKeyPair( EC_KEY **ppECkey, u8 *pECPrivkey )
|
|||||||
if( openssl_result != 0 )
|
if( openssl_result != 0 )
|
||||||
{
|
{
|
||||||
SetErrorInfo( __FUNCTION__, __LINE__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return CR_GENID_ERROR_EC_GENERATE_PRIVATE_KEY;
|
return CR_GENID_ERROR_ECC_GENERATE_PRIVATE_KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 公開鍵生成
|
// 公開鍵生成
|
||||||
@ -154,7 +154,7 @@ int GenarateECCKeyPair( EC_KEY **ppECkey, u8 *pECPrivkey )
|
|||||||
if ( openssl_result == 0 )
|
if ( openssl_result == 0 )
|
||||||
{
|
{
|
||||||
SetErrorInfo( __FUNCTION__, __LINE__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return CR_GENID_ERROR_EC_GENERATE_PUBLIC_KEY;
|
return CR_GENID_ERROR_ECC_GENERATE_PUBLIC_KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ASN.1 形式指定フラグをセットする
|
// ASN.1 形式指定フラグをセットする
|
||||||
@ -191,7 +191,7 @@ static int generate_EC_private_key( EC_KEY *eckey, u8 *privKey )
|
|||||||
if( bn_privkey == NULL )
|
if( bn_privkey == NULL )
|
||||||
{
|
{
|
||||||
SetErrorInfo( __FUNCTION__, __LINE__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return CR_GENID_ERROR_BN_NEW_0;
|
return CR_GENID_ERROR_BN_NEW;
|
||||||
}
|
}
|
||||||
BN_init( bn_privkey ); /* memset(a,0,sizeof(BIGNUM)); */
|
BN_init( bn_privkey ); /* memset(a,0,sizeof(BIGNUM)); */
|
||||||
(void)BN_bin2bn( privKey, EC_PRIVATE_KEY_LENGTH, bn_privkey );
|
(void)BN_bin2bn( privKey, EC_PRIVATE_KEY_LENGTH, bn_privkey );
|
||||||
|
|||||||
49
main.c
49
main.c
@ -255,12 +255,6 @@ int main(int ac, char *argv[])
|
|||||||
if( ret_code != 0 ) {
|
if( ret_code != 0 ) {
|
||||||
fprintf(stderr,"generate_id failed\n");
|
fprintf(stderr,"generate_id failed\n");
|
||||||
switch( ret_code ) {
|
switch( ret_code ) {
|
||||||
case CR_GENID_ERROR_ID_BUF_SIZE:
|
|
||||||
fprintf(stderr,"failed to CR_ID_BUFFER structure size\n");
|
|
||||||
break;
|
|
||||||
case CR_GENID_ERROR_ERR_BUF_SIZE:
|
|
||||||
fprintf(stderr,"failed to CR_ERR_BUFFER structure size\n");
|
|
||||||
break;
|
|
||||||
case CR_GENID_ERROR_RSA_ENC:
|
case CR_GENID_ERROR_RSA_ENC:
|
||||||
fprintf(stderr,"failed to RSA_public_encrypt\n");
|
fprintf(stderr,"failed to RSA_public_encrypt\n");
|
||||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
||||||
@ -281,19 +275,11 @@ int main(int ac, char *argv[])
|
|||||||
fprintf(stderr,"ECDSA_verify NG.\n");
|
fprintf(stderr,"ECDSA_verify NG.\n");
|
||||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
||||||
break;
|
break;
|
||||||
case CR_GENID_ERROR_SET_MEM_FUNCTIONS:
|
case CR_GENID_ERROR_ECC_GENERATE_PRIVATE_KEY:
|
||||||
fprintf(stderr,"CRYPTO_set_mem_functions error \n");
|
|
||||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
|
||||||
break;
|
|
||||||
case CR_GENID_ERROR_RSA_LOAD_PARAM:
|
|
||||||
fprintf(stderr,"load rsa param failed\n");
|
|
||||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
|
||||||
break;
|
|
||||||
case CR_GENID_ERROR_EC_GENERATE_PRIVATE_KEY:
|
|
||||||
fprintf(stderr,"error EC generate_private_key\n");
|
fprintf(stderr,"error EC generate_private_key\n");
|
||||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
||||||
break;
|
break;
|
||||||
case CR_GENID_ERROR_EC_GENERATE_PUBLIC_KEY:
|
case CR_GENID_ERROR_ECC_GENERATE_PUBLIC_KEY:
|
||||||
fprintf(stderr,"error EC generate_public_key\n");
|
fprintf(stderr,"error EC generate_public_key\n");
|
||||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
||||||
break;
|
break;
|
||||||
@ -305,37 +291,14 @@ int main(int ac, char *argv[])
|
|||||||
fprintf(stderr,"error RSA read public key\n");
|
fprintf(stderr,"error RSA read public key\n");
|
||||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
||||||
break;
|
break;
|
||||||
case CR_GENID_ERROR_BN_NEW_0:
|
case CR_GENID_ERROR_BN_NEW:
|
||||||
fprintf(stderr,"error bn_new 0\n");
|
fprintf(stderr,"error bn_new\n");
|
||||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
||||||
break;
|
break;
|
||||||
case CR_GENID_ERROR_BN_NEW_1:
|
case CR_GENID_ERROR_ECC_KEY_NEW:
|
||||||
fprintf(stderr,"error bn_new 1\n");
|
fprintf(stderr,"error EC_KEY_new_by_curve_name\n");
|
||||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
||||||
break;
|
break;
|
||||||
case CR_GENID_ERROR_BN_NEW_2:
|
|
||||||
fprintf(stderr,"error bn_new 2\n");
|
|
||||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
|
||||||
break;
|
|
||||||
case CR_GENID_ERROR_BN_CTX_NEW:
|
|
||||||
fprintf(stderr,"error bn_ctx_new\n");
|
|
||||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
|
||||||
break;
|
|
||||||
case CR_GENID_ERROR_EC_POINT_NEW:
|
|
||||||
fprintf(stderr,"error ec_point_new\n");
|
|
||||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
|
||||||
break;
|
|
||||||
case CR_GENID_ERROR_EC_KEY_NEW_0:
|
|
||||||
fprintf(stderr,"error EC_KEY_new_by_curve_name 0\n");
|
|
||||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
|
||||||
break;
|
|
||||||
case CR_GENID_ERROR_EC_KEY_NEW_1:
|
|
||||||
fprintf(stderr,"error EC_KEY_new_by_curve_name 1\n");
|
|
||||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
|
||||||
break;
|
|
||||||
case CR_GENID_ERROR_PRIVKEY_SCRAMBLE:
|
|
||||||
fprintf(stderr,"failed to decode privkey scramble.\n");
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr,"error unknown error ret_code=%d\n", ret_code);
|
fprintf(stderr,"error unknown error ret_code=%d\n", ret_code);
|
||||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user