• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

llnl / dftracer / 27009203599

05 Jun 2026 10:17AM UTC coverage: 18.437%. First build
27009203599

Pull #352

github

web-flow
Merge 93add864a into a4a7a5cb6
Pull Request #352: fix: update logger types and improve error logging messages

7268 of 53566 branches covered (13.57%)

Branch coverage included in aggregate %.

380 of 702 new or added lines in 31 files covered. (54.13%)

4776 of 11760 relevant lines covered (40.61%)

1107.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.0
/src/dftracer/core/utils/md5.cpp
1
/*
2
 * Derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm
3
 * and modified slightly to be functionally identical but condensed into control
4
 * structures.
5
 */
6

7
#include "md5.h"
8

9
/*
10
 * Constants defined by the MD5 algorithm
11
 */
12
#define A 0x67452301
13
#define B 0xefcdab89
14
#define C 0x98badcfe
15
#define D 0x10325476
16

17
static uint32_t S[] = {7,  12, 17, 22, 7,  12, 17, 22, 7,  12, 17, 22, 7,
18
                       12, 17, 22, 5,  9,  14, 20, 5,  9,  14, 20, 5,  9,
19
                       14, 20, 5,  9,  14, 20, 4,  11, 16, 23, 4,  11, 16,
20
                       23, 4,  11, 16, 23, 4,  11, 16, 23, 6,  10, 15, 21,
21
                       6,  10, 15, 21, 6,  10, 15, 21, 6,  10, 15, 21};
22

23
static uint32_t K[] = {
24
    0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a,
25
    0xa8304613, 0xfd469501, 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
26
    0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, 0xf61e2562, 0xc040b340,
27
    0x265e5a51, 0xe9b6c7aa, 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
28
    0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, 0xa9e3e905, 0xfcefa3f8,
29
    0x676f02d9, 0x8d2a4c8a, 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
30
    0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, 0x289b7ec6, 0xeaa127fa,
31
    0xd4ef3085, 0x04881d05, 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
32
    0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, 0x655b59c3, 0x8f0ccc92,
33
    0xffeff47d, 0x85845dd1, 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
34
    0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391};
35

36
/*
37
 * Padding used to make the size (in bits) of the input congruent to 448 mod 512
38
 */
