diff --git a/Makefile b/Makefile index ba42816..5cc230e 100644 --- a/Makefile +++ b/Makefile @@ -50,11 +50,6 @@ NFAST_LDLIBS = \ $(NFAST_LIBPATH)/libnflog.a \ $(NFAST_LIBPATH)/libcutils.a -lm \ -# nFast OBJS -NFAST_OBJS_PATH = $(NFAST_EXAMPLES)/nfuser/build-gcc-lib -NFAST_OBJS_LIST = \ - $(NFAST_OBJS_PATH)/nfutil.o \ - else # !USE_HSM # HSMが使用できない場合は、DUMMY_KEYを使ってテストする。 @@ -140,7 +135,7 @@ package_build : endif $(TARGET): $(OBJS) - $(LD) $(LDFLAGS) $(OBJS) -o $@ $(LDLIBS) $(NFAST_OBJS_LIST) + $(LD) $(LDFLAGS) $(OBJS) -o $@ $(LDLIBS) $(OBJS): $(HEADS) Makefile diff --git a/cr_hsm_bignum.c b/cr_hsm_bignum.c index 63be796..234e68b 100644 --- a/cr_hsm_bignum.c +++ b/cr_hsm_bignum.c @@ -34,6 +34,61 @@ static int alloc_counter = 0; /* --------------------- */ +// original : nfutil_copybytes ( nfutil.c ) +static void my_util_copybytes ( unsigned char *dst, const unsigned char *src, + unsigned nbytes, int swapends, int swapwords ) +{ + int inc; + unsigned nwords; + + /* Copies dst to src, swapping endianness and/or word order. dst and src mustn't overlap! */ + + assert( (nbytes & 3)==0 ); /* Must be whole number of M_Words */ + + if ( !swapends && !swapwords ) + { + memcpy(dst, src, nbytes); + return; + } + + if ( swapwords ) + { + dst += (nbytes-4); + inc=-4; + } + else + inc=4; + + nwords = nbytes>>2; + + if ( swapends ) + { + while ( nwords-- > 0 ) + { + dst[0]=src[3]; + dst[1]=src[2]; + dst[2]=src[1]; + dst[3]=src[0]; + dst += inc; + src += 4; + } + } + else + { + while ( nwords-- > 0 ) + { + dst[0]=src[0]; + dst[1]=src[1]; + dst[2]=src[2]; + dst[3]=src[3]; + dst += inc; + src += 4; + } + } +} + +/* --------------------- */ + int my_bignumreceiveupcall(struct NFast_Application *app, struct NFast_Call_Context *cctx, struct NFast_Transaction_Context *tctx, @@ -50,7 +105,7 @@ int my_bignumreceiveupcall(struct NFast_Application *app, if ( !pBN ) return NOMEM; alloc_counter++; - nfutil_copybytes(pBN->bytes, (const unsigned char *)source, + my_util_copybytes(pBN->bytes, (const unsigned char *)source, nbytes, 0, 0); pBN->msb_first = msbitfirst; @@ -93,7 +148,7 @@ int my_bignumsendupcall(struct NFast_Application *app, swapends = (!msbitfirst) ^ (!pBN->msb_first); swapwords = (!mswordfirst) ^ (!pBN->msw_first); - nfutil_copybytes( (unsigned char *)dest, (*bignum)->bytes, nbytes, + my_util_copybytes( (unsigned char *)dest, (*bignum)->bytes, nbytes, swapends, swapwords ); return Status_OK; }