LLVM: lib/Support/MD5.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
46#include
47#include
48#include
49
50
51
52
53
54
55#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
56#define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y))))
57#define H(x, y, z) ((x) ^ (y) ^ (z))
58#define I(x, y, z) ((y) ^ ((x) | ~(z)))
59
60
61#define STEP(f, a, b, c, d, x, t, s) \
62 (a) += f((b), (c), (d)) + (x) + (t); \
63 (a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \
64 (a) += (b);
65
66
67
68#define SET(n) \
69 (InternalState.block[(n)] = (MD5_u32plus)ptr[(n)*4] | \
70 ((MD5_u32plus)ptr[(n)*4 + 1] << 8) | \
71 ((MD5_u32plus)ptr[(n)*4 + 2] << 16) | \
72 ((MD5_u32plus)ptr[(n)*4 + 3] << 24))
73#define GET(n) (InternalState.block[(n)])
74
75using namespace llvm;
76
77
78
82 MD5_u32plus saved_a, saved_b, saved_c, saved_d;
83 unsigned long Size = Data.size();
84
85 ptr = Data.data();
86
87 a = InternalState.a;
88 b = InternalState.b;
89 c = InternalState.c;
90 d = InternalState.d;
91
92 do {
93 saved_a = a;
94 saved_b = b;
95 saved_c = c;
96 saved_d = d;
97
98
115
116
133
134
151
152
169
170 a += saved_a;
171 b += saved_b;
172 c += saved_c;
173 d += saved_d;
174
175 ptr += 64;
176 } while (Size -= 64);
177
178 InternalState.a = a;
179 InternalState.b = b;
180 InternalState.c = c;
181 InternalState.d = d;
182
183 return ptr;
184}
185
187
188
191 unsigned long used, free;
193 unsigned long Size = Data.size();
194
195 saved_lo = InternalState.lo;
196 if ((InternalState.lo = (saved_lo + Size) & 0x1fffffff) < saved_lo)
197 InternalState.hi++;
198 InternalState.hi += Size >> 29;
199
200 used = saved_lo & 0x3f;
201
202 if (used) {
203 free = 64 - used;
204
205 if (Size < free) {
206 memcpy(&InternalState.buffer[used], Ptr, Size);
207 return;
208 }
209
210 memcpy(&InternalState.buffer[used], Ptr, free);
212 Size -= free;
213 body(ArrayRef(InternalState.buffer, 64));
214 }
215
216 if (Size >= 64) {
218 Size &= 0x3f;
219 }
220
221 memcpy(InternalState.buffer, Ptr, Size);
222}
223
224
225
226
230}
231
232
233
235 unsigned long used, free;
236
237 used = InternalState.lo & 0x3f;
238
239 InternalState.buffer[used++] = 0x80;
240
241 free = 64 - used;
242
243 if (free < 8) {
244 memset(&InternalState.buffer[used], 0, free);
245 body(ArrayRef(InternalState.buffer, 64));
246 used = 0;
247 free = 64;
248 }
249
250 memset(&InternalState.buffer[used], 0, free - 8);
251
252 InternalState.lo <<= 3;
255
256 body(ArrayRef(InternalState.buffer, 64));
257
262}
263
266 final(Result);
267 return Result;
268}
269
271 auto StateToRestore = InternalState;
272
273 auto Hash = final();
274
275
276 InternalState = StateToRestore;
277
278 return Hash;
279}
280
283 toHex(*this, true, Str);
284 return Str;
285}
286
288 toHex(Result, true, Str);
289}
290
292 MD5 Hash;
296
297 return Res;
298}
#define STEP(f, a, b, c, d, x, t, s)
#define SET(ID, TYPE, VAL)
This file defines the SmallString class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
static void stringifyResult(MD5Result &Result, SmallVectorImpl< char > &Str)
Translates the bytes in Res to a hex string that is deposited into Str.
void final(MD5Result &Result)
Finishes off the hash and puts the result in result.
MD5Result final()
Finishes off the hash, and returns the 16-byte hash data.
MD5Result result()
Finishes off the hash, and returns the 16-byte hash data.
static MD5Result hash(ArrayRef< uint8_t > Data)
Computes the hash for a given bytes.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StringRef - Represent a constant reference to a string, i.e.
void write32le(void *P, uint32_t V)
This is an optimization pass for GlobalISel generic memory operations.
SmallString< 32 > digest() const