From 9dcee8d97b68cf8172f531872c98bfb181e49dde Mon Sep 17 00:00:00 2001 From: kubodera_yuichi Date: Tue, 12 Jan 2010 09:47:41 +0000 Subject: [PATCH] =?UTF-8?q?OpenSSL=E7=94=A8=E3=81=AE=E3=82=A2=E3=83=AD?= =?UTF-8?q?=E3=82=B1=E3=83=BC=E3=82=BF=E7=99=BB=E9=8C=B2=E3=81=AF=E8=B5=B7?= =?UTF-8?q?=E5=8B=95=E6=99=82=E3=81=AB=E4=B8=80=E5=9B=9E=E3=81=A0=E3=81=91?= =?UTF-8?q?=E3=81=A7=E3=82=88=E3=81=84=E3=80=82?= 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@177 ff987cc8-cf2f-4642-8568-d52cce064691 --- trunk/cr_device_cert.c | 2 +- trunk/cr_generate_id.c | 27 +++++++++++++++++++-------- trunk/cr_generate_id_private.h | 1 + 3 files changed, 21 insertions(+), 9 deletions(-) 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*/