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