From patchwork Thu Jul 14 11:28:45 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: 590377 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp1478158max; Thu, 14 Jul 2022 04:31:10 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sfpeShMtc1MFuASlPsuwj7J60aWhSIBPJ7CBnnDAMHuzHbXht6MgmV3onWAUwYPLu25L4y X-Received: by 2002:a05:6402:1cc8:b0:437:a61a:5713 with SMTP id ds8-20020a0564021cc800b00437a61a5713mr11845071edb.340.1657798270537; Thu, 14 Jul 2022 04:31:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657798270; cv=none; d=google.com; s=arc-20160816; b=ekArFO29mgZboIxcu7yUVuS4MnQpSvNo67fHp9r09jUjgbyLMtZRa8HKaKlFzHqoQ/ i2QBqTFRV3pc2A2ph3bQiMeYTeWVXeTgELGaYkCeTE/PiHyWkdv780Cf4HgcNUshkTpr mkZaT7TU/9hXHM90AFrECnFzXmJAVH9CY6S0GNoGv90HCvOyXfLFgz4/rX1kCg0KcV2C +q2fxFEYbYRuFgCsKp/a1uj4/Tx6fTZVHK28a6FiAzSiuwG7YRTa78aBpdJSbsVy9IYM /4XDfxDm6BvcdXWfTc90ptSBkcybs4fvlT3Hz5qtnHajNWd8wau6esz2CwL6UuLCsW+u moQg== 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=yEcvjorV62NBzuHAu2ICCxIXofMQKF0ti9jSsrA/yhBAxN6uE5l67PJ8daqdTPU4Lt Kw740UFcCNUbfiD8oda8a413Ofh1pEGLe/p7nl/rTXn0lodygmZp2miUdRXyRUxCLGqn YlaNOkKFM58Y8M7OBxZzrtKacJr69TMZ9yPKhL3BEbyEcCRQuGOVn8B4CWLCe9Iuttan IA6N50jAozsywYAhoWJ++15J6J8KRs2K9Hivz19oC9/N5nYUxx+iA5E0kMCWXGzbbjti 7isRE9yD72uxbreUy/Apbc/QjDSd9vieKVdQHLmwJmI9Rs4PqjXyInXZf+pB88KMsc0x HvAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=dIlOKa7z; spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id g12-20020a056402424c00b004315dd76796si2272252edb.482.2022.07.14.04.31.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 04:31:10 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=dIlOKa7z; spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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 3AE6C3889E1C for ; Thu, 14 Jul 2022 11:31:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3AE6C3889E1C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1657798269; 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=dIlOKa7zDZQ40oWmdBF/nePMAR3FjkqnUiBObq1sxz6x4hRq7w6JG9feOmmsOToI/ fGCRfi7Hjdl8jRNPr5M9VW10WFtFt5rZn0rTBAwR9GrVCXPstE3jF5DKKzk/SdVq80 8GAMAyBzzslA9iRYGj3u2/KizLAP4CZXsL7BHTXg= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by sourceware.org (Postfix) with ESMTPS id DFD02388CE97 for ; Thu, 14 Jul 2022 11:29:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DFD02388CE97 Received: by mail-oi1-x22e.google.com with SMTP id r191so1976737oie.7 for ; Thu, 14 Jul 2022 04:29:08 -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=0SGFU2HTY6low9mrYGmQh07zHSUbNMNnRDSuW2EJuRY16/CF5EuPsu8sakXI+/jC32 B+yC5tFsb9+aP3vPawwsbE5pptVzdFDtpDhOlLI9fVkKg4v5O+QjBnUXsz/YpMVhMkoa USMbbiBt54owC3GH/pk5wQ1RjYvb5e1TEobKNO3FL0F6Q7hia7BmYAUy1xBVBm9SQJCl rzKffeucZtL37e56tNG8d03qKctPy/mOfI5AMYIhuTtVIS2BF+g7FkzxV4tJYUvBfK5a gu9eGZUPY71GUIWS/28Tbe7Qe8hrYhBpJyYQXJrphvh4qJb8NwcwbWOHrYJKnw4iDvNP 5IHQ== X-Gm-Message-State: AJIora/qaI2Ffgo2mbmaBNNB8PIkQdX06fgJhJXPl1aWwy5AZG4iWlz0 aZoKfjuWZDa4NOvKi5pXqupaMsRCzX0Rdw== X-Received: by 2002:a05:6808:23cf:b0:335:63ca:419c with SMTP id bq15-20020a05680823cf00b0033563ca419cmr3970610oib.281.1657798148169; Thu, 14 Jul 2022 04:29:08 -0700 (PDT) Received: from mandiga.. ([2804:431:c7ca:19c3:3696:7000:2f6a:a6f4]) by smtp.gmail.com with ESMTPSA id k25-20020a056830243900b0061c4761c8cbsm562266ots.24.2022.07.14.04.29.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 04:29:07 -0700 (PDT) To: libc-alpha@sourceware.org, Florian Weimer Subject: [PATCH v10 9/9] manual: Add documentation for arc4random functions Date: Thu, 14 Jul 2022 08:28:45 -0300 Message-Id: <20220714112845.704678-10-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220714112845.704678-1-adhemerval.zanella@linaro.org> References: <20220714112845.704678-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, 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-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