Skip to contentSkip to conversation

crypto: hmac - Improve local variable types

PATCH In review Thorsten Blum 2 participants 2 messages Sep 24, 2024 – Oct 5, 2024 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: hmac - Improve local variable types

Since crypto_shash_blocksize(), crypto_shash_digestsize(), and crypto_shash_statesize() return an unsigned int, also use unsigned int for the local variables.

---
 crypto/hmac.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
crypto/hmac.c +7 -7
index 7cec25ff9889..6ab7ce4cb930 100644
@@ -31,9 +31,9 @@ struct hmac_ctx {
 static int hmac_setkey(struct crypto_shash *parent,
 		       const u8 *inkey, unsigned int keylen)
 {
-	int bs = crypto_shash_blocksize(parent);
-	int ds = crypto_shash_digestsize(parent);
-	int ss = crypto_shash_statesize(parent);
+	unsigned int bs = crypto_shash_blocksize(parent);
+	unsigned int ds = crypto_shash_digestsize(parent);
+	unsigned int ss = crypto_shash_statesize(parent);
 	struct hmac_ctx *tctx = crypto_shash_ctx(parent);
 	struct crypto_shash *hash = tctx->hash;
 	u8 *ipad = &tctx->pads[0];
@@ -108,8 +108,8 @@ static int hmac_update(struct shash_desc *pdesc,
 static int hmac_final(struct shash_desc *pdesc, u8 *out)
 {
 	struct crypto_shash *parent = pdesc->tfm;
-	int ds = crypto_shash_digestsize(parent);
-	int ss = crypto_shash_statesize(parent);
+	unsigned int ds = crypto_shash_digestsize(parent);
+	unsigned int ss = crypto_shash_statesize(parent);
 	const struct hmac_ctx *tctx = crypto_shash_ctx(parent);
 	const u8 *opad = &tctx->pads[ss];
 	struct shash_desc *desc = shash_desc_ctx(pdesc);
@@ -124,8 +124,8 @@ static int hmac_finup(struct shash_desc *pdesc, const u8 *data,
 {
 
 	struct crypto_shash *parent = pdesc->tfm;
-	int ds = crypto_shash_digestsize(parent);
-	int ss = crypto_shash_statesize(parent);
+	unsigned int ds = crypto_shash_digestsize(parent);
+	unsigned int ss = crypto_shash_statesize(parent);
 	const struct hmac_ctx *tctx = crypto_shash_ctx(parent);
 	const u8 *opad = &tctx->pads[ss];
 	struct shash_desc *desc = shash_desc_ctx(pdesc);
Signature · 1 line
2.46.1
maintainer
#1 lore raw
Quoted 14 lines · Thorsten Blum

Since crypto_shash_blocksize(), crypto_shash_digestsize(), and crypto_shash_statesize() return an unsigned int, also use unsigned int for the local variables.

---
 crypto/hmac.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
crypto/hmac.c +0 -0
index 7cec25ff9889..6ab7ce4cb930 100644

crypto/hmac.c struct hmac_ctx { · line 36

Quoted 9 lines
crypto/hmac.c +3 -3
@@ -31,9 +31,9 @@ struct hmac_ctx {
 static int hmac_setkey(struct crypto_shash *parent,
 		       const u8 *inkey, unsigned int keylen)
 {
-	int bs = crypto_shash_blocksize(parent);
-	int ds = crypto_shash_digestsize(parent);
-	int ss = crypto_shash_statesize(parent);
+	unsigned int bs = crypto_shash_blocksize(parent);
+	unsigned int ds = crypto_shash_digestsize(parent);
+	unsigned int ss = crypto_shash_statesize(parent);

These values are all capped by the API. So I don't think this churn is worth it.

Thanks,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt