Skip to contentSkip to conversation

crc32: Correct endianness of crc32 result

PATCH New Simon Glass 2 participants 2 messages Apr 18, 2013 – Apr 19, 2013 Library code

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 crc32: Correct endianness of crc32 result

When crc32 is handled by the hash library, it requires the data to be in big-endian format, since it reads it byte-wise. Thus at present the 'crc32' command reports incorrect data. For example, previously we might see:

Peach # crc32 40000000 100
CRC32 for 40000000 ... 400000ff ==> 0d968558

but instead with the hash library we see:

Peach # crc32 40000000 100
CRC32 for 40000000 ... 400000ff ==> 5885960d

Correct this.

---
Changes in v2:
- Remove use of put_unaligned_be32()
- Use htonl() instead of htobe32()

 lib/crc32.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/crc32.c +4 -1
index 76205da..9759212 100644
@@ -8,7 +8,9 @@
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
-#ifndef USE_HOSTCC
+#ifdef USE_HOSTCC
+#include <arpa/inet.h>
+#else
 #include <common.h>
 #endif
 #include <compiler.h>
@@ -256,5 +258,6 @@ void crc32_wd_buf(const unsigned char *input, unsigned int ilen,
 	uint32_t crc;
 
 	crc = crc32_wd(0, input, ilen, chunk_sz);
+	crc = htonl(crc);
 	memcpy(output, &crc, sizeof(crc));
 }
Signature · 1 line
1.8.2.1
#1 lore raw

PATCH v2 1/1 crc32: Correct endianness of crc32 result

Quoted 40 lines · Simon Glass

When crc32 is handled by the hash library, it requires the data to be in big-endian format, since it reads it byte-wise. Thus at present the 'crc32' command reports incorrect data. For example, previously we might see:

Peach # crc32 40000000 100
CRC32 for 40000000 ... 400000ff ==> 0d968558

but instead with the hash library we see:

Peach # crc32 40000000 100
CRC32 for 40000000 ... 400000ff ==> 5885960d

Correct this.

---
Changes in v2:
- Remove use of put_unaligned_be32()
- Use htonl() instead of htobe32()

 lib/crc32.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/crc32.c +3 -1
index 76205da..9759212 100644
@@ -8,7 +8,9 @@
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
-#ifndef USE_HOSTCC
+#ifdef USE_HOSTCC
+#include <arpa/inet.h>
+#else
 #include <common.h>
 #endif
 #include <compiler.h>

lib/crc32.c void crc32_wd_buf(const unsigned char *input, unsigned int ilen, · line 263

Quoted 6 lines
lib/crc32.c +1 -0
@@ -256,5 +258,6 @@ void crc32_wd_buf(const unsigned char *input, unsigned int ilen,
 	uint32_t crc;
 
 	crc = crc32_wd(0, input, ilen, chunk_sz);
+	crc = htonl(crc);
 	memcpy(output, &crc, sizeof(crc));
 }

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130419/f7a7664e/attachment.pgp>