public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: SESA644425 <giojahermann@gmail.com>
To: sjg@chromium.org
Cc: gioja.hermann@non.se.com, mr.nuke.me@gmail.com,
	jamin_lin@aspeedtech.com, xypron.glpk@gmx.de,
	philippe.reynes@softathome.com, thomas.perrot@bootlin.com,
	u-boot@lists.denx.de, giojahermann@gmail.com
Subject: [PATCH 1/3] lib: rsa: Fix const-correctness of rsassa_pss functions
Date: Wed,  9 Mar 2022 01:27:15 -0800	[thread overview]
Message-ID: <20220309092717.4203-2-gioja.hermann@non.se.com> (raw)
In-Reply-To: <20220309092717.4203-1-gioja.hermann@non.se.com>

Prior to introduction of modifications in rsassa_pss functions
related to padding verification, doing a pass to update
const-correctness in targeted functions to comply with
coding-rules and avoid const-cast

Signed-off-by: SESA644425 <gioja.hermann@non.se.com>
---
Despite checkpath.pl recommendation, it is not possible to use u8 instead
of uint8_t. Proceeding with u8 breaks build with error: unknown type name u8
 include/image.h      |  2 +-
 include/u-boot/rsa.h |  4 ++--
 lib/rsa/rsa-verify.c | 14 +++++++-------
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/include/image.h b/include/image.h
index 97e5f2eb24..bea93118f8 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1291,7 +1291,7 @@ ll_entry_declare(struct crypto_algo, __name, cryptos)
 struct padding_algo {
 	const char *name;
 	int (*verify)(struct image_sign_info *info,
-		      uint8_t *pad, int pad_len,
+		      const uint8_t *pad, int pad_len,
 		      const uint8_t *hash, int hash_len);
 };
 
diff --git a/include/u-boot/rsa.h b/include/u-boot/rsa.h
index b9634e38d9..085363eb1e 100644
--- a/include/u-boot/rsa.h
+++ b/include/u-boot/rsa.h
@@ -101,11 +101,11 @@ int rsa_verify_with_pkey(struct image_sign_info *info,
 			 const void *hash, uint8_t *sig, uint sig_len);
 
 int padding_pkcs_15_verify(struct image_sign_info *info,
-			   uint8_t *msg, int msg_len,
+			   const uint8_t *msg, int msg_len,
 			   const uint8_t *hash, int hash_len);
 
 int padding_pss_verify(struct image_sign_info *info,
-		       uint8_t *msg, int msg_len,
+		       const uint8_t *msg, int msg_len,
 		       const uint8_t *hash, int hash_len);
 
 #define RSA_DEFAULT_PADDING_NAME		"pkcs-1.5"
diff --git a/lib/rsa/rsa-verify.c b/lib/rsa/rsa-verify.c
index 112664059c..c2c7248f90 100644
--- a/lib/rsa/rsa-verify.c
+++ b/lib/rsa/rsa-verify.c
@@ -73,7 +73,7 @@ static int rsa_verify_padding(const uint8_t *msg, const int pad_len,
 }
 
 int padding_pkcs_15_verify(struct image_sign_info *info,
-			   uint8_t *msg, int msg_len,
+			   const uint8_t *msg, int msg_len,
 			   const uint8_t *hash, int hash_len)
 {
 	struct checksum_algo *checksum = info->checksum;
@@ -125,7 +125,7 @@ static void u32_i2osp(uint32_t val, uint8_t *buf)
  * Return: 0 if the octet string was correctly generated, others on error
  */
 static int mask_generation_function1(struct checksum_algo *checksum,
-				     uint8_t *seed, int seed_len,
+				     const uint8_t *seed, int seed_len,
 				     uint8_t *output, int output_len)
 {
 	struct image_region region[2];
@@ -176,9 +176,9 @@ out:
 }
 
 static int compute_hash_prime(struct checksum_algo *checksum,
-			      uint8_t *pad, int pad_len,
-			      uint8_t *hash, int hash_len,
-			      uint8_t *salt, int salt_len,
+			      const uint8_t *pad, int pad_len,
+			      const uint8_t *hash, int hash_len,
+			      const uint8_t *salt, int salt_len,
 			      uint8_t *hprime)
 {
 	struct image_region region[3];
@@ -215,7 +215,7 @@ out:
  * @hash_len:	Length of the hash
  */
 int padding_pss_verify(struct image_sign_info *info,
-		       uint8_t *msg, int msg_len,
+		       const uint8_t *msg, int msg_len,
 		       const uint8_t *hash, int hash_len)
 {
 	uint8_t *masked_db = NULL;
@@ -287,7 +287,7 @@ int padding_pss_verify(struct image_sign_info *info,
 
 	/* step 12 & 13 */
 	compute_hash_prime(checksum, pad_zero, 8,
-			   (uint8_t *)hash, hash_len,
+			   hash, hash_len,
 			   salt, salt_len, hprime);
 
 	/* step 14 */
-- 
2.25.1


  reply	other threads:[~2022-03-09 13:57 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-09  9:27 [PATCH 0/3] Support any-salt for padding pss verification SESA644425
2022-03-09  9:27 ` SESA644425 [this message]
2022-03-12  2:43   ` [PATCH 1/3] lib: rsa: Fix const-correctness of rsassa_pss functions Simon Glass
2022-04-11 20:14   ` Tom Rini
2022-03-09  9:27 ` [PATCH 2/3] lib: rsa: Leverage existing data buffer instead of systematic copy SESA644425
2022-03-12  2:43   ` Simon Glass
2022-04-11 20:14   ` Tom Rini
2022-03-09  9:27 ` [PATCH 3/3] lib: rsa: Update function padding_pss_verify (any-salt) SESA644425
2022-03-12  2:43   ` Simon Glass
2022-04-11 20:14   ` Tom Rini

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=20220309092717.4203-2-gioja.hermann@non.se.com \
    --to=giojahermann@gmail.com \
    --cc=gioja.hermann@non.se.com \
    --cc=jamin_lin@aspeedtech.com \
    --cc=mr.nuke.me@gmail.com \
    --cc=philippe.reynes@softathome.com \
    --cc=sjg@chromium.org \
    --cc=thomas.perrot@bootlin.com \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /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