OpenCoverage

md5.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/lib/md5.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10static const unsigned char fillbuf[64] = { 0x80, 0 };-
11-
12-
13-
14-
15void-
16md5_init_ctx (struct md5_ctx *ctx)-
17{-
18 ctx->A = 0x67452301;-
19 ctx->B = 0xefcdab89;-
20 ctx->C = 0x98badcfe;-
21 ctx->D = 0x10325476;-
22-
23 ctx->total[0] = ctx->total[1] = 0;-
24 ctx->buflen = 0;-
25}
executed 1586 times by 2 tests: end of block
Executed by:
  • md5sum
  • sort
1586
26-
27-
28-
29-
30static void-
31set_uint32 (char *cp, uint32_t v)-
32{-
33 memcpy (cp, &v, sizeof v);-
34}
executed 5168964 times by 2 tests: end of block
Executed by:
  • md5sum
  • sort
5168964
35-
36-
37-
38void *-
39md5_read_ctx (const struct md5_ctx *ctx, void *resbuf)-
40{-
41 char *r = resbuf;-
42 set_uint32 (r + 0 * sizeof ctx->A, (ctx->A));-
43 set_uint32 (r + 1 * sizeof ctx->B, (ctx->B));-
44 set_uint32 (r + 2 * sizeof ctx->C, (ctx->C));-
45 set_uint32 (r + 3 * sizeof ctx->D, (ctx->D));-
46-
47 return
executed 1292241 times by 2 tests: return resbuf;
Executed by:
  • md5sum
  • sort
resbuf;
executed 1292241 times by 2 tests: return resbuf;
Executed by:
  • md5sum
  • sort
1292241
48}-
49-
50-
51-
52void *-
53md5_finish_ctx (struct md5_ctx *ctx, void *resbuf)-
54{-
55-
56 uint32_t bytes = ctx->buflen;-
57 size_t size = (
(bytes < 56)Description
TRUEevaluated 1292240 times by 2 tests
Evaluated by:
  • md5sum
  • sort
FALSEevaluated 1 time by 1 test
Evaluated by:
  • md5sum
bytes < 56)
(bytes < 56)Description
TRUEevaluated 1292240 times by 2 tests
Evaluated by:
  • md5sum
  • sort
FALSEevaluated 1 time by 1 test
Evaluated by:
  • md5sum
? 64 / 4 : 64 * 2 / 4;
1-1292240
58-
59-
60 ctx->total[0] += bytes;-
61 if (ctx->total[0] < bytes
ctx->total[0] < bytesDescription
TRUEnever evaluated
FALSEevaluated 1292241 times by 2 tests
Evaluated by:
  • md5sum
  • sort
)
0-1292241
62 ++
never executed: ++ctx->total[1];
ctx->total[1];
never executed: ++ctx->total[1];
0
63-
64-
65 ctx->buffer[size - 2] = (ctx->total[0] << 3);-
66 ctx->buffer[size - 1] = ((ctx->total[1] << 3) | (ctx->total[0] >> 29));-
67-
68 memcpy (&((char *) ctx->buffer)[bytes], fillbuf, (size - 2) * 4 - bytes);-
69-
70-
71 md5_process_block (ctx->buffer, size * 4, ctx);-
72-
73 return
executed 1292241 times by 2 tests: return md5_read_ctx (ctx, resbuf);
Executed by:
  • md5sum
  • sort
md5_read_ctx (ctx, resbuf);
executed 1292241 times by 2 tests: return md5_read_ctx (ctx, resbuf);
Executed by:
  • md5sum
  • sort
1292241
74}-
75-
76-
77-
78-
79-
80int-
81md5_stream (FILE *stream, void *resblock)-
82{-
83 struct md5_ctx ctx;-
84 size_t sum;-
85-
86 char *buffer = malloc (32768 + 72);-
87 if (!buffer
!bufferDescription
TRUEnever evaluated
FALSEevaluated 1571 times by 1 test
Evaluated by:
  • md5sum
)
0-1571
88 return
never executed: return 1;
1;
never executed: return 1;
0
89-
90-
91 md5_init_ctx (&ctx);-
92-
93-
94 while (1)-
95 {-
96-
97-
98-
99 size_t n;-
100 sum = 0;-
101-
102-
103 while (1)-
104 {-
105 n = fread_unlocked (buffer + sum,1,32768 - sum,stream);-
106-
107 sum += n;-
108-
109 if (sum == 32768
sum == 32768Description
TRUEevaluated 250 times by 1 test
Evaluated by:
  • md5sum
FALSEevaluated 1571 times by 1 test
Evaluated by:
  • md5sum
)
250-1571
110 break;
executed 250 times by 1 test: break;
Executed by:
  • md5sum
250
111-
112 if (n == 0
n == 0Description
TRUEevaluated 1522 times by 1 test
Evaluated by:
  • md5sum
FALSEevaluated 49 times by 1 test
Evaluated by:
  • md5sum
)
49-1522
113 {-
114-
115-
116-
117 if (ferror_unlocked (stream)
ferror_unlocked (stream)Description
TRUEnever evaluated
FALSEevaluated 1522 times by 1 test
Evaluated by:
  • md5sum
)
0-1522
118 {-
119 free (buffer);-
120 return
never executed: return 1;
1;
never executed: return 1;
0
121 }-
122 goto
executed 1522 times by 1 test: goto process_partial_block;
Executed by:
  • md5sum
process_partial_block;
executed 1522 times by 1 test: goto process_partial_block;
Executed by:
  • md5sum
1522
123 }-
124-
125-
126-
127-
128 if (feof_unlocked (stream)
feof_unlocked (stream)Description
TRUEevaluated 49 times by 1 test
Evaluated by:
  • md5sum
FALSEnever evaluated
)
0-49
129 goto
executed 49 times by 1 test: goto process_partial_block;
Executed by:
  • md5sum
process_partial_block;
executed 49 times by 1 test: goto process_partial_block;
Executed by:
  • md5sum
49
130 }
never executed: end of block
0
131-
132-
133-
134-
135 md5_process_block (buffer, 32768, &ctx);-
136 }
executed 250 times by 1 test: end of block
Executed by:
  • md5sum
250
137-
138process_partial_block:
code before this statement never executed: process_partial_block:
0
139-
140-
141 if (sum > 0
sum > 0Description
TRUEevaluated 49 times by 1 test
Evaluated by:
  • md5sum
FALSEevaluated 1522 times by 1 test
Evaluated by:
  • md5sum
)
49-1522
142 md5_process_bytes (buffer, sum, &ctx);
executed 49 times by 1 test: md5_process_bytes (buffer, sum, &ctx);
Executed by:
  • md5sum
49
143-
144-
145 md5_finish_ctx (&ctx, resblock);-
146 free (buffer);-
147 return
executed 1571 times by 1 test: return 0;
Executed by:
  • md5sum
0;
executed 1571 times by 1 test: return 0;
Executed by:
  • md5sum
1571
148}-
149-
150-
151-
152-
153-
154-
155void *-
156md5_buffer (const char *buffer, size_t len, void *resblock)-
157{-
158 struct md5_ctx ctx;-
159-
160-
161 md5_init_ctx (&ctx);-
162-
163-
164 md5_process_bytes (buffer, len, &ctx);-
165-
166-
167 return
never executed: return md5_finish_ctx (&ctx, resblock);
md5_finish_ctx (&ctx, resblock);
never executed: return md5_finish_ctx (&ctx, resblock);
0
168}-
169-
170-
171void-
172md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx)-
173{-
174-
175-
176 if (ctx->buflen != 0
ctx->buflen != 0Description
TRUEevaluated 1290670 times by 1 test
Evaluated by:
  • sort
FALSEevaluated 64 times by 2 tests
Evaluated by:
  • md5sum
  • sort
)
64-1290670
177 {-
178 size_t left_over = ctx->buflen;-
179 size_t add = 128 - left_over > len
128 - left_over > lenDescription
TRUEevaluated 1290670 times by 1 test
Evaluated by:
  • sort
FALSEnever evaluated
? len : 128 - left_over;
0-1290670
180-
181 memcpy (&((char *) ctx->buffer)[left_over], buffer, add);-
182 ctx->buflen += add;-
183-
184 if (ctx->buflen > 64
ctx->buflen > 64Description
TRUEevaluated 240828 times by 1 test
Evaluated by:
  • sort
FALSEevaluated 1049842 times by 1 test
Evaluated by:
  • sort
)
240828-1049842
185 {-
186 md5_process_block (ctx->buffer, ctx->buflen & ~63, ctx);-
187-
188 ctx->buflen &= 63;-
189-
190-
191 memcpy (ctx->buffer,-
192 &((char *) ctx->buffer)[(left_over + add) & ~63],-
193 ctx->buflen);-
194 }
executed 240828 times by 1 test: end of block
Executed by:
  • sort
240828
195-
196 buffer = (const char *) buffer + add;-
197 len -= add;-
198 }
executed 1290670 times by 1 test: end of block
Executed by:
  • sort
1290670
199-
200-
201 if (len >= 64
len >= 64Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • md5sum
FALSEevaluated 1290731 times by 2 tests
Evaluated by:
  • md5sum
  • sort
)
3-1290731
202 {-
203 {-
204 md5_process_block (buffer, len & ~63, ctx);-
205 buffer = (const char *) buffer + (len & ~63);-
206 len &= 63;-
207 }-
208 }
executed 3 times by 1 test: end of block
Executed by:
  • md5sum
3
209-
210-
211 if (len > 0
len > 0Description
TRUEevaluated 64 times by 2 tests
Evaluated by:
  • md5sum
  • sort
FALSEevaluated 1290670 times by 1 test
Evaluated by:
  • sort
)
64-1290670
212 {-
213 size_t left_over = ctx->buflen;-
214-
215 memcpy (&((char *) ctx->buffer)[left_over], buffer, len);-
216 left_over += len;-
217 if (left_over >= 64
left_over >= 64Description
TRUEnever evaluated
FALSEevaluated 64 times by 2 tests
Evaluated by:
  • md5sum
  • sort
)
0-64
218 {-
219 md5_process_block (ctx->buffer, 64, ctx);-
220 left_over -= 64;-
221-
222-
223 memcpy (ctx->buffer, &ctx->buffer[16], left_over);-
224 }
never executed: end of block
0
225 ctx->buflen = left_over;-
226 }
executed 64 times by 2 tests: end of block
Executed by:
  • md5sum
  • sort
64
227}
executed 1290734 times by 2 tests: end of block
Executed by:
  • md5sum
  • sort
1290734
228void-
229md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx)-
230{-
231 uint32_t correct_words[16];-
232 const uint32_t *words = buffer;-
233 size_t nwords = len / sizeof (uint32_t);-
234 const uint32_t *endp = words + nwords;-
235 uint32_t A = ctx->A;-
236 uint32_t B = ctx->B;-
237 uint32_t C = ctx->C;-
238 uint32_t D = ctx->D;-
239 uint32_t lolen = len;-
240-
241-
242-
243-
244 ctx->total[0] += lolen;-
245 ctx->total[1] += (len >> 31 >> 1) + (ctx->total[0] < lolen);-
246-
247-
248-
249 while (words < endp
words < endpDescription
TRUEevaluated 1661253 times by 2 tests
Evaluated by:
  • md5sum
  • sort
FALSEevaluated 1533322 times by 2 tests
Evaluated by:
  • md5sum
  • sort
)
1533322-1661253
250 {-
251 uint32_t *cwp = correct_words;-
252 uint32_t A_save = A;-
253 uint32_t B_save = B;-
254 uint32_t C_save = C;-
255 uint32_t D_save = D;-
256 do { A += (D ^ (B & (C ^ D))) + (*cwp++ = (*words)) + 0xd76aa478; ++words; (A = (A << 7) | (A >> (32 - 7))); A += B; } while (0);-
257 do { D += (C ^ (A & (B ^ C))) + (*cwp++ = (*words)) + 0xe8c7b756; ++words; (D = (D << 12) | (D >> (32 - 12))); D += A; } while (0);-
258 do { C += (B ^ (D & (A ^ B))) + (*cwp++ = (*words)) + 0x242070db; ++words; (C = (C << 17) | (C >> (32 - 17))); C += D; } while (0);-
259 do { B += (A ^ (C & (D ^ A))) + (*cwp++ = (*words)) + 0xc1bdceee; ++words; (B = (B << 22) | (B >> (32 - 22))); B += C; } while (0);-
260 do { A += (D ^ (B & (C ^ D))) + (*cwp++ = (*words)) + 0xf57c0faf; ++words; (A = (A << 7) | (A >> (32 - 7))); A += B; } while (0);-
261 do { D += (C ^ (A & (B ^ C))) + (*cwp++ = (*words)) + 0x4787c62a; ++words; (D = (D << 12) | (D >> (32 - 12))); D += A; } while (0);-
262 do { C += (B ^ (D & (A ^ B))) + (*cwp++ = (*words)) + 0xa8304613; ++words; (C = (C << 17) | (C >> (32 - 17))); C += D; } while (0);-
263 do { B += (A ^ (C & (D ^ A))) + (*cwp++ = (*words)) + 0xfd469501; ++words; (B = (B << 22) | (B >> (32 - 22))); B += C; } while (0);-
264 do { A += (D ^ (B & (C ^ D))) + (*cwp++ = (*words)) + 0x698098d8; ++words; (A = (A << 7) | (A >> (32 - 7))); A += B; } while (0);-
265 do { D += (C ^ (A & (B ^ C))) + (*cwp++ = (*words)) + 0x8b44f7af; ++words; (D = (D << 12) | (D >> (32 - 12))); D += A; } while (0);-
266 do { C += (B ^ (D & (A ^ B))) + (*cwp++ = (*words)) + 0xffff5bb1; ++words; (C = (C << 17) | (C >> (32 - 17))); C += D; } while (0);-
267 do { B += (A ^ (C & (D ^ A))) + (*cwp++ = (*words)) + 0x895cd7be; ++words; (B = (B << 22) | (B >> (32 - 22))); B += C; } while (0);-
268 do { A += (D ^ (B & (C ^ D))) + (*cwp++ = (*words)) + 0x6b901122; ++words; (A = (A << 7) | (A >> (32 - 7))); A += B; } while (0);-
269 do { D += (C ^ (A & (B ^ C))) + (*cwp++ = (*words)) + 0xfd987193; ++words; (D = (D << 12) | (D >> (32 - 12))); D += A; } while (0);-
270 do { C += (B ^ (D & (A ^ B))) + (*cwp++ = (*words)) + 0xa679438e; ++words; (C = (C << 17) | (C >> (32 - 17))); C += D; } while (0);-
271 do { B += (A ^ (C & (D ^ A))) + (*cwp++ = (*words)) + 0x49b40821; ++words; (B = (B << 22) | (B >> (32 - 22))); B += C; } while (0);-
272 do { A += (C ^ (D & (B ^ C))) + correct_words[1] + 0xf61e2562; (A = (A << 5) | (A >> (32 - 5))); A += B; } while (0);-
273 do { D += (B ^ (C & (A ^ B))) + correct_words[6] + 0xc040b340; (D = (D << 9) | (D >> (32 - 9))); D += A; } while (0);-
274 do { C += (A ^ (B & (D ^ A))) + correct_words[11] + 0x265e5a51; (C = (C << 14) | (C >> (32 - 14))); C += D; } while (0);-
275 do { B += (D ^ (A & (C ^ D))) + correct_words[0] + 0xe9b6c7aa; (B = (B << 20) | (B >> (32 - 20))); B += C; } while (0);-
276 do { A += (C ^ (D & (B ^ C))) + correct_words[5] + 0xd62f105d; (A = (A << 5) | (A >> (32 - 5))); A += B; } while (0);-
277 do { D += (B ^ (C & (A ^ B))) + correct_words[10] + 0x02441453; (D = (D << 9) | (D >> (32 - 9))); D += A; } while (0);-
278 do { C += (A ^ (B & (D ^ A))) + correct_words[15] + 0xd8a1e681; (C = (C << 14) | (C >> (32 - 14))); C += D; } while (0);-
279 do { B += (D ^ (A & (C ^ D))) + correct_words[4] + 0xe7d3fbc8; (B = (B << 20) | (B >> (32 - 20))); B += C; } while (0);-
280 do { A += (C ^ (D & (B ^ C))) + correct_words[9] + 0x21e1cde6; (A = (A << 5) | (A >> (32 - 5))); A += B; } while (0);-
281 do { D += (B ^ (C & (A ^ B))) + correct_words[14] + 0xc33707d6; (D = (D << 9) | (D >> (32 - 9))); D += A; } while (0);-
282 do { C += (A ^ (B & (D ^ A))) + correct_words[3] + 0xf4d50d87; (C = (C << 14) | (C >> (32 - 14))); C += D; } while (0);-
283 do { B += (D ^ (A & (C ^ D))) + correct_words[8] + 0x455a14ed; (B = (B << 20) | (B >> (32 - 20))); B += C; } while (0);-
284 do { A += (C ^ (D & (B ^ C))) + correct_words[13] + 0xa9e3e905; (A = (A << 5) | (A >> (32 - 5))); A += B; } while (0);-
285 do { D += (B ^ (C & (A ^ B))) + correct_words[2] + 0xfcefa3f8; (D = (D << 9) | (D >> (32 - 9))); D += A; } while (0);-
286 do { C += (A ^ (B & (D ^ A))) + correct_words[7] + 0x676f02d9; (C = (C << 14) | (C >> (32 - 14))); C += D; } while (0);-
287 do { B += (D ^ (A & (C ^ D))) + correct_words[12] + 0x8d2a4c8a; (B = (B << 20) | (B >> (32 - 20))); B += C; } while (0);-
288-
289-
290 do { A += (B ^ C ^ D) + correct_words[5] + 0xfffa3942; (A = (A << 4) | (A >> (32 - 4))); A += B; } while (0);-
291 do { D += (A ^ B ^ C) + correct_words[8] + 0x8771f681; (D = (D << 11) | (D >> (32 - 11))); D += A; } while (0);-
292 do { C += (D ^ A ^ B) + correct_words[11] + 0x6d9d6122; (C = (C << 16) | (C >> (32 - 16))); C += D; } while (0);-
293 do { B += (C ^ D ^ A) + correct_words[14] + 0xfde5380c; (B = (B << 23) | (B >> (32 - 23))); B += C; } while (0);-
294 do { A += (B ^ C ^ D) + correct_words[1] + 0xa4beea44; (A = (A << 4) | (A >> (32 - 4))); A += B; } while (0);-
295 do { D += (A ^ B ^ C) + correct_words[4] + 0x4bdecfa9; (D = (D << 11) | (D >> (32 - 11))); D += A; } while (0);-
296 do { C += (D ^ A ^ B) + correct_words[7] + 0xf6bb4b60; (C = (C << 16) | (C >> (32 - 16))); C += D; } while (0);-
297 do { B += (C ^ D ^ A) + correct_words[10] + 0xbebfbc70; (B = (B << 23) | (B >> (32 - 23))); B += C; } while (0);-
298 do { A += (B ^ C ^ D) + correct_words[13] + 0x289b7ec6; (A = (A << 4) | (A >> (32 - 4))); A += B; } while (0);-
299 do { D += (A ^ B ^ C) + correct_words[0] + 0xeaa127fa; (D = (D << 11) | (D >> (32 - 11))); D += A; } while (0);-
300 do { C += (D ^ A ^ B) + correct_words[3] + 0xd4ef3085; (C = (C << 16) | (C >> (32 - 16))); C += D; } while (0);-
301 do { B += (C ^ D ^ A) + correct_words[6] + 0x04881d05; (B = (B << 23) | (B >> (32 - 23))); B += C; } while (0);-
302 do { A += (B ^ C ^ D) + correct_words[9] + 0xd9d4d039; (A = (A << 4) | (A >> (32 - 4))); A += B; } while (0);-
303 do { D += (A ^ B ^ C) + correct_words[12] + 0xe6db99e5; (D = (D << 11) | (D >> (32 - 11))); D += A; } while (0);-
304 do { C += (D ^ A ^ B) + correct_words[15] + 0x1fa27cf8; (C = (C << 16) | (C >> (32 - 16))); C += D; } while (0);-
305 do { B += (C ^ D ^ A) + correct_words[2] + 0xc4ac5665; (B = (B << 23) | (B >> (32 - 23))); B += C; } while (0);-
306-
307-
308 do { A += (C ^ (B | ~D)) + correct_words[0] + 0xf4292244; (A = (A << 6) | (A >> (32 - 6))); A += B; } while (0);-
309 do { D += (B ^ (A | ~C)) + correct_words[7] + 0x432aff97; (D = (D << 10) | (D >> (32 - 10))); D += A; } while (0);-
310 do { C += (A ^ (D | ~B)) + correct_words[14] + 0xab9423a7; (C = (C << 15) | (C >> (32 - 15))); C += D; } while (0);-
311 do { B += (D ^ (C | ~A)) + correct_words[5] + 0xfc93a039; (B = (B << 21) | (B >> (32 - 21))); B += C; } while (0);-
312 do { A += (C ^ (B | ~D)) + correct_words[12] + 0x655b59c3; (A = (A << 6) | (A >> (32 - 6))); A += B; } while (0);-
313 do { D += (B ^ (A | ~C)) + correct_words[3] + 0x8f0ccc92; (D = (D << 10) | (D >> (32 - 10))); D += A; } while (0);-
314 do { C += (A ^ (D | ~B)) + correct_words[10] + 0xffeff47d; (C = (C << 15) | (C >> (32 - 15))); C += D; } while (0);-
315 do { B += (D ^ (C | ~A)) + correct_words[1] + 0x85845dd1; (B = (B << 21) | (B >> (32 - 21))); B += C; } while (0);-
316 do { A += (C ^ (B | ~D)) + correct_words[8] + 0x6fa87e4f; (A = (A << 6) | (A >> (32 - 6))); A += B; } while (0);-
317 do { D += (B ^ (A | ~C)) + correct_words[15] + 0xfe2ce6e0; (D = (D << 10) | (D >> (32 - 10))); D += A; } while (0);-
318 do { C += (A ^ (D | ~B)) + correct_words[6] + 0xa3014314; (C = (C << 15) | (C >> (32 - 15))); C += D; } while (0);-
319 do { B += (D ^ (C | ~A)) + correct_words[13] + 0x4e0811a1; (B = (B << 21) | (B >> (32 - 21))); B += C; } while (0);-
320 do { A += (C ^ (B | ~D)) + correct_words[4] + 0xf7537e82; (A = (A << 6) | (A >> (32 - 6))); A += B; } while (0);-
321 do { D += (B ^ (A | ~C)) + correct_words[11] + 0xbd3af235; (D = (D << 10) | (D >> (32 - 10))); D += A; } while (0);-
322 do { C += (A ^ (D | ~B)) + correct_words[2] + 0x2ad7d2bb; (C = (C << 15) | (C >> (32 - 15))); C += D; } while (0);-
323 do { B += (D ^ (C | ~A)) + correct_words[9] + 0xeb86d391; (B = (B << 21) | (B >> (32 - 21))); B += C; } while (0);-
324-
325-
326 A += A_save;-
327 B += B_save;-
328 C += C_save;-
329 D += D_save;-
330 }
executed 1661253 times by 2 tests: end of block
Executed by:
  • md5sum
  • sort
1661253
331-
332-
333 ctx->A = A;-
334 ctx->B = B;-
335 ctx->C = C;-
336 ctx->D = D;-
337}
executed 1533322 times by 2 tests: end of block
Executed by:
  • md5sum
  • sort
1533322
Switch to Source codePreprocessed file

Generated by Squish Coco 4.1.2