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 );
|
||||
|
||||
int sbn_bin2bignum2 ( struct NFast_Bignum **ppBN_out,
|
||||
struct NFast_Application *app,
|
||||
const unsigned char *bin, const int size );
|
||||
|
||||
// bignum upcalls
|
||||
int my_bignumreceiveupcall(struct NFast_Application *app,
|
||||
struct NFast_Call_Context *cctx,
|
||||
@ -194,122 +190,42 @@ int my_bignumformatupcall(struct NFast_Application *app,
|
||||
return Status_OK;
|
||||
}
|
||||
|
||||
// almost copy sbn_char2bignum
|
||||
|
||||
// bin データを NFastApp の BigNum データに変換する
|
||||
int sbn_bin2bignum ( 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;
|
||||
struct NFast_Bignum *pBN;
|
||||
int d;
|
||||
size_t len, i;
|
||||
|
||||
len = size;
|
||||
|
||||
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 );
|
||||
if ( !pBN ) return NOMEM;
|
||||
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;
|
||||
pBN->msb_first = 0;
|
||||
pBN->msw_first = 0;
|
||||
|
||||
//memcpy( pBN->bytes, bin, len );
|
||||
for ( i = 0; i < len; i++ )
|
||||
pBN->bytes[i] = bin[len-1-i];
|
||||
|
||||
|
||||
while ( (i & 3) != 0 )
|
||||
pBN->bytes[i++] = 0;
|
||||
|
||||
pBN->nbytes = i;
|
||||
|
||||
*ppBN_out = pBN;
|
||||
|
||||
//PrintArray( (char*)"bin2bn array", (const char*)pBN->bytes, pBN->nbytes );
|
||||
|
||||
|
||||
pBN->nbytes = i;
|
||||
|
||||
*ppBN_out = pBN;
|
||||
|
||||
#if 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*)"bin2bn array", (const char*)pBN->bytes, pBN->nbytes );
|
||||
#endif
|
||||
|
||||
return Status_OK;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
return Status_OK;
|
||||
} // sbn_bin2bignum
|
||||
|
||||
void PrintArray( char *pStr, const unsigned char *pData, int length )
|
||||
{
|
||||
@ -755,7 +671,6 @@ int main( int argc, char *argv[] )
|
||||
blobptr = &keyinfo->pubblob;
|
||||
else
|
||||
{
|
||||
printf( "aes is symmetric key!\n" );
|
||||
blobptr = &keyinfo->privblob;
|
||||
}
|
||||
|
||||
@ -836,8 +751,8 @@ int main( int argc, char *argv[] )
|
||||
cmd.cmd = Cmd_Decrypt;
|
||||
cmd.args.decrypt.flags = 0;
|
||||
cmd.args.decrypt.key = keyid;
|
||||
cmd.args.decrypt.mech = Mech_RijndaelmCBCpNONE;
|
||||
cmd.args.decrypt.cipher.mech = Mech_RijndaelmCBCpNONE;
|
||||
cmd.args.decrypt.mech = Mech_RSApPKCS1;
|
||||
cmd.args.decrypt.cipher.mech = Mech_RSApPKCS1;
|
||||
cmd.args.decrypt.cipher.data.generic128.cipher = dec_input;
|
||||
cmd.args.decrypt.cipher.iv = dec_iv.iv;
|
||||
cmd.args.decrypt.reply_type = PlainTextType_Bytes;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user