timemory 3.3.0
Modular C++ Toolkit for Performance Analysis and Logging. Profiling API and Tools for C, C++, CUDA, Fortran, and Python. The C++ template API is essentially a framework to creating tools: it is designed to provide a unifying interface for recording various performance measurements alongside data logging and interfaces to other tools.
tim::md5::md5sum Class Reference

#include "timemory/utility/md5.hpp"

+ Collaboration diagram for tim::md5::md5sum:

Public Types

using size_type = uint32_t
 

Public Member Functions

 md5sum (const std::string &text)
 
 md5sum ()=default
 
 ~md5sum ()=default
 
 md5sum (const md5sum &)=default
 
 md5sum (md5sum &&)=default
 
md5sumoperator= (const md5sum &)=default
 
md5sumoperator= (md5sum &&)=default
 
md5sumupdate (const unsigned char *buf, size_type length)
 
md5sumupdate (const char *buf, size_type length)
 
md5sumfinalize ()
 
std::string hexdigest () const
 

Static Public Attributes

static constexpr int blocksize = 64
 

Friends

std::ostream & operator<< (std::ostream &, md5sum md5)
 

Detailed Description

Definition at line 50 of file md5.hpp.

Member Typedef Documentation

◆ size_type

using tim::md5::md5sum::size_type = uint32_t

Definition at line 53 of file md5.hpp.

Constructor & Destructor Documentation

◆ md5sum() [1/4]

TIMEMORY_UTILITY_INLINE tim::md5::md5sum::md5sum ( const std::string &  text)

Definition at line 185 of file md5.cpp.

186{
187 update(text.c_str(), text.length());
188 finalize();
189}
md5sum & update(const unsigned char *buf, size_type length)
Definition: md5.cpp:288
md5sum & finalize()
Definition: md5.cpp:338

References finalize(), and update().

◆ md5sum() [2/4]

tim::md5::md5sum::md5sum ( )
default

◆ ~md5sum()

tim::md5::md5sum::~md5sum ( )
default

◆ md5sum() [3/4]

tim::md5::md5sum::md5sum ( const md5sum )
default

◆ md5sum() [4/4]

tim::md5::md5sum::md5sum ( md5sum &&  )
default

Member Function Documentation

◆ finalize()

TIMEMORY_UTILITY_INLINE md5sum & tim::md5::md5sum::finalize ( )

Definition at line 338 of file md5.cpp.

339{
340 static unsigned char padding[64] = { 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
341 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
342 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
343 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
344 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
345
346 if(!finalized)
347 {
348 // Save number of bits
349 unsigned char bits[8];
350 encode(bits, count.data(), 8);
351
352 // pad out to 56 mod 64.
353 size_type index = count[0] / 8 % 64;
354 size_type padLen = (index < 56) ? (56 - index) : (120 - index);
355 update(padding, padLen);
356
357 // Append length (before padding)
358 update(bits, 8);
359
360 // Store state in digest
361 encode(digest.data(), state.data(), 16);
362
363 // Zeroize sensitive information.
364 memset(buffer.data(), 0, sizeof buffer);
365 memset(count.data(), 0, sizeof count);
366
367 finalized = true;
368 }
369
370 return *this;
371}
uint32_t size_type
Definition: md5.hpp:53

References update().

Referenced by md5sum().

◆ hexdigest()

TIMEMORY_UTILITY_INLINE std::string tim::md5::md5sum::hexdigest ( ) const

Definition at line 378 of file md5.cpp.

379{
380 if(!finalized)
381 return "";
382
383 char buf[33];
384 for(int i = 0; i < 16; i++)
385 sprintf(buf + i * 2, "%02x", digest[i]);
386 buf[32] = '\0';
387
388 return std::string(buf);
389}
tim::mpl::apply< std::string > string
Definition: macros.hpp:53

Referenced by tim::md5::compute_md5().

◆ operator=() [1/2]

md5sum & tim::md5::md5sum::operator= ( const md5sum )
default

◆ operator=() [2/2]

md5sum & tim::md5::md5sum::operator= ( md5sum &&  )
default

◆ update() [1/2]

TIMEMORY_UTILITY_INLINE md5sum & tim::md5::md5sum::update ( const char *  buf,
size_type  length 
)

Definition at line 327 of file md5.cpp.

328{
329 return update((const unsigned char*) input, length);
330}

References update().

◆ update() [2/2]

TIMEMORY_UTILITY_INLINE md5sum & tim::md5::md5sum::update ( const unsigned char *  buf,
size_type  length 
)

Definition at line 288 of file md5.cpp.

289{
290 // compute number of bytes mod 64
291 size_type index = count[0] / 8 % blocksize;
292
293 // Update number of bits
294 if((count[0] += (length << 3)) < (length << 3))
295 count[1]++;
296 count[1] += (length >> 29);
297
298 // number of bytes we need to fill in buffer
299 size_type firstpart = 64 - index;
300 size_type i = 0;
301
302 // transform as many times as possible.
303 if(length >= firstpart)
304 {
305 // fill buffer first, transform
306 memcpy(&buffer[index], input, firstpart);
307 transform(buffer.data());
308
309 // transform chunks of blocksize (64 bytes)
310 for(i = firstpart; i + blocksize <= length; i += blocksize)
311 transform(&input[i]);
312
313 index = 0;
314 }
315
316 // buffer remaining input
317 memcpy(&buffer[index], &input[i], length - i);
318
319 return *this;
320}
static constexpr int blocksize
Definition: md5.hpp:54

References blocksize.

Referenced by md5sum(), finalize(), and update().

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  out,
md5sum  md5 
)
friend

Definition at line 394 of file md5.cpp.

396{
397 return out << md5.hexdigest();
398}

Member Data Documentation

◆ blocksize

constexpr int tim::md5::md5sum::blocksize = 64
staticconstexpr

Definition at line 54 of file md5.hpp.

Referenced by update().


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