SetErrorInfo関数の挿入

git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_eFuse@69 ff987cc8-cf2f-4642-8568-d52cce064691
This commit is contained in:
kubodera_yuichi 2009-12-23 08:47:29 +00:00
parent ade32ed0b1
commit b445a23dac
6 changed files with 80 additions and 20 deletions

View File

@ -164,6 +164,7 @@ int GenerateCTRDeviceCert( EC_KEY *pECkey, u32 deviceId, u8 bondingOption, u8 *p
if ( sizeof( CR_DeviceCert ) > 384 ) if ( sizeof( CR_DeviceCert ) > 384 )
{ {
ret_code = CR_GENID_ERROR_CERT_BUF_SIZE; ret_code = CR_GENID_ERROR_CERT_BUF_SIZE;
SetErrorInfo( ret_code, __FILE__, __LINE__ );
goto end; goto end;
} }
@ -245,6 +246,7 @@ int GenerateCTRDeviceCert( EC_KEY *pECkey, u32 deviceId, u8 bondingOption, u8 *p
test_ret = ECDSA_sign( 0, sha256buf, 233/8, ecdsasig, &signLen, NintendoCTR2 ); test_ret = ECDSA_sign( 0, sha256buf, 233/8, ecdsasig, &signLen, NintendoCTR2 );
if (test_ret == 0) { if (test_ret == 0) {
ret_code = CR_GENID_ERROR_ECDSA_SIGN; ret_code = CR_GENID_ERROR_ECDSA_SIGN;
SetErrorInfo( ret_code, __FILE__, __LINE__ );
goto end; goto end;
} }
DEBUG_PRINT_ARRAY( "ECDSA:", (const char *)ecdsasig, signLen ); DEBUG_PRINT_ARRAY( "ECDSA:", (const char *)ecdsasig, signLen );
@ -253,6 +255,7 @@ int GenerateCTRDeviceCert( EC_KEY *pECkey, u32 deviceId, u8 bondingOption, u8 *p
test_ret = ECDSA_verify( 0, sha256buf, 233/8, ecdsasig, signLen, NintendoCTR2 ); test_ret = ECDSA_verify( 0, sha256buf, 233/8, ecdsasig, signLen, NintendoCTR2 );
if( test_ret != 1) { if( test_ret != 1) {
ret_code = CR_GENID_ERROR_ECDSA_VERIFY; ret_code = CR_GENID_ERROR_ECDSA_VERIFY;
SetErrorInfo( ret_code, __FILE__, __LINE__ );
goto end; goto end;
} }
@ -260,6 +263,7 @@ int GenerateCTRDeviceCert( EC_KEY *pECkey, u32 deviceId, u8 bondingOption, u8 *p
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_DECODE;
SetErrorInfo( ret_code, __FILE__, __LINE__ );
goto end; goto end;
} }
#if 0 #if 0

View File

@ -176,7 +176,7 @@ int crypto_aes_enc_dec( unsigned char *dst_buf, unsigned char *org_buf, u8 bondi
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, bondingOption );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
printf( "error(%d) : hsm_aes_encyrpt\n", ret_code ); SetErrorInfo( ret_code, __FILE__, __LINE__ );
return ret_code; return ret_code;
} }
@ -184,7 +184,7 @@ int crypto_aes_enc_dec( unsigned char *dst_buf, unsigned char *org_buf, u8 bondi
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, bondingOption );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
printf( "error(%d) : hsm_aes_decrypt\n", ret_code ); SetErrorInfo( ret_code, __FILE__, __LINE__ );
return ret_code; return ret_code;
} }
@ -193,7 +193,9 @@ int crypto_aes_enc_dec( unsigned char *dst_buf, unsigned char *org_buf, u8 bondi
{ {
if( org_buf[i] != local_buf_2[i] ) if( org_buf[i] != local_buf_2[i] )
{ {
return CR_GENID_ERROR_AES_VERIFY; ret_code = GR_GENID_ERROR_AES_VERIFY;
SetErrorInfo( ret_code, __FILE__, __LINE__ );
return ret_code;
} }
} }
@ -219,13 +221,13 @@ int crypto_aes_enc_dec( unsigned char *dst_buf, unsigned char *org_buf, u8 bondi
if ( AES_set_encrypt_key( pAesKey, 128, &aesEncKey ) != 0 ) if ( AES_set_encrypt_key( pAesKey, 128, &aesEncKey ) != 0 )
{ {
printf( "error : AES_set_encrypt_key\n" ); SetErrorInfo( CR_GENID_ERROR_AES_ENC, __FILE__, __LINE__ );
return CR_GENID_ERROR_AES_ENC; return CR_GENID_ERROR_AES_ENC;
} }
if ( AES_set_decrypt_key( pAesKey, 128, &aesDecKey ) != 0 ) if ( AES_set_decrypt_key( pAesKey, 128, &aesDecKey ) != 0 )
{ {
printf( "error : AES_set_decrypt_key\n" ); SetErrorInfo( CR_GENID_ERROR_AES_DEC, __FILE__, __LINE__ );
return CR_GENID_ERROR_AES_DEC; return CR_GENID_ERROR_AES_DEC;
} }
@ -240,6 +242,7 @@ int crypto_aes_enc_dec( unsigned char *dst_buf, unsigned char *org_buf, u8 bondi
{ {
if( org_buf[i] != local_buf_2[i] ) if( org_buf[i] != local_buf_2[i] )
{ {
SetErrorInfo( CR_GENID_ERROR_AES_VERIFY, __FILE__, __LINE__ );
return CR_GENID_ERROR_AES_VERIFY; return CR_GENID_ERROR_AES_VERIFY;
} }
} }
@ -265,7 +268,7 @@ int crypto_rsa_enc_dec( unsigned char *dst_buf,unsigned char *org_buf, u8 bondin
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, bondingOption );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
printf( "error(%d) : hsm_rsa_encyrpt\n", ret_code ); SetErrorInfo( ret_code, __FILE__, __LINE__ );
return ret_code; return ret_code;
} }
@ -273,7 +276,7 @@ int crypto_rsa_enc_dec( unsigned char *dst_buf,unsigned char *org_buf, u8 bondin
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, bondingOption );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
printf( "error(%d) : hsm_rsa_decrypt\n", ret_code ); SetErrorInfo( ret_code, __FILE__, __LINE__ );
return ret_code; return ret_code;
} }
@ -282,7 +285,9 @@ int crypto_rsa_enc_dec( unsigned char *dst_buf,unsigned char *org_buf, u8 bondin
{ {
if( org_buf[i] != local_buf_2[i] ) if( org_buf[i] != local_buf_2[i] )
{ {
return CR_GENID_ERROR_RSA_VERIFY; ret_code = CR_GENID_ERROR_RSA_VERIFY;
SetErrorInfo( ret_code, __FILE__, __LINE__ );
return ret_code;
} }
} }
@ -303,7 +308,6 @@ int crypto_rsa_enc_dec( unsigned char *dst_buf,unsigned char *org_buf, u8 bondin
memset(local_buf_1, 0,CR_ID_BUF_SIZE); memset(local_buf_1, 0,CR_ID_BUF_SIZE);
memset(local_buf_2, 0,CR_ID_BUF_SIZE); memset(local_buf_2, 0,CR_ID_BUF_SIZE);
// DERフォーマットのRSA鍵を読み込み // DERフォーマットのRSA鍵を読み込み
{ {
// bondingOptionによって、鍵を差し替え // bondingOptionによって、鍵を差し替え
@ -317,12 +321,14 @@ int crypto_rsa_enc_dec( unsigned char *dst_buf,unsigned char *org_buf, u8 bondin
rsa_privkey = d2i_RSAPrivateKey( NULL, &der_priv, priv_len ); rsa_privkey = d2i_RSAPrivateKey( NULL, &der_priv, priv_len );
if( rsa_privkey == NULL ) { if( rsa_privkey == NULL ) {
ret_code = CR_GENID_ERROR_RSA_READ_PRIVATE_KEY; ret_code = CR_GENID_ERROR_RSA_READ_PRIVATE_KEY;
SetErrorInfo( ret_code, __FILE__, __LINE__ );
goto end; goto end;
} }
// コマンドラインのopensslが出力する公開鍵は、SubjectPublicKeyInfo形式なので、この関数を使う。 // コマンドラインのopensslが出力する公開鍵は、SubjectPublicKeyInfo形式なので、この関数を使う。
rsa_pubkey = d2i_RSA_PUBKEY( NULL, &der_pub, pub_len ); rsa_pubkey = d2i_RSA_PUBKEY( NULL, &der_pub, pub_len );
if( rsa_pubkey == NULL ) { if( rsa_pubkey == NULL ) {
ret_code = CR_GENID_ERROR_RSA_READ_PUBLIC_KEY; ret_code = CR_GENID_ERROR_RSA_READ_PUBLIC_KEY;
SetErrorInfo( ret_code, __FILE__, __LINE__ );
goto end; goto end;
} }
} }
@ -330,12 +336,14 @@ int crypto_rsa_enc_dec( unsigned char *dst_buf,unsigned char *org_buf, u8 bondin
if( (rsa_outlen = RSA_private_encrypt(CR_ID_BUF_SIZE, org_buf, local_buf_1, if( (rsa_outlen = RSA_private_encrypt(CR_ID_BUF_SIZE, org_buf, local_buf_1,
rsa_privkey, RSA_NO_PADDING)) == -1) { rsa_privkey, RSA_NO_PADDING)) == -1) {
ret_code = CR_GENID_ERROR_RSA_ENC; ret_code = CR_GENID_ERROR_RSA_ENC;
SetErrorInfo( ret_code, __FILE__, __LINE__ );
goto end; goto end;
} }
else { else {
if((rsa_outlen = RSA_public_decrypt(rsa_outlen, local_buf_1, local_buf_2, if((rsa_outlen = RSA_public_decrypt(rsa_outlen, local_buf_1, local_buf_2,
rsa_pubkey, RSA_NO_PADDING)) == -1) { rsa_pubkey, RSA_NO_PADDING)) == -1) {
ret_code = CR_GENID_ERROR_RSA_DEC; ret_code = CR_GENID_ERROR_RSA_DEC;
SetErrorInfo( ret_code, __FILE__, __LINE__ );
goto end; goto end;
} }
else { else {
@ -348,6 +356,7 @@ int crypto_rsa_enc_dec( unsigned char *dst_buf,unsigned char *org_buf, u8 bondin
} }
if( error_flag ) { if( error_flag ) {
ret_code = CR_GENID_ERROR_RSA_VERIFY; ret_code = CR_GENID_ERROR_RSA_VERIFY;
SetErrorInfo( ret_code, __FILE__, __LINE__ );
goto end; goto end;
} }
} }

View File

@ -254,6 +254,7 @@ int cr_generate_id( u32 serial[CR_NUM_OF_SERIAL], u8 id_buf[CR_ID_BUF_SIZE], u8
&cr_id_buf->sec, &cr_id_buf->sec,
&cr_id_buf->expiryDate ); // デバイス証明書期限の元データもついでにセットしておく &cr_id_buf->expiryDate ); // デバイス証明書期限の元データもついでにセットしておく
if ( ret_code != CR_GENID_SUCCESS ) { if ( ret_code != CR_GENID_SUCCESS ) {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
goto end; goto end;
} }
@ -262,6 +263,7 @@ int cr_generate_id( u32 serial[CR_NUM_OF_SERIAL], u8 id_buf[CR_ID_BUF_SIZE], u8
//-------------------------------------------------------------- //--------------------------------------------------------------
ret_code = GenerateRandom( cr_id_buf->random, CR_RANDOM_LENGTH ); ret_code = GenerateRandom( cr_id_buf->random, CR_RANDOM_LENGTH );
if ( ret_code != CR_GENID_SUCCESS ) { if ( ret_code != CR_GENID_SUCCESS ) {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
goto end; goto end;
} }
DEBUG_PRINT_ARRAY( "rand:", (const char *)cr_id_buf->random, CR_RANDOM_LENGTH ); DEBUG_PRINT_ARRAY( "rand:", (const char *)cr_id_buf->random, CR_RANDOM_LENGTH );
@ -271,6 +273,7 @@ int cr_generate_id( u32 serial[CR_NUM_OF_SERIAL], u8 id_buf[CR_ID_BUF_SIZE], u8
//-------------------------------------------------------------- //--------------------------------------------------------------
ret_code = GenarateECCKeyPair( &deviceKeyPair, cr_id_buf->devicePrivKey ); ret_code = GenarateECCKeyPair( &deviceKeyPair, cr_id_buf->devicePrivKey );
if ( ret_code != CR_GENID_SUCCESS ) { if ( ret_code != CR_GENID_SUCCESS ) {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
goto end; goto end;
} }
@ -291,6 +294,7 @@ int cr_generate_id( u32 serial[CR_NUM_OF_SERIAL], u8 id_buf[CR_ID_BUF_SIZE], u8
cr_id_buf->deviceCertSign, cr_id_buf->deviceCertSign,
&cr_id_buf->expiryDate ); &cr_id_buf->expiryDate );
if ( ret_code != CR_GENID_SUCCESS ) { if ( ret_code != CR_GENID_SUCCESS ) {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
goto end; goto end;
} }
@ -317,6 +321,7 @@ int cr_generate_id( u32 serial[CR_NUM_OF_SERIAL], u8 id_buf[CR_ID_BUF_SIZE], u8
//-------------------------------------------------------------- //--------------------------------------------------------------
ret_code = EncryptID( id_buf, id_buf, bondingOption ); ret_code = EncryptID( id_buf, id_buf, bondingOption );
if( ret_code != CR_GENID_SUCCESS ) { if( ret_code != CR_GENID_SUCCESS ) {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
goto end; goto end;
} }

View File

@ -174,6 +174,7 @@ int hsm_initialize( void )
NULL ); NULL );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
return ret_code; return ret_code;
} }
@ -181,6 +182,7 @@ int hsm_initialize( void )
ret_code = NFastApp_Connect( hsmHandle, &hsmConnection, 0 /* flag */, NULL ); ret_code = NFastApp_Connect( hsmHandle, &hsmConnection, 0 /* flag */, NULL );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
return ret_code; return ret_code;
} }
@ -188,6 +190,7 @@ int hsm_initialize( void )
ret_code = NFKM_getinfo( hsmHandle, &hsmWorld, NULL ); ret_code = NFKM_getinfo( hsmHandle, &hsmWorld, NULL );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
return ret_code; return ret_code;
} }
@ -196,6 +199,7 @@ int hsm_initialize( void )
ret_code = hsm_aes_load_key( hsmAesKeyidentDev, &hsmAesKeyidDev ); ret_code = hsm_aes_load_key( hsmAesKeyidentDev, &hsmAesKeyidDev );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
return ret_code; return ret_code;
} }
@ -203,6 +207,7 @@ int hsm_initialize( void )
ret_code = hsm_aes_load_key( hsmAesKeyidentProd, &hsmAesKeyidProd ); ret_code = hsm_aes_load_key( hsmAesKeyidentProd, &hsmAesKeyidProd );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
return ret_code; return ret_code;
} }
#else // !ENCRYPT_AES #else // !ENCRYPT_AES
@ -210,6 +215,7 @@ int hsm_initialize( void )
ret_code = hsm_rsa_load_keypair( hsmRsaKeyidentDev, &hsmRsaPrivkeyidDev, &hsmRsaPubkeyidDev ); ret_code = hsm_rsa_load_keypair( hsmRsaKeyidentDev, &hsmRsaPrivkeyidDev, &hsmRsaPubkeyidDev );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
return ret_code; return ret_code;
} }
@ -217,11 +223,12 @@ int hsm_initialize( void )
ret_code = hsm_rsa_load_keypair( hsmRsaKeyidentProd, &hsmRsaPrivkeyidProd, &hsmRsaPubkeyidProd ); ret_code = hsm_rsa_load_keypair( hsmRsaKeyidentProd, &hsmRsaPrivkeyidProd, &hsmRsaPubkeyidProd );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
return ret_code; return ret_code;
} }
#endif // ENCRYPT_AES #endif // ENCRYPT_AES
return CR_GENID_SUCCESS; return ret_code;
} // hsm_initialize } // hsm_initialize
void hsm_finalize( void ) void hsm_finalize( void )
@ -233,23 +240,28 @@ void hsm_finalize( void )
int hsm_generate_random( unsigned char *buf, int bytes ) int hsm_generate_random( unsigned char *buf, int bytes )
{ {
int ret_code; int ret_code = CR_GENID_SUCCESS;
M_Command cmd; M_Command cmd;
M_Reply reply; M_Reply reply;
memset( &cmd, 0, sizeof( cmd ) ); memset( &cmd, 0, sizeof( cmd ) );
memset( &reply, 0, sizeof( reply ) ); memset( &reply, 0, sizeof( reply ) );
// コマンドに値をセットする
cmd.cmd = Cmd_GenerateRandom; cmd.cmd = Cmd_GenerateRandom;
cmd.args.generaterandom.lenbytes = bytes; cmd.args.generaterandom.lenbytes = bytes;
// 命令発行
ret_code = NFastApp_Transact( hsmConnection, NULL, &cmd, &reply, NULL ); ret_code = NFastApp_Transact( hsmConnection, NULL, &cmd, &reply, NULL );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
return ret_code; return ret_code;
} }
ret_code = reply.status; ret_code = reply.status;
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
return ret_code; return ret_code;
} }
@ -264,7 +276,7 @@ int hsm_generate_random( unsigned char *buf, int bytes )
int hsm_get_rtc( time_t *time ) int hsm_get_rtc( time_t *time )
{ {
int result; int ret_code = CR_GENID_SUCCESS;
M_Command cmd; M_Command cmd;
M_Reply reply; M_Reply reply;
@ -272,21 +284,28 @@ int hsm_get_rtc( time_t *time )
memset( &cmd, 0, sizeof( cmd ) ); memset( &cmd, 0, sizeof( cmd ) );
memset( &reply, 0, sizeof( reply ) ); memset( &reply, 0, sizeof( reply ) );
// コマンドに値をセットする
cmd.cmd = Cmd_GetRTC; cmd.cmd = Cmd_GetRTC;
cmd.args.getrtc.module = HSM_MODULE_ID; cmd.args.getrtc.module = HSM_MODULE_ID;
result = NFastApp_Transact( hsmConnection, NULL, &cmd, &reply, NULL ); // 命令発行
if ( result != CR_GENID_SUCCESS ) ret_code = NFastApp_Transact( hsmConnection, NULL, &cmd, &reply, NULL );
if ( ret_code != CR_GENID_SUCCESS )
{ {
return result; SetErrorInfo( ret_code, __FILE__, __LINE__ );
return ret_code;
} }
result = reply.status; ret_code = reply.status;
if ( result != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
return result; SetErrorInfo( ret_code, __FILE__, __LINE__ );
return ret_code;
} }
*time = (int)reply.reply.getrtc.time.currenttimelow; *time = (int)reply.reply.getrtc.time.currenttimelow;
NFastApp_Free_Command( hsmHandle, NULL, NULL, &cmd );
NFastApp_Free_Reply( hsmHandle, NULL, NULL, &reply );
return CR_GENID_SUCCESS; return CR_GENID_SUCCESS;
} // hsm_get_rtc } // hsm_get_rtc
@ -303,6 +322,7 @@ int hsm_aes_load_key( NFKM_KeyIdent keyident, M_KeyID *keyid )
ret_code = NFKM_findkey( hsmHandle, keyident, &keyinfo, NULL ); ret_code = NFKM_findkey( hsmHandle, keyident, &keyinfo, NULL );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
goto end; goto end;
} }
@ -311,6 +331,7 @@ int hsm_aes_load_key( NFKM_KeyIdent keyident, M_KeyID *keyid )
ret_code = NFKM_getusablemodule( hsmWorld, HSM_MODULE_ID, &hsmModuleinfo ); ret_code = NFKM_getusablemodule( hsmWorld, HSM_MODULE_ID, &hsmModuleinfo );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
goto end; goto end;
} }
@ -321,6 +342,7 @@ int hsm_aes_load_key( NFKM_KeyIdent keyident, M_KeyID *keyid )
0, keyid, "loading aes key blob", NULL ); 0, keyid, "loading aes key blob", NULL );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
goto end; goto end;
} }
@ -364,11 +386,13 @@ int hsm_aes_encrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, u
ret_code = NFastApp_Transact( hsmConnection, NULL, &cmd, &reply, NULL ); ret_code = NFastApp_Transact( hsmConnection, NULL, &cmd, &reply, NULL );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
return ret_code; return ret_code;
} }
ret_code = reply.status; ret_code = reply.status;
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
return ret_code; return ret_code;
} }
@ -415,11 +439,13 @@ int hsm_aes_decrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, u
ret_code = NFastApp_Transact( hsmConnection, NULL, &cmd, &reply, NULL ); ret_code = NFastApp_Transact( hsmConnection, NULL, &cmd, &reply, NULL );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
return ret_code; return ret_code;
} }
ret_code = reply.status; ret_code = reply.status;
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
return ret_code; return ret_code;
} }
@ -444,6 +470,7 @@ int hsm_rsa_load_keypair( NFKM_KeyIdent keyident, M_KeyID *privKeyid, M_KeyID *p
ret_code = NFKM_findkey( hsmHandle, keyident, &keyinfo, NULL ); ret_code = NFKM_findkey( hsmHandle, keyident, &keyinfo, NULL );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
goto end; goto end;
} }
@ -452,6 +479,7 @@ int hsm_rsa_load_keypair( NFKM_KeyIdent keyident, M_KeyID *privKeyid, M_KeyID *p
ret_code = NFKM_getusablemodule( hsmWorld, HSM_MODULE_ID, &hsmModuleinfo ); ret_code = NFKM_getusablemodule( hsmWorld, HSM_MODULE_ID, &hsmModuleinfo );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
goto end; goto end;
} }
@ -463,6 +491,7 @@ int hsm_rsa_load_keypair( NFKM_KeyIdent keyident, M_KeyID *privKeyid, M_KeyID *p
"loading priv key blob", NULL ); "loading priv key blob", NULL );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
goto end; goto end;
} }
@ -474,6 +503,7 @@ int hsm_rsa_load_keypair( NFKM_KeyIdent keyident, M_KeyID *privKeyid, M_KeyID *p
"loading pub key blob", NULL ); "loading pub key blob", NULL );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
goto end; goto end;
} }
@ -510,11 +540,13 @@ int hsm_rsa_encrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, u
ret_code = NFastApp_Transact( hsmConnection, NULL, &cmd, &reply, NULL ); ret_code = NFastApp_Transact( hsmConnection, NULL, &cmd, &reply, NULL );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
return ret_code; return ret_code;
} }
ret_code = reply.status; ret_code = reply.status;
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
return ret_code; return ret_code;
} }
@ -555,11 +587,13 @@ int hsm_rsa_decrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, u
ret_code = NFastApp_Transact( hsmConnection, NULL, &cmd, &reply, NULL ); ret_code = NFastApp_Transact( hsmConnection, NULL, &cmd, &reply, NULL );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
return ret_code; return ret_code;
} }
ret_code = reply.status; ret_code = reply.status;
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
return ret_code; return ret_code;
} }

View File

@ -144,6 +144,7 @@ int GetTimestamp( u8 *pYear, u8 *pMonth, u8 *pMday, u8 *pHour, u8 *pMin, u8 *pSe
#ifdef USE_HSM #ifdef USE_HSM
ret_code = hsm_get_rtc( &tv.tv_sec ); ret_code = hsm_get_rtc( &tv.tv_sec );
if( ret_code != CR_GENID_SUCCESS ) { if( ret_code != CR_GENID_SUCCESS ) {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
return ret_code; return ret_code;
} }
#else // !USE_HSM #else // !USE_HSM
@ -223,7 +224,7 @@ int GenerateRandom( u8 *pDst, int length )
ret_code = hsm_generate_random( pDst, CR_RANDOM_LENGTH ); ret_code = hsm_generate_random( pDst, CR_RANDOM_LENGTH );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
return ret_code; SetErrorInfo( CR_GENID_ERROR_ECDSA_VERIFY, __FILE__, __LINE__ );
} }
#else // !USE_HSM #else // !USE_HSM
int i; int i;

View File

@ -137,6 +137,7 @@ int GenarateECCKeyPair( EC_KEY **ppECkey, u8 *pECPrivkey )
*ppECkey = EC_KEY_new_by_curve_name( NID_sect233r1 ); *ppECkey = EC_KEY_new_by_curve_name( NID_sect233r1 );
if( *ppECkey == NULL ) if( *ppECkey == NULL )
{ {
SetErrorInfo( CR_GENID_ERROR_EC_KEY_NEW_1, __FILE__, __LINE__ );
return CR_GENID_ERROR_EC_KEY_NEW_1; return CR_GENID_ERROR_EC_KEY_NEW_1;
} }
@ -144,6 +145,7 @@ int GenarateECCKeyPair( EC_KEY **ppECkey, u8 *pECPrivkey )
openssl_result = generate_EC_private_key( *ppECkey, pECPrivkey ); openssl_result = generate_EC_private_key( *ppECkey, pECPrivkey );
if( openssl_result != 0 ) if( openssl_result != 0 )
{ {
SetErrorInfo( CR_GENID_ERROR_EC_GENERATE_PRIVATE_KEY, __FILE__, __LINE__ );
return CR_GENID_ERROR_EC_GENERATE_PRIVATE_KEY; return CR_GENID_ERROR_EC_GENERATE_PRIVATE_KEY;
} }
@ -151,6 +153,7 @@ int GenarateECCKeyPair( EC_KEY **ppECkey, u8 *pECPrivkey )
openssl_result = generate_EC_public_key( *ppECkey ); openssl_result = generate_EC_public_key( *ppECkey );
if ( openssl_result == 0 ) if ( openssl_result == 0 )
{ {
SetErrorInfo( CR_GENID_ERROR_EC_GENERATE_PUBLIC_KEY, __FILE__, __LINE__ );
return CR_GENID_ERROR_EC_GENERATE_PUBLIC_KEY; return CR_GENID_ERROR_EC_GENERATE_PUBLIC_KEY;
} }
@ -171,6 +174,7 @@ static int generate_EC_private_key( EC_KEY *eckey, u8 *privKey )
// 乱数を取得して、秘密鍵にする。 // 乱数を取得して、秘密鍵にする。
ret_code = GenerateRandom( privKey, EC_PRIVATE_KEY_LENGTH ); ret_code = GenerateRandom( privKey, EC_PRIVATE_KEY_LENGTH );
if ( ret_code != CR_GENID_SUCCESS ) { if ( ret_code != CR_GENID_SUCCESS ) {
SetErrorInfo( ret_code, __FILE__, __LINE__ );
return ret_code; return ret_code;
} }
@ -186,6 +190,7 @@ static int generate_EC_private_key( EC_KEY *eckey, u8 *privKey )
bn_privkey = BN_new(); bn_privkey = BN_new();
if( bn_privkey == NULL ) if( bn_privkey == NULL )
{ {
SetErrorInfo( CR_GENID_ERROR_BN_NEW_0, __FILE__, __LINE__ );
return CR_GENID_ERROR_BN_NEW_0; return CR_GENID_ERROR_BN_NEW_0;
} }
BN_init( bn_privkey ); /* memset(a,0,sizeof(BIGNUM)); */ BN_init( bn_privkey ); /* memset(a,0,sizeof(BIGNUM)); */
@ -291,11 +296,13 @@ int TestECDSA( EC_KEY *pECkey )
openssl_result = ECDSA_sign( 0, ecdsa_test_buf, CR_ECDSA_BUF_SIZE, ecdsasig, openssl_result = ECDSA_sign( 0, ecdsa_test_buf, CR_ECDSA_BUF_SIZE, ecdsasig,
&ecdsasiglen, pECkey ); &ecdsasiglen, pECkey );
if (openssl_result == 0) { if (openssl_result == 0) {
SetErrorInfo( CR_GENID_ERROR_ECDSA_SIGN, __FILE__, __LINE__ );
return CR_GENID_ERROR_ECDSA_SIGN; return CR_GENID_ERROR_ECDSA_SIGN;
} }
openssl_result = ECDSA_verify( 0, ecdsa_test_buf, CR_ECDSA_BUF_SIZE, ecdsasig, ecdsasiglen, pECkey ); openssl_result = ECDSA_verify( 0, ecdsa_test_buf, CR_ECDSA_BUF_SIZE, ecdsasig, ecdsasiglen, pECkey );
if( openssl_result != 1) { if( openssl_result != 1) {
SetErrorInfo( CR_GENID_ERROR_ECDSA_VERIFY, __FILE__, __LINE__ );
return CR_GENID_ERROR_ECDSA_VERIFY; return CR_GENID_ERROR_ECDSA_VERIFY;
} }