blob: 9e21f2594b3ec58b0e3594103879a8c90ab13509 [file] [log] [blame]
Andrzej Kurek9df2b412020-08-07 11:34:21 -04001/*
2 * CRC-16/ARC implementation, generated using pycrc v0.9.2, https://pycrc.org,
3 * with further FI countermeasures added manually.
4 *
5 * Used options: --model=crc-16 --algorithm=tbl --generate=c --std=C89 --table-idx-width 4
6 *
7 * Copyright (C) 2006-2020, ARM Limited, All Rights Reserved
8 * SPDX-License-Identifier: Apache-2.0
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
11 * not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 *
22 * This file is part of mbed TLS (https://tls.mbed.org)
23 */
24
25#if !defined(MBEDTLS_CONFIG_FILE)
26#include "mbedtls/config.h"
27#else
28#include MBEDTLS_CONFIG_FILE
29#endif
30
31#if defined(MBEDTLS_CRC_C)
32
33#include "mbedtls/crc.h"
34
35static const uint32_t crc_table[16] = {
36 0x0000, 0xcc01, 0xd801, 0x1400, 0xf001, 0x3c00, 0x2800, 0xe401,
37 0xa001, 0x6c00, 0x7800, 0xb401, 0x5000, 0x9c01, 0x8801, 0x4400
38};
39
40uint16_t mbedtls_crc_update( uint16_t crc, const void *data, size_t data_len )
41{
42 const unsigned char *d = (const unsigned char *)data;
43 unsigned int tbl_idx;
44
45 while ( data_len -- ) {
46 tbl_idx = crc ^ *d;
47 crc = crc_table[tbl_idx & 0x0f] ^ ( crc >> 4 );
48 tbl_idx = crc ^ ( *d >> 4 );
49 crc = crc_table[tbl_idx & 0x0f] ^ ( crc >> 4 );
50 d ++;
51 }
52 return crc;
53}
54
55#endif /* MBEDTLS_CRC_C */