mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Subject: [PATCH 3/5] public-keys: rsa: allow struct public_key to be const
Date: Mon, 20 Oct 2025 13:31:00 +0200	[thread overview]
Message-ID: <20251020-public-keys-const-v1-3-301de7918b06@pengutronix.de> (raw)
In-Reply-To: <20251020-public-keys-const-v1-0-301de7918b06@pengutronix.de>

The struct public_key fields will become const in the next step. Prepare
for this by rearranging rsa_of_read_key(): instead of assigning fields
to struct public_key and struct rsa_public_key and modifying them
afterwards, assign the initialized data to the (in future const) fields.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 crypto/rsa.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/crypto/rsa.c b/crypto/rsa.c
index 13b6553c950b033bd8940b0279bfb419f08b052a..e4fc980f9187b49511d5b1a8e68d488944d9b483 100644
--- a/crypto/rsa.c
+++ b/crypto/rsa.c
@@ -384,6 +384,7 @@ static void rsa_convert_big_endian(uint32_t *dst, const uint32_t *src, int len)
 struct public_key *rsa_of_read_key(struct device_node *node)
 {
 	const void *modulus, *rr;
+	void *brr, *bmodulus;
 	const uint64_t *public_exponent;
 	int length;
 	struct public_key *key;
@@ -394,7 +395,8 @@ struct public_key *rsa_of_read_key(struct device_node *node)
 		return ERR_PTR(-EINVAL);
 
 	key = xzalloc(sizeof(*key));
-	rsa = key->rsa = xzalloc(sizeof(*rsa));
+	rsa = xzalloc(sizeof(*rsa));
+	key->rsa = rsa;
 
 	key->key_name_hint = xstrdup(node->name + 4);
 
@@ -426,11 +428,14 @@ struct public_key *rsa_of_read_key(struct device_node *node)
 
 	rsa->len /= sizeof(uint32_t) * 8;
 
-	rsa->modulus = xzalloc(RSA_MAX_KEY_BITS / 8);
-	rsa->rr = xzalloc(RSA_MAX_KEY_BITS / 8);
+	bmodulus = xzalloc(RSA_MAX_KEY_BITS / 8);
+	brr = xzalloc(RSA_MAX_KEY_BITS / 8);
 
-	rsa_convert_big_endian(rsa->modulus, modulus, rsa->len);
-	rsa_convert_big_endian(rsa->rr, rr, rsa->len);
+	rsa_convert_big_endian(bmodulus, modulus, rsa->len);
+	rsa->modulus = bmodulus;
+
+	rsa_convert_big_endian(brr, rr, rsa->len);
+	rsa->rr = brr;
 
 	err = 0;
 out:

-- 
2.47.3




  parent reply	other threads:[~2025-10-20 12:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-20 11:30 [PATCH 0/5] public_keys: make const Sascha Hauer
2025-10-20 11:30 ` [PATCH 1/5] public-keys: ecdsa: remove list in ecdsa keys Sascha Hauer
2025-10-20 11:30 ` [PATCH 2/5] public-keys: move list out of struct public_key Sascha Hauer
2025-10-20 11:31 ` Sascha Hauer [this message]
2025-10-20 11:31 ` [PATCH 4/5] public-keys: rsa: remove unused functions Sascha Hauer
2025-10-20 11:31 ` [PATCH 5/5] public-keys: make const Sascha Hauer

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=20251020-public-keys-const-v1-3-301de7918b06@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.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