Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRC-32C Checksum #1484

Merged
merged 6 commits into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/XrdCks/XrdCks.hh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class XrdSysPlugin;
/******************************************************************************/
/* X r d C k s P C B */
/******************************************************************************/
/*! The XrdCksPCB object defines a callabck hat allows he caller to monitor the
/*! The XrdCksPCB object defines a callback hat allows he caller to monitor the
progress of a checksum calculation (calc or verify).
*/

Expand Down
49 changes: 49 additions & 0 deletions src/XrdCks/XrdCksCalccrc32C.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "XrdCks/XrdCksCalccrc32C.hh"

/*
C++ implementation of CRC-32C checksums based upon
unattributed library functions.

This file contains:
functions implementing the methods of the XrdCksCalc class

Provided by:
Anton Schwarz
University of Heidelberg
July 26, 2021

Status:
Public Domain

*/

void XrdCksCalccrc32C::Update(const char *Buff, int BLen)
{
C32CResult = (unsigned int)XrdOucCRC::Calc32C(Buff, BLen, C32CResult);
}

const char *XrdCksCalccrc32C::Type(int &csSz)
{
csSz = sizeof(TheResult);
return "crc32c";
}

XrdCksCalc *XrdCksCalccrc32C::New() { return (XrdCksCalc *)new XrdCksCalccrc32C; }

void XrdCksCalccrc32C::Init()
{
C32CResult = C32C_XINIT;
}

char *XrdCksCalccrc32C::Final()
{
TheResult = C32CResult;
#ifndef Xrd_Big_Endian
TheResult = htonl(TheResult);
#endif
return (char *)&TheResult;
}

XrdCksCalccrc32C::XrdCksCalccrc32C() { Init(); }

XrdCksCalccrc32C::~XrdCksCalccrc32C() {};
60 changes: 60 additions & 0 deletions src/XrdCks/XrdCksCalccrc32C.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#ifndef __XRDCKSCALCCRC32C_HH__
#define __XRDCKSCALCCRC32C_HH__
/******************************************************************************/
/* */
/* X r d C k s C a l c c r c 3 2 C . h h */
/* */
/* (c) 2021 by the Board of Trustees of the Leland Stanford, Jr., University */
/* All Rights Reserved */
/* Produced by Andrew Hanushevsky for Stanford University under contract */
/* DE-AC02-76-SFO0515 with the Department of Energy */
/* */
/* This file is part of the XRootD software suite. */
/* */
/* XRootD is free software: you can redistribute it and/or modify it under */
/* the terms of the GNU Lesser General Public License as published by the */
/* Free Software Foundation, either version 3 of the License, or (at your */
/* option) any later version. */
/* */
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
/* License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
/* */
/* The copyright holder's institutional names and contributor's names may not */
/* be used to endorse or promote products derived from this software without */
/* specific prior written permission of the institution or contributor. */
/******************************************************************************/

#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <inttypes.h>

#include "XrdCks/XrdCksCalc.hh"
#include "XrdSys/XrdSysPlatform.hh"
#include "XrdOuc/XrdOucCRC.hh"

class XrdCksCalccrc32C : public XrdCksCalc
{
public:
char *Final();

void Init();

XrdCksCalc *New();
void Update(const char *Buff, int BLen);
const char *Type(int &csSz);
XrdCksCalccrc32C();
virtual ~XrdCksCalccrc32C();

private:
static const unsigned int C32C_XINIT = 0;
unsigned int C32CResult;
unsigned int TheResult;
};
#endif
14 changes: 9 additions & 5 deletions src/XrdCks/XrdCksManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "XrdCks/XrdCksCalc.hh"
#include "XrdCks/XrdCksCalcadler32.hh"
#include "XrdCks/XrdCksCalccrc32.hh"
#include "XrdCks/XrdCksCalccrc32C.hh"
#include "XrdCks/XrdCksCalcmd5.hh"
#include "XrdCks/XrdCksLoader.hh"
#include "XrdCks/XrdCksManager.hh"
Expand Down Expand Up @@ -76,8 +77,9 @@ XrdCksManager::XrdCksManager(XrdSysError *erP, int rdsz, XrdVersionInfo &vInfo,
//
strcpy(csTab[0].Name, "adler32");
strcpy(csTab[1].Name, "crc32");
strcpy(csTab[2].Name, "md5");
csLast = 2;
strcpy(csTab[2].Name, "crc32c");
strcpy(csTab[3].Name, "md5");
csLast = 3;

// Compute the i/o size
//
Expand Down Expand Up @@ -280,7 +282,7 @@ int XrdCksManager::Init(const char *ConfigFN, const char *DfltCalc)
if (i) {csInfo Temp = csTab[i]; csTab[i] = csTab[0]; csTab[0] = Temp;}
}

