XRootD
XrdOucCRC Class Reference

#include <XrdOucCRC.hh>

+ Collaboration diagram for XrdOucCRC:

Public Member Functions

 XrdOucCRC ()
 
 ~XrdOucCRC ()
 

Static Public Member Functions

static void Calc32C (const void *data, size_t count, uint32_t *csval)
 
static uint32_t Calc32C (const void *data, size_t count, uint32_t prevcs=0)
 
static uint32_t Combine32C (uint32_t Cksum1, uint32_t Cksum2, int DLen)
 
static uint32_t CRC32 (const unsigned char *data, int count)
 
static bool Ver32C (const void *data, size_t count, const uint32_t *csval, bool *valok)
 
static int Ver32C (const void *data, size_t count, const uint32_t *csval, uint32_t &valcs)
 
static bool Ver32C (const void *data, size_t count, const uint32_t *csval, uint32_t *valcs)
 
static bool Ver32C (const void *data, size_t count, const uint32_t csval, uint32_t *csbad=0)
 

Detailed Description

Definition at line 38 of file XrdOucCRC.hh.

Constructor & Destructor Documentation

◆ XrdOucCRC()

XrdOucCRC::XrdOucCRC ( )
inline

Definition at line 166 of file XrdOucCRC.hh.

166 {}

◆ ~XrdOucCRC()

XrdOucCRC::~XrdOucCRC ( )
inline

Definition at line 167 of file XrdOucCRC.hh.

167 {}

Member Function Documentation

◆ Calc32C() [1/2]

void XrdOucCRC::Calc32C ( const void *  data,
size_t  count,
uint32_t *  csval 
)
static

Compute a CRC32C page checksums using hardware assist if available.

Parameters
dataPointer to the data whose checksum it to be computed.
countThe number of bytes pointed to by data.
csvalPointer to a vector to hold individual page checksums. The vector must be sized: (count/XrdSys::PageSize + (countXrdSys::PageSize != 0)). On return, each element of csval holds the checksum for the associated page.

Definition at line 200 of file XrdOucCRC.cc.

201 {
202  int i, numpages = count/XrdSys::PageSize;
203  const uint8_t* dataP = (const uint8_t*)data;
204 
205 // Calculate the CRC32C for each page
206 //
207  for (i = 0; i < numpages; i++)
208  {csval[i] = crc32c(0, dataP, XrdSys::PageSize);
209  count -= XrdSys::PageSize;
210  dataP += XrdSys::PageSize;
211  }
212 
213 // if there is anything left, calculate that as well
214 //
215  if (count > 0) csval[i] = crc32c(0, dataP, count);
216 }
uint32_t crc32c(uint32_t crc, void const *buf, size_t len)
static const int PageSize

References crc32c(), and XrdSys::PageSize.

+ Here is the call graph for this function:

◆ Calc32C() [2/2]

uint32_t XrdOucCRC::Calc32C ( const void *  data,
size_t  count,
uint32_t  prevcs = 0 
)
static

Compute a CRC32C checksum using hardware assist if available.

Parameters
dataPointer to the data whose checksum it to be computed.
countThe number of bytes pointed to by data.
prevcsThe previous checksum value. The initial checksum of checksum sequence should be zero, the default.
Returns
The CRC32C checksum.

Definition at line 190 of file XrdOucCRC.cc.

191 {
192 
193 // Return the checksum
194 //
195  return crc32c(prevcs, data, count);
196 }

References crc32c().

Referenced by XrdOfsCPFile::Append(), XrdOssCsiPages::apply_sequential_aligned_modify(), XrdOssCsiPages::BasicConsistencyCheck(), XrdXrootdPgwBadCS::boInfo(), XrdOssCsiCrcUtils::crc32c_combine(), XrdOssCsiCrcUtils::crc32c_extendwith_zero(), XrdOssCsiCrcUtils::crc32c_split2(), XrdOfsCPFile::Create(), XrdOucPgrwUtils::csCalc(), XrdOssCsiPages::FetchRangeAligned(), XrdOssCsiPages::FetchRangeUnaligned(), XrdOssCsiPages::FetchRangeUnaligned_postblock(), XrdOssCsiPages::FetchRangeUnaligned_preblock(), XrdCl::EcPgReadResponseHandler::HandleResponse(), main(), XrdOssCsiTagstoreFile::Open(), XrdOssCsiPages::pgDoCalc(), XrdOssCsiPages::StoreRangeUnaligned_postblock(), XrdOssCsiPages::StoreRangeUnaligned_preblock(), XrdClHttp::CurlPgReadOp::Success(), XrdOssCsiPages::truncate(), XrdCl::XRootDTransport::UnMarchalStatusMore(), XrdCl::XRootDTransport::UnMarshalStatusBody(), and XrdCksCalccrc32C::Update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Combine32C()

