From patchwork Wed Jul 13 17:36:57 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: 56042 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1E4953889E3D for ; Wed, 13 Jul 2022 17:39:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1E4953889E3D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1657733944; bh=lilsBdPJ8eUBWnm8PD8OzLZVpXf4E+FqQGf0QWfqk1o=; 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=TMQl+tyavRAbL6JA9z9Pi1AQpFk5fkTITlMBldsRA7KthSrl2BVJ4Kc7+wDtFeD6H xPrTrxxdGzExT35wJRZ38t7P2lpSM41YldJAFbpzFgX+6UoYrjhPRciOviAE1pVM4n CV2HPFiPPC8xXViblOwwBkjS52XgnO9wwEV0cD/c= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) by sourceware.org (Postfix) with ESMTPS id E2E753829BCA for ; Wed, 13 Jul 2022 17:37:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E2E753829BCA Received: by mail-oi1-x22c.google.com with SMTP id p132so9141159oif.9 for ; Wed, 13 Jul 2022 10:37:22 -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=lilsBdPJ8eUBWnm8PD8OzLZVpXf4E+FqQGf0QWfqk1o=; b=53MysQw/9r9bpWLCx16FoRfhqRC1oTG8T5ki+F2i/ows3fAd2cXTTDkklnFoIV3/DY AolNPAGGmHL0R2WHVuwevnthNklvumnkTuv3gvTgYpjJl4yqtNUUJa5zQVgnSEiCrQjS YtUowzunphIUtykJ8QuHpBU6lxl6lwJ6aV2L6ebFPxd9E6UfYw6JAFNvye9ySls9He1w tPhO7k4TyELLRAnsejJuVVKYySNDDgAfEgpnVM1kXEU2M6QRGdWwMQZD2FL7MVeJJP/k eRq6qf11Yj47BlDQA89JkAgRKC37yKAKhdhb62RvW4OWC8nizDqQuSNUNT4VRGnxjoDF 4VUQ== X-Gm-Message-State: AJIora9yEjHRjq9eLIWSDXsQai+qEJemSm61jxp6KOxiT/22HLnBA4nX MkwaS6c8HRPYQEU0X2xFC87Fy9EBYv4ZXg== X-Google-Smtp-Source: AGRyM1uDo+ghRqvk7FRELmMNRYcr5ZAckLW1v6qn3T5e5bsBNQFPkaqLBFjktxecDVtloWiv/M+9Sg== X-Received: by 2002:aca:210e:0:b0:33a:3557:b224 with SMTP id 14-20020aca210e000000b0033a3557b224mr984707oiz.209.1657733842092; Wed, 13 Jul 2022 10:37:22 -0700 (PDT) Received: from mandiga.. ([2804:431:c7ca:19c3:4d5a:3028:34cf:1669]) by smtp.gmail.com with ESMTPSA id o127-20020aca4185000000b00339c7af0e8esm5488651oia.51.2022.07.13.10.37.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 10:37:21 -0700 (PDT) To: libc-alpha@sourceware.org, Florian Weimer Subject: [PATCH v9 9/9] manual: Add documentation for arc4random functions Date: Wed, 13 Jul 2022 14:36:57 -0300 Message-Id: <20220713173657.516725-10-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220713173657.516725-1-adhemerval.zanella@linaro.org> References: <20220713173657.516725-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+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" From: Adhemerval Zanella Netto --- 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