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 293EA46B66 for ; Mon, 3 Jul 2023 20:15:41 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6A72B68C5A9; Mon, 3 Jul 2023 23:15:39 +0300 (EEST) Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E97D968C57F for ; Mon, 3 Jul 2023 23:15:32 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id AB7CB2404EC for ; Mon, 3 Jul 2023 22:15:32 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id TaDNfsxLbL_j for ; Mon, 3 Jul 2023 22:15:32 +0200 (CEST) Received: from lain.khirnov.net (lain.khirnov.net [IPv6:2001:67c:1138:4306::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "lain.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 0DF972404EA for ; Mon, 3 Jul 2023 22:15:32 +0200 (CEST) Received: by lain.khirnov.net (Postfix, from userid 1000) id E48261601B2; Mon, 3 Jul 2023 22:15:31 +0200 (CEST) From: Anton Khirnov To: FFmpeg development discussions and patches In-Reply-To: <54fe8899-d250-8d62-1157-621deb546040@gmail.com> References: <20230702193010.11654-1-cus@passwd.hu> <54fe8899-d250-8d62-1157-621deb546040@gmail.com> Mail-Followup-To: FFmpeg development discussions and patches Date: Mon, 03 Jul 2023 22:15:31 +0200 Message-ID: <168841533190.542.8113031316523716543@lain.khirnov.net> User-Agent: alot/0.8.1 MIME-Version: 1.0 Subject: Re: [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 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: Quoting James Almer (2023-07-03 21:33:04) > On 7/2/2023 4:30 PM, Marton Balint wrote: > > 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()); > > Maybe instead use a PRNG, like the following: > > AVLFG c; > av_lfg_init(&c, av_get_random_seed()); > for (int i = 0; i < len; i += 4) > AV_WB32(buf + i, av_lfg_get(&c)); We really REALLY should not be taking any shortcuts when generating keys. Ideally we shouldn't be generating them ourselves in the first place, as we are not a crypto library. This patch seems like a step backward to me. -- 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".