uint32_t XrdOucCRC::Combine32C ( uint32_t  Cksum1,
uint32_t  Cksum2,
int  DLen 
)
static

Combine a CRC32C checksum with a checksum computed for an adjacent block.

Parameters
Cksum1-> The first checksum.
Cksum2-> The subsequent adjacent checksum.
DLen-> Length of the data used to compute the Cksum2.
Returns
The combined checksum.
Note
Warning! The Cksum2 must have been computed for the adjacent block of data relative to the computation of Cksum1 otherwise the combined checksum will be invalid.

Definition at line 222 of file XrdOucCRC.cc.

223 {
224  return crc32c_combine(Cksum1, Cksum2, (size_t)DLen);
225 }
uint32_t crc32c_combine(uint32_t crcA, uint32_t crcB, size_t lengthB)
merge two CRC32 such that result = crc32(dataB, lengthB, crc32(dataA, lengthA))

References crc32c_combine().

Referenced by XrdCksCalccrc32C::Combine().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CRC32()

uint32_t XrdOucCRC::CRC32 ( const unsigned char *  data,
int  count 
)
static

Compute a CRC32 checksum.

Note
This is a historical method as it uses the very slow CRC32 algoritm.
Parameters
dataPointer to the data whose checksum it to be computed.
countThe number of bytes pointed to by data.
Returns
The CRC32 checksum.

Definition at line 171 of file XrdOucCRC.cc.

172 {
173  const unsigned int CRC32_XINIT = 0xffffffff;
174  const unsigned int CRC32_XOROT = 0xffffffff;
175  unsigned int crc = CRC32_XINIT;
176 
177 // Process each byte
178 //
179  while(reclen-- > 0) crc = crctable[(crc ^ *p++) & 0xff] ^ (crc >> 8);
180 
181 // Return XOR out value
182 //
183  return crc ^ CRC32_XOROT;
184 }

Referenced by XrdOfsHanKey::XrdOfsHanKey(), XrdOucReqID::XrdOucReqID(), XrdCryptoLite_bf32::Decrypt(), XrdCryptoLite_bf32::Encrypt(), XrdOucReqID::Index(), and XrdCmsKey::setHash().

+ Here is the caller graph for this function:

◆ Ver32C() [1/4]

bool XrdOucCRC::Ver32C ( const void *  data,
size_t  count,
const uint32_t *  csval,
bool *  valok 
)
static

Verify a CRC32C page checksums using hardware assist if available.

Parameters
dataPointer to the data whose checksum it to be verified.
countThe number of bytes pointed to by data.
csvalPointer to a vector of expected page checksums. The vector must be sized (count/PageSize+(countPageSize != 0)).
valokPointer to a vector of the same size as csval to hold the results of the comparison (true matches, o/w false).
Returns
True if all the checksums match with each element of valok set to true. Otherwise, false is returned and false is set in valok for each page that did not match the expected checksum.

Definition at line 283 of file XrdOucCRC.cc.

285 {
286  int i, numpages = count/XrdSys::PageSize;
287  const uint8_t* dataP = (const uint8_t*)data;
288  uint32_t actualCS;
289  bool retval = true;
290 
291 // Calculate the CRC32C for each page and make sure it is the same.
292 //
293  for (i = 0; i < numpages; i++)
294  {
295  actualCS = crc32c(0, dataP, XrdSys::PageSize);
296  if (csval[i] == actualCS) valok[i] = true;
297  else valok[i] = retval = false;
298  count -= XrdSys::PageSize;
299  dataP += XrdSys::PageSize;
300  }
301 
302 // if there is anything left, verify that as well
303 //
304  if (count > 0)
305  {
306  actualCS = crc32c(0, dataP, count);
307  if (csval[i] == actualCS) valok[i] = true;
308  else valok[i] = retval = false;
309  }
310 
311 // All done.
312 //
313  return retval;
314 }