39
static uint8_t PADDING[] = {
40
    0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
41
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
42
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
43
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
45
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
46

47
/*
48
 * Bit-manipulation functions defined by the MD5 algorithm
49
 */
50
#define F(X, Y, Z) ((X & Y) | (~X & Z))
51
#define G(X, Y, Z) ((X & Z) | (Y & ~Z))
52
#define H(X, Y, Z) (X ^ Y ^ Z)
53
#define I(X, Y, Z) (Y ^ (X | ~Z))
54

55
/*
56
 * Rotates a 32-bit word left by n bits
57
 */
58
uint32_t rotateLeft(uint32_t x, uint32_t n) {
46,848✔
59
  return (x << n) | (x >> (32 - n));
46,848✔
60
}
61

62
/*
63
 * Initialize a context
64
 */
65
void md5Init(MD5Context* ctx) {
403✔
66
  ctx->size = (uint64_t)0;
403✔
67

68
  ctx->buffer[0] = (uint32_t)A;
403✔
69
  ctx->buffer[1] = (uint32_t)B;
403✔
70
  ctx->buffer[2] = (uint32_t)C;
403✔
71
  ctx->buffer[3] = (uint32_t)D;
403✔
72
}
403✔
73

74
/*
75
 * Add some amount of input to the context
76
 *
77
 * If the input fills out a block of 512 bits, apply the algorithm (md5Step)
78
 * and save the result in the buffer. Also updates the overall size.
79
 */
80
void md5Update(MD5Context* ctx, uint8_t* input_buffer, size_t input_len) {
806✔
81
  uint32_t input[16];
82
  unsigned int offset = ctx->size % 64;
806✔
83
  ctx->size += (uint64_t)input_len;
806✔
84

85
  // Copy each byte in input_buffer into the next space in our context input
86
  for (unsigned int i = 0; i < input_len; ++i) {
44,430✔
87
    ctx->input[offset++] = (uint8_t)*(input_buffer + i);
43,624✔
88

89
    // If we've filled our context input, copy it into our local array input
90
    // then reset the offset to 0 and fill in a new buffer.
91
    // Every time we fill out a chunk, we run it through the algorithm
92
    // to enable some back and forth between cpu and i/o
93
    if (offset % 64 == 0) {
43,624✔
94
      for (unsigned int j = 0; j < 16; ++j) {
5,593✔
95
        // Convert to little-endian
96
        // The local variable `input` our 512-bit chunk separated into 32-bit
97
        // words we can use in calculations
98
        input[j] = (uint32_t)(ctx->input[(j * 4) + 3]) << 24 |
5,264✔
99
                   (uint32_t)(ctx->input[(j * 4) + 2]) << 16 |
5,264✔
100
                   (uint32_t)(ctx->input[(j * 4) + 1]) << 8 |
5,264✔
101
                   (uint32_t)(ctx->input[(j * 4)]);
5,264✔
102
      }
103
      md5Step(ctx->buffer, input);
329✔
104
      offset = 0;
329✔
105
    }
106
  }
107
}
806✔
108

109
/*
110
 * Pad the current input to get to 448 bytes, append the size in bits to the
111
 * very end, and save the result of the final iteration into digest.
112
 */
113
void md5Finalize(MD5Context* ctx) {
403✔
114
  uint32_t input[16];
115
  unsigned int offset = ctx->size % 64;
403✔
116
  unsigned int padding_length = offset < 56 ? 56 - offset : (56 + 64) - offset;
403✔
117

118
  // Fill in the padding and undo the changes to size that resulted from the
119
  // update
120
  md5Update(ctx, PADDING, padding_length);
403✔
121
  ctx->size -= (uint64_t)padding_length;
403✔
122

123
  // Do a final update (internal to this function)
124
  // Last two 32-bit words are the two halves of the size (converted from bytes
125
  // to bits)
126
  for (unsigned int j = 0; j < 14; ++j) {
6,045✔
127
    input[j] = (uint32_t)(ctx->input[(j * 4) + 3]) << 24 |
5,642✔
128
               (uint32_t)(ctx->input[(j * 4) + 2]) << 16 |
5,642✔
129
               (uint32_t)(ctx->input[(j * 4) + 1]) << 8 |
5,642✔
130
               (uint32_t)(ctx->input[(j * 4)]);
5,642✔
131
  }
132
  input[14] = (uint32_t)(ctx->size * 8);
403✔
133
  input[15] = (uint32_t)((ctx->size * 8) >> 32);
403✔
134

135
  md5Step(ctx->buffer, input);
403✔
136

137
  // Move the result into digest (convert from little-endian)
138
  for (unsigned int i = 0; i < 4; ++i) {
2,015✔
139
    ctx->digest[(i * 4) + 0] = (uint8_t)((ctx->buffer[i] & 0x000000FF));
1,612✔
140
    ctx->digest[(i * 4) + 1] = (uint8_t)((ctx->buffer[i] & 0x0000FF00) >> 8);
1,612✔
141
    ctx->digest[(i * 4) + 2] = (uint8_t)((ctx->buffer[i] & 0x00FF0000) >> 16);
1,612✔
142
    ctx->digest[(i * 4) + 3] = (uint8_t)((ctx->buffer[i] & 0xFF000000) >> 24);
1,612✔
143
  }
144
}
403✔
145

146
/*
147
 * Step on 512 bits of input with the main MD5 algorithm.
148
 */
149
void md5Step(uint32_t* buffer, uint32_t* input) {
732✔
150
  uint32_t AA = buffer[0];
732✔
151
  uint32_t BB = buffer[1];
732✔
152
  uint32_t CC = buffer[2];
732✔
153
  uint32_t DD = buffer[3];
732✔
154

155
  uint32_t E;
156

157
  unsigned int j;
158

159
  for (unsigned int i = 0; i < 64; ++i) {
47,580✔
160
    switch (i / 16) {
46,848✔
161
      case 0:
11,712✔
162
        E = F(BB, CC, DD);
11,712✔
163
        j = i;
11,712✔
164
        break;
11,712✔
165
      case 1:
11,712✔
166
        E = G(BB, CC, DD);
11,712✔
167
        j = ((i * 5) + 1) % 16;
11,712✔
168
        break;
11,712✔
169
      case 2:
11,712✔
170
        E = H(BB, CC, DD);
11,712✔
171
        j = ((i * 3) + 5) % 16;
11,712✔
172
        break;
11,712✔
173
      default:
11,712✔
174
        E = I(BB, CC, DD);
11,712✔
175
        j = (i * 7) % 16;
11,712✔
176
        break;
11,712✔
177
    }
178

179
    uint32_t temp = DD;
46,848✔
180
    DD = CC;
46,848✔
181
    CC = BB;
46,848✔
182
    BB = BB + rotateLeft(AA + E + K[i] + input[j], S[i]);
46,848✔
183
    AA = temp;
46,848✔
184
  }
185

186
  buffer[0] += AA;
732✔
187
  buffer[1] += BB;
732✔
188
  buffer[2] += CC;
732✔
189
  buffer[3] += DD;
732✔
190
}
732✔
191

192
/*
193
 * Functions that run the algorithm on the provided input and put the digest
194
 * into result. result should be able to store 16 bytes.
195
 */
196
void md5String(char* input, uint8_t* result) {
403✔
197
  MD5Context ctx;
198
  md5Init(&ctx);
403✔
199
  md5Update(&ctx, (uint8_t*)input, strlen(input));
403✔
200
  md5Finalize(&ctx);
403✔
201

202
  memcpy(result, ctx.digest, 16);
403✔
203
}
403✔
204

NEW
205
void md5File(FILE* file, uint8_t* result) {
×
NEW
206
  char* input_buffer = (char*)malloc(1024);
×
207
  size_t input_size = 0;
×
208

209
  MD5Context ctx;
210
  md5Init(&ctx);
×
211

212
  while ((input_size = fread(input_buffer, 1, 1024, file)) > 0) {
×
NEW
213
    md5Update(&ctx, (uint8_t*)input_buffer, input_size);
×
214
  }
215

216
  md5Finalize(&ctx);
×
217

218
  free(input_buffer);
×
219

220
  memcpy(result, ctx.digest, 16);
×
221
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc