Message ID | 20180531044128.1289-1-lq@chinaffmpeg.org |
---|---|
State | Superseded |
Headers | show |
On 5/31/2018 1:41 AM, Steven Liu wrote: > for support use the mbedtls > > Signed-off-by: Steven Liu <lq@chinaffmpeg.org> > --- > libavformat/hlsenc.c | 22 +++++++--------------- > 1 file changed, 7 insertions(+), 15 deletions(-) > > diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c > index 9c06551ea6..17b464f540 100644 > --- a/libavformat/hlsenc.c > +++ b/libavformat/hlsenc.c > @@ -569,18 +569,13 @@ 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); You should also remove the header includes and the relevant configure dependencies for openssl and gcrypt if you're removing these chunks. > + uint32_t tmp_number[2]; > + tmp_number[0] = av_get_random_seed(); > + tmp_number[1] = av_get_random_seed(); > + memcpy(buf, iv, len); /home/jamrial/ffmpeg/libavformat/hlsenc.c:577:17: error: 'iv' undeclared (first use in this function); did you mean 'div'? memcpy(buf, iv, len); ^~ div /home/jamrial/ffmpeg/libavformat/hlsenc.c:577:17: note: each undeclared identifier is reported only once for each function it appears in /home/jamrial/ffmpeg/libavformat/hlsenc.c:574:14: warning: variable 'tmp_number' set but not used [-Wunused-but-set-variable] uint32_t tmp_number[2]; ^~~~~~~~~~ make: *** [/home/jamrial/ffmpeg/ffbuild/common.mak:60: libavformat/hlsenc.o] Error 1 > } > > static int do_encrypt(AVFormatContext *s, VariantStream *vs) > @@ -633,10 +628,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)); sizeof(key) is 16, yet you're filling only eight bytes of random data using av_get_random_seed(). > } else { > memcpy(key, hls->key, sizeof(key)); > } >
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 9c06551ea6..17b464f540 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -569,18 +569,13 @@ 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[2]; + tmp_number[0] = av_get_random_seed(); + tmp_number[1] = av_get_random_seed(); + memcpy(buf, iv, len); } static int do_encrypt(AVFormatContext *s, VariantStream *vs) @@ -633,10 +628,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)); }
for support use the mbedtls Signed-off-by: Steven Liu <lq@chinaffmpeg.org> --- libavformat/hlsenc.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)