linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] crypto: sm3 - use the more precise type u32 instead of unsigned int
@ 2021-03-26  2:21 Tianjia Zhang
  2021-03-26  8:59 ` Ard Biesheuvel
  2021-03-26  9:38 ` Gilad Ben-Yossef
  0 siblings, 2 replies; 4+ messages in thread
From: Tianjia Zhang @ 2021-03-26  2:21 UTC (permalink / raw)
  To: Herbert Xu, David S. Miller, Gilad Ben-Yossef, Eric Biggers,
	Mimi Zohar, linux-crypto, linux-kernel, Jia Zhang
  Cc: Tianjia Zhang

In the process of calculating the hash, use the more accurate type
'u32' instead of the original 'unsigned int' to avoid ambiguity.

Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
---
 crypto/sm3_generic.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/crypto/sm3_generic.c b/crypto/sm3_generic.c
index 193c4584bd00..562e96f92f64 100644
--- a/crypto/sm3_generic.c
+++ b/crypto/sm3_generic.c
@@ -36,17 +36,17 @@ static inline u32 p1(u32 x)
 	return x ^ rol32(x, 15) ^ rol32(x, 23);
 }
 
-static inline u32 ff(unsigned int n, u32 a, u32 b, u32 c)
+static inline u32 ff(u32 n, u32 a, u32 b, u32 c)
 {
 	return (n < 16) ? (a ^ b ^ c) : ((a & b) | (a & c) | (b & c));
 }
 
-static inline u32 gg(unsigned int n, u32 e, u32 f, u32 g)
+static inline u32 gg(u32 n, u32 e, u32 f, u32 g)
 {
 	return (n < 16) ? (e ^ f ^ g) : ((e & f) | ((~e) & g));
 }
 
-static inline u32 t(unsigned int n)
+static inline u32 t(u32 n)
 {
 	return (n < 16) ? SM3_T1 : SM3_T2;
 }
