From b445a23dacff45618c763674731e6458df3a980e Mon Sep 17 00:00:00 2001 From: kubodera_yuichi Date: Wed, 23 Dec 2009 08:47:29 +0000 Subject: [PATCH] =?UTF-8?q?SetErrorInfo=E9=96=A2=E6=95=B0=E3=81=AE?= =?UTF-8?q?=E6=8C=BF=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_eFuse@69 ff987cc8-cf2f-4642-8568-d52cce064691 --- cr_deviceCert.c | 4 ++++ cr_enc_id.c | 27 ++++++++++++++++-------- cr_generate_id.c | 5 +++++ cr_hsm_code.c | 54 +++++++++++++++++++++++++++++++++++++++--------- cr_hsm_util.c | 3 ++- cr_keyPair.c | 7 +++++++ 6 files changed, 80 insertions(+), 20 deletions(-) diff --git a/cr_deviceCert.c b/cr_deviceCert.c index 8ec063b..fadc8ee 100644 --- a/cr_deviceCert.c +++ b/cr_deviceCert.c @@ -164,6 +164,7 @@ int GenerateCTRDeviceCert( EC_KEY *pECkey, u32 deviceId, u8 bondingOption, u8 *p if ( sizeof( CR_DeviceCert ) > 384 ) { ret_code = CR_GENID_ERROR_CERT_BUF_SIZE; + SetErrorInfo( ret_code, __FILE__, __LINE__ ); 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 ); if (test_ret == 0) { ret_code = CR_GENID_ERROR_ECDSA_SIGN; + SetErrorInfo( ret_code, __FILE__, __LINE__ ); goto end; } 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 ); if( test_ret != 1) { ret_code = CR_GENID_ERROR_ECDSA_VERIFY; + SetErrorInfo( ret_code, __FILE__, __LINE__ ); goto end; } @@ -260,6 +263,7 @@ int GenerateCTRDeviceCert( EC_KEY *pECkey, u32 deviceId, u8 bondingOption, u8 *p sig = d2i_ECDSA_SIG( NULL, &pECDSAsig, signLen ); if( sig == NULL ) { ret_code = CR_GENID_ERROR_ECDSA_DECODE; + SetErrorInfo( ret_code, __FILE__, __LINE__ ); goto end; } #if 0 diff --git a/cr_enc_id.c b/cr_enc_id.c index f4db7c4..933fd89 100644 --- a/cr_enc_id.c +++ b/cr_enc_id.c @@ -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 ); if ( ret_code != CR_GENID_SUCCESS ) { - printf( "error(%d) : hsm_aes_encyrpt\n", ret_code ); + SetErrorInfo( ret_code, __FILE__, __LINE__ ); 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 ); if ( ret_code != CR_GENID_SUCCESS ) { - printf( "error(%d) : hsm_aes_decrypt\n", ret_code ); + SetErrorInfo( ret_code, __FILE__, __LINE__ ); 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] ) { - 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 ) { - printf( "error : AES_set_encrypt_key\n" ); + SetErrorInfo( CR_GENID_ERROR_AES_ENC, __FILE__, __LINE__ ); return CR_GENID_ERROR_AES_ENC; } 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; } @@ -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] ) { + SetErrorInfo( CR_GENID_ERROR_AES_VERIFY, __FILE__, __LINE__ ); 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 ); if ( ret_code != CR_GENID_SUCCESS ) { - printf( "error(%d) : hsm_rsa_encyrpt\n", ret_code ); + SetErrorInfo( ret_code, __FILE__, __LINE__ ); 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 ); if ( ret_code != CR_GENID_SUCCESS ) { - printf( "error(%d) : hsm_rsa_decrypt\n", ret_code ); + SetErrorInfo( ret_code, __FILE__, __LINE__ ); 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] ) { - 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_2, 0,CR_ID_BUF_SIZE); - // DERフォーマットのRSA鍵を読み込み { // 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 ); if( rsa_privkey == NULL ) { ret_code = CR_GENID_ERROR_RSA_READ_PRIVATE_KEY; + SetErrorInfo( ret_code, __FILE__, __LINE__ ); goto end; } // コマンドラインのopensslが出力する公開鍵は、SubjectPublicKeyInfo形式なので、この関数を使う。 rsa_pubkey = d2i_RSA_PUBKEY( NULL, &der_pub, pub_len ); if( rsa_pubkey == NULL ) { ret_code = CR_GENID_ERROR_RSA_READ_PUBLIC_KEY; + SetErrorInfo( ret_code, __FILE__, __LINE__ ); 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, rsa_privkey, RSA_NO_PADDING)) == -1) { ret_code = CR_GENID_ERROR_RSA_ENC; + SetErrorInfo( ret_code, __FILE__, __LINE__ ); goto end; } else { if((rsa_outlen = RSA_public_decrypt(rsa_outlen, local_buf_1, local_buf_2, rsa_pubkey, RSA_NO_PADDING)) == -1) { ret_code = CR_GENID_ERROR_RSA_DEC; + SetErrorInfo( ret_code, __FILE__, __LINE__ ); goto end; } else { @@ -348,6 +356,7 @@ int crypto_rsa_enc_dec( unsigned char *dst_buf,unsigned char *org_buf, u8 bondin } if( error_flag ) { ret_code = CR_GENID_ERROR_RSA_VERIFY; + SetErrorInfo( ret_code, __FILE__, __LINE__ ); goto end; } } diff --git a/cr_generate_id.c b/cr_generate_id.c index eadeb0d..03d3263 100644 --- a/cr_generate_id.c +++ b/cr_generate_id.c @@ -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->expiryDate ); // 繝繝舌う繧ケ險シ譏取嶌譛滄剞縺ョ蜈繝繝シ繧ソ繧ゅ▽縺縺ァ縺ォ繧サ繝繝医@縺ヲ縺翫¥ if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); 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 ); if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); goto end; } 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 ); if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); 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->expiryDate ); if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); 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 ); if( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); goto end; } diff --git a/cr_hsm_code.c b/cr_hsm_code.c index 26a5d2c..5004b94 100644 --- a/cr_hsm_code.c +++ b/cr_hsm_code.c @@ -174,6 +174,7 @@ int hsm_initialize( void ) NULL ); if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); return ret_code; } @@ -181,6 +182,7 @@ int hsm_initialize( void ) ret_code = NFastApp_Connect( hsmHandle, &hsmConnection, 0 /* flag */, NULL ); if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); return ret_code; } @@ -188,6 +190,7 @@ int hsm_initialize( void ) ret_code = NFKM_getinfo( hsmHandle, &hsmWorld, NULL ); if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); return ret_code; } @@ -196,6 +199,7 @@ int hsm_initialize( void ) ret_code = hsm_aes_load_key( hsmAesKeyidentDev, &hsmAesKeyidDev ); if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); return ret_code; } @@ -203,6 +207,7 @@ int hsm_initialize( void ) ret_code = hsm_aes_load_key( hsmAesKeyidentProd, &hsmAesKeyidProd ); if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); return ret_code; } #else // !ENCRYPT_AES @@ -210,6 +215,7 @@ int hsm_initialize( void ) ret_code = hsm_rsa_load_keypair( hsmRsaKeyidentDev, &hsmRsaPrivkeyidDev, &hsmRsaPubkeyidDev ); if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); return ret_code; } @@ -217,11 +223,12 @@ int hsm_initialize( void ) ret_code = hsm_rsa_load_keypair( hsmRsaKeyidentProd, &hsmRsaPrivkeyidProd, &hsmRsaPubkeyidProd ); if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); return ret_code; } #endif // ENCRYPT_AES - return CR_GENID_SUCCESS; + return ret_code; } // hsm_initialize void hsm_finalize( void ) @@ -233,23 +240,28 @@ void hsm_finalize( void ) int hsm_generate_random( unsigned char *buf, int bytes ) { - int ret_code; + int ret_code = CR_GENID_SUCCESS; M_Command cmd; M_Reply reply; memset( &cmd, 0, sizeof( cmd ) ); memset( &reply, 0, sizeof( reply ) ); + // コマンドに値をセットする cmd.cmd = Cmd_GenerateRandom; cmd.args.generaterandom.lenbytes = bytes; + + // 命令発行 ret_code = NFastApp_Transact( hsmConnection, NULL, &cmd, &reply, NULL ); if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); return ret_code; } ret_code = reply.status; if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); return ret_code; } @@ -264,7 +276,7 @@ int hsm_generate_random( unsigned char *buf, int bytes ) int hsm_get_rtc( time_t *time ) { - int result; + int ret_code = CR_GENID_SUCCESS; M_Command cmd; M_Reply reply; @@ -272,21 +284,28 @@ int hsm_get_rtc( time_t *time ) memset( &cmd, 0, sizeof( cmd ) ); memset( &reply, 0, sizeof( reply ) ); + // コマンドに値をセットする cmd.cmd = Cmd_GetRTC; 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; - if ( result != CR_GENID_SUCCESS ) + ret_code = reply.status; + 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; } // 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 ); if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); 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 ); if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); goto end; } @@ -321,6 +342,7 @@ int hsm_aes_load_key( NFKM_KeyIdent keyident, M_KeyID *keyid ) 0, keyid, "loading aes key blob", NULL ); if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); 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 ); if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); return ret_code; } ret_code = reply.status; if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); 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 ); if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); return ret_code; } ret_code = reply.status; if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); 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 ); if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); 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 ); if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); 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 ); if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); 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 ); if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); 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 ); if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); return ret_code; } ret_code = reply.status; if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); 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 ); if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); return ret_code; } ret_code = reply.status; if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); return ret_code; } diff --git a/cr_hsm_util.c b/cr_hsm_util.c index 2684084..c5d056b 100644 --- a/cr_hsm_util.c +++ b/cr_hsm_util.c @@ -144,6 +144,7 @@ int GetTimestamp( u8 *pYear, u8 *pMonth, u8 *pMday, u8 *pHour, u8 *pMin, u8 *pSe #ifdef USE_HSM ret_code = hsm_get_rtc( &tv.tv_sec ); if( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); return ret_code; } #else // !USE_HSM @@ -223,7 +224,7 @@ int GenerateRandom( u8 *pDst, int length ) ret_code = hsm_generate_random( pDst, CR_RANDOM_LENGTH ); if ( ret_code != CR_GENID_SUCCESS ) { - return ret_code; + SetErrorInfo( CR_GENID_ERROR_ECDSA_VERIFY, __FILE__, __LINE__ ); } #else // !USE_HSM int i; diff --git a/cr_keyPair.c b/cr_keyPair.c index cedb10d..0eb96b6 100644 --- a/cr_keyPair.c +++ b/cr_keyPair.c @@ -137,6 +137,7 @@ int GenarateECCKeyPair( EC_KEY **ppECkey, u8 *pECPrivkey ) *ppECkey = EC_KEY_new_by_curve_name( NID_sect233r1 ); if( *ppECkey == NULL ) { + SetErrorInfo( CR_GENID_ERROR_EC_KEY_NEW_1, __FILE__, __LINE__ ); 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 ); if( openssl_result != 0 ) { + SetErrorInfo( CR_GENID_ERROR_EC_GENERATE_PRIVATE_KEY, __FILE__, __LINE__ ); 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 ); if ( openssl_result == 0 ) { + SetErrorInfo( CR_GENID_ERROR_EC_GENERATE_PUBLIC_KEY, __FILE__, __LINE__ ); return CR_GENID_ERROR_EC_GENERATE_PUBLIC_KEY; } @@ -171,6 +174,7 @@ static int generate_EC_private_key( EC_KEY *eckey, u8 *privKey ) // 荵ア謨ー繧貞叙蠕励@縺ヲ縲∫ァ伜ッ骰オ縺ォ縺吶k縲 ret_code = GenerateRandom( privKey, EC_PRIVATE_KEY_LENGTH ); if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( ret_code, __FILE__, __LINE__ ); return ret_code; } @@ -186,6 +190,7 @@ static int generate_EC_private_key( EC_KEY *eckey, u8 *privKey ) bn_privkey = BN_new(); if( bn_privkey == NULL ) { + SetErrorInfo( CR_GENID_ERROR_BN_NEW_0, __FILE__, __LINE__ ); return CR_GENID_ERROR_BN_NEW_0; } 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, &ecdsasiglen, pECkey ); if (openssl_result == 0) { + SetErrorInfo( CR_GENID_ERROR_ECDSA_SIGN, __FILE__, __LINE__ ); return CR_GENID_ERROR_ECDSA_SIGN; } openssl_result = ECDSA_verify( 0, ecdsa_test_buf, CR_ECDSA_BUF_SIZE, ecdsasig, ecdsasiglen, pECkey ); if( openssl_result != 1) { + SetErrorInfo( CR_GENID_ERROR_ECDSA_VERIFY, __FILE__, __LINE__ ); return CR_GENID_ERROR_ECDSA_VERIFY; }