![]() |
|
|||
0001 /* 0002 * crc32.h 0003 * See linux/lib/crc32.c for license and changes 0004 */ 0005 #ifndef _LINUX_CRC32_H 0006 #define _LINUX_CRC32_H 0007 0008 #include <linux/types.h> 0009 #include <linux/bitrev.h> 0010 0011 u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len); 0012 u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len); 0013 0014 /** 0015 * crc32_le_combine - Combine two crc32 check values into one. For two 0016 * sequences of bytes, seq1 and seq2 with lengths len1 0017 * and len2, crc32_le() check values were calculated 0018 * for each, crc1 and crc2. 0019 * 0020 * @crc1: crc32 of the first block 0021 * @crc2: crc32 of the second block 0022 * @len2: length of the second block 0023 * 0024 * Return: The crc32_le() check value of seq1 and seq2 concatenated, 0025 * requiring only crc1, crc2, and len2. Note: If seq_full denotes 0026 * the concatenated memory area of seq1 with seq2, and crc_full 0027 * the crc32_le() value of seq_full, then crc_full == 0028 * crc32_le_combine(crc1, crc2, len2) when crc_full was seeded 0029 * with the same initializer as crc1, and crc2 seed was 0. See 0030 * also crc32_combine_test(). 0031 */ 0032 u32 __attribute_const__ crc32_le_shift(u32 crc, size_t len); 0033 0034 static inline u32 crc32_le_combine(u32 crc1, u32 crc2, size_t len2) 0035 { 0036 return crc32_le_shift(crc1, len2) ^ crc2; 0037 } 0038 0039 u32 __pure __crc32c_le(u32 crc, unsigned char const *p, size_t len); 0040 0041 /** 0042 * __crc32c_le_combine - Combine two crc32c check values into one. For two 0043 * sequences of bytes, seq1 and seq2 with lengths len1 0044 * and len2, __crc32c_le() check values were calculated 0045 * for each, crc1 and crc2. 0046 * 0047 * @crc1: crc32c of the first block 0048 * @crc2: crc32c of the second block 0049 * @len2: length of the second block 0050 * 0051 * Return: The __crc32c_le() check value of seq1 and seq2 concatenated, 0052 * requiring only crc1, crc2, and len2. Note: If seq_full denotes 0053 * the concatenated memory area of seq1 with seq2, and crc_full 0054 * the __crc32c_le() value of seq_full, then crc_full == 0055 * __crc32c_le_combine(crc1, crc2, len2) when crc_full was 0056 * seeded with the same initializer as crc1, and crc2 seed 0057 * was 0. See also crc32c_combine_test(). 0058 */ 0059 u32 __attribute_const__ __crc32c_le_shift(u32 crc, size_t len); 0060 0061 static inline u32 __crc32c_le_combine(u32 crc1, u32 crc2, size_t len2) 0062 { 0063 return __crc32c_le_shift(crc1, len2) ^ crc2; 0064 } 0065 0066 #define crc32(seed, data, length) crc32_le(seed, (unsigned char const *)(data), length) 0067 0068 /* 0069 * Helpers for hash table generation of ethernet nics: 0070 * 0071 * Ethernet sends the least significant bit of a byte first, thus crc32_le 0072 * is used. The output of crc32_le is bit reversed [most significant bit 0073 * is in bit nr 0], thus it must be reversed before use. Except for 0074 * nics that bit swap the result internally... 0075 */ 0076 #define ether_crc(length, data) bitrev32(crc32_le(~0, data, length)) 0077 #define ether_crc_le(length, data) crc32_le(~0, data, length) 0078 0079 #endif /* _LINUX_CRC32_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |