Skip to contentSkip to conversation

crypto: dh_helper - return unsigned int for dh_data_size()

PATCH In review Tudor Ambarus 3 participants 7 messages Sep 29, 2017 – Oct 12, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 crypto: dh_helper - return unsigned int for dh_data_size()

p->key_size, p->p_size, p->g_size are all of unsigned int type.

---
 crypto/dh_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/dh_helper.c +1 -1
index 8ba8a3f..69869da 100644
@@ -28,7 +28,7 @@ static inline const u8 *dh_unpack_data(void *dst, const void *src, size_t size)
 	return src + size;
 }
 
-static inline int dh_data_size(const struct dh *p)
+static inline unsigned int dh_data_size(const struct dh *p)
 {
 	return p->key_size + p->p_size + p->g_size;
 }
Signature · 1 line
2.9.4
#1 lore raw

PATCH 2/3 crypto: dh_helper - return unsigned value for crypto_dh_key_len()

DH_KPP_SECRET_MIN_SIZE and dh_data_size() are both returning unsigned values.

---
 crypto/dh_helper.c  | 2 +-
 include/crypto/dh.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
crypto/dh_helper.c +1 -1
index 69869da..a413b31 100644
@@ -33,7 +33,7 @@ static inline unsigned int dh_data_size(const struct dh *p)
 	return p->key_size + p->p_size + p->g_size;
 }
 
-int crypto_dh_key_len(const struct dh *p)
+unsigned int crypto_dh_key_len(const struct dh *p)
 {
 	return DH_KPP_SECRET_MIN_SIZE + dh_data_size(p);
 }
include/crypto/dh.h +1 -1
index f638998..71e1bb2 100644
@@ -53,7 +53,7 @@ struct dh {
  *
  * Return: size of the key in bytes
  */
-int crypto_dh_key_len(const struct dh *params);
+unsigned int crypto_dh_key_len(const struct dh *params);
 
 /**
  * crypto_dh_encode_key() - encode the private key
Signature · 1 line
2.9.4
#3 lore raw

PATCH 3/3 KEYS: dh - make some length variables unsigned

In reply to Tudor Ambarus

Both crypto_kpp_maxsize() and crypto_dh_key_len() are returning unsigned integers.

---
 security/keys/dh.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
security/keys/dh.c +2 -2
index d1ea9f3..89e9255 100644
@@ -242,8 +242,8 @@ long __keyctl_dh_compute(struct keyctl_dh_params __user *params,
 {
 	long ret;
 	ssize_t dlen;
-	int secretlen;
-	int outlen;
+	unsigned int secretlen;
+	unsigned int outlen;
 	struct keyctl_dh_params pcopy;
 	struct dh dh_inputs;
 	struct scatterlist outsg;
Signature · 1 line
2.9.4
maintainer
#4 lore raw
In reply to Tudor Ambarus

crypto/dh_helper.c static inline const u8 *dh_unpack_data(void *dst, const void *src, size_t size) · line 34

Quoted 5 lines · Tudor Ambarus
crypto/dh_helper.c +1 -1
-static inline int dh_data_size(const struct dh *p)
+static inline unsigned int dh_data_size(const struct dh *p)
 {
 	return p->key_size + p->p_size + p->g_size;
 }

If this is a problem, do you need to do range checking?

David

#5 lore raw

Hi, David,

Quoted 9 lines · David Howells

crypto/dh_helper.c static inline const u8 *dh_unpack_data(void *dst, const void *src, size_t size) · line 34

Quoted 5 lines · Tudor Ambarus
crypto/dh_helper.c +1 -1
-static inline int dh_data_size(const struct dh *p)
+static inline unsigned int dh_data_size(const struct dh *p)
  {
  	return p->key_size + p->p_size + p->g_size;
  }

If this is a problem, do you need to do range checking?

The algorithm does not impose any constraint in this direction, as far as I'm aware of.

It's unnatural to return a signed integer in a function which just sums unsigned integers. No checking is needed, the function should return the unsigned result.

Cheers,
ta

maintainer
#2 lore raw

Re: [PATCH 2/3] crypto: dh_helper - return unsigned value for crypto_dh_key_len()

In reply to Tudor Ambarus
Quoted 4 lines · Tudor Ambarus

DH_KPP_SECRET_MIN_SIZE and dh_data_size() are both returning unsigned values.

Patch applied. 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