mirror of
https://github.com/rvtr/ctr_eFuse.git
synced 2025-11-02 00:11:04 -04:00
エラー情報を関数名と行数に変更し、指定したサイズ分コールスタックとして記録する方式にした。
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_eFuse@72 ff987cc8-cf2f-4642-8568-d52cce064691
This commit is contained in:
parent
3c0a8ea9d7
commit
5813af8471
@ -164,7 +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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,7 +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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
DEBUG_PRINT_ARRAY( "ECDSA:", (const char *)ecdsasig, signLen );
|
DEBUG_PRINT_ARRAY( "ECDSA:", (const char *)ecdsasig, signLen );
|
||||||
@ -255,7 +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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,7 +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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
|
|||||||
28
cr_enc_id.c
28
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 );
|
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 )
|
||||||
{
|
{
|
||||||
SetErrorInfo( ret_code, __FILE__, __LINE__ );
|
SetErrorInfo( __FUNCTION__, __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 )
|
||||||
{
|
{
|
||||||
SetErrorInfo( ret_code, __FILE__, __LINE__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return ret_code;
|
return ret_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,7 +194,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] )
|
||||||
{
|
{
|
||||||
ret_code = CR_GENID_ERROR_AES_VERIFY;
|
ret_code = CR_GENID_ERROR_AES_VERIFY;
|
||||||
SetErrorInfo( ret_code, __FILE__, __LINE__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return ret_code;
|
return ret_code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -221,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 )
|
||||||
{
|
{
|
||||||
SetErrorInfo( CR_GENID_ERROR_AES_ENC, __FILE__, __LINE__ );
|
SetErrorInfo( __FUNCTION__, __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 )
|
||||||
{
|
{
|
||||||
SetErrorInfo( CR_GENID_ERROR_AES_DEC, __FILE__, __LINE__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return CR_GENID_ERROR_AES_DEC;
|
return CR_GENID_ERROR_AES_DEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,7 +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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return CR_GENID_ERROR_AES_VERIFY;
|
return CR_GENID_ERROR_AES_VERIFY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -268,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 )
|
||||||
{
|
{
|
||||||
SetErrorInfo( ret_code, __FILE__, __LINE__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return ret_code;
|
return ret_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,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 )
|
||||||
{
|
{
|
||||||
SetErrorInfo( ret_code, __FILE__, __LINE__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return ret_code;
|
return ret_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,7 +286,7 @@ 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] )
|
||||||
{
|
{
|
||||||
ret_code = CR_GENID_ERROR_RSA_VERIFY;
|
ret_code = CR_GENID_ERROR_RSA_VERIFY;
|
||||||
SetErrorInfo( ret_code, __FILE__, __LINE__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return ret_code;
|
return ret_code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -321,14 +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__ );
|
SetErrorInfo( __FUNCTION__, __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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -336,14 +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__ );
|
SetErrorInfo( __FUNCTION__, __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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -356,7 +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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -185,15 +185,19 @@ int cr_generate_id( u32 serial[CR_NUM_OF_SERIAL], u8 id_buf[CR_ID_BUF_SIZE], u8
|
|||||||
CR_ID_BUFFER *cr_id_buf;
|
CR_ID_BUFFER *cr_id_buf;
|
||||||
EC_KEY *deviceKeyPair = NULL;
|
EC_KEY *deviceKeyPair = NULL;
|
||||||
|
|
||||||
|
// エラー発生時に備えて、エラーバッファの初期化とトータルのID生成カウントセット
|
||||||
|
InitErrorInfo();
|
||||||
generatingCount++;
|
generatingCount++;
|
||||||
|
|
||||||
if( sizeof(CR_ID_BUFFER) != 256 ) {
|
if( sizeof(CR_ID_BUFFER) != 256 ) {
|
||||||
ret_code = CR_GENID_ERROR_ID_BUF_SIZE;
|
ret_code = CR_GENID_ERROR_ID_BUF_SIZE;
|
||||||
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( sizeof(CR_ERR_BUFFER) > 256 ) {
|
if( sizeof(CR_ERR_BUFFER) > 256 ) {
|
||||||
ret_code = CR_GENID_ERROR_ERR_BUF_SIZE;
|
ret_code = CR_GENID_ERROR_ERR_BUF_SIZE;
|
||||||
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,7 +258,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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,7 +267,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__ );
|
SetErrorInfo( __FUNCTION__, __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 );
|
||||||
@ -273,7 +277,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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,7 +298,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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,7 +325,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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -344,10 +348,10 @@ end:
|
|||||||
cr_err_buf->totalCount = generatingCount;
|
cr_err_buf->totalCount = generatingCount;
|
||||||
cr_err_buf->magic_number = 0x01234567;
|
cr_err_buf->magic_number = 0x01234567;
|
||||||
cr_err_buf->serial0 = serial[0];
|
cr_err_buf->serial0 = serial[0];
|
||||||
GetErrorInfo( &(cr_err_buf->errorCode),
|
cr_err_buf->errorCode = ret_code;
|
||||||
cr_err_buf->fileName,
|
GetErrorInfo( cr_err_buf->callStack, &cr_err_buf->recordSize );
|
||||||
&cr_err_buf->lineNumber );
|
|
||||||
cr_err_buf->bondingOption = bondingOption;
|
cr_err_buf->bondingOption = bondingOption;
|
||||||
|
printf( "%s\n", cr_err_buf->callStack );
|
||||||
}
|
}
|
||||||
|
|
||||||
// リソースの解放
|
// リソースの解放
|
||||||
|
|||||||
@ -184,23 +184,24 @@ typedef struct {
|
|||||||
} CR_ID_BUFFER; /* 合計256bytes = 2048bit */
|
} CR_ID_BUFFER; /* 合計256bytes = 2048bit */
|
||||||
|
|
||||||
// TODO: 仕様FIXする必要あり -> 仮 version
|
// TODO: 仕様FIXする必要あり -> 仮 version
|
||||||
|
#define CALL_STACK_SIZE (234)
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u64 totalCount; /* 0x00 - 0x07 */
|
u64 totalCount; /* 0x00 - 0x07 */
|
||||||
u32 magic_number; /* 0x08 - 0x0b 0x01234567 確定!*/
|
u32 magic_number; /* 0x08 - 0x0b 0x01234567 確定!*/
|
||||||
u32 serial0; /* 0x0c - 0x0f */
|
u32 serial0; /* 0x0c - 0x0f */
|
||||||
s32 errorCode; /* 0x10 - 0x13 */
|
s32 errorCode; /* 0x10 - 0x13 */
|
||||||
u32 lineNumber; /* 0x14 - 0x17 */
|
u8 bondingOption; // TORIAEZU
|
||||||
char fileName[ 64 ]; /* 0x18 - 0x57 */
|
u8 recordSize; // コールスタックの記録サイズ
|
||||||
u8 bondingOption; /* 0x58 - 0x58 */
|
u8 callStack[ CALL_STACK_SIZE ];
|
||||||
u8 reserve[ 167 ]; /* 0x59 - 0xff */
|
|
||||||
} CR_ERR_BUFFER;
|
} CR_ERR_BUFFER;
|
||||||
|
|
||||||
extern int GetTimestamp( u8 *pYear, u8 *pMonth, u8 *pMday, u8 *pHour, u8 *pMin, u8 *pSec, time_t *pTime);
|
extern int GetTimestamp( u8 *pYear, u8 *pMonth, u8 *pMday, u8 *pHour, u8 *pMin, u8 *pSec, time_t *pTime);
|
||||||
extern int GenerateRandom( u8 *pDst, int length );
|
extern int GenerateRandom( u8 *pDst, int length );
|
||||||
extern int GenarateECCKeyPair( EC_KEY **ppECkey, u8 *pECPrivkey );
|
extern int GenarateECCKeyPair( EC_KEY **ppECkey, u8 *pECPrivkey );
|
||||||
|
|
||||||
extern void SetErrorInfo( s32 errorCode, char *fileName, u32 line );
|
extern void InitErrorInfo( void );
|
||||||
extern void GetErrorInfo( s32 *errorCode, char *fileName, u32 *line );
|
extern void SetErrorInfo( const char *funcName, u32 line );
|
||||||
|
extern void GetErrorInfo( char *stack, u8 *size );
|
||||||
|
|
||||||
extern int TestECDSA( EC_KEY *pECkey );
|
extern int TestECDSA( EC_KEY *pECkey );
|
||||||
extern int GenerateCTRDeviceCert( EC_KEY *pECkey, u32 deviceId, u8 bondingOption, u8 *pDevCertSign, u32 *pExpiryDate );
|
extern int GenerateCTRDeviceCert( EC_KEY *pECkey, u32 deviceId, u8 bondingOption, u8 *pDevCertSign, u32 *pExpiryDate );
|
||||||
|
|||||||
@ -173,7 +173,7 @@ int hsm_initialize( void )
|
|||||||
NULL );
|
NULL );
|
||||||
if ( ret_code != CR_GENID_SUCCESS )
|
if ( ret_code != CR_GENID_SUCCESS )
|
||||||
{
|
{
|
||||||
SetErrorInfo( ret_code, __FILE__, __LINE__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return ret_code;
|
return ret_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,7 +181,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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return ret_code;
|
return ret_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,7 +189,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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return ret_code;
|
return ret_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,7 +198,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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return ret_code;
|
return ret_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,7 +206,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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return ret_code;
|
return ret_code;
|
||||||
}
|
}
|
||||||
#else // !ENCRYPT_AES
|
#else // !ENCRYPT_AES
|
||||||
@ -214,7 +214,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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return ret_code;
|
return ret_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,7 +222,7 @@ 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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return ret_code;
|
return ret_code;
|
||||||
}
|
}
|
||||||
#endif // ENCRYPT_AES
|
#endif // ENCRYPT_AES
|
||||||
@ -254,13 +254,13 @@ int hsm_generate_random( unsigned char *buf, int 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__ );
|
SetErrorInfo( __FUNCTION__, __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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return ret_code;
|
return ret_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,13 +291,13 @@ int hsm_get_rtc( time_t *time )
|
|||||||
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__ );
|
SetErrorInfo( __FUNCTION__, __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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return ret_code;
|
return ret_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,7 +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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,7 +331,7 @@ int hsm_aes_load_key( NFKM_KeyIdent keyident, M_KeyID *keyid )
|
|||||||
ret_code = NFKM_getusablemodule( hsmWorld, HSM_MODULE_ID, &moduleinfo );
|
ret_code = NFKM_getusablemodule( hsmWorld, HSM_MODULE_ID, &moduleinfo );
|
||||||
if ( ret_code != CR_GENID_SUCCESS )
|
if ( ret_code != CR_GENID_SUCCESS )
|
||||||
{
|
{
|
||||||
SetErrorInfo( ret_code, __FILE__, __LINE__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,7 +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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,13 +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__ );
|
SetErrorInfo( __FUNCTION__, __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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return ret_code;
|
return ret_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -439,13 +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__ );
|
SetErrorInfo( __FUNCTION__, __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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return ret_code;
|
return ret_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -471,7 +471,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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -480,7 +480,7 @@ int hsm_rsa_load_keypair( NFKM_KeyIdent keyident, M_KeyID *privKeyid, M_KeyID *p
|
|||||||
ret_code = NFKM_getusablemodule( hsmWorld, HSM_MODULE_ID, &moduleinfo );
|
ret_code = NFKM_getusablemodule( hsmWorld, HSM_MODULE_ID, &moduleinfo );
|
||||||
if ( ret_code != CR_GENID_SUCCESS )
|
if ( ret_code != CR_GENID_SUCCESS )
|
||||||
{
|
{
|
||||||
SetErrorInfo( ret_code, __FILE__, __LINE__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -492,7 +492,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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -504,7 +504,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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -541,13 +541,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__ );
|
SetErrorInfo( __FUNCTION__, __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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return ret_code;
|
return ret_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -588,13 +588,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__ );
|
SetErrorInfo( __FUNCTION__, __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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return ret_code;
|
return ret_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -126,9 +126,10 @@
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
s32 errorCode;
|
u8 stop;
|
||||||
u32 lineNumber;
|
u8 position;
|
||||||
char fileName[64];
|
u8 emptySize;
|
||||||
|
u8 stack[ CALL_STACK_SIZE ];
|
||||||
}
|
}
|
||||||
errorInfoStruct;
|
errorInfoStruct;
|
||||||
|
|
||||||
@ -236,34 +237,45 @@ int GenerateRandom( u8 *pDst, int length )
|
|||||||
return ret_code;
|
return ret_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ƒGƒ‰<C692>[<5B>î•ñ‚Ì‹L˜^
|
void InitErrorInfo( void )
|
||||||
void SetErrorInfo( s32 errorCode, char fileName[], u32 line )
|
|
||||||
{
|
{
|
||||||
static u8 stored = 0;
|
memset( &errorInfo, 0, sizeof( errorInfo ) );
|
||||||
|
errorInfo.emptySize = CALL_STACK_SIZE;
|
||||||
if ( !stored )
|
} // InitErrorInfo
|
||||||
|
|
||||||
|
// ƒGƒ‰<C692>[<5B>î•ñ‚Ì‹L˜^
|
||||||
|
void SetErrorInfo( const char *funcName, u32 line )
|
||||||
|
{
|
||||||
|
if ( !errorInfo.stop )
|
||||||
{
|
{
|
||||||
stored = 1;
|
int len;
|
||||||
|
char str[64];
|
||||||
|
|
||||||
memset( &errorInfo, 0, sizeof( errorInfo ) );
|
sprintf( str, "%s:%d ", funcName, (int)line );
|
||||||
|
len = strlen( str );
|
||||||
|
|
||||||
errorInfo.errorCode = errorCode;
|
if ( len > errorInfo.emptySize )
|
||||||
strncpy( errorInfo.fileName, fileName, strlen( fileName ) );
|
{
|
||||||
errorInfo.lineNumber = line;
|
errorInfo.stop = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy( &errorInfo.stack[ errorInfo.position ], str, len );
|
||||||
|
errorInfo.position += len;
|
||||||
|
errorInfo.emptySize -= len;
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf( "Error info was already stored!\n" );
|
printf( "Stack is full!\n" );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} // StoreErrorInfo
|
} // StoreErrorInfo
|
||||||
|
|
||||||
// エラー情報の取得
|
// エラー情報の取得
|
||||||
void GetErrorInfo( s32 *errorCode, char *fileName, u32 *line )
|
void GetErrorInfo( char *stack, u8 *size )
|
||||||
{
|
{
|
||||||
*errorCode = errorInfo.errorCode;
|
memcpy( stack, errorInfo.stack, CALL_STACK_SIZE );
|
||||||
strncpy( fileName, errorInfo.fileName, strlen( errorInfo.fileName ) );
|
*size = CALL_STACK_SIZE - errorInfo.emptySize;
|
||||||
*line = errorInfo.lineNumber;
|
|
||||||
} // GetErrorInfo
|
} // GetErrorInfo
|
||||||
|
|
||||||
|
|||||||
14
cr_keyPair.c
14
cr_keyPair.c
@ -137,7 +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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return CR_GENID_ERROR_EC_KEY_NEW_1;
|
return CR_GENID_ERROR_EC_KEY_NEW_1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return CR_GENID_ERROR_EC_GENERATE_PRIVATE_KEY;
|
return CR_GENID_ERROR_EC_GENERATE_PRIVATE_KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return CR_GENID_ERROR_EC_GENERATE_PUBLIC_KEY;
|
return CR_GENID_ERROR_EC_GENERATE_PUBLIC_KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return ret_code;
|
return ret_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,7 +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__ );
|
SetErrorInfo( __FUNCTION__, __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)); */
|
||||||
@ -296,13 +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__ );
|
SetErrorInfo( __FUNCTION__, __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__ );
|
SetErrorInfo( __FUNCTION__, __LINE__ );
|
||||||
return CR_GENID_ERROR_ECDSA_VERIFY;
|
return CR_GENID_ERROR_ECDSA_VERIFY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user