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 --- src/gpgme.h.in | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/gpgme.h.in') diff --git a/src/gpgme.h.in b/src/gpgme.h.in index 9c0c7977..705d9741 100644 --- a/src/gpgme.h.in +++ b/src/gpgme.h.in @@ -2481,10 +2481,15 @@ typedef enum } gpgme_random_mode_t; -/* Fill BUFFER with BUFSIZE random bytes from gpg. */ +/* Fill BUFFER with BUFSIZE random bytes from gpg or return an error. */ gpgme_error_t gpgme_op_random_bytes (gpgme_ctx_t ctx, gpgme_random_mode_t mode, char *buffer, size_t bufsize); +/* Store an unbiased random value in the range [0,LIMIT) at RETVAL or + * return an error. */ +gpgme_error_t gpgme_op_random_value (gpgme_ctx_t ctx, size_t limit, + size_t *retval); + /* -- cgit v1.2.3