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 EF18746D62 for ; Mon, 10 Jul 2023 12:15:18 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1EF1B68C4F4; Mon, 10 Jul 2023 15:15:16 +0300 (EEST) Received: from mail-oo1-f50.google.com (mail-oo1-f50.google.com [209.85.161.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 502C368C3BB for ; Mon, 10 Jul 2023 15:15:09 +0300 (EEST) Received: by mail-oo1-f50.google.com with SMTP id 006d021491bc7-5634db21a78so3143701eaf.0 for ; Mon, 10 Jul 2023 05:15:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688991307; x=1691583307; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=o/RsD/g/WGC71CWe2/V4c66CCoUmoB2C+U/Ob6uQ784=; b=OuV0HgJ/hKAWg0Tg2jMhUD5inSlKD9DnFJhkZqt7PMv5FoftBfe/q3eFt+PJLvd0HB wevWz6X/xsQ8pBKcYpWaj77IADft2e/HGQkSJoVlI7a84B6CzOPs/B9CMpgMb+rug0NF xU2NvMkSvGNT/rWZhz7X8kWTiexSE+BiboBX0vzFWGe2CwP2NX//8+NtrVujSdf34IkK Qlup7f2T0u48DHQMX7A0/EcABBV6BxV0eOv09lM6ld3mH+vbAoHe5bUlJMZmnE6Ue/yi UAg8Cn5BMPWmDE7hd/tjj1vMkhc8wz1hSpCP95ePmHd7Fr2hgYxsJ7T9B3Rva/oG4VID 1KvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688991307; x=1691583307; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=o/RsD/g/WGC71CWe2/V4c66CCoUmoB2C+U/Ob6uQ784=; b=LXwBdnmV+taE83z2aRCNgZWCEVlW4VwzY+tux4PXf3aysPDR1N0YIptmxBn+KsPWB5 a1RkLc8rHTpjNE/1tDaQA6eQwi8juqb8A7Yx/SdPIhICcxdrd+aczjh902OLmnCtWjDx hUmWsSN+vbBfVPZ1jsvGBscWRqbct9M0GaC1iFFhETOidK4nUPRbmycYa4zK35SpFkea ak2f/ra6MpvQKWxLYe5Fbc5fGkeOvTc9+6390X+8bXjhUicYCmgDad2Mzji+KnVF5v4y AeJj2LM/5+qiBayAYwuMV95UvC6YtU0Ik7bxsdJDk4Q2bnHBhXA4FGmSahepkpaaiRje dAEQ== X-Gm-Message-State: ABy/qLaGZ5XjZUAtc6DCTtCrO3L1L8tdZubTrY5AKQuyPe2JC1YJB6bF JSs5enVy2v4hOoGL0O3OF9NoMlrgVCo= X-Google-Smtp-Source: APBJJlGwLSM+QamLglsGh6BdpCm5NMX5YL2eY+g0im3k7bzEhQdp1R4Rrts3qYrSSiopHMPfddzFzA== X-Received: by 2002:a4a:9741:0:b0:565:a8a8:6601 with SMTP id v1-20020a4a9741000000b00565a8a86601mr8429458ooi.8.1688991307105; Mon, 10 Jul 2023 05:15:07 -0700 (PDT) Received: from [192.168.0.12] (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id b33-20020a4a98e4000000b00565ccb41ba5sm4177332ooj.3.2023.07.10.05.15.06 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 Jul 2023 05:15:06 -0700 (PDT) Message-ID: <16b0c43b-7b5a-d7c2-8f70-d635c8b7716e@gmail.com> Date: Mon, 10 Jul 2023 09:15:10 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 To: ffmpeg-devel@ffmpeg.org References: <61f9e34f-2cae-d4d1-7164-1b8171c5d20d@gmail.com> <20230709100653.17091-1-anton@khirnov.net> Content-Language: en-US From: James Almer In-Reply-To: <20230709100653.17091-1-anton@khirnov.net> Subject: Re: [FFmpeg-devel] [PATCH] lavu/random_seed: use getrandom() when available 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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On 7/9/2023 7:06 AM, Anton Khirnov wrote: > It is a better interface for /dev/u?random on Linux, which avoids the > issues associated with opening files. > --- > configure | 2 ++ > libavutil/random_seed.c | 16 ++++++++++++++++ > 2 files changed, 18 insertions(+) > > diff --git a/configure b/configure > index 0ab0761011..f8c809e491 100755 > --- a/configure > +++ b/configure > @@ -2310,6 +2310,7 @@ SYSTEM_FUNCS=" > getauxval > getenv > gethrtime > + getrandom > getopt > GetModuleHandle > GetProcessAffinityMask > @@ -6387,6 +6388,7 @@ check_func fcntl > check_func fork > check_func gethrtime > check_func getopt > +check_func_headers "sys/random.h" getrandom > check_func getrusage > check_func gettimeofday > check_func isatty > diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c > index f167b172f2..92bf9ef8e1 100644 > --- a/libavutil/random_seed.c > +++ b/libavutil/random_seed.c > @@ -35,6 +35,9 @@ > #elif CONFIG_OPENSSL > #include > #endif > +#if HAVE_GETRANDOM > +#include > +#endif > #include > #include > #include > @@ -51,6 +54,7 @@ > #define TEST 0 > #endif > > +#if !HAVE_GETRANDOM > static int read_random(uint8_t *dst, size_t len, const char *file) > { > #if HAVE_UNISTD_H > @@ -70,6 +74,7 @@ static int read_random(uint8_t *dst, size_t len, const char *file) > return AVERROR(ENOSYS); > #endif > } > +#endif > > static uint32_t get_generic_seed(void) > { > @@ -147,7 +152,18 @@ int av_random_bytes(uint8_t* buf, size_t len) > return 0; > #endif > > + // getrandom() is a better interface for /dev/(u)random on Linux, > + // so it makes no sense to try both > +#if HAVE_GETRANDOM > + { > + ssize_t read = getrandom(buf, len, GRND_NONBLOCK); > + if (read < 0) > + return errno == EAGAIN ? AVERROR_EXTERNAL : AVERROR(errno); > + return read != len ? AVERROR_UNKNOWN : 0; This is returning no matter what the result, when it should only return on success (the !err check below), or fallback to the other implementations otherwise. > + } > +#else > err = read_random(buf, len, "/dev/urandom"); > +#endif > if (!err) > return err; > _______________________________________________ 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".