From: Stephan Mueller <smueller@chronox.de>
To: PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
Cc: herbert@gondor.apana.org.au, robh+dt@kernel.org,
mark.rutland@arm.com, ralf@linux-mips.org,
mturquette@baylibre.com, sboyd@codeaurora.org,
davem@davemloft.net, paul@crapouillou.net,
linux-crypto@vger.kernel.org, linux-mips@linux-mips.org
Subject: Re: [PATCH 3/6] crypto: jz4780-rng: Add Ingenic JZ4780 hardware PRNG driver
Date: Thu, 17 Aug 2017 20:52:49 +0200 [thread overview]
Message-ID: <20325029.4QLNKKN8OS@tauon.chronox.de> (raw)
In-Reply-To: <20170817182520.20102-4-prasannatsmkumar@gmail.com>
Am Donnerstag, 17. August 2017, 20:25:17 CEST schrieb PrasannaKumar
Muralidharan:
Hi PrasannaKumar,
> +
> +static int jz4780_rng_generate(struct crypto_rng *tfm,
> + const u8 *src, unsigned int slen,
> + u8 *dst, unsigned int dlen)
> +{
> + struct jz4780_rng_ctx *ctx = crypto_rng_ctx(tfm);
> + struct jz4780_rng *rng = ctx->rng;
> + u32 data;
> +
> + /*
> + * JZ4780 Programmers manual says the RNG should not run continuously
> + * for more than 1s. So enable RNG, read data and disable it.
> + * NOTE: No issue was observed with MIPS creator CI20 board even when
> + * RNG ran continuously for longer periods. This is just a precaution.
> + *
> + * A delay is required so that the current RNG data is not bit shifted
> + * version of previous RNG data which could happen if random data is
> + * read continuously from this device.
> + */
> + jz4780_rng_writel(rng, 1, REG_RNG_CTRL);
> + do {
> + data = jz4780_rng_readl(rng, REG_RNG_DATA);
> + memcpy((void *)dst, (void *)&data, 4);
How do you know that dst is a multiple of 4 bytes? When dlen is only 3, you
overflow the buffer.
> + dlen -= 4;
> + dst += 4;
> + udelay(20);
> + } while (dlen >= 4);
> +
> + if (dlen > 0) {
> + data = jz4780_rng_readl(rng, REG_RNG_DATA);
> + memcpy((void *)dst, (void *)&data, dlen);
> + }
> + jz4780_rng_writel(rng, 0, REG_RNG_CTRL);
> +
> + return 0;
> +}
Ciao
Stephan
next prev parent reply other threads:[~2017-08-17 18:52 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-17 18:25 [PATCH 0/6] crypto: Add driver for JZ4780 PRNG PrasannaKumar Muralidharan
2017-08-17 18:25 ` [PATCH 1/6] crypto: jz4780-rng: Add devicetree bindings for RNG in JZ4780 SoC PrasannaKumar Muralidharan
2017-08-17 18:25 ` [PATCH 2/6] crypto: jz4780-rng: Make ingenic CGU driver use syscon PrasannaKumar Muralidharan
2017-08-18 20:48 ` Paul Burton
2017-08-20 16:12 ` PrasannaKumar Muralidharan
2017-08-21 16:04 ` Paul Burton
2017-08-17 18:25 ` [PATCH 3/6] crypto: jz4780-rng: Add Ingenic JZ4780 hardware PRNG driver PrasannaKumar Muralidharan
2017-08-17 18:52 ` Stephan Mueller [this message]
2017-08-18 14:06 ` PrasannaKumar Muralidharan
2017-08-17 18:25 ` [PATCH 4/6] crypto: jz4780-rng: Add RNG node to jz4780.dtsi PrasannaKumar Muralidharan
2017-08-17 18:25 ` [PATCH 5/6] crypto: jz4780-rng: Add myself as mainatainer for JZ4780 PRNG driver PrasannaKumar Muralidharan
2017-08-17 18:25 ` [PATCH 6/6] crypto: jz4780-rng: Enable PRNG support in CI20 defconfig PrasannaKumar Muralidharan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20325029.4QLNKKN8OS@tauon.chronox.de \
--to=smueller@chronox.de \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-mips@linux-mips.org \
--cc=mark.rutland@arm.com \
--cc=mturquette@baylibre.com \
--cc=paul@crapouillou.net \
--cc=prasannatsmkumar@gmail.com \
--cc=ralf@linux-mips.org \
--cc=robh+dt@kernel.org \
--cc=sboyd@codeaurora.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox