From 2db7875da7d83bfd844234a9fccca60b17a0f016 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Thu, 7 Jun 2012 10:39:48 +0900 Subject: [PATCH] polarssl change --- ChangeLog | 12 ++++++++++++ README | 7 +++++++ polarssl-0.14.0/include/polarssl/bignum.h | 4 ++-- polarssl-0.14.0/include/polarssl/rsa.h | 4 ++-- polarssl-0.14.0/library/bignum.c | 8 ++++---- polarssl-0.14.0/library/rsa.c | 8 +++++--- 6 files changed, 32 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index d2f01a1..30fb049 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2012-06-07 Niibe Yutaka + + PolarSSL modification. + * polarssl-0.14.0/library/rsa.c (rsa_gen_key): Don't set D, DP, + DQ, and QP. It's only for key generation. + * polarssl-0.14.0/library/rsa.c (rsa_gen_key, rsa_pkcs1_encrypt): + Change f_rng function return type. + * polarssl-0.14.0/include/polarssl/rsa.h: Likewise. + * polarssl-0.14.0/library/bignum.c (mpi_is_prime, mpi_gen_prime): + Change f_rng function return type. + * polarssl-0.14.0/include/polarssl/bignum.h: Likewise. + 2012-06-06 Niibe Yutaka * Version 0.19. diff --git a/README b/README index 695217a..8ff5925 100644 --- a/README +++ b/README @@ -230,6 +230,13 @@ Gnuk is distributed with external source code. The file include/polarssl/bn_mul.h is heavily modified for ARM Cortex-M3. + The files include/polarssl/rsa.h, library/rsa.c, + include/polarssl/bignum.h, and library/bignum.c are modified so that + f_rng function returns unsigned char. + + The file library/rsa.c is modified so that it only computes things + needed for Gnuk. + The file library/aes.c is modified so that some constants can go to .sys section. diff --git a/polarssl-0.14.0/include/polarssl/bignum.h b/polarssl-0.14.0/include/polarssl/bignum.h index 80399a2..6070332 100644 --- a/polarssl-0.14.0/include/polarssl/bignum.h +++ b/polarssl-0.14.0/include/polarssl/bignum.h @@ -501,7 +501,7 @@ int mpi_inv_mod( mpi *X, const mpi *A, const mpi *N ); * 1 if memory allocation failed, * POLARSSL_ERR_MPI_NOT_ACCEPTABLE if X is not prime */ -int mpi_is_prime( mpi *X, int (*f_rng)(void *), void *p_rng ); +int mpi_is_prime( mpi *X, unsigned char (*f_rng)(void *), void *p_rng ); /** * \brief Prime number generation @@ -517,7 +517,7 @@ int mpi_is_prime( mpi *X, int (*f_rng)(void *), void *p_rng ); * POLARSSL_ERR_MPI_BAD_INPUT_DATA if nbits is < 3 */ int mpi_gen_prime( mpi *X, int nbits, int dh_flag, - int (*f_rng)(void *), void *p_rng ); + unsigned char (*f_rng)(void *), void *p_rng ); /** * \brief Checkup routine diff --git a/polarssl-0.14.0/include/polarssl/rsa.h b/polarssl-0.14.0/include/polarssl/rsa.h index 0e1f46a..c0569b4 100644 --- a/polarssl-0.14.0/include/polarssl/rsa.h +++ b/polarssl-0.14.0/include/polarssl/rsa.h @@ -183,7 +183,7 @@ void rsa_init( rsa_context *ctx, * \return 0 if successful, or an POLARSSL_ERR_RSA_XXX error code */ int rsa_gen_key( rsa_context *ctx, - int (*f_rng)(void *), + unsigned char (*f_rng)(void *), void *p_rng, int nbits, int exponent ); @@ -258,7 +258,7 @@ int rsa_private( rsa_context *ctx, * of ctx->N (eg. 128 bytes if RSA-1024 is used). */ int rsa_pkcs1_encrypt( rsa_context *ctx, - int (*f_rng)(void *), + unsigned char (*f_rng)(void *), void *p_rng, int mode, int ilen, const unsigned char *input, diff --git a/polarssl-0.14.0/library/bignum.c b/polarssl-0.14.0/library/bignum.c index cb1b7eb..5ef7351 100644 --- a/polarssl-0.14.0/library/bignum.c +++ b/polarssl-0.14.0/library/bignum.c @@ -1693,7 +1693,7 @@ static const int small_prime[] = /* * Miller-Rabin primality test (HAC 4.24) */ -int mpi_is_prime( mpi *X, int (*f_rng)(void *), void *p_rng ) +int mpi_is_prime( mpi *X, unsigned char (*f_rng)(void *), void *p_rng ) { int ret, i, j, n, s, xs; mpi W, R, T, A, RR; @@ -1755,7 +1755,7 @@ int mpi_is_prime( mpi *X, int (*f_rng)(void *), void *p_rng ) p = (unsigned char *) A.p; for( j = 0; j < A.n * ciL; j++ ) - *p++ = (unsigned char) f_rng( p_rng ); + *p++ = f_rng( p_rng ); j = mpi_msb( &A ) - mpi_msb( &W ); MPI_CHK( mpi_shift_r( &A, j + 1 ) ); @@ -1809,7 +1809,7 @@ cleanup: * Prime number generation */ int mpi_gen_prime( mpi *X, int nbits, int dh_flag, - int (*f_rng)(void *), void *p_rng ) + unsigned char (*f_rng)(void *), void *p_rng ) { int ret, k, n; unsigned char *p; @@ -1827,7 +1827,7 @@ int mpi_gen_prime( mpi *X, int nbits, int dh_flag, p = (unsigned char *) X->p; for( k = 0; k < X->n * ciL; k++ ) - *p++ = (unsigned char) f_rng( p_rng ); + *p++ = f_rng( p_rng ); k = mpi_msb( X ); if( k < nbits ) MPI_CHK( mpi_shift_l( X, nbits - k ) ); diff --git a/polarssl-0.14.0/library/rsa.c b/polarssl-0.14.0/library/rsa.c index 54a219b..943ef84 100644 --- a/polarssl-0.14.0/library/rsa.c +++ b/polarssl-0.14.0/library/rsa.c @@ -58,7 +58,7 @@ void rsa_init( rsa_context *ctx, * Generate an RSA keypair */ int rsa_gen_key( rsa_context *ctx, - int (*f_rng)(void *), + unsigned char (*f_rng)(void *), void *p_rng, int nbits, int exponent ) { @@ -101,6 +101,7 @@ int rsa_gen_key( rsa_context *ctx, } while( mpi_cmp_int( &G, 1 ) != 0 ); +#if 0 /* * D = E^-1 mod ((P-1)*(Q-1)) * DP = D mod (P - 1) @@ -111,6 +112,7 @@ int rsa_gen_key( rsa_context *ctx, MPI_CHK( mpi_mod_mpi( &ctx->DP, &ctx->D, &P1 ) ); MPI_CHK( mpi_mod_mpi( &ctx->DQ, &ctx->D, &Q1 ) ); MPI_CHK( mpi_inv_mod( &ctx->QP, &ctx->Q, &ctx->P ) ); +#endif ctx->len = ( mpi_msb( &ctx->N ) + 7 ) >> 3; @@ -295,7 +297,7 @@ cleanup: * Add the message padding, then do an RSA operation */ int rsa_pkcs1_encrypt( rsa_context *ctx, - int (*f_rng)(void *), + unsigned char (*f_rng)(void *), void *p_rng, int mode, int ilen, const unsigned char *input, @@ -323,7 +325,7 @@ int rsa_pkcs1_encrypt( rsa_context *ctx, int rng_dl = 100; do { - *p = (unsigned char) f_rng( p_rng ); + *p = f_rng( p_rng ); } while( *p == 0 && --rng_dl ); // Check if RNG failed to generate data