From patchwork Mon Dec 11 14:06:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lukasz Stelmach X-Patchwork-Id: 10105195 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5F54A602A7 for ; Mon, 11 Dec 2017 14:07:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6AC28295FA for ; Mon, 11 Dec 2017 14:07:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F74D2960A; Mon, 11 Dec 2017 14:07:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB5A8295FA for ; Mon, 11 Dec 2017 14:07:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753094AbdLKOGz (ORCPT ); Mon, 11 Dec 2017 09:06:55 -0500 Received: from mailout2.w1.samsung.com ([210.118.77.12]:33137 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752886AbdLKOGm (ORCPT ); Mon, 11 Dec 2017 09:06:42 -0500 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20171211140640euoutp0240b229794c12339bdf4d13ef137cf06b~-QpNAcf0g0713807138euoutp02i; Mon, 11 Dec 2017 14:06:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20171211140640euoutp0240b229794c12339bdf4d13ef137cf06b~-QpNAcf0g0713807138euoutp02i DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1513001200; bh=GYIBFrIYS0K8MBGXY/IbJ8YHp2t8BAtfXEwgmYG6FCE=; h=From:To:Cc:Subject:Date:In-reply-to:In-reply-to:References:From; b=mG/EvxNTEejkkW8oJqfn3rm5nr5uEzU8PbPzgBlgFlHbS+5JuwePTDkQ5Xn8qU2EQ xuSSykMHfJWnv53jUJNQ4azZYxwdbtVsipwcyYaaz2UW06Yh6e+QH1jZp1NFP2/0Q1 V13IvjTvC/Ic8Wwet//vZ2CGLzYsVK2le60VvTUY= Received: from eusmges3.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20171211140639eucas1p29046b454a29b009586c316da2e5fa526~-QpMFozEa2431424314eucas1p2Z; Mon, 11 Dec 2017 14:06:39 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3.samsung.com (EUCPMTA) with SMTP id 3E.30.12867.EE09E2A5; Mon, 11 Dec 2017 14:06:38 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20171211140638eucas1p239085a27ce0501beb8b42be94ed61b34~-QpLYbYQy0704207042eucas1p2d; Mon, 11 Dec 2017 14:06:38 +0000 (GMT) X-AuditID: cbfec7f2-f793b6d000003243-8f-5a2e90eefa3b Received: from eusync4.samsung.com ( [203.254.199.214]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id B2.54.18832.EE09E2A5; Mon, 11 Dec 2017 14:06:38 +0000 (GMT) MIME-version: 1.0 Content-transfer-encoding: 8BIT Content-type: text/plain; charset="UTF-8" Received: from localhost ([106.116.147.110]) by eusync4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0P0S008JAV72XG10@eusync4.samsung.com>; Mon, 11 Dec 2017 14:06:38 +0000 (GMT) From: =?UTF-8?q?=C5=81ukasz=20Stelmach?= To: Krzysztof Kozlowski , robh+dt@kernel.org, Stephan Mueller , Herbert Xu , "David S . Miller" , Kukjin Kim , linux-crypto@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?=C5=81ukasz=20Stelmach?= , Marek Szyprowski , Bartlomiej Zolnierkiewicz Subject: [PATCH v2 3/4] crypto: exynos - Reseed PRNG after generating 2^16 random bytes Date: Mon, 11 Dec 2017 15:06:22 +0100 Message-id: <20171211140623.7673-4-l.stelmach@samsung.com> X-Mailer: git-send-email 2.11.0 In-reply-to: <20171211140623.7673-1-l.stelmach@samsung.com> In-reply-to: <20171205123558.31087-1-l.stelmach@samsung.com> Organization: Samsung R&D Institute Poland X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrFKsWRmVeSWpSXmKPExsWy7djP87rvJuhFGTxao2+xccZ6Vos551tY LLpfyVj0P37NbHH+/AZ2i5uHVjBa3L/3k8ni8q45bBYzzu9jslh75C67ReveI+wWU0+vZXHg 8fh05QqTx5aVN5k8th1Q9di0qpPNo2/LKkaPz5vkAtiiuGxSUnMyy1KL9O0SuDJWPvnLWrBG uOJy8wz2BsZn/F2MnBwSAiYSZ1+fZ4ewxSQu3FvP1sXIxSEksJRR4urnSSwQzmdGib0fpjLC dEw9PZ8NxBYSWMYosexqIYjNKyAo8WPyPaAGDg5mAXmJI5eyQcLMApoSW3evZ4eY84VRYtq2 6UwgCTYBR4n+pSdYQRIiAvuYJB5PBFnABdQBNPTgtpNgG4QFIiXWLdkIdh+LgKrEuQUn2CG2 WUm0TnrPCnGRvMSutotgNqeAtUTn8XY2CNtGYuHZGWA2v4CWxJqm62DvSAhMZ5dofnURqtlF Yu3EA1CvCUu8Or4FGhgyEp0dB5kgGvoZJQ7P/w6VmMIosXihA4RtLfFn1UQ2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qg0J7X4EKM0B4uSOG/vntWRQgLpiSWp2ampBalFMFkm Dk6pBsYpb+/+kOR72tO1eNWU929Dmu5/viThcupv8hz7Ltn/Vl1zbHKSS15b1p6yr6yIdMoz 3po4vWuBxYTEGYsfLEhVaVDTnt5WpGIo4sMf98mC11NG3/D22vaJO96l/X4Vr714xTO31wfC j7p80X8/3yHunbthlVp7WOmz7+ppJnkMVw/N3T3nz3slluKMREMt5qLiRADy/NrvrQIAAA== X-CMS-MailID: 20171211140638eucas1p239085a27ce0501beb8b42be94ed61b34 X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20171211140638eucas1p239085a27ce0501beb8b42be94ed61b34 X-RootMTR: 20171211140638eucas1p239085a27ce0501beb8b42be94ed61b34 References: <20171211140623.7673-1-l.stelmach@samsung.com> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Cc: Marek Szyprowski , Bartlomiej Zolnierkiewicz Reseed PRNG after reading 65 kB of randomness. Although this may reduce performance, in most cases the loss is not noticeable. Reseeding of a PRNG does not increase entropy, but it helps preventing backtracking the internal state of the device from its output sequence, and hence, prevents potential attacker from predicting numbers to be generated. Signed-off-by: Ɓukasz Stelmach Reviewed-by: Stephan Mueller --- drivers/crypto/exynos-rng.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/exynos-rng.c b/drivers/crypto/exynos-rng.c index 7d8f658480d3..c72a838f1932 100644 --- a/drivers/crypto/exynos-rng.c +++ b/drivers/crypto/exynos-rng.c @@ -55,12 +55,14 @@ enum exynos_prng_type { }; /* - * Driver re-seeds itself with generated random numbers to increase - * the randomness. + * Driver re-seeds itself with generated random numbers to hinder + * backtracking of the original seed. * * Time for next re-seed in ms. */ -#define EXYNOS_RNG_RESEED_TIME 100 +#define EXYNOS_RNG_RESEED_TIME 1000 +#define EXYNOS_RNG_RESEED_BYTES 65536 + /* * In polling mode, do not wait infinitely for the engine to finish the work. */ @@ -82,6 +84,8 @@ struct exynos_rng_dev { unsigned int seed_save_len; /* Time of last seeding in jiffies */ unsigned long last_seeding; + /* Bytes generated since last seeding */ + unsigned long bytes_seeding; }; static struct exynos_rng_dev *exynos_rng_dev; @@ -126,6 +130,7 @@ static int exynos_rng_set_seed(struct exynos_rng_dev *rng, } rng->last_seeding = jiffies; + rng->bytes_seeding = 0; return 0; } @@ -165,6 +170,7 @@ static int exynos_rng_get_random(struct exynos_rng_dev *rng, EXYNOS_RNG_STATUS); *read = min_t(size_t, dlen, EXYNOS_RNG_SEED_SIZE); memcpy_fromio(dst, rng->mem + EXYNOS_RNG_OUT_BASE, *read); + rng->bytes_seeding += *read; return 0; } @@ -178,7 +184,8 @@ static void exynos_rng_reseed(struct exynos_rng_dev *rng) unsigned int read = 0; u8 seed[EXYNOS_RNG_SEED_SIZE]; - if (time_before(now, next_seeding)) + if (time_before(now, next_seeding) && + rng->bytes_seeding < EXYNOS_RNG_RESEED_BYTES) return; if (exynos_rng_get_random(rng, seed, sizeof(seed), &read))