From 926b1f1f1e3e382f08cc57fc86d5892649514007 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 14 Mar 2025 13:03:46 +0100 Subject: Add API gpgme_op_random_value. * src/genrandom.c (getrandom_size_t): New. (gpgme_op_random_value): New. * src/gpgme.def: Add new function. * src/libgpgme.vers: Ditto. * src/gpgme.h.in: Add prototype. * tests/run-genrandom.c: Add an option to use the new function. -- The implementation is not optimized but sufficient for our use case. Possible improvements for this and gpgme_op_random_bytes are a cache for random bytes in the context so that we do not need to get out to gpgme for just a few random bytes. GnuPG-bug-id: 6694 --- doc/gpgme.texi | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'doc') diff --git a/doc/gpgme.texi b/doc/gpgme.texi index a586631e..fa93083c 100644 --- a/doc/gpgme.texi +++ b/doc/gpgme.texi @@ -7142,11 +7142,26 @@ The function @code{gpgme_op_random_bytes} returns random bytes. from gpg. However, if @var{mode} is @code{GPGME_RANDOM_MODE_ZBASE32} @var{bufsize} needs to be at least 31 and will be filled with a string of 30 ASCII characters followed by a Nul; the remainder of the buffer -is not changed. This function has a limit of 1024 bytes to avoid -accidental overuse of the random generator +is not changed. The caller must provide a context @var{ctx} +initialized for GPGME_PROTOCOL_OPENPGP. This function has a limit of +1024 bytes to avoid accidental overuse of the random generator @end deftypefun +@deftypefun {gpgme_error_t} gpgme_op_random_values ( @ + @w{gpgme_ctx_t @var{ctx}}, @ + @w{size_t @var{limit}}, @ + @w{size_t *@var{retval}}) + +@since{2.0.0} + +The function @code{gpgme_op_random_value} returns an unbiased random +value in the range 0 <= value < @var{limit}. The value is returned at +@var{retval} if and only if the function returns with success. The +caller must also provide a context @var{ctx} initialized for +GPGME_PROTOCOL_OPENPGP. +@end deftypefun + @node Miscellaneous -- cgit v1.2.3