From patchwork Sun Jan 1 16:26:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Colomar X-Patchwork-Id: 62507 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 CDC8838582BE for ; Sun, 1 Jan 2023 16:27:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CDC8838582BE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1672590431; bh=uHV8REolSd5mr2+QiH7yrJms0MPgrmKrYYY4QYfMOCQ=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=MGXXYamK923lDkPbFDzDgE8pRb37F6nbdqx0cYO752HQSdUNdPGAGvxM/uzH07zGy ztM02SxnQeOGwxmKDlHDLZYDYHBwJG4hdXDksB97EcARd3ovZBG2Ou6yCr/0wi2QLA oKocZsG9x1+qSwMg9eahWq0bBZBu1BupasSaVk7Q= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id 6127C3858D1E for ; Sun, 1 Jan 2023 16:26:49 +0000 (GMT) Received: by mail-wr1-x433.google.com with SMTP id co23so24254982wrb.4 for ; Sun, 01 Jan 2023 08:26:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=uHV8REolSd5mr2+QiH7yrJms0MPgrmKrYYY4QYfMOCQ=; b=xDMoVu+u6YOIWthd1cJdevsNJ3ufW0wNODWcuPQm9MTtb2muHnnW2TfWZoz/GRpYnZ /F2iy8Jbfo+vz7C0YOPhPX414Fkeyv6vRATJ+wBnbGMY13GJSn8wQwPywPm+GtSGesVS 7Y06CdEdvzq7Xynta615oXAvTgPdmQtIjyN5gkEYDb/1vtj+Ij8bQqL0J+P6vy421D/6 nPAT+3MM0X7X79Mbz7pvBU2ZiUfeURBj8tDPDrLaIT+qI5AJOcga/eW5u0gy+QnNqyu0 ywcdAZnaQfMLaxJ+xqC6IcW79s8DSdRbjtL+GXVz9ddpXEWqL+vxFggfwNM7iMPnJThQ VuVw== X-Gm-Message-State: AFqh2koaz9LMH/KWoKzsxcBD68KUumExdroUL8emsApQX7UOI6Yt7HRs ScaOWkyKEW3kQ82FCqoykIUQpbkVOD0= X-Google-Smtp-Source: AMrXdXs8wBLH4yInToJ6CoPoqPSxMLAgOHItZ1gyZMTDFYVNP/sKa+uXltXJz6mMN18MUwwuTpB7Cw== X-Received: by 2002:adf:ea4a:0:b0:27e:8d9b:bc20 with SMTP id j10-20020adfea4a000000b0027e8d9bbc20mr16885671wrn.27.1672590408201; Sun, 01 Jan 2023 08:26:48 -0800 (PST) Received: from asus5775.alejandro-colomar.es ([170.253.36.171]) by smtp.googlemail.com with ESMTPSA id a18-20020adfed12000000b0027cfd9463d7sm19207452wro.110.2023.01.01.08.26.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Jan 2023 08:26:47 -0800 (PST) X-Google-Original-From: Alejandro Colomar To: linux-man@vger.kernel.org Cc: Alejandro Colomar , libc-alpha@sourceware.org, "Jason A. Donenfeld" Subject: [PATCH] arc4random.3: New page documenting the arc4random(3) family of functions Date: Sun, 1 Jan 2023 17:26:28 +0100 Message-Id: <20230101162627.28031-1-alx@kernel.org> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, 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: Alejandro Colomar via Libc-alpha From: Alejandro Colomar Reply-To: Alejandro Colomar Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" arc4random(3) arc4random_uniform(3) arc4random_buf(3) Signed-off-by: Alejandro Colomar --- man3/arc4random.3 | 104 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 man3/arc4random.3 diff --git a/man3/arc4random.3 b/man3/arc4random.3 new file mode 100644 index 000000000..5fd292321 --- /dev/null +++ b/man3/arc4random.3 @@ -0,0 +1,104 @@ +.\" Copyright (C) 2023 Alejandro Colomar +.\" +.\" SPDX-License-Identifier: Linux-man-pages-copyleft +.\" +.TH arc4random 3 (date) "Linux man-pages (unreleased)" +.SH NAME +arc4random, arc4random_uniform, arc4random_buf +\- cryptographically-secure pseudorandom number generator +.SH LIBRARY +Standard C library +.RI ( libc ", " -lc ) +.SH SYNOPSIS +.nf +.B #include +.PP +.B uint32_t arc4random(void); +.BI "uint32_t arc4random_uniform(uint32_t " upper_bound ); +.BI "void arc4random_buf(void " buf [. n "], size_t " n ); +.fi +.SH DESCRIPTION +These functions give cryptographically-secure random numbers. +.PP +.BR arc4random () +returns a uniformly-distributed value. +.PP +.BR arc4random_uniform () +returns a uniformly-distributed value less than +.I upper_bound +(see CAVEATS). +.PP +.BR arc4random_buf () +fills the memory pointed to by +.IR buf , +with +.I n +bytes of random data. +.PP +The +.BR rand (3) +and +.BR rand48 (3) +families of functions should only be used where +the quality of the random numbers is not a concern +.I and +there's a need for repeatability of the results. +Unless you meet both of those conditions, +use the +.BR arc4random () +functions. +.SH RETURN VALUE +.BR arc4random () +returns a random number. +.PP +.BR arc4random_uniform () +returns a random number less than +.I upper_bound +for valid input, or +.B 0 +when +.I upper_bound +is invalid. +.SH ATTRIBUTES +For an explanation of the terms used in this section, see +.BR attributes (7). +.ad l +.nh +.TS +allbox; +lbx lb lb +l l l. +Interface Attribute Value +T{ +.BR arc4random (), +.BR arc4random_uniform (), +.BR arc4random_buf () +T} Thread safety MT-Safe +.TE +.hy +.ad +.sp 1 +.SH STANDARDS +These nonstandard functions are present in several Unix systems. +.SH CAVEATS +An +.I upper_bound +of +.B 0 +doesn't make sense in a call to +.BR arc4random_uniform (). +Such a call will fail, and return +.BR 0 . +Be careful, +since that value is +.I not +less than +.IR upper_bound . +In some cases, +such as accessing an array, +using that value could result in Undefined Behavior. +.SH SEE ALSO +.BR getrandom (3), +.BR rand (3), +.BR rand48 (3), +.BR random (7)