From 81b18f2db4a0710425cf5bbb8c01ae5878177d17 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Thu, 28 Sep 2017 16:44:54 +0900 Subject: [PATCH] More for GNU/Linux emulation. --- ChangeLog | 4 ++++ polarssl/library/bignum.c | 12 +++++++----- src/Makefile | 4 ++++ src/ec_p256k1.c | 2 ++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index f8dda44..e7ac4e4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2017-09-28 NIIBE Yutaka + * src/ec_p256k1.c (coefficient_a): Remove. + + * library/bignum.c (mpi_fill_pseudo_random): Fix for 64-bit. + * src/call-rsa.c (rsa_decrypt): Fix for 64-bit machine. * src/flash.c (flash_do_storage_init): Rename from flash_init. diff --git a/polarssl/library/bignum.c b/polarssl/library/bignum.c index 0f458af..57c8380 100644 --- a/polarssl/library/bignum.c +++ b/polarssl/library/bignum.c @@ -2052,17 +2052,19 @@ jkiss (struct jkiss_state *s) static int mpi_fill_pseudo_random ( mpi *X, size_t size) { int ret; - uint32_t *p; + uint32_t *p, *p_end; MPI_CHK( mpi_grow( X, CHARS_TO_LIMBS( size ) ) ); MPI_CHK( mpi_lset( X, 0 ) ); /* Assume little endian. */ - p = X->p; - while (p < X->p + (size/ciL)) + p = (uint32_t *)X->p; + p_end = (uint32_t *)(X->p + (size/sizeof (uint32_t))); + while (p < p_end) *p++ = jkiss (&jkiss_state_v); - if ((size % ciL)) - *p = jkiss (&jkiss_state_v) & ((1 << (8*(size % ciL))) - 1); + + if ((size%sizeof (uint32_t))) + *p = jkiss (&jkiss_state_v) & ((1 << (8*(size % sizeof (uint32_t)))) - 1); cleanup: return ret; diff --git a/src/Makefile b/src/Makefile index 90f5709..8ebeb41 100644 --- a/src/Makefile +++ b/src/Makefile @@ -31,6 +31,10 @@ USE_USB = yes USE_ADC = yes USE_EVENTFLAG = yes +ifneq ($(EMULATION),) +DEFS += -DBN256_C_IMPLEMENTATION +endif + ifneq ($(ENABLE_DEBUG),) CSRC += debug.c endif diff --git a/src/ec_p256k1.c b/src/ec_p256k1.c index c97d3c8..c63978e 100644 --- a/src/ec_p256k1.c +++ b/src/ec_p256k1.c @@ -42,9 +42,11 @@ /* * a = 0, b = 7 */ +#if 0 static const bn256 coefficient_a[1] = { {{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }} }; +#endif static const bn256 coefficient_b[1] = { {{ 0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }}