From b7f4d5fa7e04498fddd60d298bc4a95241a581da Mon Sep 17 00:00:00 2001 From: James Almer Date: Tue, 4 Jul 2023 19:49:23 -0300 Subject: [PATCH] avutil/random_seed: add support for gcrypt and OpenSSL as source of randomness Reviewed-by: Anton Khirnov Signed-off-by: James Almer --- configure | 2 +- libavutil/random_seed.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 107d533b3e..d6e78297fe 100755 --- a/configure +++ b/configure @@ -3892,7 +3892,7 @@ avfilter_deps="avutil" avfilter_suggest="libm stdatomic" avformat_deps="avcodec avutil" avformat_suggest="libm network zlib stdatomic" -avutil_suggest="clock_gettime ffnvcodec libm libdrm libmfx opencl user32 vaapi vulkan videotoolbox corefoundation corevideo coremedia bcrypt stdatomic" +avutil_suggest="clock_gettime ffnvcodec gcrypt libm libdrm libmfx opencl openssl user32 vaapi vulkan videotoolbox corefoundation corevideo coremedia bcrypt stdatomic" postproc_deps="avutil gpl" postproc_suggest="libm stdatomic" swresample_deps="avutil" diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c index f5c291263e..2980e565e0 100644 --- a/libavutil/random_seed.c +++ b/libavutil/random_seed.c @@ -30,6 +30,11 @@ #include #include #endif +#if CONFIG_GCRYPT +#include +#elif CONFIG_OPENSSL +#include +#endif #include #include #include @@ -143,6 +148,17 @@ int av_random_bytes(uint8_t* buf, size_t len) #endif err = read_random(buf, len, "/dev/urandom"); + if (!err) + return err; + +#if CONFIG_GCRYPT + gcry_randomize(buf, len, GCRY_VERY_STRONG_RANDOM); + return 0; +#elif CONFIG_OPENSSL + if (RAND_bytes(buf, len) == 1) + return 0; + err = AVERROR_EXTERNAL; +#endif return err; }