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

49

50

51

52

53

54#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))

55#define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y))))

56#define H(x, y, z) ((x) ^ (y) ^ (z))

57#define I(x, y, z) ((y) ^ ((x) | ~(z)))

58

59

60#define STEP(f, a, b, c, d, x, t, s) \

61 (a) += f((b), (c), (d)) + (x) + (t); \

62 (a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \

63 (a) += (b);

64

65

66

67#define SET(n) \

68 (InternalState.block[(n)] = (MD5_u32plus)ptr[(n)*4] | \

69 ((MD5_u32plus)ptr[(n)*4 + 1] << 8) | \

70 ((MD5_u32plus)ptr[(n)*4 + 2] << 16) | \

71 ((MD5_u32plus)ptr[(n)*4 + 3] << 24))

72#define GET(n) (InternalState.block[(n)])

73

74using namespace llvm;

75

76

77

80 MD5_u32plus a, b, c, d;

81 MD5_u32plus saved_a, saved_b, saved_c, saved_d;

82 unsigned long Size = Data.size();

83

84 ptr = Data.data();

85

86 a = InternalState.a;

87 b = InternalState.b;

88 c = InternalState.c;

89 d = InternalState.d;

90

91 do {

92 saved_a = a;

93 saved_b = b;

94 saved_c = c;

95 saved_d = d;

96

97

114

115

132

133

150

151

168

169 a += saved_a;

170 b += saved_b;

171 c += saved_c;

172 d += saved_d;

173

174 ptr += 64;

175 } while (Size -= 64);

176

177 InternalState.a = a;

178 InternalState.b = b;

179 InternalState.c = c;

180 InternalState.d = d;

181

182 return ptr;

183}

184

186

187

189 MD5_u32plus saved_lo;

190 unsigned long used, free;

192 unsigned long Size = Data.size();

193

194 saved_lo = InternalState.lo;

195 if ((InternalState.lo = (saved_lo + Size) & 0x1fffffff) < saved_lo)

196 InternalState.hi++;

197 InternalState.hi += Size >> 29;

198

199 used = saved_lo & 0x3f;

200

201 if (used) {

202 free = 64 - used;

203

204 if (Size < free) {

205 memcpy(&InternalState.buffer[used], Ptr, Size);

206 return;

207 }

208

209 memcpy(&InternalState.buffer[used], Ptr, free);

210 Ptr = Ptr + free;

211 Size -= free;

212 body(ArrayRef(InternalState.buffer, 64));

213 }

214

215 if (Size >= 64) {

216 Ptr = body(ArrayRef(Ptr, Size & ~(unsigned long)0x3f));

217 Size &= 0x3f;

218 }

219

220 memcpy(InternalState.buffer, Ptr, Size);

221}

222

223

224

225

230

231

232

234 unsigned long used, free;

235

236 used = InternalState.lo & 0x3f;

237

238 InternalState.buffer[used++] = 0x80;

239

240 free = 64 - used;

241

242 if (free < 8) {

243 memset(&InternalState.buffer[used], 0, free);

244 body(ArrayRef(InternalState.buffer, 64));

245 used = 0;

246 free = 64;

247 }

248

249 memset(&InternalState.buffer[used], 0, free - 8);

250

251 InternalState.lo <<= 3;

254

255 body(ArrayRef(InternalState.buffer, 64));

256

261}

262

265 final(Result);

266 return Result;

267}

268

270 auto StateToRestore = InternalState;

271

272 auto Hash = final();

273

274

275 InternalState = StateToRestore;

276

277 return Hash;

278}

279

282 toHex(*this, true, Str);

283 return Str;

284}

285

287 toHex(Result, true, Str);

288}

289

291 MD5 Hash;

295

296 return Res;

297}

298

299#undef F

300#undef G

301#undef H

302#undef I

303#undef STEP

304#undef SET

305#undef GET

#define STEP(f, a, b, c, d, x, t, s)

Definition MD5.cpp:60

#define F(x, y, z)

Definition MD5.cpp:54

#define I(x, y, z)

Definition MD5.cpp:57

#define G(x, y, z)

Definition MD5.cpp:55

#define H(x, y, z)

Definition MD5.cpp:56

#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),...

LLVM_ABI void update(ArrayRef< uint8_t > Data)

Updates the hash for the byte stream provided.

Definition MD5.cpp:188

static LLVM_ABI void stringifyResult(MD5Result &Result, SmallVectorImpl< char > &Str)

Translates the bytes in Res to a hex string that is deposited into Str.

Definition MD5.cpp:286

LLVM_ABI void final(MD5Result &Result)

Finishes off the hash and puts the result in result.

Definition MD5.cpp:233

LLVM_ABI MD5Result final()

Finishes off the hash, and returns the 16-byte hash data.

Definition MD5.cpp:263

LLVM_ABI MD5Result result()

Finishes off the hash, and returns the 16-byte hash data.

Definition MD5.cpp:269

static LLVM_ABI MD5Result hash(ArrayRef< uint8_t > Data)

Computes the hash for a given bytes.

Definition MD5.cpp:290

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.

FunctionAddr VTableAddr uintptr_t uintptr_t Data

ArrayRef(const T &OneElt) -> ArrayRef< T >

void toHex(ArrayRef< uint8_t > Input, bool LowerCase, SmallVectorImpl< char > &Output)

Convert buffer Input to its hexadecimal representation. The returned string is double the size of Inp...

LLVM_ABI SmallString< 32 > digest() const

Definition MD5.cpp:280