Skip to content

Commit

Permalink
crypto: tegra - use kernel entropy instead of ad-hoc
Browse files Browse the repository at this point in the history
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: Varun Wadekar <vwadekar@nvidia.com>
Cc: Neil Horman <nhorman@tuxdriver.com>
Cc: linux-tegra@vger.kernel.org
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
  • Loading branch information
Linus Walleij authored and Herbert Xu committed Sep 13, 2013
1 parent a44bc80 commit f5b38c5
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions drivers/crypto/tegra-aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit f5b38c5

Please sign in to comment.