- Changed the used random function pointer to more flexible format. Renamed havege_rand() to havege_random() to prevent mistakes. Lots of changes as a consequence in library code and programs

This commit is contained in:
Paul Bakker 2011-11-27 21:07:34 +00:00
parent 880ac7eb95
commit a3d195c41f
31 changed files with 232 additions and 119 deletions

View file

@ -539,7 +539,9 @@ 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, size_t size, int (*f_rng)(void *), void *p_rng );
int mpi_fill_random( mpi *X, size_t size,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng );
/**
* \brief Greatest common divisor: G = gcd(A, B)
@ -578,7 +580,9 @@ 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,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng );
/**
* \brief Prime number generation
@ -594,7 +598,8 @@ 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, size_t nbits, int dh_flag,
int (*f_rng)(void *), void *p_rng );
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng );
/**
* \brief Checkup routine

View file

@ -90,7 +90,8 @@ int dhm_read_params( dhm_context *ctx,
*/
int dhm_make_params( dhm_context *ctx, int x_size,
unsigned char *output, size_t *olen,
int (*f_rng)(void *), void *p_rng );
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng );
/**
* \brief Import the peer's public value G^Y
@ -118,7 +119,8 @@ int dhm_read_public( dhm_context *ctx,
*/
int dhm_make_public( dhm_context *ctx, int x_size,
unsigned char *output, size_t olen,
int (*f_rng)(void *), void *p_rng );
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng );
/**
* \brief Derive and export the shared secret (G^Y)^X mod P

View file

@ -27,6 +27,8 @@
#ifndef POLARSSL_HAVEGE_H
#define POLARSSL_HAVEGE_H
#include <string.h>
#define COLLECT_SIZE 1024
/**
@ -55,10 +57,12 @@ void havege_init( havege_state *hs );
* \brief HAVEGE rand function
*
* \param p_rng A HAVEGE state
* \param output Buffer to fill
* \param len Length of buffer
*
* \return A random int
*/
int havege_rand( void *p_rng );
int havege_random( void *p_rng, unsigned char *output, size_t len );
#ifdef __cplusplus
}

View file

@ -186,7 +186,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 *),
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng,
unsigned int nbits, int exponent );
@ -261,7 +261,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 *),
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng,
int mode, size_t ilen,
const unsigned char *input,
@ -314,7 +314,7 @@ int rsa_pkcs1_decrypt( rsa_context *ctx,
* keep both hashes the same.
*/
int rsa_pkcs1_sign( rsa_context *ctx,
int (*f_rng)(void *),
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng,
int mode,
int hash_id,

View file

@ -232,7 +232,7 @@ struct _ssl_context
/*
* Callbacks (RNG, debug, I/O, verification)
*/
int (*f_rng)(void *);
int (*f_rng)(void *, unsigned char *, size_t);
void (*f_dbg)(void *, int, const char *);
int (*f_recv)(void *, unsigned char *, size_t);
int (*f_send)(void *, const unsigned char *, size_t);
@ -438,7 +438,7 @@ void ssl_set_verify( ssl_context *ssl,
* \param p_rng RNG parameter
*/
void ssl_set_rng( ssl_context *ssl,
int (*f_rng)(void *),
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng );
/**