Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp757974ybh; Sun, 12 Jul 2020 23:40:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxR3eVqbjIQH4uSKdEIq1FEAiwUIjKehvz7r42TGIXndB2zSQS5FKgeC0oJItjEwq0xfsRJ X-Received: by 2002:a05:6402:377:: with SMTP id s23mr91624665edw.200.1594622447217; Sun, 12 Jul 2020 23:40:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594622447; cv=none; d=google.com; s=arc-20160816; b=Q/ttLRlr3ml66Gc+17DmonTLV5oV/DFXiDrwcnmYUh+nxhatgBV7AgUXAvRFw0HzlC rnzfjemnnFcYT/28hpd60uL2XE3IqBVD+9xMSJMemOFoBgJqQQbMSCMa/ciqddLpMReo 8Mx3Z/IRD8bdjt8+B+bwdRA9ZA12xctKdlXP32QBXxFzEyhCpTbsVxlYkLWoUpMu11+6 w1SYZNeDIm+46tiyBM+1/3RVpERhozv//qnbfW5oQqK86gPTOm2zP+RNok9YfnIs1SHS gUwBCuG1xCiEbhP6cehISlfkzxBkTjlDUBaVAMyKqeaVNvzgdj7BM+luGLE0bFzkWY3R OEhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0FtSo+s3Xq4DNfeZ4uKVPtQ8C50oee0gTRDuz+8JCS8=; b=lCmMUZIA7OjIq8SjtsOaUvfSGgVZl7Cy+O4oRSaSdAuHwknWvyc86fQSuHdgh+faEG V5xy9pRZqs2uamZ/Ks03WNgpo0u99dfEPkBDPILq7b2bTiond0tcmQYDkwua2xoyo3a0 /nl04bPotgal+24wlSfQkRYfUGw7PxwL1pGt0L5ZMiDYYW49pAZoxH93KHCF7L/9ZoPI rmm6ZK2wdyy6kuawM+DvdpR1B8OxHxWh0czPY9RxDMp62HFoNs/a/Xsw6BRY+JiNt/Rn LPDJb+KtMfCaZf6FWhklb7ZDPOCEPwqoCuXFia4DW98yM+SVlmdj+CqBDz+yx/2/V+Fl dajQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@chronox.de header.s=strato-dkim-0002 header.b=OXfyeza5; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qx22si7999548ejb.148.2020.07.12.23.40.24; Sun, 12 Jul 2020 23:40:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@chronox.de header.s=strato-dkim-0002 header.b=OXfyeza5; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729500AbgGMGjr (ORCPT + 99 others); Mon, 13 Jul 2020 02:39:47 -0400 Received: from mo4-p03-ob.smtp.rzone.de ([81.169.146.172]:31932 "EHLO mo4-p03-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729169AbgGMGjM (ORCPT ); Mon, 13 Jul 2020 02:39:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1594622349; s=strato-dkim-0002; d=chronox.de; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=0FtSo+s3Xq4DNfeZ4uKVPtQ8C50oee0gTRDuz+8JCS8=; b=OXfyeza5eGjwEjcilC1FxmnFsAB//SZc99DrhyeIts4nqA+LW6OCO7AWwf+m8eOPuB GTHZOr5sK/N9lhpIyhcGvLwZ8I3k5/g873SPURvLCoDbDEDcF289TtqpWEqmeuOx9fWX vd9SpPuuZIfdM3evq0Ub1JvfM1b2p8PxkSpkDNHt5xcBZ0dVOs1Amgi9e8rACsVOcnqE RK6pQYnln0erT3QI9ByKMadchZmq/2EhqzBzVYs+GO2REfQDjdrX5w+vcHskhCNKsg6u V2AX5hkzW5Wpw31DVrKdFrlU/+coLEYU3cEaGJs3atMjZQBELlcqFgOAfZW5rP6RmssR BMEA== X-RZG-AUTH: ":P2ERcEykfu11Y98lp/T7+hdri+uKZK8TKWEqNyiHySGSa9k9xmwdNnzGHXPaIvSfHReW" X-RZG-CLASS-ID: mo00 Received: from positron.chronox.de by smtp.strato.de (RZmta 46.10.5 DYNA|AUTH) with ESMTPSA id y0546bw6D6bok2J (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Mon, 13 Jul 2020 08:37:50 +0200 (CEST) From: Stephan =?ISO-8859-1?Q?M=FCller?= To: Arnd Bergmann Cc: Greg Kroah-Hartman , linux-crypto@vger.kernel.org, LKML , linux-api@vger.kernel.org, "Eric W. Biederman" , "Alexander E. Patrakov" , "Ahmed S. Darwish" , "Theodore Y. Ts'o" , Willy Tarreau , Matthew Garrett , Vito Caputo , Andreas Dilger , Jan Kara , Ray Strode , William Jon McCann , zhangjs , Andy Lutomirski , Florian Weimer , Lennart Poettering , Nicolai Stange , "Peter, Matthias" , Marcelo Henrique Cerri , Roman Drahtmueller , Neil Horman , Randy Dunlap , Julia Lawall , Dan Carpenter Subject: [PATCH v31 08/12] crypto: provide access to a static Jitter RNG state Date: Mon, 13 Jul 2020 08:20:44 +0200 Message-ID: <14128491.tv2OnDr8pf@positron.chronox.de> In-Reply-To: <2050754.Mh6RI2rZIc@positron.chronox.de> References: <2050754.Mh6RI2rZIc@positron.chronox.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org To support the LRNG operation which uses the Jitter RNG separately from the kernel crypto API, at a time where potentially the regular memory management is not yet initialized, the Jitter RNG needs to provide a state whose memory is defined at compile time. As only once instance will ever be needed by the LRNG, define once static memory block which is solely to be used by the LRNG. CC: "Eric W. Biederman" CC: "Alexander E. Patrakov" CC: "Ahmed S. Darwish" CC: "Theodore Y. Ts'o" CC: Willy Tarreau CC: Matthew Garrett CC: Vito Caputo CC: Andreas Dilger CC: Jan Kara CC: Ray Strode CC: William Jon McCann CC: zhangjs CC: Andy Lutomirski CC: Florian Weimer CC: Lennart Poettering CC: Nicolai Stange Reviewed-by: Roman Drahtmueller Tested-by: Roman Drahtm=FCller Tested-by: Marcelo Henrique Cerri Tested-by: Neil Horman Signed-off-by: Stephan Mueller =2D-- crypto/jitterentropy-kcapi.c | 3 +- crypto/jitterentropy.c | 31 ++++++++++++++++++- .../crypto/internal}/jitterentropy.h | 3 ++ 3 files changed, 34 insertions(+), 3 deletions(-) rename {crypto =3D> include/crypto/internal}/jitterentropy.h (84%) diff --git a/crypto/jitterentropy-kcapi.c b/crypto/jitterentropy-kcapi.c index b43684c0dade..ed21fab13da6 100644 =2D-- a/crypto/jitterentropy-kcapi.c +++ b/crypto/jitterentropy-kcapi.c @@ -43,8 +43,7 @@ #include #include #include =2D =2D#include "jitterentropy.h" +#include =20 /*************************************************************************= ** * Helper function diff --git a/crypto/jitterentropy.c b/crypto/jitterentropy.c index 57f4a1ac738b..7ab229c6c96b 100644 =2D-- a/crypto/jitterentropy.c +++ b/crypto/jitterentropy.c @@ -117,7 +117,7 @@ struct rand_data { #define JENT_EHEALTH 9 /* Health test failed during initialization */ #define JENT_ERCT 10 /* RCT failed during initialization */ =20 =2D#include "jitterentropy.h" +#include =20 /*************************************************************************= ** * Adaptive Proportion Test @@ -854,3 +854,32 @@ int jent_entropy_init(void) =20 return 0; } + +struct rand_data *jent_lrng_entropy_collector(void) +{ + static unsigned char lrng_jent_mem[JENT_MEMORY_SIZE]; + static struct rand_data lrng_jent_state =3D { + .data =3D 0, + .old_data =3D 0, + .prev_time =3D 0, + .last_delta =3D 0, + .last_delta2 =3D 0, + .osr =3D 1, + .mem =3D lrng_jent_mem, + .memlocation =3D 0, + .memblocks =3D JENT_MEMORY_BLOCKSIZE, + .memblocksize =3D JENT_MEMORY_BLOCKS, + .memaccessloops =3D JENT_MEMORY_ACCESSLOOPS, + .rct_count =3D 0, + .apt_observations =3D 0, + .apt_count =3D 0, + .apt_base =3D 0, + .apt_base_set =3D 0, + .health_failure =3D 0 + }; + + if (jent_entropy_init()) + return NULL; + + return &lrng_jent_state; +} diff --git a/crypto/jitterentropy.h b/include/crypto/internal/jitterentropy= =2Eh similarity index 84% rename from crypto/jitterentropy.h rename to include/crypto/internal/jitterentropy.h index c83fff32d130..6e07d86eac82 100644 =2D-- a/crypto/jitterentropy.h +++ b/include/crypto/internal/jitterentropy.h @@ -15,3 +15,6 @@ extern int jent_read_entropy(struct rand_data *ec, unsign= ed char *data, extern struct rand_data *jent_entropy_collector_alloc(unsigned int osr, unsigned int flags); extern void jent_entropy_collector_free(struct rand_data *entropy_collecto= r); + +/* Access to statically allocated Jitter RNG instance */ +extern struct rand_data *jent_lrng_entropy_collector(void); =2D-=20 2.26.2