Skip to content
Snippets Groups Projects
Commit 85d8bf57 authored by Marek Behún's avatar Marek Behún Committed by Tom Rini
Browse files

lib: Add CRC32-C


This is needed for BTRFS.

Signed-off-by: default avatarMarek Behun <marek.behun@nic.cz>

 create mode 100644 lib/crc32c.c
parent 43dd6dac
No related branches found
No related tags found
No related merge requests found
......@@ -28,4 +28,8 @@ uint32_t crc32_no_comp (uint32_t, const unsigned char *, uint);
void crc32_wd_buf(const unsigned char *input, uint ilen,
unsigned char *output, uint chunk_sz);
/* lib/crc32c.c */
void crc32c_init(uint32_t *, uint32_t);
uint32_t crc32c_cal(uint32_t, const char *, int, uint32_t *);
#endif /* _UBOOT_CRC_H */
......@@ -146,6 +146,9 @@ config SHA_PROG_HW_ACCEL
config MD5
bool
config CRC32C
bool
endmenu
menu "Compression Support"
......
......@@ -71,6 +71,7 @@ obj-y += display_options.o
CFLAGS_display_options.o := $(if $(BUILD_TAG),-DBUILD_TAG='"$(BUILD_TAG)"')
obj-$(CONFIG_BCH) += bch.o
obj-y += crc32.o
obj-$(CONFIG_CRC32C) += crc32c.o
obj-y += ctype.o
obj-y += div64.o
obj-y += hang.o
......
/*
* Copied from Linux kernel crypto/crc32c.c
* Copyright (c) 2004 Cisco Systems, Inc.
* Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
* SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <compiler.h>
uint32_t crc32c_cal(uint32_t crc, const char *data, int length,
uint32_t *crc32c_table)
{
while (length--)
crc = crc32c_table[(u8)(crc ^ *data++)] ^ (crc >> 8);
return crc;
}
void crc32c_init(uint32_t *crc32c_table, uint32_t pol)
{
int i, j;
uint32_t v;
const uint32_t poly = pol; /* Bit-reflected CRC32C polynomial */
for (i = 0; i < 256; i++) {
v = i;
for (j = 0; j < 8; j++)
v = (v >> 1) ^ ((v & 1) ? poly : 0);
crc32c_table[i] = v;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment