From patchwork Fri Jul 22 12:21:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 592466 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b811:0:0:0:0 with SMTP id fc17csp452497mab; Fri, 22 Jul 2022 05:24:54 -0700 (PDT) X-Google-Smtp-Source: AGRyM1saKzwGQKLRDPUGw9bUzLG50nm8AzFD6+fMW93A0klgda3QC+daHc7YTj+q81m8FWbYC6H0 X-Received: by 2002:a17:907:3e15:b0:72b:879a:eec7 with SMTP id hp21-20020a1709073e1500b0072b879aeec7mr298421ejc.136.1658492694334; Fri, 22 Jul 2022 05:24:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658492694; cv=none; d=google.com; s=arc-20160816; b=aqhnSmsyNSq0Y7pVNcH5uC6hKFG/fAbcJRlW1koLKkEdbu4nenJOrFSk4FSrfaQB9L V/BDZ97rkA2mKtQaFl7TA+BYMlZcXNCJPHDT6VrnELZnZOBuAQblebU7LJw/SGcR1lVm jYR01KgluUF3NeviDEC3gorADxljj0R1OD58cYG79MLxk5dn01lE1MgL4CdCbvYXDYTZ NWuxa5pwrPO3czV3z1hGHcHP/8bx6UB3+ZRVCq9Ra8yDXgIniAoBxMonQ7OfYjbcfs5/ 6FNkenl7gwi/Mt82sFCBkdjoM2/7qv126Y21JjgwPktT0wsteI+1lhXas72v2OrBpzdk CEBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=aMDRCzskLjpC+tZYW99AO+E/0W0Kj1wjhROzDkqDpAY=; b=DEF4ceDEU7Grby8HAlb6qfP6ITRGapsTkXO/KhELVlfHi/+j3RSW65tiirV+2UZnrq i7/pRVZRTwq4a9/SsZ2gEEGY0QY8dNYJKh+FFgy4mqogQiy3akWOkd0fXxHMCvLwhF38 JOsPJcvk3cTF4b838pzgS2UfXaEEgzS6WSvHrn+xJKQ7w8OPGWuXKILMt6CLaL+hNBJP nzcpXhq8xwjl0Y8bna5hMNvbv/LQjx0KkVu6Sb8DqxEjd03ebXogx8OqALBFw7bpgRa7 uGp+DeylYYwZ4M6xqKp1bS4gQnSJKxI9fngHMnLmI9h9q47NrVG6tdz88YaerDGjR5zk FVkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=qg4uxLxL; spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Return-Path: Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id fl11-20020a1709072a8b00b006feb890dc1asi4271387ejc.886.2022.07.22.05.24.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 05:24:54 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=qg4uxLxL; spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 311523833792 for ; Fri, 22 Jul 2022 12:24:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 311523833792 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1658492693; bh=aMDRCzskLjpC+tZYW99AO+E/0W0Kj1wjhROzDkqDpAY=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=qg4uxLxLUdZy0BnwAWbrGHSc0A8l69ypH2+ysi6SEqm8zGR21192PdN69trr+VJs9 ywFdu4bI7XxMVAvDvcgiZh806h149RGls1IsUi/BYv2786jypKQWxn1PAHhsaKjMI0 r4gi9cwKjUfgaojAbjjPvzrCx5VIH2JMx9Du7enc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id C331638346AF for ; Fri, 22 Jul 2022 12:22:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C331638346AF Received: by mail-ot1-x32c.google.com with SMTP id a14-20020a0568300b8e00b0061c4e3eb52aso3223251otv.3 for ; Fri, 22 Jul 2022 05:22:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aMDRCzskLjpC+tZYW99AO+E/0W0Kj1wjhROzDkqDpAY=; b=GKMpLPNduLHoxG9TolBOLsmXu6XK8YRMGAGpSTTLxCkt2h4CBZFzq/acjmFtrm93ym WvHQlv6oTsiYNvxHSJeseNqfViKQRIVB3SiQh6XTTV9UITdVW0SXYew+Tdp4hwFXQ+m3 jJzmlCbLwejbadcyRH8MrYQcCG6yI+bSQBgetK1KeDPqIdu+MDiYeMrVfnuAM2FbBbM4 Bgt5z/eqhTubFRv6l4mz4E53oBFclR3GWc1BzJDgA2n9A8HDfKIeU5i8V39YL6NpGXy0 L9Gt+w/KTxtxzy+e8c+N0U/Z9L1bOrBk3KE2R6ValZ+pqK22XxBpdg0SZ/ntfIzjLE88 /9Nw== X-Gm-Message-State: AJIora9DGv5Qav0ZDmYy6glCBsDmILXDHeu0A1mlWXE8NxJ1nI5SG+r4 xFqtAbpeS93Phn5oZ/3MFFn2TkMzkBebEQ== X-Received: by 2002:a05:6830:349a:b0:61c:bfb6:b01a with SMTP id c26-20020a056830349a00b0061cbfb6b01amr118502otu.294.1658492522845; Fri, 22 Jul 2022 05:22:02 -0700 (PDT) Received: from mandiga.. ([2804:431:c7cb:8ded:a055:4527:6234:319b]) by smtp.gmail.com with ESMTPSA id 188-20020a4a1bc5000000b0035eb4e5a6cbsm1831953oop.33.2022.07.22.05.22.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 05:22:02 -0700 (PDT) To: libc-alpha@sourceware.org, Florian Weimer , Carlos O'Donell , Szabolcs Nagy Subject: [PATCH v12 9/9] manual: Add documentation for arc4random functions Date: Fri, 22 Jul 2022 09:21:37 -0300 Message-Id: <20220722122137.3270666-10-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220722122137.3270666-1-adhemerval.zanella@linaro.org> References: <20220722122137.3270666-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 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, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patch=linaro.org@sourceware.org Sender: "Libc-alpha" From: Adhemerval Zanella Netto --- manual/math.texi | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/manual/math.texi b/manual/math.texi index 477a18b6d1..141695cc30 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,51 @@ 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 reseeded with kernel entropy on @code{fork} +and @code{_Fork}. It is not cleared on either a direct @code{clone} syscall +or when using @theglibc{} @code{syscall} function. + +The prototypes for these functions are in @file{stdlib.h}. +@pindex stdlib.h + +@deftypefun uint32_t arc4random (void) +@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_buf (void *@var{buffer}, size_t @var{length}) +@standards{BSD, stdlib.h} +@safety{@mtsafe{}@asunsafe{@asucorrupt{}}@acsafe{}} +This function fills the region @var{buffer} of length @var{length} bytes +with random data. +@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