mirror of
https://github.com/rvtr/ctr_eFuse.git
synced 2025-11-02 00:11:04 -04:00
hsm_utils
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_eFuse@81 ff987cc8-cf2f-4642-8568-d52cce064691
This commit is contained in:
parent
ecaf1ba492
commit
acb6127092
@ -26,7 +26,7 @@
|
||||
|
||||
#include "simplecmd.h"
|
||||
|
||||
#define PUB_KEY_FILE "/opt/nfast/work/rsa-pub-key2048.der"
|
||||
#define PUB_KEY_FILE "/opt/nfast/work/rsa-priv-key2048.der"
|
||||
|
||||
#define MODULE_ID 1
|
||||
#define DATA_LEN 256 // bytes
|
||||
@ -86,7 +86,7 @@ int my_bignumsendlenupcall( struct NFast_Application *app,
|
||||
const M_Bignum *bignum, int *nbytes_r )
|
||||
{
|
||||
char *ptr = (char*)bignum;
|
||||
printf( "%08X\n", ptr );
|
||||
printf( "%08X\n", (unsigned int)ptr );
|
||||
while( *ptr )
|
||||
printf( "%02X ", *(ptr++) );
|
||||
|
||||
@ -113,7 +113,7 @@ int main( int argc, char *argv[] )
|
||||
rand_size = atoi( argv[1] );
|
||||
|
||||
// load rsa data(public)
|
||||
RSA *pubkey = NULL;
|
||||
RSA *privkey = NULL;
|
||||
FILE *fp;
|
||||
fp = fopen( PUB_KEY_FILE, "rb" );
|
||||
if ( !fp )
|
||||
@ -122,14 +122,14 @@ int main( int argc, char *argv[] )
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf( "before : %08X\n", pubkey );
|
||||
pubkey = d2i_RSA_PUBKEY_fp( fp, NULL );
|
||||
if ( !pubkey )
|
||||
printf( "before : %08X\n", privkey );
|
||||
privkey = d2i_RSAPrivateKey_fp( fp, NULL );
|
||||
if ( !privkey )
|
||||
{
|
||||
printf( "error : d2i_RSA_PUBKEY_fp\n" );
|
||||
printf( "error : d2i_RSAPrivateKey_fp\n" );
|
||||
return 0;
|
||||
}
|
||||
printf( "after : %08X\n", pubkey );
|
||||
printf( "after : %08X\n", privkey );
|
||||
|
||||
// init nFast
|
||||
NFastAppInitArgs app_init_args;
|
||||
@ -286,12 +286,13 @@ int main( int argc, char *argv[] )
|
||||
}
|
||||
|
||||
// import key
|
||||
NFKM_KeyIdent keyident = { (char*)"custom", (char*)"rsa-import-pubkey" };
|
||||
NFKM_KeyIdent keyident = { (char*)"simple", (char*)"rsa-import-privkey" };
|
||||
tc.cmd.cmd = Cmd_Import;
|
||||
tc.cmd.args.import.module = MODULE_ID;
|
||||
tc.cmd.args.import.data.type = KeyType_RSAPublic;
|
||||
tc.cmd.args.import.data.data.rsapublic.e = (M_Bignum)pubkey->e; // Public exponent of the RSA keypair
|
||||
tc.cmd.args.import.data.data.rsapublic.n = (M_Bignum)pubkey->n; // Modules of the RSA keypair
|
||||
tc.cmd.args.import.data.type = KeyType_RSAPrivate;
|
||||
tc.cmd.args.import.data.data.rsaprivate.p =
|
||||
tc.cmd.args.import.data.data.rsapublic.e = (M_Bignum)privkey->e; // Public exponent of the RSA keypair
|
||||
tc.cmd.args.import.data.data.rsapublic.n = (M_Bignum)privkey->n; // Modules of the RSA keypair
|
||||
result = NFastApp_Transact( nc, NULL, &(tc.cmd), &(tc.reply), NULL );
|
||||
if ( result != Status_OK )
|
||||
{
|
||||
@ -347,7 +348,7 @@ int main( int argc, char *argv[] )
|
||||
#endif
|
||||
|
||||
// find key
|
||||
NFKM_KeyIdent ki_v = { (char*)"custom", (char*)"rsa-import-pubkey" };
|
||||
NFKM_KeyIdent ki_v = { (char*)"custom", (char*)"rsa-import-privkey" };
|
||||
|
||||
printf( "appname : %s, ident : %s\n", ki_v.appname, ki_v.ident );
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user