scire
Sadh's C++ Impromptu Routines Ensemble
|
MD5 Message-Digest Algorithm. More...
#include <md5.hpp>
Public Types | |
enum | Info { DigestSize_bits = 128, DigestSize_bytes = 16, DigestSize_words = 4, BlockSize_bits = 512, BlockSize_bytes = 64, BlockSize_words = 16, Rounds = 4 } |
enum | Magic { MagicWordA = 0x01234567, MagicWordB = 0x89abcdef, MagicWordC = 0xfedcba98, MagicWordD = 0X76543210 } |
Public Member Functions | |
MD5 () | |
allocate MD5 context and init More... | |
MD5 (std::string message) | |
Construct MD5 object with a string message. More... | |
MD5 (char message[]) | |
Construct MD5 object with a string message. More... | |
void | Init () |
MD5 initialization. More... | |
bool | Update (const ByteT *input, SzType lenght) |
MD5 block update operation. More... | |
bool | Update (const SByteT *input, SzType lenght) |
MD5 block update operation. More... | |
void | Final () |
MD5 finalization. More... | |
bool | Digest (ByteT digest[DigestSize_bytes]) const |
get digest bytes in More... | |
std::string | Fingerprint () const |
fingerprint is the 128bit message-digest More... | |
std::string | StatePhrase () const |
String representation of Four State Words (ABCD) More... | |
std::string | ToString () const |
string reprsentation | fingerpring on finalize, else status words More... | |
void | Reset () |
Reset object, similar to doing Init() More... | |
Protected Member Functions | |
void | transform (const ByteT block[BlockSize_bytes]) |
the phenomenal transform function More... | |
Static Protected Member Functions | |
static Ui32t | F (Ui32t x, Ui32t y, Ui32t z) |
F(X,Y,Z) = XY v not(X) Z. More... | |
static Ui32t | G (Ui32t x, Ui32t y, Ui32t z) |
G(X,Y,Z) = XZ v Y not(Z) More... | |
static Ui32t | H (Ui32t x, Ui32t y, Ui32t z) |
H(X,Y,Z) = X xor Y xor Z. More... | |
static Ui32t | I (Ui32t x, Ui32t y, Ui32t z) |
I(X,Y,Z) = Y xor (X v not(Z)) More... | |
Related Functions | |
(Note that these are not member functions.) | |
template<typename SzType , typename Ui32t , typename ByteT , typename SByteT > | |
std::ostream & | operator<< (std::ostream &out, const MD5< SzType, Ui32t, ByteT, SByteT > &md5) |
MD5 Message-Digest Algorithm.
scire adaptation of the MD5 algorithm, adopted from RFC 1321. http://tools.ietf.org/html/rfc1321
This implemenation is templatic to facilitate machine portability. It takes four <type> parameters:
In most cases it will simply suffice to use MD5<>
Example usage:
Client should create an MD5 object. The construcor calls Init inside it, so it is redundant to call Init() upor first use of the object. To compute MD5 checksum of a buffer, call Update() once or several times with chunks of the message. A call to Final() indicated MD5 object that, message is complete. Then, MD5 object computes finalized the digest. Client can receive digest bytes by passing a byte array to fill digest values with it. Digest size is 16 byte. After a call to Final(), all subsequent Update() calls will be ignored.
MD5 object can be reused by invoking Reset() and then using it in a similar fashion.
enum scire::MD5::Info |
Enumerator | |
---|---|
DigestSize_bits |
MD5 digest size in bits. |
DigestSize_bytes |
MD5 digest size in bytes. |
DigestSize_words |
MD5 digest size in words (32bit) |
BlockSize_bits |
MD5 process message in chunks each of 512bit. |
BlockSize_bytes |
block size in bytes |
BlockSize_words |
block size in words (32bit) |
Rounds |
MD5 has 4 rounds. |
enum scire::MD5::Magic |
scire::MD5< SzType, Ui32t, ByteT, SByteT >::MD5 | ( | ) |
scire::MD5< SzType, Ui32t, ByteT, SByteT >::MD5 | ( | std::string | message | ) |
scire::MD5< SzType, Ui32t, ByteT, SByteT >::MD5 | ( | char | message[] | ) |
bool scire::MD5< SzType, Ui32t, ByteT, SByteT >::Digest | ( | ByteT | digest[DigestSize_bytes] | ) | const |
|
inlinestaticprotected |
F(X,Y,Z) = XY v not(X) Z.
from RFC 1321:
In each bit position F acts as a conditional: if X then Y else Z. The function F could have been defined using + instead of v since XY and not(X)Z will never have 1's in the same bit position.) It is interesting to note that if the bits of X, Y, and Z are independent and unbiased, the each bit of F(X,Y,Z) will be independent and unbiased.
|
virtual |
MD5 finalization.
Ends an MD5 message-digest operation, writing the the message digest and zeroizing the context.
Implements scire::IHashAlgo< SzType, Ui32t, ByteT, SByteT >.
|
virtual |
fingerprint is the 128bit message-digest
Implements scire::IHashAlgo< SzType, Ui32t, ByteT, SByteT >.
|
inlinestaticprotected |
G(X,Y,Z) = XZ v Y not(Z)
from RFC 1321:
The functions G, H, and I are similar to the function F, in that they act in "bitwise parallel" to produce their output from the bits of X, Y, and Z, in such a manner that if the corresponding bits of X, Y, and Z are independent and unbiased, then each bit of G(X,Y,Z), H(X,Y,Z), and I(X,Y,Z) will be independent and unbiased. Note that the function H is the bit-wise "xor" or "parity" function of its inputs.
|
inlinestaticprotected |
|
inlinestaticprotected |
|
virtual |
MD5 initialization.
Begins an MD5 operation, writing a new context (i.e. init class object).
Implements scire::IHashAlgo< SzType, Ui32t, ByteT, SByteT >.
|
inline |
|
virtual |
String representation of Four State Words (ABCD)
Implements scire::IHashAlgo< SzType, Ui32t, ByteT, SByteT >.
|
virtual |
string reprsentation | fingerpring on finalize, else status words
Implements scire::IHashAlgo< SzType, Ui32t, ByteT, SByteT >.
|
protected |
|
virtual |
MD5 block update operation.
Continues an MD5 message-digest operation, processing another message block, and updating the context.
input | an array of bytes |
lenght | number of bytes in input chunk |
Implements scire::IHashAlgo< SzType, Ui32t, ByteT, SByteT >.
|
virtual |
MD5 block update operation.
Continues an MD5 message-digest operation, processing another message block, and updating the context.
input | an array of bytes |
lenght | number of bytes in input chunk |
Implements scire::IHashAlgo< SzType, Ui32t, ByteT, SByteT >.
|
related |