65.9K
CodeProject is changing. Read more.
Home

Message Digest Application

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.86/5 (7 votes)

Mar 31, 2004

2 min read

viewsIcon

82904

downloadIcon

979

A program which generates the various Message Digests using only one Class, also including the different techniques for Base 64 Encoding And Decoding

Introduction

This is class which generates the Message Digest using Various algorithms. It gives support to various algorithms such as MD4 - both 128 bits and 256 bits, MD5, RIPEMD-128, RIPEMD-160, RIPEMD-256, RIPEMD-320, SHA-1, SHA-256, SHA-384, SHA-512, HAVAL SERIES and BASE 64 Encoding and Decoding.

Using the code

This one program can be used for various purpose

  1. You can create the .dll file and can use it
  2. You can create the .exe file and use it as Console Based Utility

For creating the Console based utility

  • Include all the files except the MessageDigest.def file
  • Compile Main.cpp in VC++ 6.0 and then run it

Note:- Please remove all the files from the build expect the Main.cpp while you are creating the Console based utility.

Help is included in the Main.cpp or you can run the .exe file with parameters as (NULL, -?, -help)

For creating the dll file

Include the file MessageDigest.def file and remove the main.cpp, main.h, system.h files. Then compile the "Export.cpp" and build the MessageDigest.dll

//This is the Structure of Class which will do Everything

class Signature_Context
{

private:
  UCHAR ucCur_Size_of_Buffer;
  UCHAR ucCheck;
  UCHAR ucSignature_Type;
  UCHAR ucDigest_Length;

  DOUBLE dProgress,dDelta_Progress;
  Progress ShowProgress;

  union
  {
    FILE * OutFileStream;
    PCHAR  lpChar;
  }OutPut;

  union Finger_Prints
  {
    ULONGLONG ullValues[8];
    ULONG     ulValues[16];
    UINT    uiValues[32];
    UCHAR     ucValues[64];
    UCHAR    ucullValues[8][8];
    UCHAR    uculValues[16][4];
  }Hash;
  
  struct
  {
    UCHAR ucBlockSize;
    union
    {
      PUCHAR     ucValues;
      PSHORT     sValues;
      PULONG     ulValues;
      PULONGLONG ullValues;
    }Block;
  }Message;

  union
  {
    ULONGLONG ullLength;
    UCHAR ucChar_Codes[8];
    struct
    {
      unsigned Bit_4:6;
      unsigned Bit_3:6;
      unsigned Bit_2:6;
      unsigned Bit_1:6;
    }Bits;
  }Code_Convertor;

  // Private Functions
  LONG Initialize(UCHAR,UCHAR);
  VOID Destroy(VOID);

  LONG Expected_FileSize(ULONGLONG &);

  VOID MD4_Transform(VOID);
  VOID MD5_Transform(VOID);
  VOID SHA1_Transform(VOID);
  VOID SHA256_Transform(VOID);
  VOID SHA_384_512_Transform(VOID);
  VOID RIPEMD_128_256_Transform(VOID);
  VOID RIPEMD_160_320_Transform(VOID);
  VOID HAVAL_Transform(SHORT);

  VOID HAVAL_Tailor(VOID);

  VOID Signature_Transform(UCHAR);

  VOID Signature_Final(UCHAR);

  VOID BASE64_Encode_Update(PCHAR,ULONG &);
  VOID Base64_Encode_Final(VOID);
  VOID BASE64_Decode(PCHAR);

public:
  Signature_Context(UCHAR = MD_5, UCHAR = 0); // Parameterized Constructor
  ~Signature_Context(VOID); // Destructor

  LONG Create_Signature(PCHAR,ULONG,PCHAR,SHORT,
         UCHAR = 3,UCHAR = 0,SHORT = 0,  
             LONG = NULL,LONG = NULL);

  VOID Signature_Update(PCHAR,ULONG &);
};

Points of Interest

  1. Special Logic has been developed for Base 64 encoding and decoding
  2. A some what different implementation for calculating the Message Digest
  3. In all 16 Message Digest algorithms are supported
  4. Given support to MD4 256 bit algorithm, which require 2 copies of code running parallelly
  5. Implementation of AppendChunk method which will take in some extra input while processing (Not in Console Based)
  6. The program gives back the progress of transformation (Not in Console Based)

Special Logic used for BASE 64 Encoding and Decoding.

I had used the concept of bit datatype. Check out the cool code and also the speed which i had reduced for calculation of BASE 64 Encoding and Decoding

I wonder "Why people use the shifting logic when they had Bit Data type Which gradually increases the Execution time"

An efficient use of CALLBACK from C++

Lastly, I would like to thank Respected Sir, Shyam R. Soni for his priceless guidance through out this project. It would be never be possible without him. I would also like to thanks Dominik Reichl for his very valuable tips and guidance