From: "Ard Biesheuvel" <ardb@kernel.org>
To: "Thorsten Blum" <thorsten.blum@linux.dev>,
"Herbert Xu" <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
"Nicolas Ferre" <nicolas.ferre@microchip.com>,
"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
"Claudiu Beznea" <claudiu.beznea@tuxon.dev>,
"Marek Behún" <kabel@kernel.org>,
"Linus Walleij" <linusw@kernel.org>
Cc: stable@vger.kernel.org, linux-crypto@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] crypto: atmel-sha204a - drop hwrng quality reduction for ATSHA204A
Date: Tue, 28 Apr 2026 07:58:39 +0200 [thread overview]
Message-ID: <2d42b1fc-b5d5-4dcb-8dc8-62580502f586@app.fastmail.com> (raw)
In-Reply-To: <20260427124030.315590-3-thorsten.blum@linux.dev>
Hi Thorsten,
On Mon, 27 Apr 2026, at 14:40, Thorsten Blum wrote:
> Commit 8006aff15516 ("crypto: atmel-sha204a - Set hwrng quality to
> lowest possible") reduced the hwrng quality to 1 based on a review by
> Bill Cox [1]. However, despite its title, the review only tested the
> ATSHA204, not the ATSHA204A.
>
> In the same thread, Atmel engineer Landon Cox wrote "this behavior has
> been eliminated entirely"[2] in the ATSHA204A and "this problem does not
> affect the ATECC108 or the ATECC108A (or the ATSHA204A)"[3].
>
> According to the official ATSHA204A datasheet [4], the device contains a
> high-quality hardware RNG that combines its output with an internal seed
> value stored in EEPROM or SRAM to generate random numbers. The device
> also implements all security functions using SHA-256, and the driver
> uses the chip's Random command in seed-update mode.
>
> Keep 'quality = 1' for ATSHA204, but drop the explicit hwrng quality
> reduction for ATSHA204A and fall back to the hwrng core default.
>
Interesting! Thanks for digging this up.
> [1]
> https://www.metzdowd.com/pipermail/cryptography/2014-December/023858.html
> [2]
> https://www.metzdowd.com/pipermail/cryptography/2014-December/023852.html
> [3]
> https://www.metzdowd.com/pipermail/cryptography/2014-December/023886.html
> [4]
> https://ww1.microchip.com/downloads/en/DeviceDoc/ATSHA204A-Data-Sheet-40002025A.pdf
>
> Fixes: 8006aff15516 ("crypto: atmel-sha204a - Set hwrng quality to
> lowest possible")
> Cc: stable@vger.kernel.org
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> drivers/crypto/atmel-sha204a.c | 40 ++++++++++++++++++----------------
> 1 file changed, 21 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/crypto/atmel-sha204a.c b/drivers/crypto/atmel-sha204a.c
> index dbb39ed0cea1..df69fb190e52 100644
> --- a/drivers/crypto/atmel-sha204a.c
> +++ b/drivers/crypto/atmel-sha204a.c
> @@ -19,6 +19,25 @@
> #include <linux/workqueue.h>
> #include "atmel-i2c.h"
>
> +enum atmel_sha204a_variant {
> + ATSHA204 = 1,
> + ATSHA204A,
> +};
> +
I agree that setting quality to '1' is only appropriate for the ATSHA204
but this looks a bit clunky to me.
Can we retain the comment here that you deleted below, and add
something like
static const unsigned short atsha204_quality = 1;
> +static const struct of_device_id atmel_sha204a_dt_ids[] __maybe_unused = {
> + { .compatible = "atmel,atsha204", .data = (void *)ATSHA204 },
> + { .compatible = "atmel,atsha204a", .data = (void *)ATSHA204A },
> + { /* sentinel */ }
> +};
> +MODULE_DEVICE_TABLE(of, atmel_sha204a_dt_ids);
> +
> +static const struct i2c_device_id atmel_sha204a_id[] = {
> + { .name = "atsha204", .driver_data = ATSHA204 },
> + { .name = "atsha204a", .driver_data = ATSHA204A },
> + { /* sentinel */ }
> +};
> +MODULE_DEVICE_TABLE(i2c, atmel_sha204a_id);
> +
Then, move these back to the old location, and point .data /
.driver_data to &atsha204_quality for atsha204 only.
> static void atmel_sha204a_rng_done(struct atmel_i2c_work_data *work_data,
> void *areq, int status)
> {
> @@ -171,11 +190,8 @@ static int atmel_sha204a_probe(struct i2c_client *client)
> i2c_priv->hwrng.name = dev_name(&client->dev);
> i2c_priv->hwrng.read = atmel_sha204a_rng_read;
>
> - /*
> - * According to review by Bill Cox [1], this HWRNG has very low
> entropy.
> - * [1]
> https://www.metzdowd.com/pipermail/cryptography/2014-December/023858.html
> - */
> - i2c_priv->hwrng.quality = 1;
> + if ((uintptr_t)i2c_get_match_data(client) == ATSHA204)
> + i2c_priv->hwrng.quality = 1;
>
Here you can override the field by dereferencing the match data if it
is non-NULL.
Alternatively, you could store the quality in the device_id structs
directly, but I think this is slightly more idiomatic.
> ret = devm_hwrng_register(&client->dev, &i2c_priv->hwrng);
> if (ret)
> @@ -202,20 +218,6 @@ static void atmel_sha204a_remove(struct i2c_client *client)
> kfree((void *)i2c_priv->hwrng.priv);
> }
>
> -static const struct of_device_id atmel_sha204a_dt_ids[] __maybe_unused = {
> - { .compatible = "atmel,atsha204", },
> - { .compatible = "atmel,atsha204a", },
> - { /* sentinel */ }
> -};
> -MODULE_DEVICE_TABLE(of, atmel_sha204a_dt_ids);
> -
> -static const struct i2c_device_id atmel_sha204a_id[] = {
> - { "atsha204" },
> - { "atsha204a" },
> - { /* sentinel */ }
> -};
> -MODULE_DEVICE_TABLE(i2c, atmel_sha204a_id);
> -
> static struct i2c_driver atmel_sha204a_driver = {
> .probe = atmel_sha204a_probe,
> .remove = atmel_sha204a_remove,
next prev parent reply other threads:[~2026-04-28 5:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-27 12:40 [PATCH] crypto: atmel-sha204a - drop hwrng quality reduction for ATSHA204A Thorsten Blum
2026-04-28 5:58 ` Ard Biesheuvel [this message]
2026-04-28 10:05 ` Thorsten Blum
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=2d42b1fc-b5d5-4dcb-8dc8-62580502f586@app.fastmail.com \
--to=ardb@kernel.org \
--cc=alexandre.belloni@bootlin.com \
--cc=claudiu.beznea@tuxon.dev \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=kabel@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nicolas.ferre@microchip.com \
--cc=stable@vger.kernel.org \
--cc=thorsten.blum@linux.dev \
/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