diff options
Diffstat (limited to 'include/polarssl/bignum.h')
-rw-r--r-- | include/polarssl/bignum.h | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/include/polarssl/bignum.h b/include/polarssl/bignum.h index ebc1f8f..909df1d 100644 --- a/include/polarssl/bignum.h +++ b/include/polarssl/bignum.h @@ -28,6 +28,7 @@ #define POLARSSL_BIGNUM_H #include <stdio.h> +#include <string.h> #define POLARSSL_ERR_MPI_FILE_IO_ERROR 0x0002 #define POLARSSL_ERR_MPI_BAD_INPUT_DATA 0x0004 @@ -43,13 +44,16 @@ * Define the base integer type, architecture-wise */ #if defined(POLARSSL_HAVE_INT8) +typedef signed char t_s_int; typedef unsigned char t_int; typedef unsigned short t_dbl; #else #if defined(POLARSSL_HAVE_INT16) +typedef signed short t_s_int; typedef unsigned short t_int; typedef unsigned long t_dbl; #else + typedef signed long t_s_int; typedef unsigned long t_int; #if defined(_MSC_VER) && defined(_M_IX86) typedef unsigned __int64 t_dbl; @@ -73,7 +77,7 @@ typedef unsigned long t_dbl; typedef struct { int s; /*!< integer sign */ - int n; /*!< total # of limbs */ + size_t n; /*!< total # of limbs */ t_int *p; /*!< pointer to limbs */ } mpi; @@ -101,7 +105,7 @@ void mpi_free( mpi *X, ... ); * \return 0 if successful, * 1 if memory allocation failed */ -int mpi_grow( mpi *X, int nblimbs ); +int mpi_grow( mpi *X, size_t nblimbs ); /** * \brief Copy the contents of Y into X @@ -131,28 +135,28 @@ void mpi_swap( mpi *X, mpi *Y ); * \return 0 if successful, * 1 if memory allocation failed */ -int mpi_lset( mpi *X, int z ); +int mpi_lset( mpi *X, t_s_int z ); /** * \brief Return the number of least significant bits * * \param X MPI to use */ -int mpi_lsb( const mpi *X ); +size_t mpi_lsb( const mpi *X ); /** * \brief Return the number of most significant bits * * \param X MPI to use */ -int mpi_msb( const mpi *X ); +size_t mpi_msb( const mpi *X ); /** * \brief Return the total size in bytes * * \param X MPI to use */ -int mpi_size( const mpi *X ); +size_t mpi_size( const mpi *X ); /** * \brief Import from an ASCII string @@ -180,7 +184,7 @@ int mpi_read_string( mpi *X, int radix, const char *s ); * \note Call this function with *slen = 0 to obtain the * minimum required buffer size in *slen. */ -int mpi_write_string( const mpi *X, int radix, char *s, int *slen ); +int mpi_write_string( const mpi *X, int radix, char *s, size_t *slen ); /** * \brief Read X from an opened file @@ -217,7 +221,7 @@ int mpi_write_file( const char *p, const mpi *X, int radix, FILE *fout ); * \return 0 if successful, * 1 if memory allocation failed */ -int mpi_read_binary( mpi *X, const unsigned char *buf, int buflen ); +int mpi_read_binary( mpi *X, const unsigned char *buf, size_t buflen ); /** * \brief Export X into unsigned binary data, big endian @@ -229,7 +233,7 @@ int mpi_read_binary( mpi *X, const unsigned char *buf, int buflen ); * \return 0 if successful, * POLARSSL_ERR_MPI_BUFFER_TOO_SMALL if buf isn't large enough */ -int mpi_write_binary( const mpi *X, unsigned char *buf, int buflen ); +int mpi_write_binary( const mpi *X, unsigned char *buf, size_t buflen ); /** * \brief Left-shift: X <<= count @@ -240,7 +244,7 @@ int mpi_write_binary( const mpi *X, unsigned char *buf, int buflen ); * \return 0 if successful, * 1 if memory allocation failed */ -int mpi_shift_l( mpi *X, int count ); +int mpi_shift_l( mpi *X, size_t count ); /** * \brief Right-shift: X >>= count @@ -251,7 +255,7 @@ int mpi_shift_l( mpi *X, int count ); * \return 0 if successful, * 1 if memory allocation failed */ -int mpi_shift_r( mpi *X, int count ); +int mpi_shift_r( mpi *X, size_t count ); /** * \brief Compare unsigned values @@ -287,7 +291,7 @@ int mpi_cmp_mpi( const mpi *X, const mpi *Y ); * -1 if X is lesser than z or * 0 if X is equal to z */ -int mpi_cmp_int( const mpi *X, int z ); +int mpi_cmp_int( const mpi *X, t_s_int z ); /** * \brief Unsigned addition: X = |A| + |B| @@ -347,7 +351,7 @@ int mpi_sub_mpi( mpi *X, const mpi *A, const mpi *B ); * \return 0 if successful, * 1 if memory allocation failed */ -int mpi_add_int( mpi *X, const mpi *A, int b ); +int mpi_add_int( mpi *X, const mpi *A, t_s_int b ); /** * \brief Signed substraction: X = A - b @@ -359,7 +363,7 @@ int mpi_add_int( mpi *X, const mpi *A, int b ); * \return 0 if successful, * 1 if memory allocation failed */ -int mpi_sub_int( mpi *X, const mpi *A, int b ); +int mpi_sub_int( mpi *X, const mpi *A, t_s_int b ); /** * \brief Baseline multiplication: X = A * B @@ -385,7 +389,7 @@ int mpi_mul_mpi( mpi *X, const mpi *A, const mpi *B ); * \return 0 if successful, * 1 if memory allocation failed */ -int mpi_mul_int( mpi *X, const mpi *A, t_int b ); +int mpi_mul_int( mpi *X, const mpi *A, t_s_int b ); /** * \brief Division by mpi: A = Q * B + R @@ -417,7 +421,7 @@ int mpi_div_mpi( mpi *Q, mpi *R, const mpi *A, const mpi *B ); * * \note Either Q or R can be NULL. */ -int mpi_div_int( mpi *Q, mpi *R, const mpi *A, int b ); +int mpi_div_int( mpi *Q, mpi *R, const mpi *A, t_s_int b ); /** * \brief Modulo: R = A mod B @@ -445,7 +449,7 @@ int mpi_mod_mpi( mpi *R, const mpi *A, const mpi *B ); * POLARSSL_ERR_MPI_DIVISION_BY_ZERO if b == 0, * POLARSSL_ERR_MPI_NEGATIVE_VALUE if b < 0 */ -int mpi_mod_int( t_int *r, const mpi *A, int b ); +int mpi_mod_int( t_int *r, const mpi *A, t_s_int b ); /** * \brief Sliding-window exponentiation: X = A^E mod N @@ -477,7 +481,7 @@ int mpi_exp_mod( mpi *X, const mpi *A, const mpi *E, const mpi *N, mpi *_RR ); * \return 0 if successful, * 1 if memory allocation failed */ -int mpi_fill_random( mpi *X, int size, int (*f_rng)(void *), void *p_rng ); +int mpi_fill_random( mpi *X, size_t size, int (*f_rng)(void *), void *p_rng ); /** * \brief Greatest common divisor: G = gcd(A, B) @@ -531,7 +535,7 @@ int mpi_is_prime( mpi *X, int (*f_rng)(void *), void *p_rng ); * 1 if memory allocation failed, * POLARSSL_ERR_MPI_BAD_INPUT_DATA if nbits is < 3 */ -int mpi_gen_prime( mpi *X, int nbits, int dh_flag, +int mpi_gen_prime( mpi *X, size_t nbits, int dh_flag, int (*f_rng)(void *), void *p_rng ); /** |