polarssl change

This commit is contained in:
NIIBE Yutaka
2012-06-07 10:39:48 +09:00
parent 3da8a3b326
commit 2db7875da7
6 changed files with 32 additions and 11 deletions

View File

@@ -1,3 +1,15 @@
2012-06-07 Niibe Yutaka <gniibe@fsij.org>
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 <gniibe@fsij.org>
* Version 0.19.

7
README
View File

@@ -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.

View File

@@ -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

View File

@@ -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,

View File

@@ -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 ) );

View File

@@ -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