Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp577571iob; Fri, 13 May 2022 08:03:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyo5Ia9KE67yTsipmUepb/9jQ7te0TuBs3B+cMYLf69sa5+I7NpC90mIz/5kQMSCHs8ttf2 X-Received: by 2002:a17:907:1b09:b0:6d8:faa8:4a06 with SMTP id mp9-20020a1709071b0900b006d8faa84a06mr4610413ejc.701.1652454185634; Fri, 13 May 2022 08:03:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652454185; cv=none; d=google.com; s=arc-20160816; b=vrxbPHAbuJfU1T+iEI/q1Zgj6xeo8QNm25RKrDEHpJqQd/Ktla9vXPg7FLcFoAmAWc dF+w2kzjd+GR56h7T6t+KoC3TETulFd6EG2RO9qcFxrrygecURH90LVipB5Ubtwn6zK7 s3xhR/TObmIMPvUK+chPhzGRlE3qBvYu5yZrYco8FIQbDdpKt2sipSpza765WoEB0q09 3yCNQAscZfxtHulXTXSa+ZwKB7jHfVsN0/9vQE37GPZhc6+qfekODGFtdN3RzjeWfh0G N5uHqhnFGUylojpgWnba5H8WaTO00zaxN128aTuqrkhbm7ce6aV+rbGM1ugj2ja20vN4 4pSg== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=3xUI898Ne+4SSs+pA8vpiEUtB+ITclnroAWBhu+pk+s=; b=Av2IyYxB4hZk6S+G89UIrCVYZ/4YusG3IX88BBB65a1qC/5ro0hIO/hQEdDllAjk3C rR8wwE8Tc46i7Jgt82yuUZum3qwT7+zIhA5LSwHRqyhwy2Vh1mLov0C1oG0funr5PVfs AyjJtcknNpfwCchJl36CN+iyiamuy4AipE+KmC5gc0bO11KTOuGxuuTlY2uzJZdktyow JcEeMx2cnPLw1/LVYAaUD0EB+eOgL7WtQ69mPhXhoEsmZv6TOV5t0x38DbpYImOMX3be GmQS2rRl/ipUZC/+sWwdMbFNdtjruG8o2iiXHXaFqSgL4FrXMU4183L16K3NZIWO+R1l yJ7Q== 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 gm1-20020a1709073d0100b006e8910cb819si2378562ejc.825.2022.05.13.08.02.18; Fri, 13 May 2022 08:03:05 -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 S1377338AbiEMG0a (ORCPT + 99 others); Fri, 13 May 2022 02:26:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377313AbiEMG0Z (ORCPT ); Fri, 13 May 2022 02:26:25 -0400 Received: from isilmar-4.linta.de (isilmar-4.linta.de [136.243.71.142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E669F275E4; Thu, 12 May 2022 23:26:21 -0700 (PDT) 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 F418B20140E; Fri, 13 May 2022 06:26:05 +0000 (UTC) Received: by owl.dominikbrodowski.net (Postfix, from userid 1000) id 73159809A1; Fri, 13 May 2022 08:22:36 +0200 (CEST) Date: Fri, 13 May 2022 08:22:36 +0200 From: Dominik Brodowski To: "Jason A. Donenfeld" Cc: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org Subject: Re: [PATCH v3] random: use first 128 bits of input as fast init Message-ID: References: <20220503131204.571547-1-Jason@zx2c4.com> <20220504111644.284927-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220504111644.284927-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 04, 2022 at 01:16:44PM +0200 schrieb Jason A. Donenfeld: > Before, the first 64 bytes of input, regardless of how entropic it was, > would be used to mutate the crng base key directly, and none of those > bytes would be credited as having entropy. Then 256 bits of credited > input would be accumulated, and only then would the rng transition from > the earlier "fast init" phase into being actually initialized. > > The thinking was that by mixing and matching fast init and real init, an > attacker who compromised the fast init state, considered easy to do > given how little entropy might be in those first 64 bytes, would then be > able to bruteforce bits from the actual initialization. By keeping these > separate, bruteforcing became impossible. > > However, by not crediting potentially creditable bits from those first 64 > bytes of input, we delay initialization, and actually make the problem > worse, because it means the user is drawing worse random numbers for a > longer period of time. > > Instead, we can take the first 128 bits as fast init, and allow them to > be credited, and then hold off on the next 128 bits until they've > accumulated. This is still a wide enough margin to prevent bruteforcing > the rng state, while still initializing much faster. > > Then, rather than trying to piecemeal inject into the base crng key at > various points, instead just extract from the pool when we need it, for > the crng_init==0 phase. Performance may even be better for the various > inputs here, since there are likely more calls to mix_pool_bytes() then > there are to get_random_bytes() during this phase of system execution. Have you evaluated this closer, also for systems where it takes ages to reach crng_init = 1? And might it make sense to only call extract_entropy() if there has been new input between two calls to get_random_bytes()? Thanks, Dominik