use getrandom() on recent linux distros

Instead of using the internal DRBG-based RNG, use the `getrandom()` system
call where available.
Keep the existing version as fall-back for other systems that don't provide
that system call.

... and for cases where auto-detection fails or the user simply wants to
use the internal RNG a new configure-switch is provided.

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
This commit is contained in:
Steffen Jaeckel
2022-02-01 12:39:01 +01:00
parent 2850fd7792
commit 3a3b4faa10
3 changed files with 83 additions and 2 deletions

View File

@@ -20,6 +20,8 @@
/* include rand.c to access private structures and functions */
#include "rand.c"
#ifndef USE_GETRANDOM
/* stubs to build test without whole libstrophe */
void *xmpp_alloc(const xmpp_ctx_t *ctx, size_t size)
{
@@ -160,3 +162,19 @@ int main()
return 0;
}
#else
int main()
{
uint8_t output[1024];
xmpp_rand_t *rand = xmpp_rand_new(NULL);
assert(rand != NULL);
/* this would assert if it failed */
xmpp_rand_bytes(rand, output, sizeof(output));
return 0;
}
#endif