|
||||
File indexing completed on 2025-01-30 10:27:54
0001 #ifndef __XRDOUCCRC_HH__ 0002 #define __XRDOUCCRC_HH__ 0003 /******************************************************************************/ 0004 /* */ 0005 /* X r d O u c C R C . h h */ 0006 /* */ 0007 /* (c) 2007 by the Board of Trustees of the Leland Stanford, Jr., University */ 0008 /* All Rights Reserved */ 0009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 0010 /* DE-AC02-76-SFO0515 with the Department of Energy */ 0011 /* */ 0012 /* This file is part of the XRootD software suite. */ 0013 /* */ 0014 /* XRootD is free software: you can redistribute it and/or modify it under */ 0015 /* the terms of the GNU Lesser General Public License as published by the */ 0016 /* Free Software Foundation, either version 3 of the License, or (at your */ 0017 /* option) any later version. */ 0018 /* */ 0019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 0020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 0021 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 0022 /* License for more details. */ 0023 /* */ 0024 /* You should have received a copy of the GNU Lesser General Public License */ 0025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 0026 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 0027 /* */ 0028 /* The copyright holder's institutional names and contributor's names may not */ 0029 /* be used to endorse or promote products derived from this software without */ 0030 /* specific prior written permission of the institution or contributor. */ 0031 /******************************************************************************/ 0032 0033 #include <stddef.h> 0034 #include <cstdint> 0035 0036 #include "XrdSys/XrdSysPageSize.hh" 0037 0038 class XrdOucCRC 0039 { 0040 public: 0041 0042 //------------------------------------------------------------------------------ 0043 //! Compute a CRC32 checksum. 0044 //! 0045 //! @note This is a historical method as it uses the very slow CRC32 algoritm. 0046 // It is now better to use the CRC32C hardware assisted methods. 0047 //! 0048 //! @param data Pointer to the data whose checksum it to be computed. 0049 //! @param count The number of bytes pointed to by data. 0050 //! 0051 //! @return The CRC32 checksum. 0052 //------------------------------------------------------------------------------ 0053 0054 static uint32_t CRC32(const unsigned char *data, int count); 0055 0056 //------------------------------------------------------------------------------ 0057 //! Compute a CRC32C checksum using hardware assist if available. 0058 //! 0059 //! @param data Pointer to the data whose checksum it to be computed. 0060 //! @param count The number of bytes pointed to by data. 0061 //! @param prevcs The previous checksum value. The initial checksum of 0062 //! checksum sequence should be zero, the default. 0063 //! 0064 //! @return The CRC32C checksum. 0065 //------------------------------------------------------------------------------ 0066 0067 static uint32_t Calc32C(const void* data, size_t count, uint32_t prevcs=0); 0068 0069 //------------------------------------------------------------------------------ 0070 //! Compute a CRC32C page checksums using hardware assist if available. 0071 //! 0072 //! @param data Pointer to the data whose checksum it to be computed. 0073 //! @param count The number of bytes pointed to by data. 0074 //! @param csval Pointer to a vector to hold individual page checksums. The 0075 //! vector must be sized: 0076 //! (count/XrdSys::PageSize + (count%XrdSys::PageSize != 0)). 0077 //! On return, each element of csval holds the checksum for 0078 //! the associated page. 0079 //------------------------------------------------------------------------------ 0080 0081 static void Calc32C(const void* data, size_t count, uint32_t* csval); 0082 0083 //------------------------------------------------------------------------------ 0084 //! Verify a CRC32C checksum using hardware assist if available. 0085 //! 0086 //! @param data Pointer to the data whose checksum it to be verified. 0087 //! @param count The number of bytes pointed to by data. 0088 //! @param csval The expected checksum. 0089 //! @param csbad If csbad is not nil, the computed checksum is returned. 0090 //! 0091 //! @return True if the expected checksum equals the actual checksum; 0092 //! otherwise, false is returned. 0093 //------------------------------------------------------------------------------ 0094 0095 static bool Ver32C(const void* data, size_t count, 0096 const uint32_t csval, uint32_t* csbad=0); 0097 0098 //------------------------------------------------------------------------------ 0099 //! Verify a CRC32C page checksums using hardware assist if available. 0100 //! 0101 //! @param data Pointer to the data whose checksum it to be verified. 0102 //! @param count The number of bytes pointed to by data. 0103 //! @param csval Pointer to a vector of expected page checksums. The 0104 //! vector must be sized: 0105 //! (count/XrdSys::PageSize + (count%XrdSys::PageSize != 0)). 0106 //! @param valcs Where the computed checksum is returned for the page 0107 //! whose verification failed; otherwise it is untouched. 0108 //! 0109 //! @return -1 if all the checksums match. Otherwise, the non-negative index 0110 //! into csval whose checksum does not match. 0111 //------------------------------------------------------------------------------ 0112 0113 static int Ver32C(const void* data, size_t count, 0114 const uint32_t* csval, uint32_t& valcs); 0115 0116 //------------------------------------------------------------------------------ 0117 //! Verify a CRC32C page checksums using hardware assist if available. 0118 //! 0119 //! @param data Pointer to the data whose checksum it to be verified. 0120 //! @param count The number of bytes pointed to by data. 0121 //! @param csval Pointer to a vector of expected page checksums. The 0122 //! vector must be sized (count/PageSize+(count%PageSize != 0)). 0123 //! @param valok Pointer to a vector of the same size as csval to hold 0124 //! the results of the comparison (true matches, o/w false). 0125 //! 0126 //! @return True if all the checksums match with each element of valok set to 0127 //! true. Otherwise, false is returned and false is set in valok for 0128 //! each page that did not match the expected checksum. 0129 //------------------------------------------------------------------------------ 0130 0131 static bool Ver32C(const void* data, size_t count, 0132 const uint32_t* csval, bool* valok); 0133 0134 //------------------------------------------------------------------------------ 0135 //! Verify a CRC32C page checksums using hardware assist if available. 0136 //! 0137 //! @param data Pointer to the data whose checksum it to be verified. 0138 //! @param count The number of bytes pointed to by data. 0139 //! @param csval Pointer to a vector of expected page checksums. The 0140 //! vector must be sized (count/PageSize+(count%PageSize != 0)). 0141 //! @param valcs Pointer to a vector of the same size as csval to hold 0142 //! the computed checksum. 0143 //! 0144 //! @return True if all the checksums match; false otherwise. 0145 //------------------------------------------------------------------------------ 0146 0147 static bool Ver32C(const void* data, size_t count, 0148 const uint32_t* csval, uint32_t* valcs); 0149 0150 XrdOucCRC() {} 0151 ~XrdOucCRC() {} 0152 0153 private: 0154 0155 static unsigned int crctable[256]; 0156 }; 0157 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |