[PATCH] Custom random number generation function.

Niels Möller nisse at lysator.liu.se
Fri Sep 3 10:23:32 CEST 2010


Pedro Gimeno <gmpdevel at formauri.es> writes:

> Exposing the full struct is a possibility, but such struct should
> preferably be kept opaque and only expose an interface to set the
> functions it contains. Example:
>
> void
> gmp_randinit_generic (gmp_randstate_t    rstate,
>                       gmp_randseed_fn_t  randseed_fn,
>                       gmp_randget_fn_t   randget_fn,
>                       gmp_randclear_fn_t randclear_fn,
>                       gmp_randiset_fn_t  randiset_fn);

What's the use case for this? To me, if you have a custom generator, e.g.,
one with decent cryptographic properties, and want to use it with gmp,
it makes no sense to me at all to have gmp know about seeding the
generator or save and restore its insternal state.

It's the application's job to seed and maintain the generator, and gmp
should just use it when generating various random numbers. A typical
interface of a cryptographic randomness source is something like this
(from the Nettle library):

  typedef void (nettle_random_func)(void *ctx,
				    unsigned length, uint8_t *dst);

To get GMP to use a function like that, it has to be given the function
pointer and corresponding ctx pointer.

If you want to use a randinit-style function to do that, that would be

  void
  gmp_randinit_custom (gmp_randstate_t rstate,
                       nettle_random_func *random, /* Or whatever name
                                                      you prefer for
                                                      the typedef */
                       void *ctx);

Regards,
/Niels

PS. I'm replying to gmp-discuss, at Torbjörns request. I'm not
subscribed, so keep me in cc: if you want me to follow the discussion.

-- 
Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.


More information about the gmp-discuss mailing list