diff mbox

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

Message ID 20170929092106.24276-1-tudor.ambarus@microchip.com (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show

Commit Message

Tudor Ambarus Sept. 29, 2017, 9:21 a.m. UTC
p->key_size, p->p_size, p->g_size are all of unsigned int type.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 crypto/dh_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

David Howells Oct. 3, 2017, 9:06 a.m. UTC | #1
Tudor Ambarus <tudor.ambarus@microchip.com> wrote:

> -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
Tudor Ambarus Oct. 3, 2017, 4:08 p.m. UTC | #2
Hi, David,

On 10/03/2017 12:06 PM, David Howells wrote:
> Tudor Ambarus <tudor.ambarus@microchip.com> wrote:
> 
>> -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
Herbert Xu Oct. 12, 2017, 3:19 p.m. UTC | #3
On Fri, Sep 29, 2017 at 12:21:04PM +0300, Tudor Ambarus wrote:
> p->key_size, p->p_size, p->g_size are all of unsigned int type.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Patch applied.  Thanks.
diff mbox

Patch

diff --git a/crypto/dh_helper.c b/crypto/dh_helper.c
index 8ba8a3f..69869da 100644
--- a/crypto/dh_helper.c
+++ b/crypto/dh_helper.c
@@ -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;
 }