xrootd
Loading...
Searching...
No Matches
XrdCksCalcadler32.hh
Go to the documentation of this file.
1#ifndef __XRDCKSCALCADLER32_HH__
2#define __XRDCKSCALCADLER32_HH__
3/******************************************************************************/
4/* */
5/* X r d C k s C a l c a d l e r 3 2 . h h */
6/* */
7/* (c) 2011 by the Board of Trustees of the Leland Stanford, Jr., University */
8/* All Rights Reserved */
9/* Produced by Andrew Hanushevsky for Stanford University under contract */
10/* DE-AC02-76-SFO0515 with the Department of Energy */
11/* */
12/* This file is part of the XRootD software suite. */
13/* */
14/* XRootD is free software: you can redistribute it and/or modify it under */
15/* the terms of the GNU Lesser General Public License as published by the */
16/* Free Software Foundation, either version 3 of the License, or (at your */
17/* option) any later version. */
18/* */
19/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22/* License for more details. */
23/* */
24/* You should have received a copy of the GNU Lesser General Public License */
25/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27/* */
28/* The copyright holder's institutional names and contributor's names may not */
29/* be used to endorse or promote products derived from this software without */
30/* specific prior written permission of the institution or contributor. */
31/******************************************************************************/
32
33#include <sys/types.h>
34#include <netinet/in.h>
35#include <cinttypes>
36
37#include "XrdCks/XrdCksCalc.hh"
39
40/* The following implementation of adler32 was derived from zlib and is
41 * Copyright (C) 1995-1998 Mark Adler
42 Below are the zlib license terms for this implementation.
43*/
44
45/* zlib.h -- interface of the 'zlib' general purpose compression library
46 version 1.1.4, March 11th, 2002
47
48 Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler
49
50 This software is provided 'as-is', without any express or implied
51 warranty. In no event will the authors be held liable for any damages
52 arising from the use of this software.
53
54 Permission is granted to anyone to use this software for any purpose,
55 including commercial applications, and to alter it and redistribute it
56 freely, subject to the following restrictions:
57
58 1. The origin of this software must not be misrepresented; you must not
59 claim that you wrote the original software. If you use this software
60 in a product, an acknowledgment in the product documentation would be
61 appreciated but is not required.
62 2. Altered source versions must be plainly marked as such, and must not be
63 misrepresented as being the original software.
64 3. This notice may not be removed or altered from any source distribution.
65
66 Jean-loup Gailly Mark Adler
67 jloup@gzip.org madler@alumni.caltech.edu
68
69
70 The data format used by the zlib library is described by RFCs (Request for
71 Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
72 (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
73*/
74
75#define DO1(buf) {unSum1 += *buf++; unSum2 += unSum1;}
76#define DO2(buf) DO1(buf); DO1(buf);
77#define DO4(buf) DO2(buf); DO2(buf);
78#define DO8(buf) DO4(buf); DO4(buf);
79#define DO16(buf) DO8(buf); DO8(buf);
80
82{
83public:
84
85char *Final()
86 {AdlerValue = (unSum2 << 16) | unSum1;
87#ifndef Xrd_Big_Endian
88 AdlerValue = htonl(AdlerValue);
89#endif
90 return (char *)&AdlerValue;
91 }
92
93void Init() {unSum1 = AdlerStart; unSum2 = 0;}
94
96
97void Update(const char *Buff, int BLen)
98 {int k;
99 unsigned char *buff = (unsigned char *)Buff;
100 while(BLen > 0)
101 {k = (BLen < AdlerNMax ? BLen : AdlerNMax);
102 BLen -= k;
103 while(k >= 16) {DO16(buff); k -= 16;}
104 if (k != 0) do {DO1(buff);} while (--k);
106 }
107 }
108
109const char *Type(int &csSize) {csSize = sizeof(AdlerValue); return "adler32";}
110
113
114private:
115
116static const unsigned int AdlerBase = 0xFFF1;
117static const unsigned int AdlerStart = 0x0001;
118static const int AdlerNMax = 5552;
119
120/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
121
122 unsigned int AdlerValue;
123 unsigned int unSum1;
124 unsigned int unSum2;
125};
126#endif
#define DO16(buf)
Definition XrdCksCalcadler32.hh:79
#define DO1(buf)
Definition XrdCksCalcadler32.hh:75
Definition XrdCksCalc.hh:40
Definition XrdCksCalcadler32.hh:82
void Update(const char *Buff, int BLen)
Definition XrdCksCalcadler32.hh:97
void Init()
Definition XrdCksCalcadler32.hh:93
static const unsigned int AdlerStart
Definition XrdCksCalcadler32.hh:117
XrdCksCalcadler32()
Definition XrdCksCalcadler32.hh:111
XrdCksCalc * New()
Definition XrdCksCalcadler32.hh:95
const char * Type(int &csSize)
Definition XrdCksCalcadler32.hh:109
virtual ~XrdCksCalcadler32()
Definition XrdCksCalcadler32.hh:112
unsigned int unSum1
Definition XrdCksCalcadler32.hh:123
char * Final()
Definition XrdCksCalcadler32.hh:85
unsigned int AdlerValue
Definition XrdCksCalcadler32.hh:122
static const int AdlerNMax
Definition XrdCksCalcadler32.hh:118
unsigned int unSum2
Definition XrdCksCalcadler32.hh:124
static const unsigned int AdlerBase
Definition XrdCksCalcadler32.hh:116