From patchwork Sat Nov 7 14:30:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandy Harris X-Patchwork-Id: 7575561 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DD4819F1AF for ; Sat, 7 Nov 2015 14:31:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E9795203F3 for ; Sat, 7 Nov 2015 14:31:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 03990203AD for ; Sat, 7 Nov 2015 14:31:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753551AbbKGOax (ORCPT ); Sat, 7 Nov 2015 09:30:53 -0500 Received: from mail-qg0-f47.google.com ([209.85.192.47]:35557 "EHLO mail-qg0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753528AbbKGOas (ORCPT ); Sat, 7 Nov 2015 09:30:48 -0500 Received: by qgec40 with SMTP id c40so51541802qge.2; Sat, 07 Nov 2015 06:30:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1ZqzsdjzFWlhS1zKJz9np91qR9d/osf2Q8thzCAQRyo=; b=pMGCbSeYv+P92UPkTH7bMaMGkGy/DsKtTexliZfBmFASDzCJfT35X6LAWlCUIBaXGc E1OoQWQuoTfj59eaNTNng1dzeNfrGp/1BgZ5IojEphMOk/9sMQq1wb2TBtvcB3SGI3wb 9OUcppjA80kY2VRaDg+nGx+CWn8kfRucq20neW7x+aiS+XoUg2xg/emRxZfeGJxJgfco lCF+LGnHZ8UhBZcUDJm+yRXYwGg69lZrvjfqwP7keFd92oFO1iqIRhnZVXnQzScQMdFI in1zNfApjkOAcBv7FY9OEl96/i40NayQ0pP0qaGuaPl/OT6PU0goBu1L6m/tSAWMLSPX bAIQ== X-Received: by 10.141.28.136 with SMTP id f130mr19895134qhe.66.1446906647271; Sat, 07 Nov 2015 06:30:47 -0800 (PST) Received: from Sandy-laptop.hitronhub.home (CPE00fc8d085973-CM00fc8d085970.cpe.net.cable.rogers.com. [99.224.153.28]) by smtp.gmail.com with ESMTPSA id d8sm1367697qgd.34.2015.11.07.06.30.46 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 07 Nov 2015 06:30:46 -0800 (PST) From: Sandy Harris To: "Theodore Ts\\'o" , Jason Cooper , "H. Peter Anvin" , John Denker Cc: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org Subject: [PATCH 3/7] Initialise pools randomly if CONFIG_RANDOM_INIT=y Date: Sat, 7 Nov 2015 09:30:38 -0500 Message-Id: <1446906642-19372-3-git-send-email-sandyinchina@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1446906642-19372-1-git-send-email-sandyinchina@gmail.com> References: <1446906642-19372-1-git-send-email-sandyinchina@gmail.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Sandy Harris --- drivers/char/random.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/drivers/char/random.c b/drivers/char/random.c index d0da5d8..e222e0f 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -231,7 +231,7 @@ * not be attributed to the Phil, Colin, or any of authors of PGP. * * Further background information on this topic may be obtained from - * RFC 1750, "Randomness Recommendations for Security", by Donald + * RFC 4086, "Randomness Requirements for Security", by Donald * Eastlake, Steve Crocker, and Jeff Schiller. */ @@ -275,13 +275,19 @@ /* * Configuration information */ +#ifdef CONFIG_RANDOM_INIT + +#include + +#else #define INPUT_POOL_SHIFT 12 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5)) #define OUTPUT_POOL_SHIFT 10 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5)) -#define SEC_XFER_SIZE 512 -#define EXTRACT_SIZE 10 +#endif +#define EXTRACT_SIZE 10 +#define SEC_XFER_SIZE 512 #define DEBUG_RANDOM_BOOT 0 #define LONGS(x) (((x) + sizeof(unsigned long) - 1)/sizeof(unsigned long)) @@ -296,6 +302,27 @@ #define ENTROPY_SHIFT 3 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT) +/* sanity checks */ + +#if ((ENTROPY_SHIFT+INPUT_POOL_SHIFT) >= 16) +#ifndef CONFIG_64BIT +#error *_SHIFT values problematic for credit_entropy_bits() +#endif +#endif + +#if ((INPUT_POOL_WORDS%16) || (OUTPUT_POOL_WORDS%16)) +#error Pool size not divisible by 16, which code assumes +#endif + +#if (INPUT_POOL_WORDS < 32) +#error Input pool less than a quarter of default size +#endif + +#if (INPUT_POOL_WORDS < OUTPUT_POOL_WORDS) +#error Strange configuration, input pool smalller than output +#endif + + /* * The minimum number of bits of entropy before we wake up a read on * /dev/random. Should be enough to do a significant reseed. @@ -442,16 +469,23 @@ struct entropy_store { }; static void push_to_pool(struct work_struct *work); + +#ifndef CONFIG_RANDOM_INIT static __u32 input_pool_data[INPUT_POOL_WORDS]; static __u32 blocking_pool_data[OUTPUT_POOL_WORDS]; static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS]; +#endif static struct entropy_store input_pool = { .poolinfo = &poolinfo_table[0], .name = "input", .limit = 1, .lock = __SPIN_LOCK_UNLOCKED(input_pool.lock), - .pool = input_pool_data +#ifdef CONFIG_RANDOM_INIT + .pool = pools, +#else + .pool = input_pool_data, +#endif }; static struct entropy_store blocking_pool = { @@ -460,7 +494,11 @@ static struct entropy_store blocking_pool = { .limit = 1, .pull = &input_pool, .lock = __SPIN_LOCK_UNLOCKED(blocking_pool.lock), +#ifdef CONFIG_RANDOM_INIT + .pool = pools + INPUT_POOL_WORDS, +#else .pool = blocking_pool_data, +#endif .push_work = __WORK_INITIALIZER(blocking_pool.push_work, push_to_pool), }; @@ -470,7 +508,11 @@ static struct entropy_store nonblocking_pool = { .name = "nonblocking", .pull = &input_pool, .lock = __SPIN_LOCK_UNLOCKED(nonblocking_pool.lock), +#ifdef CONFIG_RANDOM_INIT + .pool = pools + INPUT_POOL_WORDS + OUTPUT_POOL_WORDS, +#else .pool = nonblocking_pool_data, +#endif .push_work = __WORK_INITIALIZER(nonblocking_pool.push_work, push_to_pool), };