From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc2c.google.com (mail-oo1-xc2c.google.com [IPv6:2607:f8b0:4864:20::c2c]) by sourceware.org (Postfix) with ESMTPS id 34655385801B for ; Thu, 14 Jul 2022 11:08:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 34655385801B Received: by mail-oo1-xc2c.google.com with SMTP id r8-20020a4abf08000000b00425b1256454so269879oop.13 for ; Thu, 14 Jul 2022 04:08:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=6yaHtAx9W8F0lHDHt43dnKCL3ZY7PQ84D9NCGTv6tOI=; b=jaY8lv6/qXH7HWMiDM/Mh8/yyP6u/aHIHPLvg+QXVvoEQ38DHlcG96cVJJn5KjCwqZ wagvpsHnZGgy+xTr3HzPxzKobWlCe5jPhE44qXlVdOdQXeX2eTGtq0JYj6Bi+hx+v+jp AJ6gWDdDtHi4a7TDICDSbW/XoclgjQa+Oyx1HzMZ1bvrBpo/MqRqhcwblwtBVPpL3pFq xTDd5VX/24J2D+o7WBJRHF8ezHgSePlN/hAr1cgvfLQXJZYJHC95jNWr818JoMiH1Js/ jjO6rDIy0HbxgSMtSWddlJR+0oCo7br78UWEO6EOeQrrEhnO7tEP4LU+6ewb22re7pNa CKCQ== X-Gm-Message-State: AJIora9tdEPPMP3EivLNfy8iRcElodidn78e9KzwtexxqisWkA3YpTwB 7FTHpIAWx29YJD2Awo48g8pszw== X-Google-Smtp-Source: AGRyM1sqCny7GJk/b5I1MTWNxFPpXN6r+d0V4joD1/1+uQ0cOMtTHS7RU7WBJgYUeB531pmPn61bDA== X-Received: by 2002:a4a:a3cb:0:b0:435:485c:813e with SMTP id t11-20020a4aa3cb000000b00435485c813emr2820291ool.34.1657796897810; Thu, 14 Jul 2022 04:08:17 -0700 (PDT) Received: from ?IPV6:2804:431:c7ca:19c3:4427:c171:4fa9:c3d9? ([2804:431:c7ca:19c3:4427:c171:4fa9:c3d9]) by smtp.gmail.com with ESMTPSA id u20-20020a056870701400b0010c222f9faesm686967oae.10.2022.07.14.04.08.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Jul 2022 04:08:17 -0700 (PDT) Message-ID: <0208516c-6101-e6f1-f2b4-b2dce2bcedc4@linaro.org> Date: Thu, 14 Jul 2022 08:08:14 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.0.2 Subject: Re: [PATCH v9 9/9] manual: Add documentation for arc4random functions Content-Language: en-US To: Mark Harris Cc: libc-alpha@sourceware.org, Florian Weimer References: <20220713173657.516725-1-adhemerval.zanella@linaro.org> <20220713173657.516725-10-adhemerval.zanella@linaro.org> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Jul 2022 11:08:21 -0000 On 14/07/22 07:03, Mark Harris wrote: > Adhemerval Zanella via Libc-alpha wrote: >> diff --git a/manual/math.texi b/manual/math.texi >> index 477a18b6d1..ab96726e57 100644 >> --- a/manual/math.texi >> +++ b/manual/math.texi >> @@ -1447,6 +1447,7 @@ systems. >> * ISO Random:: @code{rand} and friends. >> * BSD Random:: @code{random} and friends. >> * SVID Random:: @code{drand48} and friends. >> +* High Quality Random:: @code{arc4random} and friends. >> @end menu >> >> @node ISO Random >> @@ -1985,6 +1986,50 @@ This function is a GNU extension and should not be used in portable >> programs. >> @end deftypefun >> >> +@node High Quality Random >> +@subsection High Quality Random Number Functions >> + >> +This section describes the random number functions provided as a GNU >> +extension, based on OpenBSD interfaces. >> + >> +@Theglibc{} uses kernel entropy obtained either through @code{getrandom} >> +or by reading @file{/dev/urandom} to seed and periodically re-seed the >> +internal state. A per-thread data pool is used, which allows fast output >> +generation. >> + >> +Although these functions provide higher random quality than ISO, BSD, and >> +SVID functions, these still use a Pseudo-Random generator and should not >> +be used in cryptographic contexts. >> + >> +The internal state is cleared and reseed with kernel entropy on @code{fork} > > s/reseed/reseeded/ Ack. > >> +and @code{_Fork}. It is not cleared for either direct @code{clone} syscall > > s/for either/on either a/ > >> +or when using @theglibc{} @code{syscall} function. >> + >> +The prototypes for these functions are in @file{stdlib.h}. >> +@pindex stdlib.h >> + >> +@deftypefun int32_t arc4random (void) > > s/int32_t/uint32_t/ Ack. > >> +@standards{BSD, stdlib.h} >> +@safety{@mtsafe{}@asunsafe{@asucorrupt{}}@acsafe{}} >> +This function returns a single 32-bit value in the range of @code{0} to >> +@code{2^32−1} (inclusive), which is twice the range of @code{rand} and >> +@code{random}. >> +@end deftypefun >> + >> +@deftypefun void arc4random (void *@var{buffer}, size_t @var{length}) > > s/arc4random/arc4random_buf/ Ack. > >> +@standards{BSD, stdlib.h} >> +@safety{@mtsafe{}@asunsafe{@asucorrupt{}}@acsafe{}} >> +This function fills the region @var{buffer} of @var{length} with random data. > > s/of @var{length}/of length @var{length} bytes/ Ack. > > >> +@end deftypefun >> + >> +@deftypefun uint32_t arc4random_uniform (uint32_t @var{upper_bound}) >> +@standards{BSD, stdlib.h} >> +@safety{@mtsafe{}@asunsafe{@asucorrupt{}}@acsafe{}} >> +This function returns a single 32-bit value, uniformly distributed but >> +less than the @var{upper_bound}. It avoids the @w{modulo bias} when the >> +upper bound is not a power of two. >> +@end deftypefun >> + >> @node FP Function Optimizations >> @section Is Fast Code or Small Code preferred? >> @cindex Optimization >> -- >> 2.34.1 >>