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 28B7246CB6 for ; Fri, 7 Jul 2023 11:54:13 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9C8B568C7C0; Fri, 7 Jul 2023 14:54:10 +0300 (EEST) Received: from mail-oi1-f170.google.com (mail-oi1-f170.google.com [209.85.167.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8D10168C75F for ; Fri, 7 Jul 2023 14:54:04 +0300 (EEST) Received: by mail-oi1-f170.google.com with SMTP id 5614622812f47-3a1ebb79579so1460568b6e.3 for ; Fri, 07 Jul 2023 04:54:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688730842; x=1691322842; 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=f1tl8bltm989LsW0sKEGc3a4QUyRWdyYFMpwHM0RA3g=; b=roieiAIATmqpPJSKPcM5IU+fIhusIgBJBTUKgJNUmC0Fqx4F0E7iiqlL6M7PYOX7h+ gbiFk2ftt8J/FsbxK7D2c3TZnM6NfMNyr2u4a2k9at/8su/zJX2ZQUUIRHuueNUnVe6i 0PiOiWKCh6VtdSQgTDM3SoGRxEc1rl22rss8wf/Yp3UWUogjo+AfoYBWRVky2XoWozbG rWzE7KWkrtodnt8y82+0o/re5p33CjfB4T8hX6pxN8sL75Vwjbn8wwmpyGKh4BUh9aOf l1bNhuUMLlvng3D6mF4EGMrMJtAeG7Mz/N6uv2NayiW2GSsdZWzYz8Fln+6QSzzpbJNS ogXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688730842; x=1691322842; 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=f1tl8bltm989LsW0sKEGc3a4QUyRWdyYFMpwHM0RA3g=; b=TGZifrR+BePMpP2UgVbhMD5E01Fk+cWRaLIkFpgeXfdasVxIRTxM2+cjG633+U7GqT S7OTH6avhy6m92k2Qr8nKFfnFjWiJU1EQKwRREjHXR2dsm3YnDGffo3D02Ozwc8rqPsF umcb0cnssghrocmO4rvilCjYbI3mswehIJDKYgL3OIAf8MbceBAHH1CS6tr9WDNFJZHF TuORJMrTJWtH0vty9lZRDQs+GKGdhjb5bs4iGA0F1Oqxy90QoxgCzKD+Gz2M1ZxOXcbi ooQhE6G1jytcGrMjGOgYuDKtOSLlwfvMEnsAnNBmjTJ83UoTyw67UfR+E8GsDL7W3gSj xIkw== X-Gm-Message-State: ABy/qLZlmLNwTjVU4EvVzZD4AOMEfqKN8P33lPf+BdTrABILqlBC0srU GAe2K3xXR1aZ78nHDBz+pJbYT8+5Ubo= X-Google-Smtp-Source: APBJJlFMc8bhZ1XmHkFj6UkJ2NKuM7bO9nQJ9PmN5/+befdw2nmyVKPSzKtO5LfVMV5vpVH7RwgT2g== X-Received: by 2002:a05:6808:1b29:b0:3a1:c93c:6d28 with SMTP id bx41-20020a0568081b2900b003a1c93c6d28mr5403915oib.23.1688730842439; Fri, 07 Jul 2023 04:54:02 -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 15-20020aca120f000000b003a38eba0bcdsm1578792ois.0.2023.07.07.04.54.01 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 07 Jul 2023 04:54:02 -0700 (PDT) Message-ID: <61f9e34f-2cae-d4d1-7164-1b8171c5d20d@gmail.com> Date: Fri, 7 Jul 2023 08:54:05 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 To: ffmpeg-devel@ffmpeg.org References: <20230707102136.16235-1-anton@khirnov.net> Content-Language: en-US From: James Almer In-Reply-To: <20230707102136.16235-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/7/2023 7:21 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 | 15 +++++++++++++++ > 2 files changed, 17 insertions(+) > > diff --git a/configure b/configure > index d6e78297fe..a4b09577cf 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 2980e565e0..9a3a5aa133 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,17 @@ 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); > + err = read < 0 ? AVERROR(errno) : > + read != len ? AVERROR_UNKNOWN : 0; The documentation states "By default, when reading from the random source, getrandom() blocks if no random bytes are available, and when reading from the urandom source, it blocks if the entropy pool has not yet been initialized.If the GRND_NONBLOCK flag is set, then getrandom() does not block in these cases, but instead immediately returns -1 with errno set to EAGAIN." Returning EAGAIN may end up clashing with our usage of said error value internally (Marton's patch will make use of this function in hls), so maybe prevent said value from propagating here. LGTM 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".