hsm_utils:HSM用のmalloc upcalls切り出し

git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_eFuse@112 ff987cc8-cf2f-4642-8568-d52cce064691
This commit is contained in:
kubodera_yuichi 2009-12-28 00:36:29 +00:00
parent dcd93a3c04
commit 915d377370
7 changed files with 82 additions and 110 deletions

View File

@ -84,7 +84,7 @@ XLDLIBS= $(LIBPATH_SWORLD)/librqcard.a \
COMMON_OBJECTS = $(REFPATH)/nfutil.o $(REFPATH)/nfopt.o $(REFPATH)/getdate.o $(REFPATH)/report.o $(REFPATH)/report-usage.o $(REFPATH)/nftypes.o $(REFPATH)/tokenise.o
EXTRA_OBJECTS = mybignum.o
EXTRA_OBJECTS = my_hsm_bignum.o my_hsm_alloc.o
COMMON_HEADERS= $(REFPATH)/nfutil.h $(REFPATH)/nfopt.h $(REFPATH)/nftypes.h $(REFPATH)/tokenise.h
@ -96,8 +96,11 @@ $(SRCPATH)/getdate.c: ;
# Simple (non-threaded) programs ------------
mybignum.o: mybignum.c
$(CC) $(CFLAGS) $(CPPFLAGS) -o mybignum.o -c mybignum.c
my_hsm_bignum.o: my_hsm_bignum.c
$(CC) $(CFLAGS) $(CPPFLAGS) -o my_hsm_bignum.o -c my_hsm_bignum.c
my_hsm_alloc.o: my_hsm_alloc.c
$(CC) $(CFLAGS) $(CPPFLAGS) -o my_hsm_alloc.o -c my_hsm_alloc.c
import_common_key: import_common_key.c $(EXTRA_OBJECTS)
$(CC) $(CFLAGS) $(CPPFLAGS) -o import_common_key import_common_key.c $(COMMON_OBJECTS) $(EXTRA_OBJECTS) $(LDLIBS)

View File

