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>
This commit is contained in:
James Almer
2023-07-04 19:49:23 -03:00
parent 68e9d2835f
commit b7f4d5fa7e
2 changed files with 17 additions and 1 deletions

View File

@@ -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;
}