mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 2/3] scripts: mxsimage: re-use crc32 implementation from crypto/crc32.c
Date: Tue, 12 Dec 2023 09:16:22 +0100	[thread overview]
Message-ID: <20231212081623.1548734-3-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20231212081623.1548734-1-s.hauer@pengutronix.de>

We already have crc32_be in the tree, so re-use that.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 scripts/mxsimage.c | 49 +++++-----------------------------------------
 1 file changed, 5 insertions(+), 44 deletions(-)

diff --git a/scripts/mxsimage.c b/scripts/mxsimage.c
index d33c4c8a0a..cebbab25ad 100644
--- a/scripts/mxsimage.c
+++ b/scripts/mxsimage.c
@@ -15,6 +15,10 @@
 #include <arpa/inet.h>
 #include <linux/kernel.h>
 
+#include "common.h"
+#include "common.c"
+#include "../crypto/crc32.c"
+
 #define SB_BLOCK_SIZE		16
 
 static char *prepfile;
@@ -376,38 +380,6 @@ struct sb_image_ctx {
  *                         JTAG/SPI2_EEPROM/SD_SSP0/SD_SSP1
  */
 
-static uint32_t crc_table[256];
-static int crc_table_valid;
-
-static void make_crc_table(void)
-{
-	uint32_t mask;
-	int i, j;
-	uint32_t poly; /* polynomial exclusive-or pattern */
-
-	if (crc_table_valid)
-		return;
-
-	/*
-	 * the polynomial used by PBL is 1 + x1 + x2 + x4 + x5 + x7 + x8 + x10
-	 * + x11 + x12 + x16 + x22 + x23 + x26 + x32.
-	 */
-	poly = 0x04c11db7;
-
-	for (i = 0; i < 256; i++) {
-		mask = i << 24;
-		for (j = 0; j < 8; j++) {
-			if (mask & 0x80000000)
-				mask = (mask << 1) ^ poly;
-			else
-				mask <<= 1;
-		}
-		crc_table[i] = mask;
-	}
-
-	crc_table_valid = 1;
-}
-
 /*
  * OpenSSL 1.1.0 and newer compatibility functions:
  * https://wiki.openssl.org/index.php/1.1_API_Changes
@@ -441,18 +413,7 @@ int EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *ctx)
 
 static uint32_t pbl_crc32(uint32_t in_crc, const char *buf, uint32_t len)
 {
-	uint32_t crc32_val;
-	int i;
-
-	make_crc_table();
-
-	crc32_val = ~in_crc;
-
-	for (i = 0; i < len; i++)
-		crc32_val = (crc32_val << 8) ^
-			crc_table[(crc32_val >> 24) ^ (*buf++ & 0xff)];
-
-	return crc32_val;
+	return crc32_be(~in_crc, buf, len);
 }
 /*
  * AES libcrypto
-- 
2.39.2




  parent reply	other threads:[~2023-12-12  8:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-12  8:16 [PATCH 0/3] scripts: Drop some crc32 implementations Sascha Hauer
2023-12-12  8:16 ` [PATCH 1/3] scripts: pblimage: re-use crc32 implementation from crypto/crc32.c Sascha Hauer
2023-12-12  8:16 ` Sascha Hauer [this message]
2023-12-12  8:16 ` [PATCH 3/3] scripts: socfpga_mkimage: " Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231212081623.1548734-3-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox