libxcks  0.1.0.1
libxcks::MD2 Class Referencefinal

Computes the MD2 hash from a byte stream. More...

#include <md2.hpp>

Inheritance diagram for libxcks::MD2:
Collaboration diagram for libxcks::MD2:

Public Member Functions

 MD2 ()
 Default constructor. More...
 
void reset () override
 Resets the MD2 hash to initial state of computation. More...
 
uint8_t * getValue (uint8_t *buffer) const override
 Returns the MD2 hash value in the first 20 bytes of the given address. More...
 
size_t getSize () const override
 Returns the minimal size to allocate in memory to store the hash with the getValue(buffer) method. More...
 
void update (const uint8_t *buf, size_t len) override
 Updates the MD2 hash with specified array of bytes. More...
 
std::string getName () const override
 Returns the name of the checksum or the hash algorithm. More...
 
ChecksumAlgoId getID () const override
 Returns an unique identifier for the checksum or the hash algorithm. More...
 
- Public Member Functions inherited from libxcks::ChecksumEx
std::string toString (const bool hexInUpperCase=false) const override
 Returns the hash value has a string. More...
 
- Public Member Functions inherited from libxcks::Checksum
virtual ~Checksum ()
 Destructor. More...
 
virtual ArrayString getAltNames () const
 Returns the alternative name(s) of the checksum or the hash algorithm. More...
 

Static Public Member Functions

static std::string getHashName ()
 Returns the name of the hash algorithm. More...
 
static constexpr ChecksumAlgoId getIdentifier ()
 Returns an unique identifier for the hash algorithm. More...
 
static ChecksumgetNewInstance ()
 Gets a new instance of this class. More...
 
- Static Public Member Functions inherited from libxcks::Checksum
static ArrayString getAlternativeNames ()
 Returns the alternative name(s) of the checksum or the hash algorithm. More...
 

Protected Member Functions

void finish ()
 Process the remaining bytes in the internal buffer and the usual prolog according to the standard. More...
 

Protected Attributes

uint8_t C [16]
 Buffer used for computing md2 hash. More...
 
uint8_t X [48]
 Buffer used for computing md2 hash. More...
 
int count
 Current size of the input buffer. More...
 
uint8_t ibuffer [16]
 Input buffer. More...
 

Additional Inherited Members

- Static Protected Member Functions inherited from libxcks::ChecksumEx
static uint32_t swapOnLE (const uint32_t value)
 Swaps bytes on little endian architectures. More...
 
static uint32_t swapOnBE (const uint32_t value)
 Swaps bytes on big endian architectures. More...
 
static uint64_t swapOnLE (const uint64_t value)
 Swaps bytes on little endian architectures. More...
 
static uint64_t swapOnBE (const uint64_t value)
 Swaps bytes on big endian architectures. More...
 

Detailed Description

Computes the MD2 hash from a byte stream.

This class is a rewrite in C++ of the md2 hash computing algorithm present in the Python Cryptography Toolkit. Please see the Python Cryptography Toolkit project website for more informations.

Using this class in very simple:
Use the update method to provide to the class the bytes for computing the hash.

The MD2 hash value can be gotten by two ways:

  • The getValue method which puts the MD2 hash value in an array of 16 bytes.
  • The toString method which returns the MD2 hash value in a string.

The MD2 hash computing can be reseted by the reset method.

Definition at line 56 of file md2.hpp.

Constructor & Destructor Documentation

◆ MD2()

libxcks::MD2::MD2 ( )

Default constructor.

Definition at line 40 of file md2.cpp.

Member Function Documentation

◆ finish()

void libxcks::MD2::finish ( )
protected

Process the remaining bytes in the internal buffer and the usual prolog according to the standard.

Definition at line 63 of file md2.cpp.

◆ getHashName()

static std::string libxcks::MD2::getHashName ( )
inlinestatic

Returns the name of the hash algorithm.

Returns
The name of the hash algorithm.

Definition at line 141 of file md2.hpp.

◆ getID()

ChecksumAlgoId libxcks::MD2::getID ( ) const
inlineoverridevirtual

Returns an unique identifier for the checksum or the hash algorithm.

Remarks
The unique ID should be the CRC32 checksum of the algorithm's name returned by getName() but it's only a convention.
Returns
An unique identifier for the checksum or the hash algorithm.

Implements libxcks::Checksum.

Definition at line 131 of file md2.hpp.

◆ getIdentifier()

static constexpr ChecksumAlgoId libxcks::MD2::getIdentifier ( )
inlinestaticconstexpr

Returns an unique identifier for the hash algorithm.

Remarks
The unique ID should be the CRC32 checksum of the algorithm's name returned by getHashName() but it's only a convention.
Returns
An unique identifier for the hash algorithm.

Definition at line 155 of file md2.hpp.

◆ getName()

std::string libxcks::MD2::getName ( ) const
inlineoverridevirtual

Returns the name of the checksum or the hash algorithm.

Returns
The name of the checksum or the hash algorithm.

Implements libxcks::Checksum.

Definition at line 117 of file md2.hpp.

◆ getNewInstance()

static Checksum* libxcks::MD2::getNewInstance ( )
inlinestatic

Gets a new instance of this class.

The caller is responsible of the deletion of the instance with the delete operator.

Returns
A new instance of this class.

Definition at line 168 of file md2.hpp.

◆ getSize()

size_t libxcks::MD2::getSize ( ) const
inlineoverridevirtual

Returns the minimal size to allocate in memory to store the hash with the getValue(buffer) method.

Returns
The minimal size to allocate in memory to store the hash with the getValue(buffer) method.

Implements libxcks::Checksum.

Definition at line 94 of file md2.hpp.

◆ getValue()

uint8_t * libxcks::MD2::getValue ( uint8_t *  buffer) const
overridevirtual

Returns the MD2 hash value in the first 20 bytes of the given address.

Parameters
bufferThe buffer where the MD2 hash value will be stored.
Returns
The address of the buffer.
Remarks
The memory for the 20 bytes must have been allocated before calling this method.

Implements libxcks::Checksum.

Definition at line 143 of file md2.cpp.

◆ reset()

void libxcks::MD2::reset ( )
overridevirtual

Resets the MD2 hash to initial state of computation.

Implements libxcks::ChecksumEx.

Definition at line 50 of file md2.cpp.

◆ update()

void libxcks::MD2::update ( const uint8_t *  buf,
size_t  len 
)
overridevirtual

Updates the MD2 hash with specified array of bytes.

Parameters
bufThe byte array to update the MD2 hash with.
lenThe number of bytes to use for the update.

Implements libxcks::Checksum.

Definition at line 81 of file md2.cpp.

Member Data Documentation

◆ C

uint8_t libxcks::MD2::C[16]
protected

Buffer used for computing md2 hash.

Definition at line 60 of file md2.hpp.

◆ count

int libxcks::MD2::count
protected

Current size of the input buffer.

Definition at line 63 of file md2.hpp.

◆ ibuffer

uint8_t libxcks::MD2::ibuffer[16]
protected

Input buffer.

Definition at line 64 of file md2.hpp.

◆ X

uint8_t libxcks::MD2::X[48]
protected

Buffer used for computing md2 hash.

Definition at line 61 of file md2.hpp.


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