diff --git a/cr_hsm_code.c b/cr_hsm_code.c index bac29c2..7103a09 100644 --- a/cr_hsm_code.c +++ b/cr_hsm_code.c @@ -156,11 +156,19 @@ int hsm_initialize( void ) int ret_code = CR_GENID_SUCCESS; // TODO: HSMリセットを入れる。 + ret_code = hsm_reset_module(); + if ( ret_code != CR_GENID_SUCCESS ) + { + SetErrorInfo( __FUNCTION__, __LINE__ ); + return ret_code; + } + // init HSM ret_code = NFastApp_InitEx( &hsmHandle, NULL, NULL ); if ( ret_code != CR_GENID_SUCCESS ) { + SetErrorInfo( __FUNCTION__, __LINE__ ); return ret_code; } @@ -240,6 +248,37 @@ void hsm_finalize( void ) NFastApp_Finish( hsmHandle, NULL ); } // hsm_finalize +int hsm_reset_module( void ) +{ + int ret_code = CR_GENID_SUCCESS; + M_Command cmd; + M_Reply reply; + + memset( &cmd, 0, sizeof( cmd ) ); + memset( &reply, 0, sizeof( reply ) ); + + cmd.cmd = Cmd_ClearUnit; + cmd.args.clearunit.module = HSM_MODULE_ID; + + ret_code = NFastApp_Transsct( hsmConnection, NULL, &cmd, &reply, NULL ); + if ( ret_code != CR_GENID_SUCCESS ) + { + SetErrorInfo( __FUNCTION__, __LINE__ ); + return ret_code; + } + ret_code = reply.status; + if ( ret_code != CR_GENID_SUCCESS ) + { + SetErrorInfo( __FUNCTION__, __LINE__ ); + return ret_code; + } + + NFastApp_Free_Command( hsmHandle, NULL, NULL, &cmd ); + NFastApp_Free_Reply( hsmHandle, NULL, NULL, &reply ); + + return ret_code; +} // hsm_reset_module + int hsm_generate_random( unsigned char *buf, int bytes ) { int ret_code = CR_GENID_SUCCESS; diff --git a/cr_hsm_code.h b/cr_hsm_code.h index ab5df96..b62baf3 100644 --- a/cr_hsm_code.h +++ b/cr_hsm_code.h @@ -121,6 +121,7 @@ extern "C" { // functions int hsm_initialize( void ); void hsm_finalize( void ); +int hsm_reset_module( void ); int hsm_generate_random( unsigned char *buf, int bytes ); int hsm_get_rtc( time_t *time ); int hsm_aes_encrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, unsigned char bondingOption );