|
|
|
SHA1.HGo to the documentation of this file.00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. 00006 \\/ M anipulation | 00007 ------------------------------------------------------------------------------- 00008 License 00009 This file is part of OpenFOAM. 00010 00011 OpenFOAM is free software; you can redistribute it and/or modify it 00012 under the terms of the GNU General Public License as published by the 00013 Free Software Foundation; either version 2 of the License, or (at your 00014 option) any later version. 00015 00016 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00019 for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with OpenFOAM; if not, write to the Free Software Foundation, 00023 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00024 00025 Class 00026 Foam::SHA1 00027 00028 Description 00029 Functions to compute SHA1 message digest according to the NIST 00030 specification FIPS-180-1. 00031 00032 Adapted from the gnulib implementation. 00033 00034 SeeAlso 00035 Foam::SHA1Digest 00036 00037 SourceFiles 00038 SHA1I.H 00039 SHA1.C 00040 00041 \*---------------------------------------------------------------------------*/ 00042 00043 #ifndef SHA1_H 00044 #define SHA1_H 00045 00046 #include <string> 00047 #include <cstddef> 00048 #include <stdint.h> // C++0x uses <cstdint> 00049 00050 #include "SHA1Digest.H" 00051 00052 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00053 00054 namespace Foam 00055 { 00056 00057 // Forward declaration of classes 00058 class Ostream; 00059 00060 // Forward declaration of friend functions and operators 00061 class SHA1; 00062 class SHA1Digest; 00063 Ostream& operator<<(Ostream&, const SHA1&); 00064 00065 00066 /*---------------------------------------------------------------------------*\ 00067 Class SHA1 Declaration 00068 \*---------------------------------------------------------------------------*/ 00069 00070 class SHA1 00071 { 00072 // Private data 00073 00074 //- Track if the hashsum has been finalized (added count, etc) 00075 bool finalized_; 00076 00077 //- The hash sums 00078 uint32_t hashsumA_; 00079 uint32_t hashsumB_; 00080 uint32_t hashsumC_; 00081 uint32_t hashsumD_; 00082 uint32_t hashsumE_; 00083 00084 //- The total number processed, saved as 64-bit 00085 uint32_t bufTotal_[2]; 00086 00087 //- The number of elements pending in the buffer 00088 uint32_t bufLen_; 00089 00090 //- The input processing buffer 00091 uint32_t buffer_[32]; 00092 00093 // Private Member Functions 00094 00095 //- Swap bytes from internal to network (big-endian) order 00096 static inline uint32_t swapBytes(uint32_t); 00097 00098 //- Copy the 4-byte value into the memory location pointed to by *dst. 00099 // If the architecture allows unaligned access this is equivalent to 00100 // *(uint32_t *) cp = val 00101 static inline void set_uint32(unsigned char *cp, uint32_t); 00102 00103 //- Process data block-wise, LEN must be a multiple of 64! 00104 void processBlock(const void *data, size_t len); 00105 00106 //- Process for the next LEN bytes, LEN need not be a multiple of 64. 00107 void processBytes(const void *data, size_t len); 00108 00109 //- Calculate current digest from appended data. 00110 void calcDigest(SHA1Digest&) const; 00111 00112 public: 00113 00114 // Constructors 00115 00116 //- Construct null 00117 inline SHA1(); 00118 00119 //- Construct and append initial std::string 00120 explicit inline SHA1(const std::string&); 00121 00122 //- Construct and append initial string 00123 explicit inline SHA1(const char*); 00124 00125 // Member Functions 00126 00127 //- Reset the hashed data before appending more 00128 void clear(); 00129 00130 //- Append data for processing 00131 inline SHA1& append(const char* data, size_t len); 00132 00133 //- Append string for processing 00134 inline SHA1& append(const std::string&); 00135 00136 //- Append string for processing 00137 inline SHA1& append(const char* str); 00138 00139 //- Finalized the calculations (normally not needed directly). 00140 // Returns false if no bytes were passed for processing 00141 bool finalize(); 00142 00143 //- Calculate current digest from appended data. 00144 SHA1Digest digest() const; 00145 00146 00147 // Member Operators 00148 00149 //- Equality operator 00150 inline bool operator==(const SHA1Digest&) const; 00151 00152 //- Inequality operator 00153 inline bool operator!=(const SHA1Digest&) const; 00154 00155 //- Equality operator 00156 inline bool operator==(const SHA1&) const; 00157 00158 //- Inequality operator 00159 inline bool operator!=(const SHA1&) const; 00160 00161 //- Convert to a digest, calculate current digest from appended data. 00162 inline operator SHA1Digest() const; 00163 00164 // Friend Functions 00165 00166 // Friend Operators 00167 00168 inline friend Ostream& operator<<(Ostream&, const SHA1&); 00169 00170 }; 00171 00172 00173 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00174 00175 } // End namespace Foam 00176 00177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00178 00179 #include "SHA1I.H" 00180 00181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00182 00183 #endif 00184 00185 // ************************************************************************* // |