From patchwork Sat Feb 27 13:38:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephan Mueller X-Patchwork-Id: 388494 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA24AC433E6 for ; Sat, 27 Feb 2021 13:45:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B059164ED5 for ; Sat, 27 Feb 2021 13:45:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230147AbhB0Npe (ORCPT ); Sat, 27 Feb 2021 08:45:34 -0500 Received: from mo4-p04-ob.smtp.rzone.de ([81.169.146.179]:24360 "EHLO mo4-p04-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230107AbhB0Npa (ORCPT ); Sat, 27 Feb 2021 08:45:30 -0500 ARC-Seal: i=1; a=rsa-sha256; t=1614433250; cv=none; d=strato.com; s=strato-dkim-0002; b=ZoUZ+brI853u5u5nSLILgGx0UIzGELSL9vASrB9n523OeKhzYxrFL94tHDs5bdwpbE rfJG0LwWl1qJPKmkKmGCEvP5Jvet2czRq+0NykhGuQLkWq9rqx3+rYi/WA0cyYYmrqSq ZDCWOnHOsuoFBdJgc2CieGp50fqAbiAZUlSqYeaOCR9Wb38VmNn50EgxqfW097axlD2U mKkObc4BhdF9q50h1MIK7Cni3RFQ7hKSYje71PUNY7NyurO+QpOn7Mt2qAgUe21aOGM3 H+Xakx+sJZg/LnFIUjLQC9E74UTlg/qlOBA1k/lKuVzPJubPBZxciyWyzOcFnISZchRs 7SqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1614433250; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=aDr4BSmx17CO+92UG7sxwfwUiB8PKlvHnJTNQ/f4X44=; b=QDGyR8L0XqgUH5rC5SxP6hFku4m2gnzBE52Pm5mKglM5jdSfguolo5Lj3ZPj8CLcdq 6TtAso+F29qB/N6Tcv7w2NawZdZuShGHz+SFVhkWF0XsQkI5fwhbEI527RowywUOPyET YsX+uF3DGURiQEHGBFpT5Koe7GptYVQikBspFdksk+F5klV+4MuQpo50lXjLLLVO+9ee ASk+87pCti+ZzGC9JaB+7r/1UQTL2oUiHTO/M73rGx1wyJTMdQ2n6uot6A/DCeBwImBj lWcxZ15+dlBVJaLU67eot7jfNto2DlWNrOhuGLCL5LxTfFZHnoRVS4T8anMnTh5NJUqq x8lg== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1614433250; s=strato-dkim-0002; d=chronox.de; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=aDr4BSmx17CO+92UG7sxwfwUiB8PKlvHnJTNQ/f4X44=; b=tBHPwvv3+y800rwYu63UEJL+NMiquFfUdUM4G7LyCd58kEajGbLA613K+LnoD23Qmi R19FO7j+kIp2brs8EThO7UFaJD9ai6p4AhhwYxtwLsShmcHnk67ZKJzomUGMFNCnbmLg Z6d8weDa6sNfCdlDkNZEUQZX9AbKo0RGEQFmnW8ydUTcCfSioyjzWiT91l/3OxUKBGAz Bwdq0wCyE97zVebqidgnBENydH0xgomMfLVanDAhsr760h5B01BKCBeaXyL8MFUZ4QvX mfqlqS2i5nIjGUOeH9vcN8F85EhZgKDJf9ncF0A/4m9cwbC/4NXpswoxuFg7DG7VaBHG LrEQ== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2ERcEykfu11Y98lp/T7+hdri+uKZK8TKWEqNyiHySGSa9k9xmwdNnzGHXPZIfSc8k+7" X-RZG-CLASS-ID: mo00 Received: from positron.chronox.de by smtp.strato.de (RZmta 47.19.0 DYNA|AUTH) with ESMTPSA id 608030x1RDenUDC (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Sat, 27 Feb 2021 14:40:49 +0100 (CET) From: Stephan =?iso-8859-1?q?M=FCller?= To: Tso Ted , linux-crypto@vger.kernel.org Cc: Willy Tarreau , Nicolai Stange , LKML , Arnd Bergmann , Greg Kroah-Hartman , "Eric W. Biederman" , "Alexander E. Patrakov" , "Ahmed S. Darwish" , Matthew Garrett , Vito Caputo , Andreas Dilger , Jan Kara , Ray Strode , William Jon McCann , zhangjs , Andy Lutomirski , Florian Weimer , Lennart Poettering , Peter Matthias , Marcelo Henrique Cerri , Neil Horman , Randy Dunlap , Julia Lawall , Dan Carpenter , Andy Lavr , Eric Biggers , "Jason A. Donenfeld" , Petr Tesarik , John Haxby Subject: [PATCH v38 09/13] crypto: provide access to a static Jitter RNG state Date: Sat, 27 Feb 2021 14:38:17 +0100 Message-ID: <2020890.OBFZWjSADL@positron.chronox.de> In-Reply-To: <3277560.QJadu78ljV@positron.chronox.de> References: <3277560.QJadu78ljV@positron.chronox.de> MIME-Version: 1.0 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: Torsten Duwe 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üller Tested-by: Marcelo Henrique Cerri Tested-by: Neil Horman Signed-off-by: Stephan Mueller --- crypto/jitterentropy-kcapi.c | 3 +- crypto/jitterentropy.c | 31 ++++++++++++++++++- .../crypto/internal}/jitterentropy.h | 3 ++ 3 files changed, 34 insertions(+), 3 deletions(-) rename {crypto => include/crypto/internal}/jitterentropy.h (84%) diff --git a/crypto/jitterentropy-kcapi.c b/crypto/jitterentropy-kcapi.c index e8a4165a1874..c90e60910827 100644 --- a/crypto/jitterentropy-kcapi.c +++ b/crypto/jitterentropy-kcapi.c @@ -43,8 +43,7 @@ #include #include #include - -#include "jitterentropy.h" +#include /*************************************************************************** * Helper function diff --git a/crypto/jitterentropy.c b/crypto/jitterentropy.c index 6e147c43fc18..fa1459f09b01 100644 --- 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 */ -#include "jitterentropy.h" +#include /*************************************************************************** * Adaptive Proportion Test @@ -854,3 +854,32 @@ int jent_entropy_init(void) 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 = { + .data = 0, + .old_data = 0, + .prev_time = 0, + .last_delta = 0, + .last_delta2 = 0, + .osr = 1, + .mem = lrng_jent_mem, + .memlocation = 0, + .memblocks = JENT_MEMORY_BLOCKSIZE, + .memblocksize = JENT_MEMORY_BLOCKS, + .memaccessloops = JENT_MEMORY_ACCESSLOOPS, + .rct_count = 0, + .apt_observations = 0, + .apt_count = 0, + .apt_base = 0, + .apt_base_set = 0, + .health_failure = 0 + }; + + if (jent_entropy_init()) + return NULL; + + return &lrng_jent_state; +} diff --git a/crypto/jitterentropy.h b/include/crypto/internal/jitterentropy.h similarity index 84% rename from crypto/jitterentropy.h rename to include/crypto/internal/jitterentropy.h index c83fff32d130..6e07d86eac82 100644 --- a/crypto/jitterentropy.h +++ b/include/crypto/internal/jitterentropy.h @@ -15,3 +15,6 @@ extern int jent_read_entropy(struct rand_data *ec, unsigned 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_collector); + +/* Access to statically allocated Jitter RNG instance */ +extern struct rand_data *jent_lrng_entropy_collector(void);