summaryrefslogtreecommitdiff
path: root/libavutil/random_seed.c
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2023-07-04 19:49:23 -0300
committerJames Almer <jamrial@gmail.com>2023-07-06 15:30:27 -0300
commitb7f4d5fa7e04498fddd60d298bc4a95241a581da (patch)
tree7873dfb90141b64cb64489cfc24f22076dec65c9 /libavutil/random_seed.c
parent68e9d2835fa3e5c0f73a32a8455fdcd9a5a01e77 (diff)
avutil/random_seed: add support for gcrypt and OpenSSL as source of randomness
Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavutil/random_seed.c')
-rw-r--r--libavutil/random_seed.c16
1 files changed, 16 insertions, 0 deletions
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 <windows.h>
#include <bcrypt.h>
#endif
+#if CONFIG_GCRYPT
+#include <gcrypt.h>
+#elif CONFIG_OPENSSL
+#include <openssl/rand.h>
+#endif
#include <fcntl.h>
#include <math.h>
#include <time.h>
@@ -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;
}