All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libcrc32c: keep intermediate crc state in cpu order
       [not found]         ` <4731FD41.1090704@panasas.com>
@ 2007-11-08  8:20           ` Benny Halevy
  2007-11-08 13:37             ` Herbert Xu
  2007-11-08 18:41             ` Dave Jiang
  0 siblings, 2 replies; 4+ messages in thread
From: Benny Halevy @ 2007-11-08  8:20 UTC (permalink / raw)
  To: open-iscsi, linux-crypto, David S. Miller, Clay Haapala
  Cc: fujita.tomonori, michaelc, djiang, Herbert Xu

crypto/crc32.c:chksum_final() is computing the digest as
*(__le32 *)out = ~cpu_to_le32(mctx->crc);
so the low-level crc32c_le routines should just keep
the crc in cpu order, otherwise it is getting swabbed
one too many times on big-endian machines.

Signed-off-by: Benny Halevy <bhalevy@fs1.bhalevy.com>
---
 lib/libcrc32c.c |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/lib/libcrc32c.c b/lib/libcrc32c.c
index 802f11f..b5c3287 100644
--- a/lib/libcrc32c.c
+++ b/lib/libcrc32c.c
@@ -33,7 +33,6 @@
 #include <linux/crc32c.h>
 #include <linux/compiler.h>
 #include <linux/module.h>
-#include <asm/byteorder.h>
 
 MODULE_AUTHOR("Clay Haapala <chaapala@cisco.com>");
 MODULE_DESCRIPTION("CRC32c (Castagnoli) calculations");
@@ -161,15 +160,13 @@ static const u32 crc32c_table[256] = {
  */
 
 u32 __pure
-crc32c_le(u32 seed, unsigned char const *data, size_t length)
+crc32c_le(u32 crc, unsigned char const *data, size_t length)
 {
-	u32 crc = __cpu_to_le32(seed);
-	
 	while (length--)
 		crc =
 		    crc32c_table[(crc ^ *data++) & 0xFFL] ^ (crc >> 8);
 
-	return __le32_to_cpu(crc);
+	return crc;
 }
 
 #endif	/* CRC_LE_BITS == 8 */
-- 
1.5.3.3

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

* Re: [PATCH] libcrc32c: keep intermediate crc state in cpu order
  2007-11-08  8:20           ` [PATCH] libcrc32c: keep intermediate crc state in cpu order Benny Halevy
@ 2007-11-08 13:37             ` Herbert Xu
  2007-11-08 18:41             ` Dave Jiang
  1 sibling, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2007-11-08 13:37 UTC (permalink / raw)
  To: Benny Halevy
  Cc: open-iscsi, linux-crypto, David S. Miller, Clay Haapala,
	fujita.tomonori, michaelc, djiang

On Thu, Nov 08, 2007 at 10:20:34AM +0200, Benny Halevy wrote:
> crypto/crc32.c:chksum_final() is computing the digest as
> *(__le32 *)out = ~cpu_to_le32(mctx->crc);
> so the low-level crc32c_le routines should just keep
> the crc in cpu order, otherwise it is getting swabbed
> one too many times on big-endian machines.
> 
> Signed-off-by: Benny Halevy <bhalevy@fs1.bhalevy.com>

Patch applied.  Thanks!

I'll send this to stable too.
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: [PATCH] libcrc32c: keep intermediate crc state in cpu order
  2007-11-08  8:20           ` [PATCH] libcrc32c: keep intermediate crc state in cpu order Benny Halevy
  2007-11-08 13:37             ` Herbert Xu
@ 2007-11-08 18:41             ` Dave Jiang
  2007-11-08 19:29               ` Benny Halevy
  1 sibling, 1 reply; 4+ messages in thread
From: Dave Jiang @ 2007-11-08 18:41 UTC (permalink / raw)
  To: Benny Halevy
  Cc: open-iscsi, linux-crypto, David S. Miller, Clay Haapala,
	fujita.tomonori, michaelc, Herbert Xu

Resolved my issue with BE open-iscsi initiator and LE IET target. Thanks!

Benny Halevy wrote:
> crypto/crc32.c:chksum_final() is computing the digest as
> *(__le32 *)out = ~cpu_to_le32(mctx->crc);
> so the low-level crc32c_le routines should just keep
> the crc in cpu order, otherwise it is getting swabbed
> one too many times on big-endian machines.
> 
> Signed-off-by: Benny Halevy <bhalevy@fs1.bhalevy.com>
> ---
>  lib/libcrc32c.c |    7 ++-----
>  1 files changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/lib/libcrc32c.c b/lib/libcrc32c.c
> index 802f11f..b5c3287 100644
> --- a/lib/libcrc32c.c
> +++ b/lib/libcrc32c.c
> @@ -33,7 +33,6 @@
>  #include <linux/crc32c.h>
>  #include <linux/compiler.h>
>  #include <linux/module.h>
> -#include <asm/byteorder.h>
>  
>  MODULE_AUTHOR("Clay Haapala <chaapala@cisco.com>");
>  MODULE_DESCRIPTION("CRC32c (Castagnoli) calculations");
> @@ -161,15 +160,13 @@ static const u32 crc32c_table[256] = {
>   */
>  
>  u32 __pure
> -crc32c_le(u32 seed, unsigned char const *data, size_t length)
> +crc32c_le(u32 crc, unsigned char const *data, size_t length)
>  {
> -	u32 crc = __cpu_to_le32(seed);
> -	
>  	while (length--)
>  		crc =
>  		    crc32c_table[(crc ^ *data++) & 0xFFL] ^ (crc >> 8);
>  
> -	return __le32_to_cpu(crc);
> +	return crc;
>  }
>  
>  #endif	/* CRC_LE_BITS == 8 */


-- 

------------------------------------------------------
Dave Jiang
Software Engineer
MontaVista Software, Inc.
http://www.mvista.com
------------------------------------------------------

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

* Re: [PATCH] libcrc32c: keep intermediate crc state in cpu order
  2007-11-08 18:41             ` Dave Jiang
@ 2007-11-08 19:29               ` Benny Halevy
  0 siblings, 0 replies; 4+ messages in thread
From: Benny Halevy @ 2007-11-08 19:29 UTC (permalink / raw)
  To: Dave Jiang
  Cc: open-iscsi, linux-crypto, David S. Miller, Clay Haapala,
	fujita.tomonori, michaelc, Herbert Xu

On Nov. 08, 2007, 20:41 +0200, Dave Jiang <djiang@mvista.com> wrote:
> Resolved my issue with BE open-iscsi initiator and LE IET target. Thanks!

Super!  Thanks for testing!

And many thanks to Tomo for identifying the byte-order problem
in the crypto code.

Benny


> 
> Benny Halevy wrote:
>> crypto/crc32.c:chksum_final() is computing the digest as
>> *(__le32 *)out = ~cpu_to_le32(mctx->crc);
>> so the low-level crc32c_le routines should just keep
>> the crc in cpu order, otherwise it is getting swabbed
>> one too many times on big-endian machines.
>>
>> Signed-off-by: Benny Halevy <bhalevy@fs1.bhalevy.com>
>> ---
>>  lib/libcrc32c.c |    7 ++-----
>>  1 files changed, 2 insertions(+), 5 deletions(-)
>>
>> diff --git a/lib/libcrc32c.c b/lib/libcrc32c.c
>> index 802f11f..b5c3287 100644
>> --- a/lib/libcrc32c.c
>> +++ b/lib/libcrc32c.c
>> @@ -33,7 +33,6 @@
>>  #include <linux/crc32c.h>
>>  #include <linux/compiler.h>
>>  #include <linux/module.h>
>> -#include <asm/byteorder.h>
>>  
>>  MODULE_AUTHOR("Clay Haapala <chaapala@cisco.com>");
>>  MODULE_DESCRIPTION("CRC32c (Castagnoli) calculations");
>> @@ -161,15 +160,13 @@ static const u32 crc32c_table[256] = {
>>   */
>>  
>>  u32 __pure
>> -crc32c_le(u32 seed, unsigned char const *data, size_t length)
>> +crc32c_le(u32 crc, unsigned char const *data, size_t length)
>>  {
>> -	u32 crc = __cpu_to_le32(seed);
>> -	
>>  	while (length--)
>>  		crc =
>>  		    crc32c_table[(crc ^ *data++) & 0xFFL] ^ (crc >> 8);
>>  
>> -	return __le32_to_cpu(crc);
>> +	return crc;
>>  }
>>  
>>  #endif	/* CRC_LE_BITS == 8 */
> 
> 

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

end of thread, other threads:[~2007-11-08 19:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <473186E9.5080300@panasas.com>
     [not found] ` <4731A5C5.3030109@panasas.com>
     [not found]   ` <4731D387.5090901@panasas.com>
     [not found]     ` <20071108001400O.tomof@acm.org>
     [not found]       ` <4731DA0C.5090702@panasas.com>
     [not found]         ` <4731FD41.1090704@panasas.com>
2007-11-08  8:20           ` [PATCH] libcrc32c: keep intermediate crc state in cpu order Benny Halevy
2007-11-08 13:37             ` Herbert Xu
2007-11-08 18:41             ` Dave Jiang
2007-11-08 19:29               ` Benny Halevy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.