From patchwork Mon Sep 9 07:35:54 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 2859671 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9AB7ABF43F for ; Mon, 9 Sep 2013 07:36:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 56960203F4 for ; Mon, 9 Sep 2013 07:36:42 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 07DC9203E3 for ; Mon, 9 Sep 2013 07:36:41 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VIw1T-00050k-Fq; Mon, 09 Sep 2013 07:36:35 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VIw1R-0006bT-9D; Mon, 09 Sep 2013 07:36:33 +0000 Received: from mail-la0-f42.google.com ([209.85.215.42]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VIw1O-0006at-Ba for linux-arm-kernel@lists.infradead.org; Mon, 09 Sep 2013 07:36:31 +0000 Received: by mail-la0-f42.google.com with SMTP id ep20so4685154lab.29 for ; Mon, 09 Sep 2013 00:36:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=LO5UxD+fb3dHRfQtHG0DLcE5E+8OkqERRT76VVqW4uE=; b=BPx80b6Up6/Pt/CxrLGhIpntx0Xv698TzJUJj74PeyotWjcfKD3DKugslfW5je/Wnv zx1mbQyj/JpbJLKnIEzKoIAtpupcGbh5M1yLTrbtEkh3p0vsnR/7PY5x6D9l6PSxLKi+ Ogr8GiIvUsdlaFW5OZTfNo6UbwQ/8rgQbG1scW3eNUEN91swo6ZafXoB9u5miEkykyBO P0B6xzAXFjb9pf6HCuXmPKHjRaSPkt8M8SrLfcsNrCX1QoGJ5Rf+sobzBDvfJrK6hCea GalkCVdSqwrlpS3meaxRzN95P5s8mti46JglYpiGB/EuGr6ezm4KpwQwhn/VHqNBFIUe rwnQ== X-Gm-Message-State: ALoCoQlz2RlIf1tE5hjPhChqrL1lVeteDY/adsaF3pHkE0pNetqb/N3dbqKXquQ9Cogjas9gK9M5 X-Received: by 10.152.6.97 with SMTP id z1mr1217500laz.26.1378712167140; Mon, 09 Sep 2013 00:36:07 -0700 (PDT) Received: from localhost.localdomain ([85.235.11.236]) by mx.google.com with ESMTPSA id k6sm5537754lae.9.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 09 Sep 2013 00:36:06 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu Subject: [PATCH] crypto: tegra: use kernel entropy instead of ad-hoc Date: Mon, 9 Sep 2013 09:35:54 +0200 Message-Id: <1378712154-30602-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 1.8.3.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130909_033630_551849_64861661 X-CRM114-Status: GOOD ( 12.86 ) X-Spam-Score: -2.6 (--) Cc: Neil Horman , Stephen Warren , Linus Walleij , Varun Wadekar , linux-tegra@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 The way I read the Tegra AES RNG is that it has a homebrew algorithm for initializing the 128bit RNG using timespec and the unique chip ID. This looks like reinventing the (square) wheel, instead just grab 128bits from the kernel entropy pool where the time and (after another patch) chip unique ID is already mixed in. Incidentally this also gets rid of a rather ugly cross-dependence on the machine using an extern declaration. Cc: Stephen Warren Cc: Varun Wadekar Cc: Neil Horman Cc: linux-tegra@vger.kernel.org Signed-off-by: Linus Walleij Acked-by: Stephen Warren --- Only compile-tested as I don't have this platform. --- drivers/crypto/tegra-aes.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/drivers/crypto/tegra-aes.c b/drivers/crypto/tegra-aes.c index 2d58da9..7f42bfe 100644 --- a/drivers/crypto/tegra-aes.c +++ b/drivers/crypto/tegra-aes.c @@ -199,8 +199,6 @@ static void aes_workqueue_handler(struct work_struct *work); static DECLARE_WORK(aes_work, aes_workqueue_handler); static struct workqueue_struct *aes_wq; -extern unsigned long long tegra_chip_uid(void); - static inline u32 aes_readl(struct tegra_aes_dev *dd, u32 offset) { return readl(dd->io_base + offset); @@ -713,9 +711,8 @@ static int tegra_aes_rng_reset(struct crypto_rng *tfm, u8 *seed, struct tegra_aes_dev *dd = aes_dev; struct tegra_aes_ctx *ctx = &rng_ctx; struct tegra_aes_slot *key_slot; - struct timespec ts; int ret = 0; - u64 nsec, tmp[2]; + u8 tmp[16]; /* 16 bytes = 128 bits of entropy */ u8 *dt; if (!ctx || !dd) { @@ -778,14 +775,8 @@ static int tegra_aes_rng_reset(struct crypto_rng *tfm, u8 *seed, if (dd->ivlen >= (2 * DEFAULT_RNG_BLK_SZ + AES_KEYSIZE_128)) { dt = dd->iv + DEFAULT_RNG_BLK_SZ + AES_KEYSIZE_128; } else { - getnstimeofday(&ts); - nsec = timespec_to_ns(&ts); - do_div(nsec, 1000); - nsec ^= dd->ctr << 56; - dd->ctr++; - tmp[0] = nsec; - tmp[1] = tegra_chip_uid(); - dt = (u8 *)tmp; + get_random_bytes(tmp, sizeof(tmp)); + dt = tmp; } memcpy(dd->dt, dt, DEFAULT_RNG_BLK_SZ);