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: 19815 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f70.google.com (mail-yh0-f70.google.com [209.85.213.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1632B24687 for ; Mon, 9 Sep 2013 07:36:10 +0000 (UTC) Received: by mail-yh0-f70.google.com with SMTP id i72sf7321708yha.1 for ; Mon, 09 Sep 2013 00:36:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=mime-version:x-gm-message-state:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=LO5UxD+fb3dHRfQtHG0DLcE5E+8OkqERRT76VVqW4uE=; b=KwrMAeWK6nud2OMpqVtoN8hATggrHxdXtlmb+nzvzMhfVMjAPcXMY0I90ppExM0zh4 RC/TGCVAbptcXmLVxDaAWxLAG1xybZvC07yDhzO4HHLSh81uh4CkY8JhfK6EgZ4+h7dw 8XREkJjjhHIIdzpzNkhpfcGSopLOT47zU2IndrHVhfMa+jE1Is2L6RB4w+IEm/J4OTx4 HGam2zi7svWUVmoxwN9/3X22X94QM0PHIjDul7o2ftPjKz0j14PvB/xn6wp3MXMNgwsA tq3gAJM55GwzdFU47wOsWfhSPFfWQnrLYqjRP2Z8fEkwSiZ4WxkpZPVMjVW2tDUFgDFY vXGg== X-Received: by 10.236.26.202 with SMTP id c50mr5857793yha.14.1378712169561; Mon, 09 Sep 2013 00:36:09 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.2.166 with SMTP id 6ls356792qev.69.gmail; Mon, 09 Sep 2013 00:36:09 -0700 (PDT) X-Received: by 10.52.119.228 with SMTP id kx4mr13655016vdb.12.1378712169437; Mon, 09 Sep 2013 00:36:09 -0700 (PDT) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id ti4si2840453vec.137.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 09 Sep 2013 00:36:09 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id ia10so3612228vcb.20 for ; Mon, 09 Sep 2013 00:36:09 -0700 (PDT) X-Gm-Message-State: ALoCoQlCRRV1XciDy/Bl2rG4Z5T67V9Kynf3ECZijTy+t/hqCoHyFCgPWOMsHfN4/UDCzONkPnNp X-Received: by 10.58.137.167 with SMTP id qj7mr16023189veb.1.1378712169301; Mon, 09 Sep 2013 00:36:09 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp72848vcz; Mon, 9 Sep 2013 00:36:08 -0700 (PDT) X-Received: by 10.152.29.103 with SMTP id j7mr14876530lah.7.1378712167987; Mon, 09 Sep 2013 00:36:07 -0700 (PDT) Received: from mail-la0-f50.google.com (mail-la0-f50.google.com [209.85.215.50]) by mx.google.com with ESMTPS id b4si4360912lab.101.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 09 Sep 2013 00:36:07 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.215.50 is neither permitted nor denied by best guess record for domain of linus.walleij@linaro.org) client-ip=209.85.215.50; Received: by mail-la0-f50.google.com with SMTP id es20so4610642lab.37 for ; Mon, 09 Sep 2013 00:36:07 -0700 (PDT) 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 Cc: linux-arm-kernel@lists.infradead.org, Linus Walleij , Stephen Warren , Varun Wadekar , Neil Horman , linux-tegra@vger.kernel.org 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-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: linus.walleij@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 --- 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);