それとなく最終形態に近づける(鍵名など)

git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_eFuse@140 ff987cc8-cf2f-4642-8568-d52cce064691
This commit is contained in:
kubodera_yuichi 2010-01-06 02:20:37 +00:00
parent 80376b03d1
commit 5c72fef3d8
4 changed files with 79 additions and 69 deletions

View File

@ -343,7 +343,7 @@ int GenerateCTRDeviceCert( EC_KEY *pECkey, u32 device_id, u8 bonding_option, u8
ret_code = CR_GENID_ERROR_ECC_READ_PUBLIC_KEY; ret_code = CR_GENID_ERROR_ECC_READ_PUBLIC_KEY;
goto end; goto end;
} }
#if 1 #if 0
// TODO: ハッシュ処理 // TODO: ハッシュ処理
int i; int i;
u8 verifyHash[30]; u8 verifyHash[30];
@ -371,7 +371,7 @@ int GenerateCTRDeviceCert( EC_KEY *pECkey, u32 device_id, u8 bonding_option, u8
DEBUG_PRINT_ARRAY( (char*)"sign(HSM)", (const char *)signBuf, signLen ); DEBUG_PRINT_ARRAY( (char*)"sign(HSM)", (const char *)signBuf, signLen );
// 署名ベリファイ // 署名ベリファイ
ret_code = ECDSA_verify( 0, &verifyHash[1], 233/8, signBuf, signLen, NCT2 ); ret_code = ECDSA_verify( 0, verifyHash, 30, signBuf, signLen, NCT2 );
if( ret_code != 1) { if( ret_code != 1) {
ret_code = CR_GENID_ERROR_ECDSA_VERIFY; ret_code = CR_GENID_ERROR_ECDSA_VERIFY;
SetErrorInfo( __FUNCTION__, __LINE__ ); SetErrorInfo( __FUNCTION__, __LINE__ );

View File

@ -375,10 +375,12 @@ end:
#ifdef MY_CRYPTO_DEBUG #ifdef MY_CRYPTO_DEBUG
ERR_free_strings(); ERR_free_strings();
#endif /* MY_CRYPTO_DEBUG */ #endif /* MY_CRYPTO_DEBUG */
if ( cr_print_flag )
{
printf( "hsm alloc counter : %d\n", my_hsm_get_alloc_counter() ); printf( "hsm alloc counter : %d\n", my_hsm_get_alloc_counter() );
printf( "hsmbn alloc counter : %d\n", my_bignum_get_alloc_counter() ); printf( "hsmbn alloc counter : %d\n", my_bignum_get_alloc_counter() );
printf( "miya alloc counter : %d\n", cr_mem_get_counter() ); printf( "miya alloc counter : %d\n", cr_mem_get_counter() );
}
return ret_code; /* success */ return ret_code; /* success */
} }

View File

@ -170,6 +170,7 @@ int my_char2bignum ( struct NFast_Bignum **ppBN_out,
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++;
pBN->msb_first = 0; pBN->msb_first = 0;
pBN->msw_first = 0; pBN->msw_first = 0;
@ -212,6 +213,7 @@ int my_bin2bignum ( struct NFast_Bignum **ppBN_out,
pBN = (struct NFast_Bignum *)NFastApp_Malloc( app, sizeof(struct NFast_Bignum), NULL, NULL ); pBN = (struct NFast_Bignum *)NFastApp_Malloc( app, sizeof(struct NFast_Bignum), NULL, NULL );
if ( !pBN ) return NOMEM; if ( !pBN ) return NOMEM;
alloc_counter++;
pBN->msb_first = 0; pBN->msb_first = 0;
pBN->msw_first = 0; pBN->msw_first = 0;
@ -317,6 +319,7 @@ int my_bignumCopy( struct NFast_Bignum **dst,
struct NFast_Bignum *pBN; struct NFast_Bignum *pBN;
pBN = (struct NFast_Bignum *)NFastApp_Malloc( app, sizeof(struct NFast_Bignum), NULL, NULL ); pBN = (struct NFast_Bignum *)NFastApp_Malloc( app, sizeof(struct NFast_Bignum), NULL, NULL );
if ( !pBN ) return NOMEM; if ( !pBN ) return NOMEM;
alloc_counter++;
pBN->msb_first = src->msb_first; pBN->msb_first = src->msb_first;
pBN->msw_first = src->msw_first; pBN->msw_first = src->msw_first;

View File

@ -131,24 +131,21 @@
#include "rqcard-applic.h" #include "rqcard-applic.h"
#include "rqcard-fips.h" #include "rqcard-fips.h"
// TORIAEZU : nFast variables // nFast variables
NFast_AppHandle hsmHandle; NFast_AppHandle hsmHandle;
NFastApp_Connection hsmConnection; NFastApp_Connection hsmConnection;
NFKM_WorldInfo *hsmWorld = NULL; // allocate NFKM_WorldInfo *hsmWorld = NULL; // allocate
// TODO: 最終鍵に変更する
#ifdef ENCRYPT_AES #ifdef ENCRYPT_AES
M_KeyID hsmAesKeyidDev, hsmAesKeyidProd; M_KeyID hsmAesKeyidDev, hsmAesKeyidProd;
// TODO : 最終的な鍵の名前を決める "efuse-aes-dev, efuse-aes-prod" const NFKM_KeyIdent hsmAesKeyidentDev = { (char*)"simple", (char*)"efuse-aes-dev" };
const NFKM_KeyIdent hsmAesKeyidentDev = { (char*)"simple", (char*)"efuse-aes-key-dummy-dev" }; const NFKM_KeyIdent hsmAesKeyidentProd = { (char*)"simple", (char*)"efuse-aes-prod" };
const NFKM_KeyIdent hsmAesKeyidentProd = { (char*)"simple", (char*)"efuse-aes-key-dummy-prod" };
static int hsm_aes_load_key( NFKM_KeyIdent keyident, M_KeyID *keyid ); static int hsm_aes_load_key( NFKM_KeyIdent keyident, M_KeyID *keyid );
#else // !ENCRYPT_AES #else // !ENCRYPT_AES
M_KeyID hsmRsaPrivkeyidDev, hsmRsaPubkeyidDev, hsmRsaPrivkeyidProd, hsmRsaPubkeyidProd; M_KeyID hsmRsaPrivkeyidDev, hsmRsaPubkeyidDev, hsmRsaPrivkeyidProd, hsmRsaPubkeyidProd;
// TODO : 最終的な鍵の名前を決める "efuse-rsa-priv-dev, efuse-rsa-priv-prod" const NFKM_KeyIdent hsmRsaKeyidentDev = { (char*)"simple", (char*)"efuse-rsa-priv-dev" };
const NFKM_KeyIdent hsmRsaKeyidentDev = { (char*)"simple", (char*)"rsa-dummykeypair-dev" }; const NFKM_KeyIdent hsmRsaKeyidentProd = { (char*)"simple", (char*)"efuse-rsa-priv-prod" };
const NFKM_KeyIdent hsmRsaKeyidentProd = { (char*)"simple", (char*)"rsa-dummykeypair-prod" };
static int hsm_rsa_load_keypair( NFKM_KeyIdent keyident, M_KeyID *privKeyid, M_KeyID *pubKeyid ); static int hsm_rsa_load_keypair( NFKM_KeyIdent keyident, M_KeyID *privKeyid, M_KeyID *pubKeyid );
#endif // ENCRYPT_AES #endif // ENCRYPT_AES
@ -157,11 +154,8 @@ static int hsm_rsa_load_keypair( NFKM_KeyIdent keyident, M_KeyID *privKeyid, M_K
M_KeyID hsmEcdsaPrivkeyidDev, hsmEcdsaPubkeyidDev; M_KeyID hsmEcdsaPrivkeyidDev, hsmEcdsaPubkeyidDev;
M_KeyID hsmEcdsaPrivkeyidProd, hsmEcdsaPubkeyidProd; M_KeyID hsmEcdsaPrivkeyidProd, hsmEcdsaPubkeyidProd;
// TODO : 最終的な鍵の名前を決める "nct2-priv-dev, nct2-priv-prod", 公開鍵は入れない const NFKM_KeyIdent hsmEcdsaPrivkeyidentDev = { (char*)"simple", (char*)"nct2-priv-dev" };
const NFKM_KeyIdent hsmEcdsaPrivkeyidentDev = { (char*)"simple", (char*)"nintendo-ctr2-priv-dummy-dev" }; const NFKM_KeyIdent hsmEcdsaPrivkeyidentProd = { (char*)"simple", (char*)"nct2-priv-prod" };
const NFKM_KeyIdent hsmEcdsaPubkeyidentDev = { (char*)"simple", (char*)"nintendo-ctr2-pub-dummy-dev" };
const NFKM_KeyIdent hsmEcdsaPrivkeyidentProd = { (char*)"simple", (char*)"nintendo-ctr2-priv-dummy-prod" };
const NFKM_KeyIdent hsmEcdsaPubkeyidentProd = { (char*)"simple", (char*)"nintendo-ctr2-pub-dummy-prod" };
int hsm_ecdsa_load_keypair( NFKM_KeyIdent privKeyident, M_KeyID *privKeyid, int hsm_ecdsa_load_keypair( NFKM_KeyIdent privKeyident, M_KeyID *privKeyid,
NFKM_KeyIdent pubKeyident, M_KeyID *pubKeyid ); NFKM_KeyIdent pubKeyident, M_KeyID *pubKeyid );
@ -180,11 +174,8 @@ 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_malloc, 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 ) if ( ret_code != CR_GENID_SUCCESS )
{ {
SetErrorInfo( __FUNCTION__, __LINE__ ); SetErrorInfo( __FUNCTION__, __LINE__ );
@ -258,7 +249,7 @@ int hsm_initialize( void )
// load ecdsa dev keypair // load ecdsa dev keypair
ret_code = hsm_ecdsa_load_keypair( hsmEcdsaPrivkeyidentDev, &hsmEcdsaPrivkeyidDev, ret_code = hsm_ecdsa_load_keypair( hsmEcdsaPrivkeyidentDev, &hsmEcdsaPrivkeyidDev,
hsmEcdsaPubkeyidentDev, &hsmEcdsaPubkeyidDev ); NULL, &hsmEcdsaPubkeyidDev );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
SetErrorInfo( __FUNCTION__, __LINE__ ); SetErrorInfo( __FUNCTION__, __LINE__ );
@ -267,15 +258,13 @@ int hsm_initialize( void )
// load ecdsa prod keypair // load ecdsa prod keypair
ret_code = hsm_ecdsa_load_keypair( hsmEcdsaPrivkeyidentProd, &hsmEcdsaPrivkeyidProd, ret_code = hsm_ecdsa_load_keypair( hsmEcdsaPrivkeyidentProd, &hsmEcdsaPrivkeyidProd,
hsmEcdsaPubkeyidentProd, &hsmEcdsaPubkeyidProd ); NULL, &hsmEcdsaPubkeyidProd );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
SetErrorInfo( __FUNCTION__, __LINE__ ); SetErrorInfo( __FUNCTION__, __LINE__ );
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
@ -773,7 +762,10 @@ int hsm_ecdsa_load_keypair( NFKM_KeyIdent privKeyident, M_KeyID *privKeyid,
goto end; goto end;
} }
// find priv key // priv
if ( privKeyident != NULL )
{
// find key
ret_code = NFKM_findkey( hsmHandle, privKeyident, &keyinfo, NULL ); ret_code = NFKM_findkey( hsmHandle, privKeyident, &keyinfo, NULL );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
@ -781,7 +773,7 @@ int hsm_ecdsa_load_keypair( NFKM_KeyIdent privKeyident, M_KeyID *privKeyid,
goto end; goto end;
} }
// load priv key blob // load key blob
blobptr = &(keyinfo->privblob); blobptr = &(keyinfo->privblob);
ret_code = NFKM_cmd_loadblob( hsmHandle, hsmConnection, ret_code = NFKM_cmd_loadblob( hsmHandle, hsmConnection,
moduleinfo->module, blobptr, moduleinfo->module, blobptr,
@ -795,8 +787,16 @@ int hsm_ecdsa_load_keypair( NFKM_KeyIdent privKeyident, M_KeyID *privKeyid,
NFKM_freekey( hsmHandle, keyinfo, NULL ); NFKM_freekey( hsmHandle, keyinfo, NULL );
keyinfo = NULL; keyinfo = NULL;
}
else
{
*privKeyid = 0;
} // priv
// find pub key // pub
if ( pubKeyident != NULL )
{
// find key
ret_code = NFKM_findkey( hsmHandle, pubKeyident, &keyinfo, NULL ); ret_code = NFKM_findkey( hsmHandle, pubKeyident, &keyinfo, NULL );
if ( ret_code != CR_GENID_SUCCESS ) if ( ret_code != CR_GENID_SUCCESS )
{ {
@ -804,7 +804,7 @@ int hsm_ecdsa_load_keypair( NFKM_KeyIdent privKeyident, M_KeyID *privKeyid,
goto end; goto end;
} }
// load public key blob // load key blob
blobptr = &(keyinfo->pubblob); blobptr = &(keyinfo->pubblob);
ret_code = NFKM_cmd_loadblob( hsmHandle, hsmConnection, ret_code = NFKM_cmd_loadblob( hsmHandle, hsmConnection,
moduleinfo->module, blobptr, moduleinfo->module, blobptr,
@ -815,6 +815,11 @@ int hsm_ecdsa_load_keypair( NFKM_KeyIdent privKeyident, M_KeyID *privKeyid,
SetErrorInfo( __FUNCTION__, __LINE__ ); SetErrorInfo( __FUNCTION__, __LINE__ );
goto end; goto end;
} }
}
else
{
*pubKeyid = 0;
} // pub
end: end:
NFKM_freekey( hsmHandle, keyinfo, NULL ); NFKM_freekey( hsmHandle, keyinfo, NULL );
@ -883,7 +888,7 @@ int hsm_ecdsa_sign( unsigned char *sign_buf, unsigned char *data_buf, unsigned c
// verify // verify
#if 1 #if 0
struct NFast_Bignum *rBn, *sBn; struct NFast_Bignum *rBn, *sBn;
my_bignumCopy( &rBn, reply.reply.sign.sig.data.ecdsa.r, hsmHandle ); my_bignumCopy( &rBn, reply.reply.sign.sig.data.ecdsa.r, hsmHandle );
my_bignumCopy( &sBn, reply.reply.sign.sig.data.ecdsa.s, hsmHandle ); my_bignumCopy( &sBn, reply.reply.sign.sig.data.ecdsa.s, hsmHandle );