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: 590073 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp783735max; Wed, 13 Jul 2022 10:38:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tV8SyGjxYcVchtDark0WJPe4oXTRkYXDEHSE0j1a8QZSTr0yGmsU3LJ10M63zh3jeFPaIS X-Received: by 2002:a17:907:2d0e:b0:72b:4af7:7ccd with SMTP id gs14-20020a1709072d0e00b0072b4af77ccdmr4582730ejc.209.1657733932722; Wed, 13 Jul 2022 10:38:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657733932; cv=none; d=google.com; s=arc-20160816; b=f5g7JoPK7qInNJyiDM115LREygThwz+ccnBATqNrvJZ5VMKK/DXZFEddzbOtxLvxE7 Tifi7TbX4pIAfrwNTW4QOC1HTpwKaxE0jQCuVw/8gIDbHf1D7blK3LiJzh0O6P7rey/d GIqq/LPhTY1/sbq2OjDxIPMzkacIixIROD8dJ+wchtOhIsbQ3mDv0L536H/KbVMWPL+d 5eDfLXgK19zI079Vz6g0ivBPhY42l1KPGy1EG7ZNeYm2K6ua1MH0I7POecEvoO89M2N7 NvohEJa2j5raf3Ad91E4ns9d5XDhxmAEw2YBLFX1saJekuWhTO3VJ3Mw2kKizlmCTEMq 8T6w== 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=lilsBdPJ8eUBWnm8PD8OzLZVpXf4E+FqQGf0QWfqk1o=; b=GEBhy7lhJMgLDBgV4F/R6WUkP3mXesvpRYbRNZNi0JqfO6MkJIFDHHBPIs7HvQqRFi 4SyCVKiyfYgWVlC7MQQvMe9lfCBcd4OwhIcOItTG/VfhCb5JdFKQ6ObNjxG5OebfnBJW LzdnKqxWQUS5kPzswj2egt7E3IERc7IWpEXftImXWQnEoqxJgEFq9yffuRMGUnp7M5xD UjxmkL12PqwbWksR2DhVaR2G+RDLcguFv7hnAoVU1QGUNXOyA4U3CiaFEQqwO5TZBpYN zyQ0R1BKbhmygs09ATIy47x3G6gtBVhsQ+A9d8kAMhkhsr6SemDaVvreJE59Yk9mfXQa pNAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b="ZW7e/0fm"; 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 go31-20020a1709070d9f00b0072b3cd7beb8si23698386ejc.938.2022.07.13.10.38.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 10:38:52 -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="ZW7e/0fm"; 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 9019F382A2F3 for ; Wed, 13 Jul 2022 17:38:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9019F382A2F3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1657733931; 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=ZW7e/0fmxSgFd6JyzYHk0lR+RhsPyUecWsU+DvGOOnLKiwNvGjQPjllYR0SkAVjzM e8z4bBcaZkzfTDF09P+QZKEOvDJ/EhifoBMlKAL6LK3Fqq9DehScUi9ycHF5IZvaoX q3ce+GmgWOORSIkDIu3IeSc3nCbcgOB+saagECw8= 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-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+patch=linaro.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