From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47763C4332F for ; Tue, 18 Oct 2022 07:04:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229719AbiJRHEb (ORCPT ); Tue, 18 Oct 2022 03:04:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230028AbiJRHE3 (ORCPT ); Tue, 18 Oct 2022 03:04:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09DFC13DDA; Tue, 18 Oct 2022 00:04:27 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A6CC061487; Tue, 18 Oct 2022 07:04:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2AB3C433C1; Tue, 18 Oct 2022 07:04:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666076666; bh=nzOkWr31YDiUOeIbP4635LhimacOpccRoPiypQjEzA8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=EOnM0MeBov5bhe9aPWFjq9/qju0h1sLn4ikh0b+N16j6eKKRq4sl4qL7enrW/bMUx c1HQguA+ds7DQo0tJNARGtxUOy6mgr/9OPQIMdb7LexoALaeMpktI5JhU/MLrlrgAV MUZrj6pfr7H0X/yphD3LL9OnX/5k7EAc8rErw35LdKuq5ADTam26azDrVEKgh0zjSX dN1B6Zfp8Dtv7j0jeSYYZ/rsLASxZDSucOypJw4J/BK+qFAJQoRJnSkS/qDARbdpHa lpupiXAbvjtoYbFbYnjMoAtdmmC26A9p+RIFTaKAho2Zni595cROGiZ9IoP+MPZaBk NfImpGadDPPxg== Date: Tue, 18 Oct 2022 00:04:24 -0700 From: Eric Biggers To: "Jason A. Donenfeld" Cc: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, sneves@dei.uc.pt Subject: Re: [PATCH] random: use rejection sampling for uniform bounded random integers Message-ID: References: <20221017023752.3907-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Mon, Oct 17, 2022 at 11:31:03PM -0600, Jason A. Donenfeld wrote: > On Mon, Oct 17, 2022 at 11:27:17AM -0700, Eric Biggers wrote: > > On Sun, Oct 16, 2022 at 08:37:53PM -0600, Jason A. Donenfeld wrote: > > > In order to be efficient, we implement a kernel-specific variant of > > > Daniel Lemire's algorithm from "Fast Random Integer Generation in an > > > Interval", linked below. The kernel's variant takes advantage of > > > constant folding to avoid divisions entirely in the vast majority of > > > cases, works on both 32-bit and 64-bit architectures, and requests a > > > minimal amount of bytes from the RNG. > > > > > > Link: https://arxiv.org/pdf/1805.10941.pdf > > > > Thanks for doing this! Your code looks correct, but it was hard for me to > > understand until I read the paper that is linked to. Could you include a brief > > comment in the code that explains the algorithm? Also, though the code looks > > correct, I assume that you've also explicitly tested that each of the four code > > paths produce uniform random numbers as intended? > > Yes, I've tested those, and they work. (Threw a lot of cores and ram at > it.) > > I could include a comment, sure. What do you have in mind? A > line-by-line thing, or just a short blurb at the top of the function? > > Jason A comment at the top of the function would be good. - Eric