References crc32c(), and XrdSys::PageSize.

+ Here is the call graph for this function:

◆ Ver32C() [2/4]

int XrdOucCRC::Ver32C ( const void *  data,
size_t  count,
const uint32_t *  csval,
uint32_t &  valcs 
)
static

Verify a CRC32C page checksums using hardware assist if available.

Parameters
dataPointer to the data whose checksum it to be verified.
countThe number of bytes pointed to by data.
csvalPointer to a vector of expected page checksums. The vector must be sized: (count/XrdSys::PageSize + (countXrdSys::PageSize != 0)).
valcsWhere the computed checksum is returned for the page whose verification failed; otherwise it is untouched.
Returns
-1 if all the checksums match. Otherwise, the non-negative index into csval whose checksum does not match.

Definition at line 245 of file XrdOucCRC.cc.

247 {
248  int i, numpages = count/XrdSys::PageSize;
249  const uint8_t* dataP = (const uint8_t*)data;
250  uint32_t actualCS;
251 
252 // Calculate the CRC32C for each page and make sure it is the same.
253 //
254  for (i = 0; i < numpages; i++)
255  {
256  actualCS = crc32c(0, dataP, XrdSys::PageSize);
257  if (csval[i] != actualCS)
258  {valcs = actualCS;
259  return i;
260  }
261  count -= XrdSys::PageSize;
262  dataP += XrdSys::PageSize;
263  }
264 
265 // if there is anything left, verify that as well
266 //
267  if (count > 0)
268  {
269  actualCS = crc32c(0, dataP, count);
270  if (csval[i] != actualCS)
271  {valcs = actualCS;
272  return i;
273  }
274  }
275 
276 // Everything matched.
277 //
278  return -1;
279 }

References crc32c(), and XrdSys::PageSize.

+ Here is the call graph for this function:

◆ Ver32C() [3/4]

bool XrdOucCRC::Ver32C ( const void *  data,
size_t  count,
const uint32_t *  csval,
uint32_t *  valcs 
)
static

Verify a CRC32C page checksums using hardware assist if available.

Parameters
dataPointer to the data whose checksum it to be verified.
countThe number of bytes pointed to by data.
csvalPointer to a vector of expected page checksums. The vector must be sized (count/PageSize+(countPageSize != 0)).
valcsPointer to a vector of the same size as csval to hold the computed checksum.
Returns
True if all the checksums match; false otherwise.

Definition at line 318 of file XrdOucCRC.cc.

320 {
321  int i, numpages = count/XrdSys::PageSize;
322  const uint8_t* dataP = (const uint8_t*)data;
323  bool retval = true;
324 
325 // Calculate the CRC32C for each page and make sure it is the same.
326 //
327  for (i = 0; i < numpages; i++)
328  {
329  valcs[i] = crc32c(0, dataP, XrdSys::PageSize);
330  if (csval[i] != valcs[i]) retval = false;
331  count -= XrdSys::PageSize;
332  dataP += XrdSys::PageSize;
333  }
334 
335 // if there is anything left, verify that as well
336 //
337  if (count > 0)
338  {
339  valcs[i] = crc32c(0, dataP, count);
340  if (csval[i] != valcs[i]) retval = false;
341  }
342 
343 // All done.
344 //
345  return retval;
346 }

References crc32c(), and XrdSys::PageSize.

+ Here is the call graph for this function:

◆ Ver32C() [4/4]

bool XrdOucCRC::Ver32C ( const void *  data,
size_t  count,
const uint32_t  csval,
uint32_t *  csbad = 0 
)
static

Verify a CRC32C checksum using hardware assist if available.

Parameters
dataPointer to the data whose checksum it to be verified.
countThe number of bytes pointed to by data.
csvalThe expected checksum.
csbadIf csbad is not nil, the computed checksum is returned.
Returns
True if the expected checksum equals the actual checksum; otherwise, false is returned.

Definition at line 231 of file XrdOucCRC.cc.

233 {
234  uint32_t actualCS;
235 
236 // Verify the checksum
237 //
238  actualCS = crc32c(0, data, count);
239  if (valcs) *valcs = actualCS;
240  return csval == actualCS;
241 }

References crc32c().

Referenced by XrdOucPgrwUtils::csVer(), XrdOssCsiPages::pgWritePrelockCheck(), and XrdOfsCPFile::RestoreInfo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: