// SPDX-License-Identifier: GPL-2.0-only
/*
* crc7 . c
*/
#include <linux/crc7.h>
#include <linux/export.h>
#include <linux/module.h>
#include <linux/types.h>
/*
* Table for CRC - 7 ( polynomial x ^ 7 + x ^ 3 + 1 ) .
* This is a big - endian CRC ( msbit is highest power of x ) ,
* aligned so the msbit of the byte is the x ^ 6 coefficient
* and the lsbit is not used .
*/
static const u8 crc7_be_syndrome_table[256 ] = {
0 x00, 0 x12, 0 x24, 0 x36, 0 x48, 0 x5a, 0 x6c, 0 x7e,
0 x90, 0 x82, 0 xb4, 0 xa6, 0 xd8, 0 xca, 0 xfc, 0 xee,
0 x32, 0 x20, 0 x16, 0 x04, 0 x7a, 0 x68, 0 x5e, 0 x4c,
0 xa2, 0 xb0, 0 x86, 0 x94, 0 xea, 0 xf8, 0 xce, 0 xdc,
0 x64, 0 x76, 0 x40, 0 x52, 0 x2c, 0 x3e, 0 x08, 0 x1a,
0 xf4, 0 xe6, 0 xd0, 0 xc2, 0 xbc, 0 xae, 0 x98, 0 x8a,
0 x56, 0 x44, 0 x72, 0 x60, 0 x1e, 0 x0c, 0 x3a, 0 x28,
0 xc6, 0 xd4, 0 xe2, 0 xf0, 0 x8e, 0 x9c, 0 xaa, 0 xb8,
0 xc8, 0 xda, 0 xec, 0 xfe, 0 x80, 0 x92, 0 xa4, 0 xb6,
0 x58, 0 x4a, 0 x7c, 0 x6e, 0 x10, 0 x02, 0 x34, 0 x26,
0 xfa, 0 xe8, 0 xde, 0 xcc, 0 xb2, 0 xa0, 0 x96, 0 x84,
0 x6a, 0 x78, 0 x4e, 0 x5c, 0 x22, 0 x30, 0 x06, 0 x14,
0 xac, 0 xbe, 0 x88, 0 x9a, 0 xe4, 0 xf6, 0 xc0, 0 xd2,
0 x3c, 0 x2e, 0 x18, 0 x0a, 0 x74, 0 x66, 0 x50, 0 x42,
0 x9e, 0 x8c, 0 xba, 0 xa8, 0 xd6, 0 xc4, 0 xf2, 0 xe0,
0 x0e, 0 x1c, 0 x2a, 0 x38, 0 x46, 0 x54, 0 x62, 0 x70,
0 x82, 0 x90, 0 xa6, 0 xb4, 0 xca, 0 xd8, 0 xee, 0 xfc,
0 x12, 0 x00, 0 x36, 0 x24, 0 x5a, 0 x48, 0 x7e, 0 x6c,
0 xb0, 0 xa2, 0 x94, 0 x86, 0 xf8, 0 xea, 0 xdc, 0 xce,
0 x20, 0 x32, 0 x04, 0 x16, 0 x68, 0 x7a, 0 x4c, 0 x5e,
0 xe6, 0 xf4, 0 xc2, 0 xd0, 0 xae, 0 xbc, 0 x8a, 0 x98,
0 x76, 0 x64, 0 x52, 0 x40, 0 x3e, 0 x2c, 0 x1a, 0 x08,
0 xd4, 0 xc6, 0 xf0, 0 xe2, 0 x9c, 0 x8e, 0 xb8, 0 xaa,
0 x44, 0 x56, 0 x60, 0 x72, 0 x0c, 0 x1e, 0 x28, 0 x3a,
0 x4a, 0 x58, 0 x6e, 0 x7c, 0 x02, 0 x10, 0 x26, 0 x34,
0 xda, 0 xc8, 0 xfe, 0 xec, 0 x92, 0 x80, 0 xb6, 0 xa4,
0 x78, 0 x6a, 0 x5c, 0 x4e, 0 x30, 0 x22, 0 x14, 0 x06,
0 xe8, 0 xfa, 0 xcc, 0 xde, 0 xa0, 0 xb2, 0 x84, 0 x96,
0 x2e, 0 x3c, 0 x0a, 0 x18, 0 x66, 0 x74, 0 x42, 0 x50,
0 xbe, 0 xac, 0 x9a, 0 x88, 0 xf6, 0 xe4, 0 xd2, 0 xc0,
0 x1c, 0 x0e, 0 x38, 0 x2a, 0 x54, 0 x46, 0 x70, 0 x62,
0 x8c, 0 x9e, 0 xa8, 0 xba, 0 xc4, 0 xd6, 0 xe0, 0 xf2
};
/**
* crc7_be - update the CRC7 for the data buffer
* @ crc : previous CRC7 value
* @ buffer : data pointer
* @ len : number of bytes in the buffer
* Context : any
*
* Returns the updated CRC7 value .
* The CRC7 is left - aligned in the byte ( the lsbit is always 0 ) , as that
* makes the computation easier , and all callers want it in that form .
*
*/
u8 crc7_be(u8 crc, const u8 *buffer, size_t len)
{
while (len--)
crc = crc7_be_syndrome_table[crc ^ *buffer++];
return crc;
}
EXPORT_SYMBOL(crc7_be);
MODULE_DESCRIPTION("CRC7 calculations" );
MODULE_LICENSE("GPL" );
Messung V0.5 in Prozent C=95 H=60 G=79