- 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
diff --git a/include/polarssl/bignum.h b/include/polarssl/bignum.h
index 1308557..12435f7 100644
--- a/include/polarssl/bignum.h
+++ b/include/polarssl/bignum.h
@@ -539,7 +539,9 @@
* \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 @@
* 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 @@
* 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
diff --git a/include/polarssl/dhm.h b/include/polarssl/dhm.h
index 1cbfc6c..52b0bf9 100644
--- a/include/polarssl/dhm.h
+++ b/include/polarssl/dhm.h
@@ -90,7 +90,8 @@
*/
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_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
diff --git a/include/polarssl/havege.h b/include/polarssl/havege.h
index 4be0e59..48d0f16 100644
--- a/include/polarssl/havege.h
+++ b/include/polarssl/havege.h
@@ -27,6 +27,8 @@
#ifndef POLARSSL_HAVEGE_H
#define POLARSSL_HAVEGE_H
+#include <string.h>
+
#define COLLECT_SIZE 1024
/**
@@ -55,10 +57,12 @@
* \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
}
diff --git a/include/polarssl/rsa.h b/include/polarssl/rsa.h
index c9ecbcd..629aa0f 100644
--- a/include/polarssl/rsa.h
+++ b/include/polarssl/rsa.h
@@ -186,7 +186,7 @@
* \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 @@
* 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 @@
* 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,
diff --git a/include/polarssl/ssl.h b/include/polarssl/ssl.h
index 5e2cae3..02d75c7 100644
--- a/include/polarssl/ssl.h
+++ b/include/polarssl/ssl.h
@@ -232,7 +232,7 @@
/*
* 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 @@
* \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 );
/**