diff --git a/trunk/cr_device_cert.c b/trunk/cr_device_cert.c index e1262ef..4acc74a 100644 --- a/trunk/cr_device_cert.c +++ b/trunk/cr_device_cert.c @@ -185,7 +185,7 @@ int GenerateCTRDeviceCert( EC_KEY *pECkey, u32 device_id, u8 bonding_option, u8 memset( &deviceCert, 0, sizeof(deviceCert) ); - // sigType + // sigType // ECDSA+SHA256 = 0x00010005, ECDSA+SHA1 = 0x00010002 deviceCert.sigType[0] = 0x00; deviceCert.sigType[1] = 0x01; diff --git a/trunk/cr_generate_id.c b/trunk/cr_generate_id.c index a5dbc34..19db009 100644 --- a/trunk/cr_generate_id.c +++ b/trunk/cr_generate_id.c @@ -155,7 +155,20 @@ int cr_generate_id_initialize( u8 err_buf[CR_ID_BUF_SIZE] ) // init for error info InitErrorInfo(); - + + // OpenSSL のメモリリーク防止のため、オリジナルのアロケータを使用。 + if ( CRYPTO_set_mem_functions( cr_mem_malloc, cr_mem_realloc, cr_mem_free ) != 1 ) + { + CR_ERR_BUFFER *cr_err_buf = (CR_ERR_BUFFER *)err_buf; + memset( cr_err_buf, 0, sizeof( CR_ERR_BUFFER ) ); + cr_err_buf->errorCode = CR_GENID_ERROR_SET_MEM_FUNCTIONS; + GetErrorInfo( cr_err_buf->callStack, &cr_err_buf->recordSize ); +#ifdef DEBUG_PRINT + printf( "error(%d), CALL_STACK : %s\n", (int)cr_err_buf->errorCode, cr_err_buf->callStack ); +#endif + return CR_GENID_FAILED; + } + #ifdef USE_HSM ret_code = hsm_initialize(); if ( ret_code != CR_GENID_SUCCESS ) @@ -225,15 +238,13 @@ int cr_generate_id( u32 device_id[CR_NUM_OF_DEVICEID], u8 id_buf[CR_ID_BUF_SIZE] //-------------------------------------------------------------- // 暗号処理初期化 //-------------------------------------------------------------- - - // メモリリーク防止のため、オリジナルのアロケータを使用。 - CRYPTO_set_mem_functions(cr_mem_malloc, cr_mem_realloc, cr_mem_free); - cr_mem_bufmgr_initialize(); + cr_mem_bufmgr_initialize(); #ifdef MY_CRYPTO_DEBUG ERR_load_crypto_strings(); #endif /* MY_CRYPTO_DEBUG */ + // ダイジェストアルゴリズムを追加する OpenSSL_add_all_digests(); @@ -267,7 +278,7 @@ int cr_generate_id( u32 device_id[CR_NUM_OF_DEVICEID], u8 id_buf[CR_ID_BUF_SIZE] printf("\n"); } #endif /* DEBUG_PRINT */ - + //-------------------------------------------------------------- // タイムスタンプセット //-------------------------------------------------------------- @@ -282,7 +293,7 @@ int cr_generate_id( u32 device_id[CR_NUM_OF_DEVICEID], u8 id_buf[CR_ID_BUF_SIZE] SetErrorInfo( __FUNCTION__, __LINE__ ); goto end; } - + //-------------------------------------------------------------- // 乱数を生成してセット //-------------------------------------------------------------- @@ -301,7 +312,7 @@ int cr_generate_id( u32 device_id[CR_NUM_OF_DEVICEID], u8 id_buf[CR_ID_BUF_SIZE] SetErrorInfo( __FUNCTION__, __LINE__ ); goto end; } - + //-------------------------------------------------------------- // 生成した鍵ペアをECDSAで動作確認 //-------------------------------------------------------------- diff --git a/trunk/cr_generate_id_private.h b/trunk/cr_generate_id_private.h index 391088a..a0cdcd3 100644 --- a/trunk/cr_generate_id_private.h +++ b/trunk/cr_generate_id_private.h @@ -174,6 +174,7 @@ extern "C" { #define CR_GENID_ERROR_RSA_ENC (-15) #define CR_GENID_ERROR_RSA_DEC (-16) #define CR_GENID_ERROR_RSA_VERIFY (-17) +#define CR_GENID_ERROR_SET_MEM_FUNCTIONS (-18) typedef struct { u32 magic_number; /* 0x00 - 0x03 = 0xdeadb00f mI*/