|
||||
File indexing completed on 2025-01-18 10:01:25
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 /** 0032 * @file crc.h 0033 * @brief CRC functions. 0034 */ 0035 0036 0037 #ifndef _CRC_H_ 0038 #define _CRC_H_ 0039 0040 #include <stdint.h> 0041 0042 #ifdef __cplusplus 0043 extern "C" { 0044 #endif 0045 0046 0047 /* Multi-binary functions */ 0048 0049 /** 0050 * @brief Generate CRC from the T10 standard, runs appropriate version. 0051 * 0052 * This function determines what instruction sets are enabled and 0053 * selects the appropriate version at runtime. 0054 * 0055 * @returns 16 bit CRC 0056 */ 0057 uint16_t crc16_t10dif( 0058 uint16_t init_crc, //!< initial CRC value, 16 bits 0059 const unsigned char *buf, //!< buffer to calculate CRC on 0060 uint64_t len //!< buffer length in bytes (64-bit data) 0061 ); 0062 0063 0064 /** 0065 * @brief Generate CRC and copy T10 standard, runs appropriate version. 0066 * 0067 * Stitched CRC + copy function. 0068 * 0069 * @returns 16 bit CRC 0070 */ 0071 uint16_t crc16_t10dif_copy( 0072 uint16_t init_crc, //!< initial CRC value, 16 bits 0073 uint8_t *dst, //!< buffer destination for copy 0074 uint8_t *src, //!< buffer source to crc + copy 0075 uint64_t len //!< buffer length in bytes (64-bit data) 0076 ); 0077 0078 0079 /** 0080 * @brief Generate CRC from the IEEE standard, runs appropriate version. 0081 * 0082 * This function determines what instruction sets are enabled and 0083 * selects the appropriate version at runtime. 0084 * Note: CRC32 IEEE standard is widely used in HDLC, Ethernet, Gzip and 0085 * many others. Its polynomial is 0x04C11DB7 in normal and 0xEDB88320 0086 * in reflection (or reverse). In ISA-L CRC, function crc32_ieee is 0087 * actually designed for normal CRC32 IEEE version. And function 0088 * crc32_gzip_refl is actually designed for reflected CRC32 IEEE. 0089 * These two versions of CRC32 IEEE are not compatible with each other. 0090 * Users who want to replace their not optimized crc32 ieee with ISA-L's 0091 * crc32 function should be careful of that. 0092 * Since many applications use CRC32 IEEE reflected version, Please have 0093 * a check whether crc32_gzip_refl is right one for you instead of 0094 * crc32_ieee. 0095 * 0096 * @returns 32 bit CRC 0097 */ 0098 0099 uint32_t crc32_ieee( 0100 uint32_t init_crc, //!< initial CRC value, 32 bits 0101 const unsigned char *buf, //!< buffer to calculate CRC on 0102 uint64_t len //!< buffer length in bytes (64-bit data) 0103 ); 0104 0105 /** 0106 * @brief Generate the customized CRC 0107 * based on RFC 1952 CRC (http://www.ietf.org/rfc/rfc1952.txt) standard, 0108 * runs appropriate version. 0109 * 0110 * This function determines what instruction sets are enabled and 0111 * selects the appropriate version at runtime. 0112 * 0113 * Note: CRC32 IEEE standard is widely used in HDLC, Ethernet, Gzip and 0114 * many others. Its polynomial is 0x04C11DB7 in normal and 0xEDB88320 0115 * in reflection (or reverse). In ISA-L CRC, function crc32_ieee is 0116 * actually designed for normal CRC32 IEEE version. And function 0117 * crc32_gzip_refl is actually designed for reflected CRC32 IEEE. 0118 * These two versions of CRC32 IEEE are not compatible with each other. 0119 * Users who want to replace their not optimized crc32 ieee with ISA-L's 0120 * crc32 function should be careful of that. 0121 * Since many applications use CRC32 IEEE reflected version, Please have 0122 * a check whether crc32_gzip_refl is right one for you instead of 0123 * crc32_ieee. 0124 * 0125 * @returns 32 bit CRC 0126 */ 0127 uint32_t crc32_gzip_refl( 0128 uint32_t init_crc, //!< initial CRC value, 32 bits 0129 const unsigned char *buf, //!< buffer to calculate CRC on 0130 uint64_t len //!< buffer length in bytes (64-bit data) 0131 ); 0132 0133 0134 /** 0135 * @brief ISCSI CRC function, runs appropriate version. 0136 * 0137 * This function determines what instruction sets are enabled and 0138 * selects the appropriate version at runtime. 0139 * 0140 * @returns 32 bit CRC 0141 */ 0142 unsigned int crc32_iscsi( 0143 unsigned char *buffer, //!< buffer to calculate CRC on 0144 int len, //!< buffer length in bytes 0145 unsigned int init_crc //!< initial CRC value 0146 ); 0147 0148 0149 /* Base functions */ 0150 0151 /** 0152 * @brief ISCSI CRC function, baseline version 0153 * @returns 32 bit CRC 0154 */ 0155 unsigned int crc32_iscsi_base( 0156 unsigned char *buffer, //!< buffer to calculate CRC on 0157 int len, //!< buffer length in bytes 0158 unsigned int crc_init //!< initial CRC value 0159 ); 0160 0161 0162 /** 0163 * @brief Generate CRC from the T10 standard, runs baseline version 0164 * @returns 16 bit CRC 0165 */ 0166 uint16_t crc16_t10dif_base( 0167 uint16_t seed, //!< initial CRC value, 16 bits 0168 uint8_t *buf, //!< buffer to calculate CRC on 0169 uint64_t len //!< buffer length in bytes (64-bit data) 0170 ); 0171 0172 0173 /** 0174 * @brief Generate CRC and copy T10 standard, runs baseline version. 0175 * @returns 16 bit CRC 0176 */ 0177 uint16_t crc16_t10dif_copy_base( 0178 uint16_t init_crc, //!< initial CRC value, 16 bits 0179 uint8_t *dst, //!< buffer destination for copy 0180 uint8_t *src, //!< buffer source to crc + copy 0181 uint64_t len //!< buffer length in bytes (64-bit data) 0182 ); 0183 0184 0185 /** 0186 * @brief Generate CRC from the IEEE standard, runs baseline version 0187 * @returns 32 bit CRC 0188 */ 0189 uint32_t crc32_ieee_base( 0190 uint32_t seed, //!< initial CRC value, 32 bits 0191 uint8_t *buf, //!< buffer to calculate CRC on 0192 uint64_t len //!< buffer length in bytes (64-bit data) 0193 ); 0194 0195 /** 0196 * @brief Generate the customized CRC 0197 * based on RFC 1952 CRC (http://www.ietf.org/rfc/rfc1952.txt) standard, 0198 * runs baseline version 0199 * @returns 32 bit CRC 0200 */ 0201 uint32_t crc32_gzip_refl_base( 0202 uint32_t seed, //!< initial CRC value, 32 bits 0203 uint8_t *buf, //!< buffer to calculate CRC on 0204 uint64_t len //!< buffer length in bytes (64-bit data) 0205 ); 0206 0207 0208 #ifdef __cplusplus 0209 } 0210 #endif 0211 0212 #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 |