- Change buffer size on mpi_write_file() to cover larger size MPIs

This commit is contained in:
Paul Bakker 2012-09-26 19:20:46 +00:00
parent 49d75678a5
commit 5531c6d92c
2 changed files with 7 additions and 5 deletions

View file

@ -70,14 +70,15 @@
#define POLARSSL_MPI_MAX_BITS ( 8 * POLARSSL_MPI_MAX_SIZE ) /**< Maximum number of bits for usable MPIs. */ #define POLARSSL_MPI_MAX_BITS ( 8 * POLARSSL_MPI_MAX_SIZE ) /**< Maximum number of bits for usable MPIs. */
/* /*
* When reading from files with mpi_read_file() the buffer should have space * When reading from files with mpi_read_file() and writing to files with
* mpi_write_file() the buffer should have space
* for a (short) label, the MPI (in the provided radix), the newline * for a (short) label, the MPI (in the provided radix), the newline
* characters and the '\0'. * characters and the '\0'.
* *
* By default we assume at least a 10 char label, a minimum radix of 10 * By default we assume at least a 10 char label, a minimum radix of 10
* (decimal) and a maximum of 4096 bit numbers (1234 decimal chars). * (decimal) and a maximum of 4096 bit numbers (1234 decimal chars).
*/ */
#define POLARSSL_MPI_READ_BUFFER_SIZE 1250 #define POLARSSL_MPI_RW_BUFFER_SIZE 1250
/* /*
* Define the base integer type, architecture-wise * Define the base integer type, architecture-wise

View file

@ -444,7 +444,7 @@ int mpi_read_file( mpi *X, int radix, FILE *fin )
* Buffer should have space for (short) label and decimal formatted MPI, * Buffer should have space for (short) label and decimal formatted MPI,
* newline characters and '\0' * newline characters and '\0'
*/ */
char s[ POLARSSL_MPI_READ_BUFFER_SIZE ]; char s[ POLARSSL_MPI_RW_BUFFER_SIZE ];
memset( s, 0, sizeof( s ) ); memset( s, 0, sizeof( s ) );
if( fgets( s, sizeof( s ) - 1, fin ) == NULL ) if( fgets( s, sizeof( s ) - 1, fin ) == NULL )
@ -473,9 +473,10 @@ int mpi_write_file( const char *p, const mpi *X, int radix, FILE *fout )
int ret; int ret;
size_t n, slen, plen; size_t n, slen, plen;
/* /*
* Buffer should have space for minus sign, hexified MPI and '\0' * Buffer should have space for (short) label and decimal formatted MPI,
* newline characters and '\0'
*/ */
char s[ 2 * POLARSSL_MPI_MAX_SIZE + 2 ]; char s[ POLARSSL_MPI_RW_BUFFER_SIZE ];
n = sizeof( s ); n = sizeof( s );
memset( s, 0, n ); memset( s, 0, n );