From c74a9a8c0275bd12e5136ca76963f8e03a714471 Mon Sep 17 00:00:00 2001 From: kubodera_yuichi Date: Tue, 29 Dec 2009 05:05:40 +0000 Subject: [PATCH] =?UTF-8?q?ECDSA=E9=8D=B5=E3=83=9A=E3=82=A2=E3=83=AD?= =?UTF-8?q?=E3=83=BC=E3=83=89=E6=88=90=E5=8A=9F?= 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@127 ff987cc8-cf2f-4642-8568-d52cce064691 --- Makefile | 1 - cr_hsm_code.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index fb38342..eb6fc4a 100644 --- a/Makefile +++ b/Makefile @@ -53,7 +53,6 @@ NFAST_LDLIBS = \ # nFast OBJS NFAST_OBJS_PATH = $(NFAST_EXAMPLES)/nfuser/build-gcc-lib NFAST_OBJS_LIST = \ - $(NFAST_OBJS_PATH)/simplebignum.o \ $(NFAST_OBJS_PATH)/nfutil.o \ else # !USE_HSM diff --git a/cr_hsm_code.c b/cr_hsm_code.c index fc24df0..58c3390 100644 --- a/cr_hsm_code.c +++ b/cr_hsm_code.c @@ -149,6 +149,16 @@ const NFKM_KeyIdent hsmRsaKeyidentProd = { (char*)"simple", (char*)"rsa-dummykey static int hsm_rsa_load_keypair( NFKM_KeyIdent keyident, M_KeyID *privKeyid, M_KeyID *pubKeyid ); #endif // ENCRYPT_AES +// ECDSA key +M_KeyID hsmEcdsaPrivkeyidDev, hsmEcdsaPubkeyidDev; +M_KeyID hsmEcdsaPrivkeyidProd, hsmEcdsaPubkeyidProd; +const NFKM_KeyIdent hsmEcdsaPrivkeyidentDev = { (char*)"simple", (char*)"nintendo-ctr2-priv-dummy-dev" }; +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, + NFKM_KeyIdent pubKeyident, M_KeyID *pubKeyid ); + // init HSM int hsm_initialize( void ) { @@ -237,6 +247,23 @@ int hsm_initialize( void ) } #endif // ENCRYPT_AES + // load ecdsa dev keypair + ret_code = hsm_ecdsa_load_keypair( hsmEcdsaPrivkeyidentDev, &hsmEcdsaPrivkeyidDev, + hsmEcdsaPubkeyidentDev, &hsmEcdsaPrivkeyidDev ); + if ( ret_code != CR_GENID_SUCCESS ) + { + SetErrorInfo( __FUNCTION__, __LINE__ ); + return ret_code; + } + // load ecdsa prod keypair + ret_code = hsm_ecdsa_load_keypair( hsmEcdsaPrivkeyidentProd, &hsmEcdsaPrivkeyidProd, + hsmEcdsaPubkeyidentProd, &hsmEcdsaPrivkeyidProd ); + if ( ret_code != CR_GENID_SUCCESS ) + { + SetErrorInfo( __FUNCTION__, __LINE__ ); + return ret_code; + } + return ret_code; } // hsm_initialize @@ -714,4 +741,70 @@ int hsm_rsa_decrypt( unsigned char *dst_buf, unsigned char *org_buf, int size, u #endif // !ENCRYPT_AES +int hsm_ecdsa_load_keypair( NFKM_KeyIdent privKeyident, M_KeyID *privKeyid, + NFKM_KeyIdent pubKeyident, M_KeyID *pubKeyid ) +{ + int ret_code = CR_GENID_SUCCESS; + NFKM_Key *keyinfo = NULL; + NFKM_ModuleInfo *moduleinfo = NULL; + M_ByteBlock *blobptr = NULL; + + // find priv key + ret_code = NFKM_findkey( hsmHandle, privKeyident, &keyinfo, NULL ); + if ( ret_code != CR_GENID_SUCCESS ) + { + SetErrorInfo( __FUNCTION__, __LINE__ ); + goto end; + } + + // get usable Module + moduleinfo = hsmWorld->modules[0]; + ret_code = NFKM_getusablemodule( hsmWorld, HSM_MODULE_ID, &moduleinfo ); + if ( ret_code != CR_GENID_SUCCESS ) + { + SetErrorInfo( __FUNCTION__, __LINE__ ); + goto end; + } + + // load priv key blob + blobptr = &keyinfo->privblob; + ret_code = NFKM_cmd_loadblob( hsmHandle, hsmConnection, + moduleinfo->module, blobptr, + 0, privKeyid, + "loading priv key blob", NULL ); + if ( ret_code != CR_GENID_SUCCESS ) + { + SetErrorInfo( __FUNCTION__, __LINE__ ); + goto end; + } + + NFKM_freekey( hsmHandle, keyinfo, NULL ); + keyinfo = NULL; + + // find pub key + ret_code = NFKM_findkey( hsmHandle, pubKeyident, &keyinfo, NULL ); + if ( ret_code != CR_GENID_SUCCESS ) + { + SetErrorInfo( __FUNCTION__, __LINE__ ); + goto end; + } + + // load public key blob + blobptr = &keyinfo->pubblob; + ret_code = NFKM_cmd_loadblob( hsmHandle, hsmConnection, + moduleinfo->module, blobptr, + 0, pubKeyid, + "loading pub key blob", NULL ); + if ( ret_code != CR_GENID_SUCCESS ) + { + SetErrorInfo( __FUNCTION__, __LINE__ ); + goto end; + } + +end: + NFKM_freekey( hsmHandle, keyinfo, NULL ); + + return ret_code; +} // hsm_ecdsa_load_keypair + #endif // USE_HSM