![]() |
|
|||
File indexing completed on 2025-09-17 09:02:13
0001 /********************************************************************** 0002 Copyright(c) 2011-2015 Intel Corporation All rights reserved. 0003 0004 Redistribution and use in source and binary forms, with or without 0005 modification, are permitted provided that the following conditions 0006 are met: 0007 * Redistributions of source code must retain the above copyright 0008 notice, this list of conditions and the following disclaimer. 0009 * Redistributions in binary form must reproduce the above copyright 0010 notice, this list of conditions and the following disclaimer in 0011 the documentation and/or other materials provided with the 0012 distribution. 0013 * Neither the name of Intel Corporation nor the names of its 0014 contributors may be used to endorse or promote products derived 0015 from this software without specific prior written permission. 0016 0017 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 0018 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 0019 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 0020 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 0021 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 0022 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 0023 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0024 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0025 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0026 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 0027 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0028 **********************************************************************/ 0029 0030 /** 0031 * @file crc.h 0032 * @brief CRC functions. 0033 */ 0034 0035 #ifndef _CRC_H_ 0036 #define _CRC_H_ 0037 0038 #include <stdint.h> 0039 0040 #ifdef __cplusplus 0041 extern "C" { 0042 #endif 0043 0044 /* Multi-binary functions */ 0045 0046 /** 0047 * @brief Generate CRC from the T10 standard, runs appropriate version. 0048 * 0049 * This function determines what instruction sets are enabled and 0050 * selects the appropriate version at runtime. 0051 * 0052 * @returns 16 bit CRC 0053 */ 0054 uint16_t 0055 crc16_t10dif(uint16_t init_crc, //!< initial CRC value, 16 bits 0056 const unsigned char *buf, //!< buffer to calculate CRC on 0057 uint64_t len //!< buffer length in bytes (64-bit data) 0058 ); 0059 0060 /** 0061 * @brief Generate CRC and copy T10 standard, runs appropriate version. 0062 * 0063 * Stitched CRC + copy function. 0064 * 0065 * @returns 16 bit CRC 0066 */ 0067 uint16_t 0068 crc16_t10dif_copy(uint16_t init_crc, //!< initial CRC value, 16 bits 0069 uint8_t *dst, //!< buffer destination for copy 0070 uint8_t *src, //!< buffer source to crc + copy 0071 uint64_t len //!< buffer length in bytes (64-bit data) 0072 ); 0073 0074 /** 0075 * @brief Generate CRC from the IEEE standard, runs appropriate version. 0076 * 0077 * This function determines what instruction sets are enabled and 0078 * selects the appropriate version at runtime. 0079 * Note: CRC32 IEEE standard is widely used in HDLC, Ethernet, Gzip and 0080 * many others. Its polynomial is 0x04C11DB7 in normal and 0xEDB88320 0081 * in reflection (or reverse). In ISA-L CRC, function crc32_ieee is 0082 * actually designed for normal CRC32 IEEE version. And function 0083 * crc32_gzip_refl is actually designed for reflected CRC32 IEEE. 0084 * These two versions of CRC32 IEEE are not compatible with each other. 0085 * Users who want to replace their not optimized crc32 ieee with ISA-L's 0086 * crc32 function should be careful of that. 0087 * Since many applications use CRC32 IEEE reflected version, Please have 0088 * a check whether crc32_gzip_refl is right one for you instead of 0089 * crc32_ieee. 0090 * 0091 * @returns 32 bit CRC 0092 */ 0093 0094 uint32_t 0095 crc32_ieee(uint32_t init_crc, //!< initial CRC value, 32 bits 0096 const unsigned char *buf, //!< buffer to calculate CRC on 0097 uint64_t len //!< buffer length in bytes (64-bit data) 0098 ); 0099 0100 /** 0101 * @brief Generate the customized CRC 0102 * based on RFC 1952 CRC (http://www.ietf.org/rfc/rfc1952.txt) standard, 0103 * runs appropriate version. 0104 * 0105 * This function determines what instruction sets are enabled and 0106 * selects the appropriate version at runtime. 0107 * 0108 * Note: CRC32 IEEE standard is widely used in HDLC, Ethernet, Gzip and 0109 * many others. Its polynomial is 0x04C11DB7 in normal and 0xEDB88320 0110 * in reflection (or reverse). In ISA-L CRC, function crc32_ieee is 0111 * actually designed for normal CRC32 IEEE version. And function 0112 * crc32_gzip_refl is actually designed for reflected CRC32 IEEE. 0113 * These two versions of CRC32 IEEE are not compatible with each other. 0114 * Users who want to replace their not optimized crc32 ieee with ISA-L's 0115 * crc32 function should be careful of that. 0116 * Since many applications use CRC32 IEEE reflected version, Please have 0117 * a check whether crc32_gzip_refl is right one for you instead of 0118 * crc32_ieee. 0119 * 0120 * @returns 32 bit CRC 0121 */ 0122 uint32_t 0123 crc32_gzip_refl(uint32_t init_crc, //!< initial CRC value, 32 bits 0124 const unsigned char *buf, //!< buffer to calculate CRC on 0125 uint64_t len //!< buffer length in bytes (64-bit data) 0126 ); 0127 0128 /** 0129 * @brief ISCSI CRC function, runs appropriate version. 0130 * 0131 * This function determines what instruction sets are enabled and 0132 * selects the appropriate version at runtime. 0133 * 0134 * @returns 32 bit CRC 0135 */ 0136 unsigned int 0137 crc32_iscsi(unsigned char *buffer, //!< buffer to calculate CRC on 0138 int len, //!< buffer length in bytes 0139 unsigned int init_crc //!< initial CRC value 0140 ); 0141 0142 /* Base functions */ 0143 0144 /** 0145 * @brief ISCSI CRC function, baseline version 0146 * @returns 32 bit CRC 0147 */ 0148 unsigned int 0149 crc32_iscsi_base(unsigned char *buffer, //!< buffer to calculate CRC on 0150 int len, //!< buffer length in bytes 0151 unsigned int crc_init //!< initial CRC value 0152 ); 0153 0154 /** 0155 * @brief Generate CRC from the T10 standard, runs baseline version 0156 * @returns 16 bit CRC 0157 */ 0158 uint16_t 0159 crc16_t10dif_base(uint16_t seed, //!< initial CRC value, 16 bits 0160 uint8_t *buf, //!< buffer to calculate CRC on 0161 uint64_t len //!< buffer length in bytes (64-bit data) 0162 ); 0163 0164 /** 0165 * @brief Generate CRC and copy T10 standard, runs baseline version. 0166 * @returns 16 bit CRC 0167 */ 0168 uint16_t 0169 crc16_t10dif_copy_base(uint16_t init_crc, //!< initial CRC value, 16 bits 0170 uint8_t *dst, //!< buffer destination for copy 0171 uint8_t *src, //!< buffer source to crc + copy 0172 uint64_t len //!< buffer length in bytes (64-bit data) 0173 ); 0174 0175 /** 0176 * @brief Generate CRC from the IEEE standard, runs baseline version 0177 * @returns 32 bit CRC 0178 */ 0179 uint32_t 0180 crc32_ieee_base(uint32_t seed, //!< initial CRC value, 32 bits 0181 uint8_t *buf, //!< buffer to calculate CRC on 0182 uint64_t len //!< buffer length in bytes (64-bit data) 0183 ); 0184 0185 /** 0186 * @brief Generate the customized CRC 0187 * based on RFC 1952 CRC (http://www.ietf.org/rfc/rfc1952.txt) standard, 0188 * runs baseline version 0189 * @returns 32 bit CRC 0190 */ 0191 uint32_t 0192 crc32_gzip_refl_base(uint32_t seed, //!< initial CRC value, 32 bits 0193 uint8_t *buf, //!< buffer to calculate CRC on 0194 uint64_t len //!< buffer length in bytes (64-bit data) 0195 ); 0196 0197 #ifdef __cplusplus 0198 } 0199 #endif 0200 0201 #endif // _CRC_H_
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |