ATLAS Offline Software
Loading...
Searching...
No Matches
MD5 Class Reference

#include <MD5.h>

Collaboration diagram for MD5:

Classes

struct  Context

Public Member Functions

 MD5 (const unsigned char *buffer, unsigned long len)
 MD5 (const char *buffer, size_t len)
 MD5 (const std::string &buffer)
void raw_digest (unsigned char *s) const
void uuid_digest (uuid_t &uuid) const
std::string hex_digest () const

Private Types

typedef uint32_t MD5_u32plus

Private Member Functions

void init ()
void update (const void *data, size_t size)
void digest (unsigned char *result)
const void * body (const void *data, size_t size)

Private Attributes

Context m_ctx
unsigned char m_digest [16]

Detailed Description

Definition at line 19 of file MD5.h.

Member Typedef Documentation

◆ MD5_u32plus

typedef uint32_t MD5::MD5_u32plus
private

Definition at line 30 of file MD5.h.

Constructor & Destructor Documentation

◆ MD5() [1/3]

MD5::MD5 ( const unsigned char * buffer,
unsigned long len )

Definition at line 56 of file MD5.cxx.

57{
58 init();
59 update (buffer, len);
61}
void digest(unsigned char *result)
Definition MD5.cxx:322
void init()
Definition MD5.cxx:269
void update(const void *data, size_t size)
Definition MD5.cxx:281
unsigned char m_digest[16]
Definition MD5.h:39

◆ MD5() [2/3]

MD5::MD5 ( const char * buffer,
size_t len )

Definition at line 65 of file MD5.cxx.

66{
67 init();
68 update (buffer, len);
70}

◆ MD5() [3/3]

MD5::MD5 ( const std::string & buffer)

Definition at line 74 of file MD5.cxx.

75{
76 init();
77 update (s.c_str(), s.size());
79}

Member Function Documentation

◆ body()

const void * MD5::body ( const void * data,
size_t size )
private

Definition at line 161 of file MD5.cxx.

162{
163 const unsigned char *ptr;
164 MD5_u32plus a, b, c, d;
165 MD5_u32plus saved_a, saved_b, saved_c, saved_d;
166 Context* ctx = &m_ctx;
167
168 ptr = (const unsigned char *)data;
169
170 a = ctx->a;
171 b = ctx->b;
172 c = ctx->c;
173 d = ctx->d;
174
175 do {
176 saved_a = a;
177 saved_b = b;
178 saved_c = c;
179 saved_d = d;
180
181/* Round 1 */
182 STEP(F, a, b, c, d, SET(0), 0xd76aa478, 7)
183 STEP(F, d, a, b, c, SET(1), 0xe8c7b756, 12)
184 STEP(F, c, d, a, b, SET(2), 0x242070db, 17)
185 STEP(F, b, c, d, a, SET(3), 0xc1bdceee, 22)
186 STEP(F, a, b, c, d, SET(4), 0xf57c0faf, 7)
187 STEP(F, d, a, b, c, SET(5), 0x4787c62a, 12)
188 STEP(F, c, d, a, b, SET(6), 0xa8304613, 17)
189 STEP(F, b, c, d, a, SET(7), 0xfd469501, 22)
190 STEP(F, a, b, c, d, SET(8), 0x698098d8, 7)
191 STEP(F, d, a, b, c, SET(9), 0x8b44f7af, 12)
192 STEP(F, c, d, a, b, SET(10), 0xffff5bb1, 17)
193 STEP(F, b, c, d, a, SET(11), 0x895cd7be, 22)
194 STEP(F, a, b, c, d, SET(12), 0x6b901122, 7)
195 STEP(F, d, a, b, c, SET(13), 0xfd987193, 12)
196 STEP(F, c, d, a, b, SET(14), 0xa679438e, 17)
197 STEP(F, b, c, d, a, SET(15), 0x49b40821, 22)
198
199/* Round 2 */
200 STEP(G, a, b, c, d, GET(1), 0xf61e2562, 5)
201 STEP(G, d, a, b, c, GET(6), 0xc040b340, 9)
202 STEP(G, c, d, a, b, GET(11), 0x265e5a51, 14)
203 STEP(G, b, c, d, a, GET(0), 0xe9b6c7aa, 20)
204 STEP(G, a, b, c, d, GET(5), 0xd62f105d, 5)
205 STEP(G, d, a, b, c, GET(10), 0x02441453, 9)
206 STEP(G, c, d, a, b, GET(15), 0xd8a1e681, 14)
207 STEP(G, b, c, d, a, GET(4), 0xe7d3fbc8, 20)
208 STEP(G, a, b, c, d, GET(9), 0x21e1cde6, 5)
209 STEP(G, d, a, b, c, GET(14), 0xc33707d6, 9)
210 STEP(G, c, d, a, b, GET(3), 0xf4d50d87, 14)
211 STEP(G, b, c, d, a, GET(8), 0x455a14ed, 20)
212 STEP(G, a, b, c, d, GET(13), 0xa9e3e905, 5)
213 STEP(G, d, a, b, c, GET(2), 0xfcefa3f8, 9)
214 STEP(G, c, d, a, b, GET(7), 0x676f02d9, 14)
215 STEP(G, b, c, d, a, GET(12), 0x8d2a4c8a, 20)
216
217/* Round 3 */
218 STEP(H, a, b, c, d, GET(5), 0xfffa3942, 4)
219 STEP(H2, d, a, b, c, GET(8), 0x8771f681, 11)
220 STEP(H, c, d, a, b, GET(11), 0x6d9d6122, 16)
221 STEP(H2, b, c, d, a, GET(14), 0xfde5380c, 23)
222 STEP(H, a, b, c, d, GET(1), 0xa4beea44, 4)
223 STEP(H2, d, a, b, c, GET(4), 0x4bdecfa9, 11)
224 STEP(H, c, d, a, b, GET(7), 0xf6bb4b60, 16)
225 STEP(H2, b, c, d, a, GET(10), 0xbebfbc70, 23)
226 STEP(H, a, b, c, d, GET(13), 0x289b7ec6, 4)
227 STEP(H2, d, a, b, c, GET(0), 0xeaa127fa, 11)
228 STEP(H, c, d, a, b, GET(3), 0xd4ef3085, 16)
229 STEP(H2, b, c, d, a, GET(6), 0x04881d05, 23)
230 STEP(H, a, b, c, d, GET(9), 0xd9d4d039, 4)
231 STEP(H2, d, a, b, c, GET(12), 0xe6db99e5, 11)
232 STEP(H, c, d, a, b, GET(15), 0x1fa27cf8, 16)
233 STEP(H2, b, c, d, a, GET(2), 0xc4ac5665, 23)
234
235/* Round 4 */
236 STEP(I, a, b, c, d, GET(0), 0xf4292244, 6)
237 STEP(I, d, a, b, c, GET(7), 0x432aff97, 10)
238 STEP(I, c, d, a, b, GET(14), 0xab9423a7, 15)
239 STEP(I, b, c, d, a, GET(5), 0xfc93a039, 21)
240 STEP(I, a, b, c, d, GET(12), 0x655b59c3, 6)
241 STEP(I, d, a, b, c, GET(3), 0x8f0ccc92, 10)
242 STEP(I, c, d, a, b, GET(10), 0xffeff47d, 15)
243 STEP(I, b, c, d, a, GET(1), 0x85845dd1, 21)
244 STEP(I, a, b, c, d, GET(8), 0x6fa87e4f, 6)
245 STEP(I, d, a, b, c, GET(15), 0xfe2ce6e0, 10)
246 STEP(I, c, d, a, b, GET(6), 0xa3014314, 15)
247 STEP(I, b, c, d, a, GET(13), 0x4e0811a1, 21)
248 STEP(I, a, b, c, d, GET(4), 0xf7537e82, 6)
249 STEP(I, d, a, b, c, GET(11), 0xbd3af235, 10)
250 STEP(I, c, d, a, b, GET(2), 0x2ad7d2bb, 15)
251 STEP(I, b, c, d, a, GET(9), 0xeb86d391, 21)
252
253 a += saved_a;
254 b += saved_b;
255 c += saved_c;
256 d += saved_d;
257
258 ptr += 64;
259 } while (size -= 64);
260
261 ctx->a = a;
262 ctx->b = b;
263 ctx->c = c;
264 ctx->d = d;
265
266 return ptr;
267}
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
static Double_t a
#define GET(n)
Definition MD5.cxx:153
#define STEP(f, a, b, c, d, x, t, s)
Definition MD5.cxx:121
#define SET(n)
Definition MD5.cxx:147
#define F(x, y, z)
Definition MD5.cxx:112
#define I(x, y, z)
Definition MD5.cxx:116
#define G(x, y, z)
Definition MD5.cxx:113
#define H(x, y, z)
Definition MD5.cxx:114
#define H2(x, y, z)
Definition MD5.cxx:115
uint32_t MD5_u32plus
Definition MD5.h:30
Context m_ctx
Definition MD5.h:38
while((inf=(TStreamerInfo *) nextinfo()) !=0)
void * ptr(T *p)
Definition SGImplSvc.cxx:74

◆ digest()

void MD5::digest ( unsigned char * result)
private

Definition at line 322 of file MD5.cxx.

323{
324 unsigned long used, available;
325 Context* ctx = &m_ctx;
326
327 used = ctx->lo & 0x3f;
328
329 ctx->buffer[used++] = 0x80;
330
331 available = 64 - used;
332
333 if (available < 8) {
334 memset(&ctx->buffer[used], 0, available);
335 body(ctx->buffer, 64);
336 used = 0;
337 available = 64;
338 }
339
340 memset(&ctx->buffer[used], 0, available - 8);
341
342 ctx->lo <<= 3;
343 // cppcheck-suppress objectIndex
344 OUT(&ctx->buffer[56], ctx->lo)
345 // cppcheck-suppress objectIndex
346 OUT(&ctx->buffer[60], ctx->hi)
347
348 body(ctx->buffer, 64);
349
350 OUT(&result[0], ctx->a)
351 OUT(&result[4], ctx->b)
352 OUT(&result[8], ctx->c)
353 OUT(&result[12], ctx->d)
354
355 memset(ctx, 0, sizeof(*ctx));
356}
#define OUT(dst, src)
Definition MD5.cxx:316
const void * body(const void *data, size_t size)
Definition MD5.cxx:161

◆ hex_digest()

std::string MD5::hex_digest ( ) const

Definition at line 94 of file MD5.cxx.

95{
96 char s[33];
97 for (int i = 0; i < 16; i++) {
98 snprintf (s+i*2, 3, "%02x", m_digest[i]);
99 }
100 s[32] = '\0';
101 return s;
102}

◆ init()

void MD5::init ( )
private

Definition at line 269 of file MD5.cxx.

270{
271 Context* ctx = &m_ctx;
272 ctx->a = 0x67452301;
273 ctx->b = 0xefcdab89;
274 ctx->c = 0x98badcfe;
275 ctx->d = 0x10325476;
276
277 ctx->lo = 0;
278 ctx->hi = 0;
279}

◆ raw_digest()

void MD5::raw_digest ( unsigned char * s) const

Definition at line 82 of file MD5.cxx.

83{
84 memcpy (s, m_digest, 16);
85}

◆ update()

void MD5::update ( const void * data,
size_t size )
private

Definition at line 281 of file MD5.cxx.

282{
283 MD5_u32plus saved_lo;
284 unsigned long used, available;
285 Context* ctx = &m_ctx;
286
287 saved_lo = ctx->lo;
288 if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo)
289 ctx->hi++;
290 ctx->hi += size >> 29;
291
292 used = saved_lo & 0x3f;
293
294 if (used) {
295 available = 64 - used;
296
297 if (size < available) {
298 memcpy(&ctx->buffer[used], data, size);
299 return;
300 }
301
302 memcpy(&ctx->buffer[used], data, available);
303 data = (const unsigned char *)data + available;
304 size -= available;
305 body(ctx->buffer, 64);
306 }
307
308 if (size >= 64) {
309 data = body(data, size & ~(unsigned long)0x3f);
310 size &= 0x3f;
311 }
312
313 memcpy(ctx->buffer, data, size);
314}

◆ uuid_digest()

void MD5::uuid_digest ( uuid_t & uuid) const

Definition at line 88 of file MD5.cxx.

89{
90 memcpy (&uuid, m_digest, 16);
91}

Member Data Documentation

◆ m_ctx

Context MD5::m_ctx
private

Definition at line 38 of file MD5.h.

◆ m_digest

unsigned char MD5::m_digest[16]
private

Definition at line 39 of file MD5.h.


The documentation for this class was generated from the following files: