From 1f5eba052d511851db927eb7f0a602a08f45529f Mon Sep 17 00:00:00 2001 From: kubodera_yuichi Date: Thu, 7 Jan 2010 00:51:19 +0000 Subject: [PATCH] =?UTF-8?q?=E3=82=B5=E3=83=B3=E3=83=97=E3=83=AB=E3=81=AE?= =?UTF-8?q?=E3=82=AA=E3=83=96=E3=82=B8=E3=82=A7=E3=82=AF=E3=83=88nfutil.o?= =?UTF-8?q?=E3=82=92=E9=99=A4=E5=A4=96=E3=81=97=E3=80=81=E3=81=9D=E3=81=AE?= =?UTF-8?q?=E3=81=86=E3=81=A1=E3=81=AE=E9=96=A2=E6=95=B0nfutil=5Fcopybytes?= =?UTF-8?q?=E3=81=A0=E3=81=91=E3=82=82=E3=82=89=E3=81=A3=E3=81=A6=E3=81=8F?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_eFuse@148 ff987cc8-cf2f-4642-8568-d52cce064691 --- Makefile | 7 +----- cr_hsm_bignum.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 8 deletions(-) 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; }