@@ -54,7 +54,7 @@ static inline u32 t(unsigned int n)
 static void sm3_expand(u32 *t, u32 *w, u32 *wt)
 {
 	int i;
-	unsigned int tmp;
+	u32 tmp;
 
 	/* load the input */
 	for (i = 0; i <= 15; i++)
@@ -123,8 +123,8 @@ static void sm3_compress(u32 *w, u32 *wt, u32 *m)
 
 static void sm3_transform(struct sm3_state *sst, u8 const *src)
 {
-	unsigned int w[68];
-	unsigned int wt[64];
+	u32 w[68];
+	u32 wt[64];
 
 	sm3_expand((u32 *)src, w, wt);
 	sm3_compress(w, wt, sst->state);
-- 
2.19.1.3.ge56e4f7


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] crypto: sm3 - use the more precise type u32 instead of unsigned int
  2021-03-26  2:21 [PATCH] crypto: sm3 - use the more precise type u32 instead of unsigned int Tianjia Zhang
@ 2021-03-26  8:59 ` Ard Biesheuvel
  2021-03-26  9:38 ` Gilad Ben-Yossef
  1 sibling, 0 replies; 4+ messages in thread
From: Ard Biesheuvel @ 2021-03-26  8:59 UTC (permalink / raw)
  To: Tianjia Zhang
  Cc: Herbert Xu, David S. Miller, Gilad Ben-Yossef, Eric Biggers,
	Mimi Zohar, Linux Crypto Mailing List, Linux Kernel Mailing List,
	Jia Zhang

On Fri, 26 Mar 2021 at 03:22, Tianjia Zhang
<tianjia.zhang@linux.alibaba.com> wrote:
>
> In the process of calculating the hash, use the more accurate type
> 'u32' instead of the original 'unsigned int' to avoid ambiguity.
>
> Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>

I don't see the point of this patch. u32 and unsigned int are always
the same type, regardless of architecture.


> ---
>  crypto/sm3_generic.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/crypto/sm3_generic.c b/crypto/sm3_generic.c
> index 193c4584bd00..562e96f92f64 100644
> --- a/crypto/sm3_generic.c
> +++ b/crypto/sm3_generic.c
> @@ -36,17 +36,17 @@ static inline u32 p1(u32 x)
>         return x ^ rol32(x, 15) ^ rol32(x, 23);
>  }
>
> -static inline u32 ff(unsigned int n, u32 a, u32 b, u32 c)
> +static inline u32 ff(u32 n, u32 a, u32 b, u32 c)
>  {
>         return (n < 16) ? (a ^ b ^ c) : ((a & b) | (a & c) | (b & c));
>  }
>
> -static inline u32 gg(unsigned int n, u32 e, u32 f, u32 g)
> +static inline u32 gg(u32 n, u32 e, u32 f, u32 g)
>  {
>         return (n < 16) ? (e ^ f ^ g) : ((e & f) | ((~e) & g));
>  }
>
> -static inline u32 t(unsigned int n)
> +static inline u32 t(u32 n)
>  {
>         return (n < 16) ? SM3_T1 : SM3_T2;
>  }
> @@ -54,7 +54,7 @@ static inline u32 t(unsigned int n)
>  static void sm3_expand(u32 *t, u32 *w, u32 *wt)
>  {
>         int i;
> -       unsigned int tmp;
> +       u32 tmp;
>
>         /* load the input */
>         for (i = 0; i <= 15; i++)
> @@ -123,8 +123,8 @@ static void sm3_compress(u32 *w, u32 *wt, u32 *m)
>
>  static void sm3_transform(struct sm3_state *sst, u8 const *src)
>  {
> -       unsigned int w[68];
> -       unsigned int wt[64];
> +       u32 w[68];
> +       u32 wt[64];
>
>         sm3_expand((u32 *)src, w, wt);
>         sm3_compress(w, wt, sst->state);
> --
> 2.19.1.3.ge56e4f7
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] crypto: sm3 - use the more precise type u32 instead of unsigned int
  2021-03-26  2:21 [PATCH] crypto: sm3 - use the more precise type u32 instead of unsigned int Tianjia Zhang
  2021-03-26  8:59 ` Ard Biesheuvel
@ 2021-03-26  9:38 ` Gilad Ben-Yossef
  2021-04-07  3:26   ` Tianjia Zhang
  1 sibling, 1 reply; 4+ messages in thread
From: Gilad Ben-Yossef @ 2021-03-26  9:38 UTC (permalink / raw)
  To: Tianjia Zhang
  Cc: Herbert Xu, David S. Miller, Eric Biggers, Mimi Zohar,
	Linux Crypto Mailing List, Linux kernel mailing list, Jia Zhang

Hi,

Thank you for the patch!

On Fri, Mar 26, 2021 at 5:21 AM Tianjia Zhang
<tianjia.zhang@linux.alibaba.com> wrote:
>
> In the process of calculating the hash, use the more accurate type
> 'u32' instead of the original 'unsigned int' to avoid ambiguity.

I don't think there is any ambiguity here, as both forms are always
the same size.

Generally, I tend to use the convention of using 'u32' as denoting
variables where the size is meaningful - e.g. mathematical operations
that are defined in the standard on 32 bit buffers,  versus using
plain 'int' types where it isn't - e.g. loop counters etc.

Having said that, even under my own definition possibly the w and wt
arrays in sm3_trandform() should be changed to u32.
I don't object to changing those if it bugs you :-)

Cheers,
Gilad


> Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
> ---
>  crypto/sm3_generic.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/crypto/sm3_generic.c b/crypto/sm3_generic.c
> index 193c4584bd00..562e96f92f64 100644
> --- a/crypto/sm3_generic.c
> +++ b/crypto/sm3_generic.c
> @@ -36,17 +36,17 @@ static inline u32 p1(u32 x)
>         return x ^ rol32(x, 15) ^ rol32(x, 23);
>  }
>
> -static inline u32 ff(unsigned int n, u32 a, u32 b, u32 c)
> +static inline u32 ff(u32 n, u32 a, u32 b, u32 c)
>  {
>         return (n < 16) ? (a ^ b ^ c) : ((a & b) | (a & c) | (b & c));
>  }
>
> -static inline u32 gg(unsigned int n, u32 e, u32 f, u32 g)
> +static inline u32 gg(u32 n, u32 e, u32 f, u32 g)
>  {
>         return (n < 16) ? (e ^ f ^ g) : ((e & f) | ((~e) & g));
>  }
>
> -static inline u32 t(unsigned int n)
> +static inline u32 t(u32 n)
>  {
>         return (n < 16) ? SM3_T1 : SM3_T2;
>  }
> @@ -54,7 +54,7 @@ static inline u32 t(unsigned int n)
>  static void sm3_expand(u32 *t, u32 *w, u32 *wt)
>  {
>         int i;
> -       unsigned int tmp;
> +       u32 tmp;
>
>         /* load the input */
>         for (i = 0; i <= 15; i++)
> @@ -123,8 +123,8 @@ static void sm3_compress(u32 *w, u32 *wt, u32 *m)
>
>  static void sm3_transform(struct sm3_state *sst, u8 const *src)
>  {
> -       unsigned int w[68];
> -       unsigned int wt[64];
> +       u32 w[68];
> +       u32 wt[64];
>
>         sm3_expand((u32 *)src, w, wt);
>         sm3_compress(w, wt, sst->state);
> --
> 2.19.1.3.ge56e4f7
>


-- 
Gilad Ben-Yossef
Chief Coffee Drinker

values of β will give rise to dom!

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] crypto: sm3 - use the more precise type u32 instead of unsigned int
  2021-03-26  9:38 ` Gilad Ben-Yossef
@ 2021-04-07  3:26   ` Tianjia Zhang
  0 siblings, 0 replies; 4+ messages in thread
From: Tianjia Zhang @ 2021-04-07  3:26 UTC (permalink / raw)
  To: Gilad Ben-Yossef, Ard Biesheuvel
  Cc: Herbert Xu, David S. Miller, Eric Biggers, Mimi Zohar,
	Linux Crypto Mailing List, Linux kernel mailing list, Jia Zhang



On 3/26/21 5:38 PM, Gilad Ben-Yossef wrote:
> Hi,
> 
> Thank you for the patch!
> 
> On Fri, Mar 26, 2021 at 5:21 AM Tianjia Zhang
> <tianjia.zhang@linux.alibaba.com> wrote:
>>
>> In the process of calculating the hash, use the more accurate type
>> 'u32' instead of the original 'unsigned int' to avoid ambiguity.
> 
> I don't think there is any ambiguity here, as both forms are always
> the same size.
> 
> Generally, I tend to use the convention of using 'u32' as denoting
> variables where the size is meaningful - e.g. mathematical operations
> that are defined in the standard on 32 bit buffers,  versus using
> plain 'int' types where it isn't - e.g. loop counters etc.
> 
> Having said that, even under my own definition possibly the w and wt
> arrays in sm3_trandform() should be changed to u32.
> I don't object to changing those if it bugs you :-)
> 
> Cheers,
> Gilad
> 
> 

Thanks for your opinions. This is just to make the form more uniform. 
This is not a mistake. If it is not necessary, just ignore this 
modification.

Best regards,
Tianjia

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-04-07  3:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-26  2:21 [PATCH] crypto: sm3 - use the more precise type u32 instead of unsigned int Tianjia Zhang
2021-03-26  8:59 ` Ard Biesheuvel
2021-03-26  9:38 ` Gilad Ben-Yossef
2021-04-07  3:26   ` Tianjia Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).