diff options
author | Marek BehĂșn <marek.behun@nic.cz> | 2017-09-03 17:00:23 +0200 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2017-10-02 20:31:25 -0400 |
commit | 85d8bf57131a21424b50e50884372e813345f09a (patch) | |
tree | 89b5c9a646761fa4e060043a8ca1a5bd4c46cbbc /lib/crc32c.c | |
parent | 43dd6dacb200757c7088af00eec78c82a7e8cbff (diff) | |
download | u-boot-85d8bf57131a21424b50e50884372e813345f09a.tar.gz u-boot-85d8bf57131a21424b50e50884372e813345f09a.tar.bz2 u-boot-85d8bf57131a21424b50e50884372e813345f09a.zip |
lib: Add CRC32-C
This is needed for BTRFS.
Signed-off-by: Marek Behun <marek.behun@nic.cz>
create mode 100644 lib/crc32c.c
Diffstat (limited to 'lib/crc32c.c')
-rw-r--r-- | lib/crc32c.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/crc32c.c b/lib/crc32c.c new file mode 100644 index 0000000000..322c08ff5d --- /dev/null +++ b/lib/crc32c.c @@ -0,0 +1,38 @@ +/* + * 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; + } +} |