Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp340601iob; Fri, 13 May 2022 02:57:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgrbKd0nSHb2BaWHrglBYYo+uMFUAMdJzN4nGa4OxCFNyjbTtM2t7JluGjwA04Wil7L1R9 X-Received: by 2002:a17:902:76cb:b0:15e:e178:e2eb with SMTP id j11-20020a17090276cb00b0015ee178e2ebmr3997024plt.0.1652435823373; Fri, 13 May 2022 02:57:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652435823; cv=none; d=google.com; s=arc-20160816; b=0nItmOmny7NktxXeLeMwQFfiQiT5ECADvcEuUmrfCMoRxuFe538skFnY3tlV/z2+TK 5mPoaNa7E1vcf0ZMe0O+L2GXbdMB+7c1TersmlSh1R2IzOvEFSfDDUVq2hQJbtmlCWb9 oAbr8nyGyhAOJUfvoikXFQgubun+ivK+/hiVOnTU8X76HOxsSjKd0sD4HG8fSMAVF8al WWNPXzCnclkiloVK+IC9vHgIBNPzD7k4oXRUdUjaAy5LHqGmiV/RB+1VgJp4Ntvx93aJ ck4IVAb9JKRC3U1JTle8NGopCgVt+zLoo/ohFfERnMywCQ1ZZ3/+M91sS7+rUFZVMrCB C98Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=iEjqp9BGqhDD9BXrorldPBOdeaTsBv2QChvIoD9D0b8=; b=QxEf9zFL+AJdxcankxj4jsuEbisShOkOhufjEwBS8Vuem8FIYg4ob8Jd4ApZQ05b52 kIN0Vc5iLabzoapUi/WWsoZn+giBk5Utp2WT/nsXm8BJDJ6fBboe+k+Rr3uRANkZOhQB SgdFVpUigSz0qHVER2D2nL0QCaJifVDMNU/fCHXP0mDifRik+HCN43pewgyl9VH3eTMh 9GG/X8UD2nI51zq9ceZLRIlAvrS94KFtXUTSWWrECR+u4saPgo4jKR7PiXYKE5mrrbf0 LJORP7o67Cdxg4gH0JnMMWWAPQXlwgYCjCnG91hcBMG5IEqEONR/PODw5Bm+EAE00vmQ 62rA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z24-20020a63e118000000b003c24706f62asi2322101pgh.481.2022.05.13.02.56.37; Fri, 13 May 2022 02:57:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377322AbiEMG00 (ORCPT + 99 others); Fri, 13 May 2022 02:26:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359614AbiEMG0W (ORCPT ); Fri, 13 May 2022 02:26:22 -0400 Received: from isilmar-4.linta.de (isilmar-4.linta.de [136.243.71.142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 294E5289A8; Thu, 12 May 2022 23:26:07 -0700 (PDT) X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES Received: from owl.dominikbrodowski.net (owl.brodo.linta [10.2.0.111]) by isilmar-4.linta.de (Postfix) with ESMTPSA id AD3032013E7; Fri, 13 May 2022 06:26:05 +0000 (UTC) Received: by owl.dominikbrodowski.net (Postfix, from userid 1000) id C835E80957; Fri, 13 May 2022 08:18:53 +0200 (CEST) Date: Fri, 13 May 2022 08:18:53 +0200 From: Dominik Brodowski To: "Jason A. Donenfeld" Cc: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, netdev@vger.kernel.org, Jakub Kicinski , Theodore Ts'o Subject: Re: [PATCH] random32: use real rng for non-deterministic randomness Message-ID: References: <20220511143257.88442-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220511143257.88442-1-Jason@zx2c4.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Am Wed, May 11, 2022 at 04:32:57PM +0200 schrieb Jason A. Donenfeld: > random32.c has two RNGs in it: one that is meant to be used > deterministically, with some predefined seed, and one that does the same > exact thing as random.c, except does it poorly. The first one has some > use cases. The second one no longer does and can be replaced with calls > to random.c's proper random number generator. > > The relatively recent siphash-based bad random32.c code was added in > response to concerns that the prior random32.c was too deterministic. > Out of fears that random.c was (at the time) too slow, this code was > anonymously contributed by somebody who was likely reusing the alias of > long time anonymous contributor George Spelvin. Then out of that emerged > a kind of shadow entropy gathering system, with its own tentacles > throughout various net code, added willy nilly. > > Stop????making????crappy????bespoke????random????number????generators????. > > Fortunately, recently advances in random.c mean that we can stop playing > with this sketchiness, and just use get_random_u32(), which is now fast > enough. In micro benchmarks using RDPMC, I'm seeing the same median > cycle count between the two functions, with the mean being _slightly_ > higher due to batches refilling (which we can optimize further need be). > However, when doing *real* benchmarks of the net functions that actually > use these random numbers, the mean cycles actually *decreased* slightly > (with the median still staying the same), likely because the additional > prandom code means icache misses and complexity, whereas random.c is > generally already being used by something else nearby. > > The biggest benefit of this is that there are many users of prandom who > probably should be using cryptographically secure random numbers. This > makes all of those accidental cases become secure by just flipping a > switch. Later on, we can do a tree-wide cleanup to remove the static > inline wrapper functions that this commit adds. > > Cc: Jakub Kicinski > Cc: Theodore Ts'o > Signed-off-by: Jason A. Donenfeld > --- > Jakub - If there are no objections to this plan, I intend on taking this > through the random.git tree, which is what this commit is based on, with > its recent siphash changes and such. -Jason Nice! However, wouldn't it be much better to clean up the indirection introduced here as well? prandom_u32() as wrapper for get_random_u32() and prandom_bytes() as wrapper for get_random_bytes() seems unnecessary... Thanks, Dominik