git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_eFuse@139 ff987cc8-cf2f-4642-8568-d52cce064691

This commit is contained in:
kubodera_yuichi 2010-01-06 01:23:58 +00:00
parent 5a1ea7706f
commit 80376b03d1
4 changed files with 33 additions and 5 deletions

View File

@ -119,6 +119,7 @@
#ifdef USE_HSM #ifdef USE_HSM
#include "cr_hsm_code.h" #include "cr_hsm_code.h"
#include "cr_hsm_alloc.h" // temp
#endif // USE_HSM #endif // USE_HSM
// openssl // openssl
#include <openssl/sha.h> #include <openssl/sha.h>
@ -375,6 +376,10 @@ end:
ERR_free_strings(); ERR_free_strings();
#endif /* MY_CRYPTO_DEBUG */ #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 */ return ret_code; /* success */
} }

View File

@ -30,6 +30,10 @@
/* --------------------- */ /* --------------------- */
static int alloc_counter = 0;
/* --------------------- */
int my_bignumreceiveupcall(struct NFast_Application *app, int my_bignumreceiveupcall(struct NFast_Application *app,
struct NFast_Call_Context *cctx, struct NFast_Call_Context *cctx,
struct NFast_Transaction_Context *tctx, 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); pBN = (struct NFast_Bignum *)NFastApp_Malloc(app, sizeof(struct NFast_Bignum), cctx, tctx);
if ( !pBN ) return NOMEM; if ( !pBN ) return NOMEM;
alloc_counter++;
nfutil_copybytes(pBN->bytes, (const unsigned char *)source, nfutil_copybytes(pBN->bytes, (const unsigned char *)source,
nbytes, 0, 0); nbytes, 0, 0);
@ -102,6 +107,7 @@ void my_bignumfreeupcall(struct NFast_Application *app,
{ {
NFastApp_Free(app, (*bignum), cctx, tctx); NFastApp_Free(app, (*bignum), cctx, tctx);
*bignum=NULL; *bignum=NULL;
alloc_counter--;
} }
/* --------------------- */ /* --------------------- */
@ -356,4 +362,11 @@ int my_compare ( const struct NFast_Bignum *pA,
return 0; return 0;
} }
/* --------------------- */
int my_bignum_get_alloc_counter( void )
{
return alloc_counter;
}
#endif // HSM #endif // HSM

View File

@ -170,6 +170,8 @@ extern void my_printbignum ( FILE *f,
extern int my_compare ( const struct NFast_Bignum *pA, extern int my_compare ( const struct NFast_Bignum *pA,
const struct NFast_Bignum *pB ); const struct NFast_Bignum *pB );
extern int my_bignum_get_alloc_counter( void );
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -116,6 +116,7 @@
#include <time.h> #include <time.h>
#include <sys/time.h> #include <sys/time.h>
#include <string.h> #include <string.h>
#include <cr_alloc.h>
#ifdef USE_HSM #ifdef USE_HSM
#include "cr_hsm_code.h" #include "cr_hsm_code.h"
@ -179,8 +180,10 @@ int hsm_initialize( void )
} }
#endif #endif
printf( "init, hsm alloc counter : %d\n", my_hsm_get_alloc_counter() );
// init HSM // 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 ); //ret_code = NFastApp_InitEx( &hsmHandle, NULL, NULL );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
@ -271,6 +274,8 @@ int hsm_initialize( void )
return ret_code; return ret_code;
} }
printf( "init end, hsm alloc counter : %d\n", my_hsm_get_alloc_counter() );
return ret_code; return ret_code;
} // hsm_initialize } // hsm_initialize
@ -290,6 +295,9 @@ int hsm_finalize( void )
// void // void
NFastApp_Finish( hsmHandle, NULL ); 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; return ret_code;
} // hsm_finalize } // hsm_finalize
@ -861,10 +869,10 @@ int hsm_ecdsa_sign( unsigned char *sign_buf, unsigned char *data_buf, unsigned c
#if 1 #if 1
// signature bignum -> bin // signature bignum -> bin
rLen = reply.reply.sign.sig.data.ecdsa.r->nbytes; 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 ); my_bignum2bin ( rPtr, rLen, hsmHandle, reply.reply.sign.sig.data.ecdsa.r );
sLen = reply.reply.sign.sig.data.ecdsa.s->nbytes; 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 ); my_bignum2bin ( sPtr, sLen, hsmHandle, reply.reply.sign.sig.data.ecdsa.s );
#endif #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 ); // ‰½ŒÌ©ƒAƒ{<7B>[ƒg·é //NFastApp_Free_Command( hsmHandle, NULL, NULL, &cmd ); // ‰½ŒÌ©ƒAƒ{<7B>[ƒg·é
NFastApp_Free_Reply( hsmHandle, NULL, NULL, &reply ); NFastApp_Free_Reply( hsmHandle, NULL, NULL, &reply );
free( rPtr ); cr_mem_free( rPtr );
free( sPtr ); cr_mem_free( sPtr );
return CR_GENID_SUCCESS; return CR_GENID_SUCCESS;
} // hsm_ecdsa_sign } // hsm_ecdsa_sign