mirror of
https://github.com/rvtr/ctr_eFuse.git
synced 2025-11-02 00:11:04 -04:00
hsm_utils:sbn_bin2bignumを簡略化
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_eFuse@84 ff987cc8-cf2f-4642-8568-d52cce064691
This commit is contained in:
parent
6903586a02
commit
9c5bd82ff6
@ -51,10 +51,6 @@ int sbn_bin2bignum ( struct NFast_Bignum **ppBN_out,
|
|||||||
|
|
||||||
void PrintArray( char *pStr, const unsigned char *pData, int length );
|
void PrintArray( char *pStr, const unsigned char *pData, int length );
|
||||||
|
|
||||||
int sbn_bin2bignum2 ( struct NFast_Bignum **ppBN_out,
|
|
||||||
struct NFast_Application *app,
|
|
||||||
const unsigned char *bin, const int size );
|
|
||||||
|
|
||||||
// bignum upcalls
|
// bignum upcalls
|
||||||
int my_bignumreceiveupcall(struct NFast_Application *app,
|
int my_bignumreceiveupcall(struct NFast_Application *app,
|
||||||
struct NFast_Call_Context *cctx,
|
struct NFast_Call_Context *cctx,
|
||||||
@ -194,7 +190,8 @@ int my_bignumformatupcall(struct NFast_Application *app,
|
|||||||
return Status_OK;
|
return Status_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// almost copy sbn_char2bignum
|
|
||||||
|
// bin データを NFastApp の BigNum データに変換する
|
||||||
int sbn_bin2bignum ( struct NFast_Bignum **ppBN_out,
|
int sbn_bin2bignum ( struct NFast_Bignum **ppBN_out,
|
||||||
struct NFast_Application *app,
|
struct NFast_Application *app,
|
||||||
const unsigned char *bin, const int size )
|
const unsigned char *bin, const int size )
|
||||||
@ -207,14 +204,12 @@ int sbn_bin2bignum ( struct NFast_Bignum **ppBN_out,
|
|||||||
|
|
||||||
if ( len > MAXBIGNUMBITS/4 ) return Status_OutOfRange;
|
if ( len > MAXBIGNUMBITS/4 ) return Status_OutOfRange;
|
||||||
|
|
||||||
//pBN = (struct NFast_Bignum *)NFastApp_Malloc(app, sizeof(struct NFast_Bignum), cctx, tctx);
|
|
||||||
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;
|
||||||
|
|
||||||
pBN->msb_first = 0;
|
pBN->msb_first = 0;
|
||||||
pBN->msw_first = 0;
|
pBN->msw_first = 0;
|
||||||
|
|
||||||
//memcpy( pBN->bytes, bin, len );
|
|
||||||
for ( i = 0; i < len; i++ )
|
for ( i = 0; i < len; i++ )
|
||||||
pBN->bytes[i] = bin[len-1-i];
|
pBN->bytes[i] = bin[len-1-i];
|
||||||
|
|
||||||
@ -225,91 +220,12 @@ int sbn_bin2bignum ( struct NFast_Bignum **ppBN_out,
|
|||||||
|
|
||||||
*ppBN_out = pBN;
|
*ppBN_out = pBN;
|
||||||
|
|
||||||
//PrintArray( (char*)"bin2bn array", (const char*)pBN->bytes, pBN->nbytes );
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* Read in from the LS digit */
|
PrintArray( (char*)"bin2bn array", (const char*)pBN->bytes, pBN->nbytes );
|
||||||
for ( i=0; i<len; i++ )
|
|
||||||
{
|
|
||||||
//d = char2hex(text[len-1-i]);
|
|
||||||
d = bin[ len-1-i ];
|
|
||||||
|
|
||||||
// ???
|
|
||||||
if ( d < 0 ) return Status_Malformed;
|
|
||||||
if ( i & 1 )
|
|
||||||
pBN->bytes[i/2] |= (d << 4);
|
|
||||||
else
|
|
||||||
pBN->bytes[i/2] = d;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Pad to words if necessary */
|
|
||||||
i = (len+1)/2;
|
|
||||||
while ( (i & 3) != 0 )
|
|
||||||
pBN->bytes[i++] = 0;
|
|
||||||
|
|
||||||
assert(i <= INT_MAX);
|
|
||||||
pBN->nbytes=(int)i;
|
|
||||||
*ppBN_out=pBN;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return Status_OK;
|
return Status_OK;
|
||||||
}
|
} // sbn_bin2bignum
|
||||||
|
|
||||||
int sbn_bin2bignum2 ( struct NFast_Bignum **ppBN_out,
|
|
||||||
struct NFast_Application *app,
|
|
||||||
const unsigned char *bin, const int size )
|
|
||||||
{
|
|
||||||
struct NFast_Bignum *pBN;
|
|
||||||
int d;
|
|
||||||
size_t len, i;
|
|
||||||
|
|
||||||
/* Strip leading whitespace */
|
|
||||||
|
|
||||||
// while ( text[0] != 0 && isspace((unsigned char)text[0]) )
|
|
||||||
// text++;
|
|
||||||
|
|
||||||
/* Strip trailing whitespace */
|
|
||||||
// len=strlen(text);
|
|
||||||
// while ( len > 0 && isspace((unsigned char)text[len-1]) )
|
|
||||||
// len--;
|
|
||||||
|
|
||||||
len = size;
|
|
||||||
|
|
||||||
if ( len > MAXBIGNUMBITS/4 ) return Status_OutOfRange;
|
|
||||||
|
|
||||||
pBN = (struct NFast_Bignum *)NFastApp_Malloc(app, sizeof(struct NFast_Bignum), NULL, NULL );
|
|
||||||
if ( !pBN ) return NOMEM;
|
|
||||||
|
|
||||||
pBN->msb_first = 0;
|
|
||||||
pBN->msw_first = 0;
|
|
||||||
|
|
||||||
/* Read in from the LS digit */
|
|
||||||
for ( i=0; i<len; i++ )
|
|
||||||
{
|
|
||||||
//d = char2hex(text[len-1-i]);
|
|
||||||
d = bin[len-1-i];
|
|
||||||
if ( d < 0 ) return Status_Malformed;
|
|
||||||
if ( i & 1 )
|
|
||||||
pBN->bytes[i/2] |= (d << 4);
|
|
||||||
else
|
|
||||||
pBN->bytes[i/2] = d;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Pad to words if necessary */
|
|
||||||
i = (len+1)/2;
|
|
||||||
while ( (i & 3) != 0 )
|
|
||||||
pBN->bytes[i++] = 0;
|
|
||||||
|
|
||||||
assert(i <= INT_MAX);
|
|
||||||
pBN->nbytes=(int)i;
|
|
||||||
*ppBN_out=pBN;
|
|
||||||
|
|
||||||
//PrintArray( (char*)"bin2bn2 array", (const char*)pBN->bytes, pBN->nbytes );
|
|
||||||
|
|
||||||
return Status_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PrintArray( char *pStr, const unsigned char *pData, int length )
|
void PrintArray( char *pStr, const unsigned char *pData, int length )
|
||||||
{
|
{
|
||||||
@ -755,7 +671,6 @@ int main( int argc, char *argv[] )
|
|||||||
blobptr = &keyinfo->pubblob;
|
blobptr = &keyinfo->pubblob;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf( "aes is symmetric key!\n" );
|
|
||||||
blobptr = &keyinfo->privblob;
|
blobptr = &keyinfo->privblob;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -836,8 +751,8 @@ int main( int argc, char *argv[] )
|
|||||||
cmd.cmd = Cmd_Decrypt;
|
cmd.cmd = Cmd_Decrypt;
|
||||||
cmd.args.decrypt.flags = 0;
|
cmd.args.decrypt.flags = 0;
|
||||||
cmd.args.decrypt.key = keyid;
|
cmd.args.decrypt.key = keyid;
|
||||||
cmd.args.decrypt.mech = Mech_RijndaelmCBCpNONE;
|
cmd.args.decrypt.mech = Mech_RSApPKCS1;
|
||||||
cmd.args.decrypt.cipher.mech = Mech_RijndaelmCBCpNONE;
|
cmd.args.decrypt.cipher.mech = Mech_RSApPKCS1;
|
||||||
cmd.args.decrypt.cipher.data.generic128.cipher = dec_input;
|
cmd.args.decrypt.cipher.data.generic128.cipher = dec_input;
|
||||||
cmd.args.decrypt.cipher.iv = dec_iv.iv;
|
cmd.args.decrypt.cipher.iv = dec_iv.iv;
|
||||||
cmd.args.decrypt.reply_type = PlainTextType_Bytes;
|
cmd.args.decrypt.reply_type = PlainTextType_Bytes;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user