From patchwork Tue Dec 5 12:35:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lukasz Stelmach X-Patchwork-Id: 10092817 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 CE1CC6035E for ; Tue, 5 Dec 2017 12:37:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D174629510 for ; Tue, 5 Dec 2017 12:37:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C60AB29566; Tue, 5 Dec 2017 12:37:04 +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 722C529511 for ; Tue, 5 Dec 2017 12:37:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752391AbdLEMgw (ORCPT ); Tue, 5 Dec 2017 07:36:52 -0500 Received: from mailout2.w1.samsung.com ([210.118.77.12]:39920 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752712AbdLEMgH (ORCPT ); Tue, 5 Dec 2017 07:36:07 -0500 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20171205123605euoutp028cb4e6674836b1f43a3cd2f14b961dad~9ZiaAm4-21278112781euoutp02a; Tue, 5 Dec 2017 12:36:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20171205123605euoutp028cb4e6674836b1f43a3cd2f14b961dad~9ZiaAm4-21278112781euoutp02a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1512477365; bh=r6O6zD114Xhv86wBvQvB7MBgwW9GZWvmXR16/e6zoYo=; h=From:To:Cc:Subject:Date:In-reply-to:References:From; b=Eqq31jgBjjE4ozx+aRdWTqUpbBR9Lsb3+8kda51cWnSj1Bm6SrFRmB1O5Et9OUbBj 93Tggdrszlho4KKBqmrsyqKJqmSRXkJHd+RyIBT3QbPl5pk23yoEkVUo/DX2B69Y9G CP6ealTYdNB1Q3ODu6hN1jT0tb5Lj0lyJlF2P45U= Received: from eusmges3.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20171205123604eucas1p154e320fdcc6bb0f5680a154528e06e38~9ZiZVVtB31684916849eucas1p1j; Tue, 5 Dec 2017 12:36:04 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3.samsung.com (EUCPMTA) with SMTP id F8.16.12867.4B2962A5; Tue, 5 Dec 2017 12:36:04 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20171205123604eucas1p2a6a2738e3cf1f9c300e8d128362429ed~9ZiYsJ9AZ0553505535eucas1p2W; Tue, 5 Dec 2017 12:36:04 +0000 (GMT) X-AuditID: cbfec7f2-f793b6d000003243-5e-5a2692b45c26 Received: from eusync3.samsung.com ( [203.254.199.213]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id DF.A7.18832.3B2962A5; Tue, 5 Dec 2017 12:36:03 +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 eusync3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0P0H00ML3N038SC0@eusync3.samsung.com>; Tue, 05 Dec 2017 12:36:03 +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?= , m.szyprowski@samsung.com, b.zolnierkie@samsung.com Subject: [PATCH 3/3] crypto: exynos - Reseed PRNG after generating 2^16 random bytes Date: Tue, 05 Dec 2017 13:35:58 +0100 Message-id: <20171205123558.31087-4-l.stelmach@samsung.com> X-Mailer: git-send-email 2.11.0 In-reply-to: <20171205123558.31087-1-l.stelmach@samsung.com> Organization: Samsung R&D Institute Poland X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrDKsWRmVeSWpSXmKPExsWy7djPc7pbJqlFGTx/J2WxccZ6Vos551tY LLpfyVj0P37NbHH+/AZ2i5uHVjBa3L/3k8ni8q45bBYzzu9jslh75C67ReveI+wWU0+vZXHg 8fh05QqTx5aVN5k8th1Q9di0qpPNo2/LKkaPz5vkAtiiuGxSUnMyy1KL9O0SuDI2bvjOWrBT sGLlrF2MDYy/ebsYOTkkBEwkGl/PYoGwxSQu3FvP1sXIxSEksJRR4v+zbYwQzmdGid8bpzB1 MXKAdZx54QARX8YoceFqExNIN6+AoMSPyfdYQGqYBeQljlzKBgkzC2hKbN29nh2i/gujxN5P /8C2sQk4SvQvPcEKkhAR2Msk8ebsXhaIjlKJs/NuM4MMEhYIkzjVnQMSZhFQlbh1vQ1ql7XE 7yNLmSCulpfY1XaRFcTmFLCRWHh2BhuIzS+gJbGm6ToLyHwJgf9sEm0nL0E1uEh8mzqLEcIW lnh1fAs7hC0j0dlxkAmioZ9R4vD871CJKYwSixc6QNjWEn9WTWSDOJRPYtK26cyQUOGV6GgT gijxkGh/+pMNwnaUeHl/CQvE90AzZz5rY5r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vPbj0b0xXBEs3g8LEQlG5Q9xbmnVvezdq5Zj9 cp/essaxmmuSyIf7V2bMt5UQZ64RMmtfY/47eE9S+8/YCHW+LWyuNxb23mKQMXiyfF9e3e3i VkvlzrivhhP6jvWV9LsqsRRnJBpqMRcVJwIA+tFgdJICAAA= X-CMS-MailID: 20171205123604eucas1p2a6a2738e3cf1f9c300e8d128362429ed X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20171205123604eucas1p2a6a2738e3cf1f9c300e8d128362429ed X-RootMTR: 20171205123604eucas1p2a6a2738e3cf1f9c300e8d128362429ed References: <20171205123558.31087-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 Reseed PRNG after reading 65 kB of randomness. Although this may reduce performance, in most casese the loss is not noticable. Signed-off-by: Ɓukasz Stelmach Reviewed-by: Stephan Mueller --- drivers/crypto/exynos-rng.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/exynos-rng.c b/drivers/crypto/exynos-rng.c index 002e9d2a83cc..0bf07a655813 100644 --- a/drivers/crypto/exynos-rng.c +++ b/drivers/crypto/exynos-rng.c @@ -54,12 +54,15 @@ 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. */ @@ -81,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; @@ -125,6 +130,7 @@ static int exynos_rng_set_seed(struct exynos_rng_dev *rng, } rng->last_seeding = jiffies; + rng->bytes_seeding = 0; return 0; } @@ -166,6 +172,8 @@ static int exynos_rng_get_random(struct exynos_rng_dev *rng, memcpy_fromio(dst, rng->mem + EXYNOS_RNG_OUT_BASE, *read); return 0; + + } /* Re-seed itself from time to time */ @@ -177,7 +185,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)) @@ -206,6 +215,7 @@ static int exynos_rng_generate(struct crypto_rng *tfm, dlen -= read; dst += read; + rng->bytes_seeding += read; exynos_rng_reseed(rng); } while (dlen > 0);