1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Functions to compute SHA1 message digest according to the NIST
30 specification FIPS-180-1.
32 Adapted from the gnulib implementation.
41 \*---------------------------------------------------------------------------*/
48 #include <stdint.h> // C++0x uses <cstdint>
50 #include "SHA1Digest.H"
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 // Forward declaration of classes
60 // Forward declaration of friend functions and operators
63 Ostream& operator<<(Ostream&, const SHA1&);
66 /*---------------------------------------------------------------------------*\
67 Class SHA1 Declaration
68 \*---------------------------------------------------------------------------*/
74 //- Track if the hashsum has been finalized (added count, etc)
84 //- The total number processed, saved as 64-bit
85 uint32_t bufTotal_[2];
87 //- The number of elements pending in the buffer
90 //- The input processing buffer
93 // Private Member Functions
95 //- Swap bytes from internal to network (big-endian) order
96 static inline uint32_t swapBytes(uint32_t);
98 //- Copy the 4-byte value into the memory location pointed to by *dst.
99 // If the architecture allows unaligned access this is equivalent to
100 // *(uint32_t *) cp = val
101 static inline void set_uint32(unsigned char *cp, uint32_t);
103 //- Process data block-wise, LEN must be a multiple of 64!
104 void processBlock(const void *data, size_t len);
106 //- Process for the next LEN bytes, LEN need not be a multiple of 64.
107 void processBytes(const void *data, size_t len);
109 //- Calculate current digest from appended data.
110 void calcDigest(SHA1Digest&) const;
119 //- Construct and append initial std::string
120 explicit inline SHA1(const std::string&);
122 //- Construct and append initial string
123 explicit inline SHA1(const char*);
127 //- Reset the hashed data before appending more
130 //- Append data for processing
131 inline SHA1& append(const char* data, size_t len);
133 //- Append string for processing
134 inline SHA1& append(const std::string&);
136 //- Append string for processing
137 inline SHA1& append(const char* str);
139 //- Finalized the calculations (normally not needed directly).
140 // Returns false if no bytes were passed for processing
143 //- Calculate current digest from appended data.
144 SHA1Digest digest() const;
149 //- Equality operator
150 inline bool operator==(const SHA1Digest&) const;
152 //- Inequality operator
153 inline bool operator!=(const SHA1Digest&) const;
155 //- Equality operator
156 inline bool operator==(const SHA1&) const;
158 //- Inequality operator
159 inline bool operator!=(const SHA1&) const;
161 //- Convert to a digest, calculate current digest from appended data.
162 inline operator SHA1Digest() const;
168 inline friend Ostream& operator<<(Ostream&, const SHA1&);
173 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
175 } // End namespace Foam
177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185 // ************************************************************************* //