@ -22,11 +22,11 @@
#include "rqcard-applic.h"
#include "rqcard-fips.h"
#include "ncthread-upcalls.h"
//#include "ncthread-upcalls.h"
//#include "picky-upcalls.h"
#include "mybignum.h"
#include "my_hsm_bignum.h"
#include "my_hsm_alloc.h"
#define PRIV_KEY_FILE "./test_key/test-ecc-privkey.der"
#define PUB_KEY_FILE "./test_key/test-ecc-pubkey.der"
@ -61,40 +61,10 @@ typedef struct
}
RSAPublicKeyData;
static void *my_malloc( size_t nbytes,
struct NFast_Call_Context *cctx, struct NFast_Transaction_Context *tctx );
static void *my_realloc( void *ptr, size_t nbytes,
struct NFast_Call_Context *cctx, struct NFast_Transaction_Context *tctx );
static void my_free( void *ptr,
struct NFast_Call_Context *cctx, struct NFast_Transaction_Context *tctx );
void PrintArray( char *pStr, const unsigned char *pData, int length );
int BN_bn2binWrapper( BIGNUM *bn, unsigned char **ptr, int *len );
int my_bin2bignumWrapper( NFast_AppHandle app, unsigned char *ptr, struct NFast_Bignum **nbn, int size );
const NFast_MallocUpcalls my_malloc_upcalls =
{
my_malloc, my_realloc, my_free
};
static void *my_malloc( size_t nbytes,
struct NFast_Call_Context *cctx, struct NFast_Transaction_Context *tctx )
{
return malloc( nbytes );
}
static void *my_realloc( void *ptr, size_t nbytes,
struct NFast_Call_Context *cctx, struct NFast_Transaction_Context *tctx )
{
return realloc( ptr, nbytes );
}
static void my_free( void *ptr,
struct NFast_Call_Context *cctx, struct NFast_Transaction_Context *tctx )
{
free( ptr );
}
void PrintArray( char *pStr, const unsigned char *pData, int length )
{
int i;

View File

@ -20,11 +20,10 @@
#include "rqcard-applic.h"
#include "rqcard-fips.h"
#include "ncthread-upcalls.h"
//#include "picky-upcalls.h"
#include "mybignum.h"
#include "my_hsm_bignum.h"
#include "my_hsm_alloc.h"
#define PRIV_KEY_FILE "/opt/nfast/work/rsa-priv-key2048.der"
#define PUB_KEY_FILE "/opt/nfast/work/rsa-pub-key2048.der"
@ -59,77 +58,8 @@ typedef struct
}
RSAPublicKeyData;
static void *my_malloc( size_t nbytes,
struct NFast_Call_Context *cctx, struct NFast_Transaction_Context *tctx );
static void *my_realloc( void *ptr, size_t nbytes,
struct NFast_Call_Context *cctx, struct NFast_Transaction_Context *tctx );
static void my_free( void *ptr,
struct NFast_Call_Context *cctx, struct NFast_Transaction_Context *tctx );
int sbn_bin2bignum ( struct NFast_Bignum **ppBN_out,
struct NFast_Application *app,
const unsigned char *bin, const int size );
void PrintArray( char *pStr, const unsigned char *pData, int length );
const NFast_MallocUpcalls my_malloc_upcalls =
{
my_malloc, my_realloc, my_free
};
static void *my_malloc( size_t nbytes,
struct NFast_Call_Context *cctx, struct NFast_Transaction_Context *tctx )
{
return malloc( nbytes );
}
static void *my_realloc( void *ptr, size_t nbytes,
struct NFast_Call_Context *cctx, struct NFast_Transaction_Context *tctx )
{
return realloc( ptr, nbytes );
}
static void my_free( void *ptr,
struct NFast_Call_Context *cctx, struct NFast_Transaction_Context *tctx )
{
free( ptr );
}
// 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 len, i;
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;
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;
#if 0
PrintArray( (char*)"bin2bn array", (const char*)pBN->bytes, pBN->nbytes );
#endif
return Status_OK;
} // sbn_bin2bignum
void PrintArray( char *pStr, const unsigned char *pData, int length )
{
int i;

39
hsm_utils/my_hsm_alloc.c Normal file
View File

@ -0,0 +1,39 @@
/*
* my_hsm_alloc.c
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include "nfastapp.h"
#include "nfutil.h"
#include "my_hsm_alloc.h"
/* --------------------- */
const NFast_MallocUpcalls my_malloc_upcalls =
{
my_malloc, my_realloc, my_free
};
static void *my_malloc( size_t nbytes,
struct NFast_Call_Context *cctx, struct NFast_Transaction_Context *tctx )
{
return malloc( nbytes );
}
static void *my_realloc( void *ptr, size_t nbytes,
struct NFast_Call_Context *cctx, struct NFast_Transaction_Context *tctx )
{
return realloc( ptr, nbytes );
}
static void my_free( void *ptr,
struct NFast_Call_Context *cctx, struct NFast_Transaction_Context *tctx )
{
free( ptr );
}

30
hsm_utils/my_hsm_alloc.h Normal file
View File

@ -0,0 +1,30 @@
/*
* my_hsm_alloc.h
*/
#ifndef MY_HSM_ALLOC_H
#define MY_HSM_ALLOC_H
#include "nfastapp.h"
#ifdef __cplusplus
extern "C" {
#endif
extern NFast_MallocUpcalls my_hsm_malloc_upcalls;
void *my_hsm_malloc( size_t nbytes,
struct NFast_Call_Context *cctx, struct NFast_Transaction_Context *tctx );
void *my_hsm_realloc( void *ptr, size_t nbytes,
struct NFast_Call_Context *cctx, struct NFast_Transaction_Context *tctx );
void my_hsm_free( void *ptr,
struct NFast_Call_Context *cctx, struct NFast_Transaction_Context *tctx );
#ifdef __cplusplus
}
#endif
#endif // MY_HSM_ALLOC_H

View File

@ -22,8 +22,8 @@
*
*/
#ifndef MY_BIGNUM_H
#define MY_BIGNUM_H
#ifndef MY_ALLOC_H
#define MY_ALLOC_H
#include "nfastapp.h"