tpm: add kconfig control in tcg2_create_digest()
[J-u-boot.git] / lib / crc32c.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
85d8bf57
MB
2/*
3 * Copied from Linux kernel crypto/crc32c.c
4 * Copyright (c) 2004 Cisco Systems, Inc.
5 * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
85d8bf57
MB
11 */
12
85d8bf57
MB
13#include <compiler.h>
14
15uint32_t crc32c_cal(uint32_t crc, const char *data, int length,
16 uint32_t *crc32c_table)
17{
18 while (length--)
19 crc = crc32c_table[(u8)(crc ^ *data++)] ^ (crc >> 8);
20
21 return crc;
22}
23
24void crc32c_init(uint32_t *crc32c_table, uint32_t pol)
25{
26 int i, j;
27 uint32_t v;
28 const uint32_t poly = pol; /* Bit-reflected CRC32C polynomial */
29
30 for (i = 0; i < 256; i++) {
31 v = i;
32 for (j = 0; j < 8; j++)
33 v = (v >> 1) ^ ((v & 1) ? poly : 0);
34
35 crc32c_table[i] = v;
36 }
37}
This page took 0.189165 seconds and 4 git commands to generate.