diff mbox

[FFmpeg-devel,v2] avformat/hlsenc: reimplement randomize of hls use av_get_random_seed

Message ID 20180601025656.76187-1-lq@chinaffmpeg.org
State Superseded
Headers show

Commit Message

Liu Steven June 1, 2018, 2:56 a.m. UTC
---
 configure            |  1 -
 libavformat/hlsenc.c | 31 ++++++++++---------------------
 2 files changed, 10 insertions(+), 22 deletions(-)

Comments

Michael Niedermayer June 1, 2018, 11:49 p.m. UTC | #1
On Fri, Jun 01, 2018 at 10:56:56AM +0800, Steven Liu wrote:
> ---
>  configure            |  1 -
>  libavformat/hlsenc.c | 31 ++++++++++---------------------
>  2 files changed, 10 insertions(+), 22 deletions(-)
> 
> diff --git a/configure b/configure
> index 22eeca22a5..a3d0f5837a 100755
> --- a/configure
> +++ b/configure
> @@ -3127,7 +3127,6 @@ fifo_muxer_deps="threads"
>  flac_demuxer_select="flac_parser"
>  hds_muxer_select="flv_muxer"
>  hls_muxer_select="mpegts_muxer"
> -hls_muxer_suggest="gcrypt openssl"
>  image2_alias_pix_demuxer_select="image2_demuxer"
>  image2_brender_pix_demuxer_select="image2_demuxer"
>  ipod_muxer_select="mov_muxer"
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index 2268f898b0..3012b2a727 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -27,12 +27,6 @@
>  #include <unistd.h>
>  #endif
>  
> -#if CONFIG_GCRYPT
> -#include <gcrypt.h>
> -#elif CONFIG_OPENSSL
> -#include <openssl/rand.h>
> -#endif
> -
>  #include "libavutil/avassert.h"
>  #include "libavutil/mathematics.h"
>  #include "libavutil/parseutils.h"
> @@ -569,18 +563,16 @@ fail:
>      return ret;
>  }
>  
> -static int randomize(uint8_t *buf, int len)
> +
> +static void randomize(uint8_t *buf, int len)
>  {
> -#if CONFIG_GCRYPT
> -    gcry_randomize(buf, len, GCRY_VERY_STRONG_RANDOM);
> -    return 0;
> -#elif CONFIG_OPENSSL
> -    if (RAND_bytes(buf, len))
> -        return 0;
> -#else
> -    return AVERROR(ENOSYS);
> -#endif
> -    return AVERROR(EINVAL);
> +    uint32_t tmp_number[4];
> +    int i = 0;
> +
> +    for (i = 0; i < 4; i++)
> +        tmp_number[i] = av_get_random_seed();
> +
> +    memcpy(buf, tmp_number, len);

There should be some check or assert of something on len

thx


[...]
diff mbox

Patch

diff --git a/configure b/configure
index 22eeca22a5..a3d0f5837a 100755
--- a/configure
+++ b/configure
@@ -3127,7 +3127,6 @@  fifo_muxer_deps="threads"
 flac_demuxer_select="flac_parser"
 hds_muxer_select="flv_muxer"
 hls_muxer_select="mpegts_muxer"
-hls_muxer_suggest="gcrypt openssl"
 image2_alias_pix_demuxer_select="image2_demuxer"
 image2_brender_pix_demuxer_select="image2_demuxer"
 ipod_muxer_select="mov_muxer"
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 2268f898b0..3012b2a727 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -27,12 +27,6 @@ 
 #include <unistd.h>
 #endif
 
-#if CONFIG_GCRYPT
-#include <gcrypt.h>
-#elif CONFIG_OPENSSL
-#include <openssl/rand.h>
-#endif
-
 #include "libavutil/avassert.h"
 #include "libavutil/mathematics.h"
 #include "libavutil/parseutils.h"
@@ -569,18 +563,16 @@  fail:
     return ret;
 }
 
-static int randomize(uint8_t *buf, int len)
+
+static void randomize(uint8_t *buf, int len)
 {
-#if CONFIG_GCRYPT
-    gcry_randomize(buf, len, GCRY_VERY_STRONG_RANDOM);
-    return 0;
-#elif CONFIG_OPENSSL
-    if (RAND_bytes(buf, len))
-        return 0;
-#else
-    return AVERROR(ENOSYS);
-#endif
-    return AVERROR(EINVAL);
+    uint32_t tmp_number[4];
+    int i = 0;
+
+    for (i = 0; i < 4; i++)
+        tmp_number[i] = av_get_random_seed();
+
+    memcpy(buf, tmp_number, len);
 }
 
 static int do_encrypt(AVFormatContext *s, VariantStream *vs)
@@ -633,10 +625,7 @@  static int do_encrypt(AVFormatContext *s, VariantStream *vs)
 
     if (!*hls->key_string) {
         if (!hls->key) {
-            if ((ret = randomize(key, sizeof(key))) < 0) {
-                av_log(s, AV_LOG_ERROR, "Cannot generate a strong random key\n");
-                return ret;
-            }
+            randomize(key, sizeof(key));
         } else {
             memcpy(key, hls->key, sizeof(key));
         }