// See if there are any chacksums to configure
// See if there are any checksums to configure
//
if (csLast < 0)
{eDest->Emsg("Config", "No checksums defined; cannot configure!");
Expand All @@ -295,6 +297,8 @@ int XrdCksManager::Init(const char *ConfigFN, const char *DfltCalc)
csTab[i].Obj = new XrdCksCalcadler32;
else if (!strcmp("crc32", csTab[i].Name))
csTab[i].Obj = new XrdCksCalccrc32;
else if (!strcmp("crc32c", csTab[i].Name))
csTab[i].Obj = new XrdCksCalccrc32C;
else if (!strcmp("md5", csTab[i].Name))
csTab[i].Obj = new XrdCksCalcmd5;
else {eDest->Emsg("Config", "Invalid native checksum -",
Expand Down Expand Up @@ -396,7 +400,7 @@ XrdCksManager::csInfo *XrdCksManager::Find(const char *Name)
return 0;
}

// Attempte to dynamically load this object
// Attempt to dynamically load this object
//
{ char buff[2048];
*buff = 0;
Expand Down Expand Up @@ -589,7 +593,7 @@ int XrdCksManager::Set(const char *Pfn, XrdCksData &Cks, int myTime)
XrdOucXAttr<XrdCksXAttr> xCS;
csInfo *csIP = &csTab[0];

// Verify the incomming checksum for correctness
// Verify the incoming checksum for correctness
//
if (csLast < 0 || (*Cks.Name && !(csIP = Find(Cks.Name)))) return -ENOTSUP;
if (Cks.Length != csIP->Len) return -EDOM;
Expand Down
2 changes: 2 additions & 0 deletions src/XrdCl/XrdClCheckSumManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "XrdCks/XrdCksCalc.hh"
#include "XrdCks/XrdCksCalcmd5.hh"
#include "XrdCks/XrdCksCalccrc32.hh"
#include "XrdCks/XrdCksCalccrc32C.hh"
#include "XrdCks/XrdCksCalcadler32.hh"
#include "XrdSys/XrdSysE2T.hh"
#include "XrdSys/XrdSysPthread.hh"
Expand All @@ -48,6 +49,7 @@ namespace XrdCl
pLoader = new XrdCksLoader( XrdVERSIONINFOVAR( XrdCl ) );
pCalculators["md5"] = new XrdCksCalcmd5();
pCalculators["crc32"] = new XrdCksCalccrc32;
pCalculators["crc32c"] = new XrdCksCalccrc32C;
pCalculators["adler32"] = new XrdCksCalcadler32;
}

Expand Down
6 changes: 6 additions & 0 deletions src/XrdOuc/XrdOucCache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ int XrdOucCacheIO::pgRead(char *buff,
{
int bytes;

// Make sure the offset is on a 4K boundary and the size is a multiple of
// 4k as well (we use simple and for this).
//
if ((offs & XrdSys::PageMask)
|| (rdlen & XrdSys::PageMask)) return -EINVAL;

// Read the data into the buffer
//
bytes = Read(buff, offs, rdlen);
Expand Down
1 change: 1 addition & 0 deletions src/XrdUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ add_library(
#-----------------------------------------------------------------------------
XrdCks/XrdCksAssist.cc XrdCks/XrdCksAssist.hh
XrdCks/XrdCksCalccrc32.cc XrdCks/XrdCksCalccrc32.hh
XrdCks/XrdCksCalccrc32C.cc XrdCks/XrdCksCalccrc32C.hh
XrdCks/XrdCksCalcmd5.cc XrdCks/XrdCksCalcmd5.hh
XrdCks/XrdCksConfig.cc XrdCks/XrdCksConfig.hh
XrdCks/XrdCksLoader.cc XrdCks/XrdCksLoader.hh
Expand Down