mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] crypto: crc32: add big endian CRC implementation
@ 2021-12-09 10:58 Ahmad Fatoum
  2021-12-13 22:17 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2021-12-09 10:58 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

This implementation is a straight copy of the tableless
implementation inside Linux' lib/crc32.c

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 crypto/crc32.c | 12 ++++++++++++
 include/crc.h  |  1 +
 2 files changed, 13 insertions(+)

diff --git a/crypto/crc32.c b/crypto/crc32.c
index 232c023adb88..998cbc9de297 100644
--- a/crypto/crc32.c
+++ b/crypto/crc32.c
@@ -187,6 +187,18 @@ STATIC uint32_t crc32_no_comp(uint32_t crc, const void *_buf, unsigned int len)
     return crc;
 }
 
+STATIC uint32_t crc32_be(uint32_t crc, const void *_buf, unsigned int len)
+{
+	const unsigned char *buf = _buf;
+	int i;
+	while (len--) {
+		crc ^= *buf++ << 24;
+		for (i = 0; i < 8; i++)
+			crc = (crc << 1) ^ ((crc & 0x80000000) ? 0x04c11db7 : 0);
+	}
+	return crc;
+}
+
 STATIC int file_crc(char *filename, ulong start, ulong size, ulong *crc,
 		    ulong *total)
 {
diff --git a/include/crc.h b/include/crc.h
index eb972705c21a..a5204aaabb9c 100644
--- a/include/crc.h
+++ b/include/crc.h
@@ -36,6 +36,7 @@ static inline u16 crc_itu_t_byte(u16 crc, const u8 data)
 #endif
 
 uint32_t crc32(uint32_t, const void *, unsigned int);
+uint32_t crc32_be(uint32_t, const void *, unsigned int);
 uint32_t crc32_no_comp(uint32_t, const void *, unsigned int);
 int file_crc(char *filename, unsigned long start, unsigned long size,
 	     unsigned long *crc, unsigned long *total);
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


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

* Re: [PATCH] crypto: crc32: add big endian CRC implementation
  2021-12-09 10:58 [PATCH] crypto: crc32: add big endian CRC implementation Ahmad Fatoum
@ 2021-12-13 22:17 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2021-12-13 22:17 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Thu, Dec 09, 2021 at 11:58:32AM +0100, Ahmad Fatoum wrote:
> This implementation is a straight copy of the tableless
> implementation inside Linux' lib/crc32.c
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  crypto/crc32.c | 12 ++++++++++++
>  include/crc.h  |  1 +
>  2 files changed, 13 insertions(+)

Applied, thanks

Sascha

> 
> diff --git a/crypto/crc32.c b/crypto/crc32.c
> index 232c023adb88..998cbc9de297 100644
> --- a/crypto/crc32.c
> +++ b/crypto/crc32.c
> @@ -187,6 +187,18 @@ STATIC uint32_t crc32_no_comp(uint32_t crc, const void *_buf, unsigned int len)
>      return crc;
>  }
>  
> +STATIC uint32_t crc32_be(uint32_t crc, const void *_buf, unsigned int len)
> +{
> +	const unsigned char *buf = _buf;
> +	int i;
> +	while (len--) {
> +		crc ^= *buf++ << 24;
> +		for (i = 0; i < 8; i++)
> +			crc = (crc << 1) ^ ((crc & 0x80000000) ? 0x04c11db7 : 0);
> +	}
> +	return crc;
> +}
> +
>  STATIC int file_crc(char *filename, ulong start, ulong size, ulong *crc,
>  		    ulong *total)
>  {
> diff --git a/include/crc.h b/include/crc.h
> index eb972705c21a..a5204aaabb9c 100644
> --- a/include/crc.h
> +++ b/include/crc.h
> @@ -36,6 +36,7 @@ static inline u16 crc_itu_t_byte(u16 crc, const u8 data)
>  #endif
>  
>  uint32_t crc32(uint32_t, const void *, unsigned int);
> +uint32_t crc32_be(uint32_t, const void *, unsigned int);
>  uint32_t crc32_no_comp(uint32_t, const void *, unsigned int);
>  int file_crc(char *filename, unsigned long start, unsigned long size,
>  	     unsigned long *crc, unsigned long *total);
> -- 
> 2.30.2
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


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

end of thread, other threads:[~2021-12-13 22:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-09 10:58 [PATCH] crypto: crc32: add big endian CRC implementation Ahmad Fatoum
2021-12-13 22:17 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox