From 80376b03d1ad95066a103a8e2bfc166a4c97edc6 Mon Sep 17 00:00:00 2001 From: kubodera_yuichi Date: Wed, 6 Jan 2010 01:23:58 +0000 Subject: [PATCH] git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_eFuse@139 ff987cc8-cf2f-4642-8568-d52cce064691 --- cr_generate_id.c | 5 +++++ cr_hsm_bignum.c | 13 +++++++++++++ cr_hsm_bignum.h | 2 ++ cr_hsm_code.c | 18 +++++++++++++----- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/cr_generate_id.c b/cr_generate_id.c index f7c0779..21938ca 100644 --- a/cr_generate_id.c +++ b/cr_generate_id.c @@ -119,6 +119,7 @@ #ifdef USE_HSM #include "cr_hsm_code.h" +#include "cr_hsm_alloc.h" // temp #endif // USE_HSM // openssl #include @@ -375,6 +376,10 @@ end: ERR_free_strings(); #endif /* MY_CRYPTO_DEBUG */ + printf( "hsm alloc counter : %d\n", my_hsm_get_alloc_counter() ); + printf( "hsmbn alloc counter : %d\n", my_bignum_get_alloc_counter() ); + printf( "miya alloc counter : %d\n", cr_mem_get_counter() ); + return ret_code; /* success */ } diff --git a/cr_hsm_bignum.c b/cr_hsm_bignum.c index 2727a07..e475b37 100644 --- a/cr_hsm_bignum.c +++ b/cr_hsm_bignum.c @@ -30,6 +30,10 @@ /* --------------------- */ +static int alloc_counter = 0; + +/* --------------------- */ + int my_bignumreceiveupcall(struct NFast_Application *app, struct NFast_Call_Context *cctx, struct NFast_Transaction_Context *tctx, @@ -44,6 +48,7 @@ int my_bignumreceiveupcall(struct NFast_Application *app, pBN = (struct NFast_Bignum *)NFastApp_Malloc(app, sizeof(struct NFast_Bignum), cctx, tctx); if ( !pBN ) return NOMEM; + alloc_counter++; nfutil_copybytes(pBN->bytes, (const unsigned char *)source, nbytes, 0, 0); @@ -102,6 +107,7 @@ void my_bignumfreeupcall(struct NFast_Application *app, { NFastApp_Free(app, (*bignum), cctx, tctx); *bignum=NULL; + alloc_counter--; } /* --------------------- */ @@ -356,4 +362,11 @@ int my_compare ( const struct NFast_Bignum *pA, return 0; } +/* --------------------- */ + +int my_bignum_get_alloc_counter( void ) +{ + return alloc_counter; +} + #endif // HSM diff --git a/cr_hsm_bignum.h b/cr_hsm_bignum.h index 21b098a..8d69cee 100644 --- a/cr_hsm_bignum.h +++ b/cr_hsm_bignum.h @@ -170,6 +170,8 @@ extern void my_printbignum ( FILE *f, extern int my_compare ( const struct NFast_Bignum *pA, const struct NFast_Bignum *pB ); +extern int my_bignum_get_alloc_counter( void ); + #ifdef __cplusplus } #endif diff --git a/cr_hsm_code.c b/cr_hsm_code.c index c8070e3..9ed4f32 100644 --- a/cr_hsm_code.c +++ b/cr_hsm_code.c @@ -116,6 +116,7 @@ #include #include #include +#include #ifdef USE_HSM #include "cr_hsm_code.h" @@ -179,8 +180,10 @@ int hsm_initialize( void ) } #endif + printf( "init, hsm alloc counter : %d\n", my_hsm_get_alloc_counter() ); + // init HSM - ret_code = NFastApp_Init( &hsmHandle, my_hsm_alloc, my_hsm_realloc, my_hsm_free, NULL ); + ret_code = NFastApp_Init( &hsmHandle, my_hsm_malloc, my_hsm_realloc, my_hsm_free, NULL ); //ret_code = NFastApp_InitEx( &hsmHandle, NULL, NULL ); if ( ret_code != CR_GENID_SUCCESS ) { @@ -271,6 +274,8 @@ int hsm_initialize( void ) return ret_code; } + printf( "init end, hsm alloc counter : %d\n", my_hsm_get_alloc_counter() ); + return ret_code; } // hsm_initialize @@ -290,6 +295,9 @@ int hsm_finalize( void ) // void NFastApp_Finish( hsmHandle, NULL ); + printf( "final, hsm alloc counter : %d\n", my_hsm_get_alloc_counter() ); + printf( "final, hsmbn alloc counter : %d\n", my_bignum_get_alloc_counter() ); + return ret_code; } // hsm_finalize @@ -861,10 +869,10 @@ int hsm_ecdsa_sign( unsigned char *sign_buf, unsigned char *data_buf, unsigned c #if 1 // signature bignum -> bin rLen = reply.reply.sign.sig.data.ecdsa.r->nbytes; - rPtr = (unsigned char*)malloc( rLen ); + rPtr = (unsigned char*)cr_mem_malloc( rLen ); my_bignum2bin ( rPtr, rLen, hsmHandle, reply.reply.sign.sig.data.ecdsa.r ); sLen = reply.reply.sign.sig.data.ecdsa.s->nbytes; - sPtr = (unsigned char*)malloc( sLen ); + sPtr = (unsigned char*)cr_mem_malloc( sLen ); my_bignum2bin ( sPtr, sLen, hsmHandle, reply.reply.sign.sig.data.ecdsa.s ); #endif @@ -938,8 +946,8 @@ int hsm_ecdsa_sign( unsigned char *sign_buf, unsigned char *data_buf, unsigned c //NFastApp_Free_Command( hsmHandle, NULL, NULL, &cmd ); // 何故かアボートする NFastApp_Free_Reply( hsmHandle, NULL, NULL, &reply ); - free( rPtr ); - free( sPtr ); + cr_mem_free( rPtr ); + cr_mem_free( sPtr ); return CR_GENID_SUCCESS; } // hsm_ecdsa_sign