From patchwork Thu Jul 21 13:05:07 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: 592141 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b811:0:0:0:0 with SMTP id fc17csp446436mab; Thu, 21 Jul 2022 06:07:54 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uYc5azWH2vDesAeq82QCg2qttqpnV8giAX+1oNjiewpBNQqDKTNSZCcrSjKlDyTMI+5W44 X-Received: by 2002:a05:6402:501d:b0:437:e000:a898 with SMTP id p29-20020a056402501d00b00437e000a898mr58305744eda.265.1658408873893; Thu, 21 Jul 2022 06:07:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658408873; cv=none; d=google.com; s=arc-20160816; b=U091ptqh+3bZ481gqEZkmWcmVVIX8IzRyqp9a8L50aLp42me0XZ2wDo02XcW3RZhAu cLIxwDMcl5mi/hy8VmiTJrDp+gWiU7nfTEa9G4oFjRPSb5Tt1CZTKDnEcDMXlS74tO4Z jp65F97KtDv0h6D4cG3EPj0PxV/idKf35Eh4QzbJ0h/4O2NiCMvBlerP2GGHPyQQcW90 nLIDtKRSweMdSiz3tZG56Cy80Q6xAx4r0BWXX4LqJ1H4NFvMyxEI6IxzDEawGVuBChp9 PI71rNxEvLiRo55uyRsOD8Y0csDH78AuREmRk3GbcVxSRw7/xMCPWrbTh3AqdUxUx3Wt XQAw== 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=aRug85u4+uk2maWybRamr0N5Er844R6UJ4IBz/zpDGtNpoN9fqk5eZH5SnwEXvrBx6 hZ/zMVtbnWb15hQRjh3UOukH98GRbD/Awnewf1BDO0TIL24oKOsmcvw9gQV4p6LoUXbn 3AgS51FMMJCmDNMqsCiapOj+LxMaO+J3yd4/yObPYkMdsxGxX3YJAaq7/GZPRGtuoT1A E5mnqZcqVk5ofEhIJxa6ENnDRkUDoz0nDCVU+TbChlUvHMor1TDCpfXzzxOvjqtT/VKK bvoA6jqbNlE85A70mlxnL9+dhuVwKOujRN96BeRH3v3idEafCgLNMaI/h3wCX/96VOOv 7xag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=hFWTtLNW; 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 i12-20020aa7dd0c000000b0043a7384a858si1813029edv.299.2022.07.21.06.07.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 06:07:53 -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=hFWTtLNW; 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 C3E333835414 for ; Thu, 21 Jul 2022 13:07:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C3E333835414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1658408872; 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=hFWTtLNWorou8p7jl7e3Qva+7Sp56qVOSJ2966QY5jcLBQPcZJUzBSX46zSOgZbBT gQfxeMCBuxffRneOa6y0Ps9sZcB8R/GigXaXnUnJIimx6Eqz/+o9NWbZPLsBuNufwa p9KYO9kmb04FAiB6ErN/jgrbPV8KRHVL7jxnf+S8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id 48E42385BAFC for ; Thu, 21 Jul 2022 13:05:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 48E42385BAFC Received: by mail-ot1-x329.google.com with SMTP id g19-20020a9d1293000000b0061c7bfda5dfso1092231otg.1 for ; Thu, 21 Jul 2022 06:05:33 -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=WI664vqDyUs2LTn31p/6ALja4Yq7F3p1QMnrejBB2/BYHFDEJ/JCymg0J+13P9zCAI STMn5ZFSFvonWxNf1RhIHKFZvTxXY/Bw9yFzvAd/SxXmpHXTRB7n/ce8jNLpvioK50Im Os+cr/EGWyBac5jIwKtJEhdw/KYOcB6oTlSKWa12hYA1J3L3dcmzN6F6krUSdg/U7P/M NRwhtck/gcqnd3iE0pJEkHswKGU06tvmJYIAZ2L775/PhQuwuLnEznNnbi0TqIYHkMpn 2UDVu3/KYopiSPryK7tgj6cz7xoYWnrvHQXlR4xJ2DjXhMfOS6ewox6TDF5fUfSyY2uE //cg== X-Gm-Message-State: AJIora/ss7rJcRlrDXxJBiUAIOnyNCbVLNbPTrl3st2mre8LJdRCa8Fo vcblNgeeHterEk5zmBClpZGCkWToUQgJZA== X-Received: by 2002:a05:6830:11c6:b0:61c:c75b:7fa5 with SMTP id v6-20020a05683011c600b0061cc75b7fa5mr785080otq.243.1658408732379; Thu, 21 Jul 2022 06:05:32 -0700 (PDT) Received: from mandiga.. ([2804:431:c7cb:8ded:c7ae:e809:e8fb:6cb9]) by smtp.gmail.com with ESMTPSA id a32-20020a056870a1a000b0010d997ffe7asm767553oaf.37.2022.07.21.06.05.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 06:05:32 -0700 (PDT) To: libc-alpha@sourceware.org, Florian Weimer , Carlos O'Donell Subject: [PATCH v11 9/9] manual: Add documentation for arc4random functions Date: Thu, 21 Jul 2022 10:05:07 -0300 Message-Id: <20220721130507.3017393-10-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220721130507.3017393-1-adhemerval.zanella@linaro.org> References: <20220721130507.3017393-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