* [FFmpeg-devel] [PATCH v3 2/3] avutil/random_seed: add av_random_bytes()
2023-07-04 23:26 [FFmpeg-devel] [PATCH v3 1/3] avutil/random_seed: use fread() in read_random() James Almer
@ 2023-07-04 23:26 ` James Almer
2023-07-05 10:24 ` Anton Khirnov
2023-07-04 23:26 ` [FFmpeg-devel] [PATCH v3 3/3] avutil/random_seed: add support for gcrypt and OpenSSL as source of randomness James Almer
` (2 subsequent siblings)
3 siblings, 1 reply; 16+ messages in thread
From: James Almer @ 2023-07-04 23:26 UTC (permalink / raw)
To: ffmpeg-devel
Uses the existing code for av_get_random_seed() to return a buffer with
cryptographically secure random data, or an error if none could be generated.
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavutil/random_seed.c | 33 ++++++++++++++++++++++-----------
libavutil/random_seed.h | 12 ++++++++++++
2 files changed, 34 insertions(+), 11 deletions(-)
diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c
index a51149235b..f5c291263e 100644
--- a/libavutil/random_seed.c
+++ b/libavutil/random_seed.c
@@ -46,7 +46,7 @@
#define TEST 0
#endif
-static int read_random(uint32_t *dst, const char *file)
+static int read_random(uint8_t *dst, size_t len, const char *file)
{
#if HAVE_UNISTD_H
FILE *fp = avpriv_fopen_utf8(file, "r");
@@ -54,10 +54,10 @@ static int read_random(uint32_t *dst, const char *file)
if (!fp)
return AVERROR_UNKNOWN;
- err = fread(dst, 1, sizeof(*dst), fp);
+ err = fread(dst, 1, len, fp);
fclose(fp);
- if (err != sizeof(*dst))
+ if (err != len)
return AVERROR_UNKNOWN;
return 0;
@@ -121,27 +121,38 @@ static uint32_t get_generic_seed(void)
return AV_RB32(digest) + AV_RB32(digest + 16);
}
-uint32_t av_get_random_seed(void)
+int av_random_bytes(uint8_t* buf, size_t len)
{
- uint32_t seed;
+ int err;
#if HAVE_BCRYPT
BCRYPT_ALG_HANDLE algo_handle;
NTSTATUS ret = BCryptOpenAlgorithmProvider(&algo_handle, BCRYPT_RNG_ALGORITHM,
MS_PRIMITIVE_PROVIDER, 0);
if (BCRYPT_SUCCESS(ret)) {
- NTSTATUS ret = BCryptGenRandom(algo_handle, (UCHAR*)&seed, sizeof(seed), 0);
+ NTSTATUS ret = BCryptGenRandom(algo_handle, (PUCHAR)buf, len, 0);
BCryptCloseAlgorithmProvider(algo_handle, 0);
if (BCRYPT_SUCCESS(ret))
- return seed;
+ return 0;
}
#endif
#if HAVE_ARC4RANDOM
- return arc4random();
+ arc4random_buf(buf, len);
+ return 0;
#endif
- if (!read_random(&seed, "/dev/urandom"))
- return seed;
- return get_generic_seed();
+ err = read_random(buf, len, "/dev/urandom");
+
+ return err;
+}
+
+uint32_t av_get_random_seed(void)
+{
+ uint32_t seed;
+
+ if (av_random_bytes((uint8_t *)&seed, sizeof(seed)) < 0)
+ return get_generic_seed();
+
+ return seed;
}
diff --git a/libavutil/random_seed.h b/libavutil/random_seed.h
index 0462a048e0..8df37da8f8 100644
--- a/libavutil/random_seed.h
+++ b/libavutil/random_seed.h
@@ -36,6 +36,18 @@
*/
uint32_t av_get_random_seed(void);
+/**
+ * Generate cryptographically secure random data, i.e. suitable for use as
+ * encryption keys and similar.
+ *
+ * @param buf buffer into which the random data will be written
+ * @param len size of buf in bytes
+ *
+ * @retval 0 success, and len bytes of random data was written into buf, or
+ * a negative AVERROR code if random data could not be generated.
+ */
+int av_random_bytes(uint8_t *buf, size_t len);
+
/**
* @}
*/
--
2.41.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3 2/3] avutil/random_seed: add av_random_bytes()
2023-07-04 23:26 ` [FFmpeg-devel] [PATCH v3 2/3] avutil/random_seed: add av_random_bytes() James Almer
@ 2023-07-05 10:24 ` Anton Khirnov
2023-07-05 12:12 ` [FFmpeg-devel] [PATCH v4 2/4] " James Almer
0 siblings, 1 reply; 16+ messages in thread
From: Anton Khirnov @ 2023-07-05 10:24 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting James Almer (2023-07-05 01:26:13)
> diff --git a/libavutil/random_seed.h b/libavutil/random_seed.h
> index 0462a048e0..8df37da8f8 100644
> --- a/libavutil/random_seed.h
> +++ b/libavutil/random_seed.h
> @@ -36,6 +36,18 @@
> */
> uint32_t av_get_random_seed(void);
>
> +/**
> + * Generate cryptographically secure random data, i.e. suitable for use as
> + * encryption keys and similar.
> + *
> + * @param buf buffer into which the random data will be written
> + * @param len size of buf in bytes
> + *
> + * @retval 0 success, and len bytes of random data was written into buf, or
> + * a negative AVERROR code if random data could not be generated.
@retval declares behavior for a specific return value out of several, so
there should be a separate @retval for each of those
See e.g. doxy for avcodec_send_packet() [1] for an example of what it
looks like.
[1] http://ffmpeg.org/doxygen/trunk/group__lavc__decoding.html#ga58bc4bf1e0ac59e27362597e467efff3
--
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 16+ messages in thread
* [FFmpeg-devel] [PATCH v4 2/4] avutil/random_seed: add av_random_bytes()
2023-07-05 10:24 ` Anton Khirnov
@ 2023-07-05 12:12 ` James Almer
2023-07-05 12:46 ` Anton Khirnov
0 siblings, 1 reply; 16+ messages in thread
From: James Almer @ 2023-07-05 12:12 UTC (permalink / raw)
To: ffmpeg-devel
Uses the existing code for av_get_random_seed() to return a buffer with
cryptographically secure random data, or an error if none could be generated.
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavutil/random_seed.c | 33 ++++++++++++++++++++++-----------
libavutil/random_seed.h | 13 +++++++++++++
2 files changed, 35 insertions(+), 11 deletions(-)
diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c
index a51149235b..f5c291263e 100644
--- a/libavutil/random_seed.c
+++ b/libavutil/random_seed.c
@@ -46,7 +46,7 @@
#define TEST 0
#endif
-static int read_random(uint32_t *dst, const char *file)
+static int read_random(uint8_t *dst, size_t len, const char *file)
{
#if HAVE_UNISTD_H
FILE *fp = avpriv_fopen_utf8(file, "r");
@@ -54,10 +54,10 @@ static int read_random(uint32_t *dst, const char *file)
if (!fp)
return AVERROR_UNKNOWN;
- err = fread(dst, 1, sizeof(*dst), fp);
+ err = fread(dst, 1, len, fp);
fclose(fp);
- if (err != sizeof(*dst))
+ if (err != len)
return AVERROR_UNKNOWN;
return 0;
@@ -121,27 +121,38 @@ static uint32_t get_generic_seed(void)
return AV_RB32(digest) + AV_RB32(digest + 16);
}
-uint32_t av_get_random_seed(void)
+int av_random_bytes(uint8_t* buf, size_t len)
{
- uint32_t seed;
+ int err;
#if HAVE_BCRYPT
BCRYPT_ALG_HANDLE algo_handle;
NTSTATUS ret = BCryptOpenAlgorithmProvider(&algo_handle, BCRYPT_RNG_ALGORITHM,
MS_PRIMITIVE_PROVIDER, 0);
if (BCRYPT_SUCCESS(ret)) {
- NTSTATUS ret = BCryptGenRandom(algo_handle, (UCHAR*)&seed, sizeof(seed), 0);
+ NTSTATUS ret = BCryptGenRandom(algo_handle, (PUCHAR)buf, len, 0);
BCryptCloseAlgorithmProvider(algo_handle, 0);
if (BCRYPT_SUCCESS(ret))
- return seed;
+ return 0;
}
#endif
#if HAVE_ARC4RANDOM
- return arc4random();
+ arc4random_buf(buf, len);
+ return 0;
#endif
- if (!read_random(&seed, "/dev/urandom"))
- return seed;
- return get_generic_seed();
+ err = read_random(buf, len, "/dev/urandom");
+
+ return err;
+}
+
+uint32_t av_get_random_seed(void)
+{
+ uint32_t seed;
+
+ if (av_random_bytes((uint8_t *)&seed, sizeof(seed)) < 0)
+ return get_generic_seed();
+
+ return seed;
}
diff --git a/libavutil/random_seed.h b/libavutil/random_seed.h
index 0462a048e0..e67e6e38c4 100644
--- a/libavutil/random_seed.h
+++ b/libavutil/random_seed.h
@@ -36,6 +36,19 @@
*/
uint32_t av_get_random_seed(void);
+/**
+ * Generate cryptographically secure random data, i.e. suitable for use as
+ * encryption keys and similar.
+ *
+ * @param buf buffer into which the random data will be written
+ * @param len size of buf in bytes
+ *
+ * @retval 0 success, len bytes of random data was written
+ * into buf
+ * @retval "a negative AVERROR code" random data could not be generated
+ */
+int av_random_bytes(uint8_t *buf, size_t len);
+
/**
* @}
*/
--
2.41.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [FFmpeg-devel] [PATCH v4 2/4] avutil/random_seed: add av_random_bytes()
2023-07-05 12:12 ` [FFmpeg-devel] [PATCH v4 2/4] " James Almer
@ 2023-07-05 12:46 ` Anton Khirnov
2023-07-05 13:24 ` James Almer
0 siblings, 1 reply; 16+ messages in thread
From: Anton Khirnov @ 2023-07-05 12:46 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting James Almer (2023-07-05 14:12:47)
> Uses the existing code for av_get_random_seed() to return a buffer with
> cryptographically secure random data, or an error if none could be generated.
>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> libavutil/random_seed.c | 33 ++++++++++++++++++++++-----------
> libavutil/random_seed.h | 13 +++++++++++++
> 2 files changed, 35 insertions(+), 11 deletions(-)
LGTM
--
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [FFmpeg-devel] [PATCH v4 2/4] avutil/random_seed: add av_random_bytes()
2023-07-05 12:46 ` Anton Khirnov
@ 2023-07-05 13:24 ` James Almer
0 siblings, 0 replies; 16+ messages in thread
From: James Almer @ 2023-07-05 13:24 UTC (permalink / raw)
To: ffmpeg-devel
On 7/5/2023 9:46 AM, Anton Khirnov wrote:
> Quoting James Almer (2023-07-05 14:12:47)
>> Uses the existing code for av_get_random_seed() to return a buffer with
>> cryptographically secure random data, or an error if none could be generated.
>>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>> libavutil/random_seed.c | 33 ++++++++++++++++++++++-----------
>> libavutil/random_seed.h | 13 +++++++++++++
>> 2 files changed, 35 insertions(+), 11 deletions(-)
>
> LGTM
Applied, thanks.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 16+ messages in thread
* [FFmpeg-devel] [PATCH v3 3/3] avutil/random_seed: add support for gcrypt and OpenSSL as source of randomness
2023-07-04 23:26 [FFmpeg-devel] [PATCH v3 1/3] avutil/random_seed: use fread() in read_random() James Almer
2023-07-04 23:26 ` [FFmpeg-devel] [PATCH v3 2/3] avutil/random_seed: add av_random_bytes() James Almer
@ 2023-07-04 23:26 ` James Almer
2023-07-05 12:56 ` Anton Khirnov
2023-07-05 12:43 ` [FFmpeg-devel] [PATCH v3 1/3] avutil/random_seed: use fread() in read_random() Anton Khirnov
2023-07-05 15:34 ` Rémi Denis-Courmont
3 siblings, 1 reply; 16+ messages in thread
From: James Almer @ 2023-07-04 23:26 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
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 <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;
}
--
2.41.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3 3/3] avutil/random_seed: add support for gcrypt and OpenSSL as source of randomness
2023-07-04 23:26 ` [FFmpeg-devel] [PATCH v3 3/3] avutil/random_seed: add support for gcrypt and OpenSSL as source of randomness James Almer
@ 2023-07-05 12:56 ` Anton Khirnov
2023-07-05 13:03 ` James Almer
0 siblings, 1 reply; 16+ messages in thread
From: Anton Khirnov @ 2023-07-05 12:56 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting James Almer (2023-07-05 01:26:14)
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> 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"
What will this do exactly?
--
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3 3/3] avutil/random_seed: add support for gcrypt and OpenSSL as source of randomness
2023-07-05 12:56 ` Anton Khirnov
@ 2023-07-05 13:03 ` James Almer
2023-07-06 7:52 ` Anton Khirnov
0 siblings, 1 reply; 16+ messages in thread
From: James Almer @ 2023-07-05 13:03 UTC (permalink / raw)
To: ffmpeg-devel
On 7/5/2023 9:56 AM, Anton Khirnov wrote:
> Quoting James Almer (2023-07-05 01:26:14)
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>> 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"
>
> What will this do exactly?
It's a soft dependency. Only if OpenSSL or GCrypt are enabled they will
be added to avutil's library dependencies.
Notice the bcrypt entry, also used in random_seed, and all the hwcontext
backends.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3 3/3] avutil/random_seed: add support for gcrypt and OpenSSL as source of randomness
2023-07-05 13:03 ` James Almer
@ 2023-07-06 7:52 ` Anton Khirnov
2023-07-06 17:03 ` James Almer
0 siblings, 1 reply; 16+ messages in thread
From: Anton Khirnov @ 2023-07-06 7:52 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting James Almer (2023-07-05 15:03:07)
> On 7/5/2023 9:56 AM, Anton Khirnov wrote:
> > Quoting James Almer (2023-07-05 01:26:14)
> >> Signed-off-by: James Almer <jamrial@gmail.com>
> >> ---
> >> 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"
> >
> > What will this do exactly?
>
> It's a soft dependency. Only if OpenSSL or GCrypt are enabled they will
> be added to avutil's library dependencies.
> Notice the bcrypt entry, also used in random_seed, and all the hwcontext
> backends.
Ok then.
--
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3 3/3] avutil/random_seed: add support for gcrypt and OpenSSL as source of randomness
2023-07-06 7:52 ` Anton Khirnov
@ 2023-07-06 17:03 ` James Almer
2023-07-06 17:56 ` Marton Balint
0 siblings, 1 reply; 16+ messages in thread
From: James Almer @ 2023-07-06 17:03 UTC (permalink / raw)
To: ffmpeg-devel
On 7/6/2023 4:52 AM, Anton Khirnov wrote:
> Quoting James Almer (2023-07-05 15:03:07)
>> On 7/5/2023 9:56 AM, Anton Khirnov wrote:
>>> Quoting James Almer (2023-07-05 01:26:14)
>>>> Signed-off-by: James Almer <jamrial@gmail.com>
>>>> ---
>>>> 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"
>>>
>>> What will this do exactly?
>>
>> It's a soft dependency. Only if OpenSSL or GCrypt are enabled they will
>> be added to avutil's library dependencies.
>> Notice the bcrypt entry, also used in random_seed, and all the hwcontext
>> backends.
>
> Ok then.
Any opinion on the order of function calls? Should i leave /dev/urandom
as last resort after all (if any) external lib implementations failed,
considering what Remí mentioned?
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3 3/3] avutil/random_seed: add support for gcrypt and OpenSSL as source of randomness
2023-07-06 17:03 ` James Almer
@ 2023-07-06 17:56 ` Marton Balint
2023-07-06 18:36 ` James Almer
0 siblings, 1 reply; 16+ messages in thread
From: Marton Balint @ 2023-07-06 17:56 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Thu, 6 Jul 2023, James Almer wrote:
> On 7/6/2023 4:52 AM, Anton Khirnov wrote:
>> Quoting James Almer (2023-07-05 15:03:07)
>>> On 7/5/2023 9:56 AM, Anton Khirnov wrote:
>>>> Quoting James Almer (2023-07-05 01:26:14)
>>>>> Signed-off-by: James Almer <jamrial@gmail.com>
>>>>> ---
>>>>> 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"
>>>>
>>>> What will this do exactly?
>>>
>>> It's a soft dependency. Only if OpenSSL or GCrypt are enabled they will
>>> be added to avutil's library dependencies.
>>> Notice the bcrypt entry, also used in random_seed, and all the hwcontext
>>> backends.
>>
>> Ok then.
>
> Any opinion on the order of function calls? Should i leave /dev/urandom as
> last resort after all (if any) external lib implementations failed,
> considering what Remí mentioned?
I think it is fine as is. Buffering can be turned off with
setvbuf(f, NULL, _IONBF, 0); so that should not relevant.
Regards,
Marton
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3 3/3] avutil/random_seed: add support for gcrypt and OpenSSL as source of randomness
2023-07-06 17:56 ` Marton Balint
@ 2023-07-06 18:36 ` James Almer
0 siblings, 0 replies; 16+ messages in thread
From: James Almer @ 2023-07-06 18:36 UTC (permalink / raw)
To: ffmpeg-devel
On 7/6/2023 2:56 PM, Marton Balint wrote:
>
>
> On Thu, 6 Jul 2023, James Almer wrote:
>
>> On 7/6/2023 4:52 AM, Anton Khirnov wrote:
>>> Quoting James Almer (2023-07-05 15:03:07)
>>>> On 7/5/2023 9:56 AM, Anton Khirnov wrote:
>>>>> Quoting James Almer (2023-07-05 01:26:14)
>>>>>> Signed-off-by: James Almer <jamrial@gmail.com>
>>>>>> ---
>>>>>> 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"
>>>>>
>>>>> What will this do exactly?
>>>>
>>>> It's a soft dependency. Only if OpenSSL or GCrypt are enabled they
>>>> will
>>>> be added to avutil's library dependencies.
>>>> Notice the bcrypt entry, also used in random_seed, and all the
>>>> hwcontext
>>>> backends.
>>>
>>> Ok then.
>>
>> Any opinion on the order of function calls? Should i leave
>> /dev/urandom as last resort after all (if any) external lib
>> implementations failed, considering what Remí mentioned?
>
> I think it is fine as is. Buffering can be turned off with
> setvbuf(f, NULL, _IONBF, 0); so that should not relevant.
Ok, applied as is, then.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3 1/3] avutil/random_seed: use fread() in read_random()
2023-07-04 23:26 [FFmpeg-devel] [PATCH v3 1/3] avutil/random_seed: use fread() in read_random() James Almer
2023-07-04 23:26 ` [FFmpeg-devel] [PATCH v3 2/3] avutil/random_seed: add av_random_bytes() James Almer
2023-07-04 23:26 ` [FFmpeg-devel] [PATCH v3 3/3] avutil/random_seed: add support for gcrypt and OpenSSL as source of randomness James Almer
@ 2023-07-05 12:43 ` Anton Khirnov
2023-07-05 13:24 ` James Almer
2023-07-05 15:34 ` Rémi Denis-Courmont
3 siblings, 1 reply; 16+ messages in thread
From: Anton Khirnov @ 2023-07-05 12:43 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting James Almer (2023-07-05 01:26:12)
> This ensures the requested amount of bytes is read.
> Also remove /dev/random as it's no longer necessary.
>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> libavutil/random_seed.c | 23 ++++++++++++-----------
> 1 file changed, 12 insertions(+), 11 deletions(-)
LGTM
--
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3 1/3] avutil/random_seed: use fread() in read_random()
2023-07-04 23:26 [FFmpeg-devel] [PATCH v3 1/3] avutil/random_seed: use fread() in read_random() James Almer
` (2 preceding siblings ...)
2023-07-05 12:43 ` [FFmpeg-devel] [PATCH v3 1/3] avutil/random_seed: use fread() in read_random() Anton Khirnov
@ 2023-07-05 15:34 ` Rémi Denis-Courmont
3 siblings, 0 replies; 16+ messages in thread
From: Rémi Denis-Courmont @ 2023-07-05 15:34 UTC (permalink / raw)
To: ffmpeg-devel
Le keskiviikkona 5. heinäkuuta 2023, 2.26.12 EEST James Almer a écrit :
> This ensures the requested amount of bytes is read.
You're moving the problem though. Now, you may read more than necessary (and
block longer than necessary) due to stdio internal buffering, which you did not
disable.
> Also remove /dev/random as it's no longer necessary.
>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> libavutil/random_seed.c | 23 ++++++++++++-----------
> 1 file changed, 12 insertions(+), 11 deletions(-)
>
> diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c
> index 66dd504ef0..a51149235b 100644
> --- a/libavutil/random_seed.c
> +++ b/libavutil/random_seed.c
> @@ -49,17 +49,20 @@
> static int read_random(uint32_t *dst, const char *file)
> {
> #if HAVE_UNISTD_H
> - int fd = avpriv_open(file, O_RDONLY);
> - int err = -1;
> + FILE *fp = avpriv_fopen_utf8(file, "r");
> + size_t err;
>
> - if (fd == -1)
> - return -1;
> - err = read(fd, dst, sizeof(*dst));
> - close(fd);
> + if (!fp)
> + return AVERROR_UNKNOWN;
> + err = fread(dst, 1, sizeof(*dst), fp);
> + fclose(fp);
>
> - return err;
> + if (err != sizeof(*dst))
> + return AVERROR_UNKNOWN;
> +
> + return 0;
> #else
> - return -1;
> + return AVERROR(ENOSYS);
> #endif
> }
>
> @@ -138,9 +141,7 @@ uint32_t av_get_random_seed(void)
> return arc4random();
> #endif
>
> - if (read_random(&seed, "/dev/urandom") == sizeof(seed))
> - return seed;
> - if (read_random(&seed, "/dev/random") == sizeof(seed))
> + if (!read_random(&seed, "/dev/urandom"))
> return seed;
> return get_generic_seed();
> }
--
雷米‧德尼-库尔蒙
http://www.remlab.net/
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 16+ messages in thread