From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 0A65946ABA for ; Sun, 2 Jul 2023 19:30:26 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8C64D68C3ED; Sun, 2 Jul 2023 22:30:23 +0300 (EEST) Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DF09E68C3A3 for ; Sun, 2 Jul 2023 22:30:16 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 430A3E8BAA; Sun, 2 Jul 2023 21:27:32 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 86-5UnmbppHD; Sun, 2 Jul 2023 21:27:30 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 6C6F4E73A4; Sun, 2 Jul 2023 21:27:30 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sun, 2 Jul 2023 21:30:09 +0200 Message-Id: <20230702193010.11654-1-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avformat/hlsenc: fall back to av_get_random_seed() when generating AES128 key X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: It should be OK to use av_get_random_seed() to generate the key instead of using openSSL/Gcrypt functions. This removes the hard dependancy of those libs for key generation functionality. Fixes ticket #10441. Signed-off-by: Marton Balint --- libavformat/hlsenc.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 1e0848ce3d..0b22c71186 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -40,6 +40,7 @@ #include "libavutil/intreadwrite.h" #include "libavutil/opt.h" #include "libavutil/log.h" +#include "libavutil/random_seed.h" #include "libavutil/time.h" #include "libavutil/time_internal.h" @@ -710,18 +711,18 @@ 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; + return; #elif CONFIG_OPENSSL if (RAND_bytes(buf, len)) - return 0; -#else - return AVERROR(ENOSYS); + return; #endif - return AVERROR(EINVAL); + av_assert0(len % 4 == 0); + for (int i = 0; i < len; i += 4) + AV_WB32(buf + i, av_get_random_seed()); } static int do_encrypt(AVFormatContext *s, VariantStream *vs) @@ -775,10 +776,7 @@ static int do_encrypt(AVFormatContext *s, VariantStream *vs) if (!*hls->key_string) { AVDictionary *options = NULL; 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)); } -- 2.35.3 _______________________________________________ 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".