I'm trying to implement a function defined in a library but I'm having problems to use it. This question help me to implement it, but I couldn't use the function.
Here is the typedef:
typedef void (*paillier_get_rand_t) ( void* buf, int len );
And here is how I implement it:
void get_rand(void* buf, int len) {
buf = (void *)rand(); // I don't know if it works but isn't the problem
}
And here how I create the pointer to the function and call it.
int modulus = 4;
void* buf;
paillier_pubkey_t* pub;
paillier_prvkey_t* prv;
paillier_keygen(modulus, &pub, &prv, &get_rand);
Question 1) How I send the parameters buf and len? Question 2) Now the error is different:
reference to `paillier_keygen(int, paillier_pubkey_t**, paillier_prvkey_t**, void (*)(void*, int))' undefined
The function paillier_keygen
is used to generate the respectives key for the algorithm and the function get_rand
is used to obtain the randomness needed by the probabilistic algorithms.
I'm implementing this typedef because I need to do it to be able to use the lib.
EDIT:
I found one function who is already defined and I can use called paillier_get_rand_devurandom
.
/* These functions may be passed to the paillier_keygen and paillier_enc functions to provide a source of random numbers. The first reads bytes from /dev/random. On Linux, this device exclusively returns entropy gathered from environmental noise and therefore frequently blocks when not enough is available. The second returns bytes from /dev/urandom. On Linux, this device also returns environmental noise, but augments it with a pseudo-random number generator when not enough is available. The latter is probably the better choice unless you have a specific reason to believe it is insufficient. */
void paillier_get_rand_devurandom( void* buf, int len );
If I used like before
paillier_keygen(modulus, &pub, &prv, paillier_get_rand_devurandom(buf, 4));
I get error: invalid use of void expression
If I used like this:
paillier_keygen(modulus, &pub, &prv, &paillier_get_rand_devurandom);
I get:
undefined reference to `paillier_get_rand_devurandom(void*, int)'
undefined reference to `paillier_keygen(int, paillier_pubkey_t**, paillier_prvkey_t**, void (*)(void*, int))'
The library is included. Here I add more info about the signatures:
/* Generate a keypair of length modulusbits using randomness from the provided get_rand function. Space will be allocated for each of the keys, and the given pointers will be set to point to the new paillier_pubkey_t and paillier_prvkey_t structures. The functions paillier_get_rand_devrandom and paillier_get_rand_devurandom may be passed as the final argument. */
void paillier_keygen( int modulusbits,
paillier_pubkey_t** pub, paillier_prvkey_t** prv, paillier_get_rand_t get_rand );
/* This is the type of the callback functions used to obtain the randomness needed by the probabilistic algorithms. The functions paillier_get_rand_devrandom and paillier_get_rand_devurandom (documented later) may be passed to any library function requiring a paillier_get_rand_t, or you may implement your own. If you implement your own such function, it should fill in "len" random bytes in the array "buf". */
typedef void (*paillier_get_rand_t) ( void* buf, int len );