41 #if defined (__GLIBC__)
51 static const unsigned char fillbuf[64] = { 0x80, 0 };
57 inline uint32_t Foam::SHA1::swapBytes(uint32_t
n)
60 #if (__BYTE_ORDER == __BIG_ENDIAN)
66 | (((
n) & 0xff00) << 8)
67 | (((
n) >> 8) & 0xff00)
72 const short x = 0x0100;
75 if (*(
reinterpret_cast<const char*
>(&
x)))
84 | (((
n) & 0xff00) << 8)
85 | (((
n) >> 8) & 0xff00)
93 inline void Foam::SHA1::set_uint32(
unsigned char *
cp, uint32_t v)
95 memcpy(
cp, &v,
sizeof(uint32_t));
101 void Foam::SHA1::processBytes(
const void *data,
size_t len)
112 size_t remaining = bufLen_;
115 sizeof(buffer_) - remaining > len
117 :
sizeof(buffer_) - remaining
120 unsigned char* bufp =
reinterpret_cast<unsigned char*
>(buffer_);
122 memcpy(&bufp[remaining], data,
add);
127 processBlock(buffer_, bufLen_ & ~63);
132 memcpy(buffer_, &bufp[(remaining +
add) & ~63], bufLen_);
135 data =
reinterpret_cast<const unsigned char*
>(data) +
add;
142 processBlock(memcpy(buffer_, data, 64), 64);
143 data =
reinterpret_cast<const unsigned char*
>(data) + 64;
150 unsigned char* bufp =
reinterpret_cast<unsigned char*
>(buffer_);
151 size_t remaining = bufLen_;
153 memcpy (&bufp[remaining], data, len);
157 processBlock(buffer_, 64);
159 memcpy(buffer_, &buffer_[16], remaining);
167 #define K1 0x5a827999
168 #define K2 0x6ed9eba1
169 #define K3 0x8f1bbcdc
170 #define K4 0xca62c1d6
173 #define F1(B,C,D) ( D ^ ( B & ( C ^ D ) ) )
174 #define F2(B,C,D) (B ^ C ^ D)
175 #define F3(B,C,D) ( ( B & C ) | ( D & ( B | C ) ) )
176 #define F4(B,C,D) (B ^ C ^ D)
181 void Foam::SHA1::processBlock(
const void *data,
size_t len)
183 const uint32_t *words =
reinterpret_cast<const uint32_t*
>(data);
184 size_t nwords = len /
sizeof(uint32_t);
185 const uint32_t *endp = words + nwords;
189 uint32_t a = hashsumA_;
190 uint32_t
b = hashsumB_;
191 uint32_t
c = hashsumC_;
192 uint32_t d = hashsumD_;
193 uint32_t
e = hashsumE_;
199 if (bufTotal_[0] < len)
205 #define rol_uint32(x, nbits) (((x) << (nbits)) | ((x) >> (32 - (nbits))))
207 #define M(I) ( tm = x[I & 0x0F] ^ x[(I-14) & 0x0F] \
208 ^ x[(I-8) & 0x0F] ^ x[(I-3) & 0x0F] \
209 , (x[I & 0x0F] = rol_uint32(tm, 1)) )
211 #define R(A,B,C,D,E,F,K,M) \
214 E += rol_uint32(A, 5) + F(B, C, D) + K + M; \
215 B = rol_uint32(B, 30); \
221 for (
int t = 0; t < 16; ++t)
223 x[t] = swapBytes(*words);
317 void Foam::SHA1::calcDigest(SHA1Digest& dig)
const
319 if (bufTotal_[0] || bufTotal_[1])
321 unsigned char *r = dig.v_;
323 set_uint32(r + 0 *
sizeof(uint32_t), swapBytes(hashsumA_));
324 set_uint32(r + 1 *
sizeof(uint32_t), swapBytes(hashsumB_));
325 set_uint32(r + 2 *
sizeof(uint32_t), swapBytes(hashsumC_));
326 set_uint32(r + 3 *
sizeof(uint32_t), swapBytes(hashsumD_));
327 set_uint32(r + 4 *
sizeof(uint32_t), swapBytes(hashsumE_));
341 hashsumA_ = 0x67452301;
342 hashsumB_ = 0xefcdab89;
343 hashsumC_ = 0x98badcfe;
344 hashsumD_ = 0x10325476;
345 hashsumE_ = 0xc3d2e1f0;
347 bufTotal_[0] = bufTotal_[1] = 0;
361 uint32_t bytes = bufLen_;
362 size_t size = (bytes < 56 ? 64 : 128) /
sizeof(uint32_t);
365 bufTotal_[0] += bytes;
366 if (bufTotal_[0] < bytes)
372 if (!bufTotal_[0] && !bufTotal_[1])
378 buffer_[size-2] = swapBytes((bufTotal_[1] << 3) | (bufTotal_[0] >> 29));
379 buffer_[size-1] = swapBytes(bufTotal_[0] << 3);
381 unsigned char* bufp =
reinterpret_cast<unsigned char *
>(buffer_);
383 memcpy(&bufp[bytes], fillbuf, (size-2) *
sizeof(uint32_t) - bytes);
386 processBlock(buffer_, size *
sizeof(uint32_t));
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Functions to compute SHA1 message digest according to the NIST specification FIPS-180-1.
bool finalise()
Finalised the calculations (normally not needed directly).
void clear()
Reset the hashed data before appending more.
SHA1Digest digest() const
Calculate current digest from appended data.
const dimensionedScalar c
Speed of light in a vacuum.
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
static scalar R(const scalar a, const scalar x)
bool cp(const fileName &src, const fileName &dst, const bool followLink=true)
Copy, recursively if necessary, the source to the destination.