MCPcopy Create free account
hub / github.com/OpenFOAM/OpenFOAM-dev / processBlock

Function processBlock

src/OpenFOAM/primitives/hashes/SHA1/SHA1.C:181–314  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

179// Most of this code comes from GnuPG's cipher/sha1.c
180
181void Foam::SHA1::processBlock(const void *data, size_t len)
182{
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;
186
187 // calculate with sixteen words of 32-bits
188 uint32_t x[16];
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_;
194
195 // First increment the byte count.
196 // RFC 1321 specifies the possible length of the file up to 2^64 bits.
197 // Here we only compute the number of bytes. Do a double word increment.
198 bufTotal_[0] += len;
199 if (bufTotal_[0] < len)
200 {
201 ++bufTotal_[1];
202 }
203
204 // rotate left uint32_t by n bits
205 #define rol_uint32(x, nbits) (((x) << (nbits)) | ((x) >> (32 - (nbits))))
206
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)) )
210
211 #define R(A,B,C,D,E,F,K,M) \
212 do \
213 { \
214 E += rol_uint32(A, 5) + F(B, C, D) + K + M; \
215 B = rol_uint32(B, 30); \
216 } while (0)
217
218 while (words < endp)
219 {
220 uint32_t tm;
221 for (int t = 0; t < 16; ++t)
222 {
223 x[t] = swapBytes(*words);
224 ++words;
225 }
226
227 R( a, b, c, d, e, F1, K1, x[ 0] );
228 R( e, a, b, c, d, F1, K1, x[ 1] );
229 R( d, e, a, b, c, F1, K1, x[ 2] );
230 R( c, d, e, a, b, F1, K1, x[ 3] );
231 R( b, c, d, e, a, F1, K1, x[ 4] );
232 R( a, b, c, d, e, F1, K1, x[ 5] );
233 R( e, a, b, c, d, F1, K1, x[ 6] );
234 R( d, e, a, b, c, F1, K1, x[ 7] );
235 R( c, d, e, a, b, F1, K1, x[ 8] );
236 R( b, c, d, e, a, F1, K1, x[ 9] );
237 R( a, b, c, d, e, F1, K1, x[10] );
238 R( e, a, b, c, d, F1, K1, x[11] );

Callers 2

processBytesFunction · 0.85
finalizeFunction · 0.85

Calls 1

swapBytesFunction · 0.85

Tested by

no test coverage detected