From patchwork Wed Jun 29 16:23: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: 1650216 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=sqgejB3m; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LY6JB2Gmvz9s07 for ; Thu, 30 Jun 2022 02:25:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2D9DE382D479 for ; Wed, 29 Jun 2022 16:25:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D9DE382D479 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1656519912; bh=I7CJvqAdXHHg74wVVkZ5wDvOyo3pbZbccmfd16mEXlI=; 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=sqgejB3mkW451/3wU8BDncZQaFbGohsRDugfFPzS5I7zF95DfFJAW6LfxUK3/5ZGH l/4maRN0INUY7HMSAArh9uJQq3ObYBGU9BncaxO8RXBrnCRt7XKR26ApJVLr/xPNIc qenji7AYHnyLFEHEaEeV0iAYOGAiJSgM3jMqrv/o= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) by sourceware.org (Postfix) with ESMTPS id D90E93846473 for ; Wed, 29 Jun 2022 16:23:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D90E93846473 Received: by mail-oi1-x234.google.com with SMTP id l81so22313268oif.9 for ; Wed, 29 Jun 2022 09:23:28 -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:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=I7CJvqAdXHHg74wVVkZ5wDvOyo3pbZbccmfd16mEXlI=; b=sa8xKS+ooiX+Kn3WIA9ug4ss9b9wAX0fO6q5WqipZ+Q5T1PtfjJA0CSNkyEpUVmviZ eBT6p4lWJM9783DpV7gOuAWnyQSLRDk0JrgI0EIGl4J1LHrKoZHkdx7Wu7M2OxwwE+CT n5DAwEYdTvw4+GhDHvYH/CZbhnWbwkLgCBAKZB27vkvbmno7h2N46hlWtZtgWyYnl7b6 LqyeaOc4tfRC/2TOSgaj3GbeFUOGyLjojgrO3hmQUo7sRoaERrW7w3SGyj8p4E8y7fYm Kkp+Z/R4GW7Blms/g79M8bYyKfrkoKxiBjMUt0QD5g9ZWHdoXCMVNtEpdCSIjDSbleuB L2SQ== X-Gm-Message-State: AJIora8g7SINeSUTEtilPfuX/rPJ59ar51/J93p4lC4+loSX0rhbpvKu lqwBk2rn0TAmOzutp/UOfuCVkHe0Kw2ll44d X-Google-Smtp-Source: AGRyM1tTVxnyHOuWKxJyK8GQgEOTMeDrR/ty0gH0do6nFZ0nC7yVGqWbl3xdb0yasbvgl6cbKv3UQA== X-Received: by 2002:a05:6808:1523:b0:32f:73ee:95cd with SMTP id u35-20020a056808152300b0032f73ee95cdmr3812307oiw.156.1656519807894; Wed, 29 Jun 2022 09:23:27 -0700 (PDT) Received: from ubuntu22-vm.. ([177.138.183.172]) by smtp.gmail.com with ESMTPSA id x31-20020a4a97e2000000b00425beedad70sm2615577ooi.32.2022.06.29.09.23.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jun 2022 09:23:27 -0700 (PDT) To: libc-alpha@sourceware.org, Florian Weimer Subject: [PATCH v7 9/9] manual: Add documentation for arc4random functions Date: Wed, 29 Jun 2022 16:23:07 +0000 Message-Id: <20220629162307.3410023-10-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220629162307.3410023-1-adhemerval.zanella@linaro.org> References: <20220629162307.3410023-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 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+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" --- manual/math.texi | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) 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} +and @code{_Fork}. It is not cleared for either 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 int32_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 (void *@var{buffer}, size_t @var{length}) +@standards{BSD, stdlib.h} +@safety{@mtsafe{}@asunsafe{@asucorrupt{}}@acsafe{}} +This function fills the region @var{buffer} of @var{length} 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