Friday, 10 September 2010

C++ DiceLockSecurity Namespace

Source Code

HOW TO

Compute Ripemd 160 Hash Algorithm with Ripemd160 Class Print E-mail
In these lines we are going to show how to set up Microsoft Visual C++ 2008 Professional to use Ripemd160 class implemented in DiceLockSecurity namespace to compute Ripemd 160 Secure Hash Algorithm of streams with HashDigester FREE product.

In this page we are going to show the steps to use Ripemd160 Class in a simple application, it does not show all Ripemd160 class capabilities. If you want a deeper knowledge of the class you can get DigesterCheck Hash Algorithms Source Code 2.0.0.2

This article is structured in three concepts:
- Project Creation
- Project Properties
- Execution


Project Creation

Create the project

In Microsoft Visual C++ 2008 Professional select File, New, Project..., select Project type Visual C++ CLR Console Application call it UsingHashDigester for example like in:


Insert Source Code

Edit stdafx.h file and insert the following C++ code:

 

// stdafx.h : include file for standard system include files,

// or project specific include files that are used frequently, but

// are changed infrequently

//

 

#pragma once

 

// TODO: reference additional headers your program requires here

#include "hashDigester.h"

 

Edit UsingHashDigester.cpp file and insert the following C++ code where a Ripemd160 object is instantiated and used to compute the hash of "abc" test data with Ripemd 160 hash algorithm:

 

// UsingHashDigester.cpp : main project file.

 

#include "stdafx.h"

 

using namespace System;  

using namespace DiceLockSecurity;

using namespace DiceLockSecurity::Hash; 

 

int main(array<System::String ^> ^args)

{

    DefaultCryptoRandomStream* stream;

    DefaultCryptoRandomStream* hashStream;

    Ripemd160* ripemd160;

    unsigned short int i;

 

    Console::WriteLine(L""); 

    stream = new DefaultCryptoRandomStream();

    stream->SetCryptoRandomStreamUC("abc",3);

    ripemd160 = new Ripemd160();

    hashStream = new DefaultCryptoRandomStream();

    hashStream->SetCryptoRandomStreamBit(ripemd160->GetBitHashLength());

    ripemd160->SetMessageDigest(hashStream);

    ripemd160->Initialize();

    ripemd160->Add(stream);

    ripemd160->Finalize();

   

    Console::WriteLine(" RIPEMD expected hash: 8eb208f7e05d987a9b044a8e98c6b087f15a0bfc");

    Console::Write(" HashDigester    hash: ");

    for (i=0; i<ripemd160->GetUCHashLength(); i+=4) {

          Console::Write("{0}",(((unsigned char)ripemd160->GetMessageDigest()->GetULPosition(i>>2))).ToString("x2"));

          Console::Write("{0}",(((unsigned char)(ripemd160->GetMessageDigest()->GetULPosition(i>>2) >> 8))).ToString("x2"));

          Console::Write("{0}",(((unsigned char)(ripemd160->GetMessageDigest()->GetULPosition(i>>2) >> 16))).ToString("x2"));

          Console::Write("{0}",(((unsigned char)(ripemd160->GetMessageDigest()->GetULPosition(i>>2) >> 24))).ToString("x2"));

    }

    Console::WriteLine("");

    Console::WriteLine(L""); 

 

    delete ripemd160;

    delete hashStream;

    delete stream; 

    return 0;

}
 

HashDigester DLL

Copy HashDigester.dll dynamic link library file where the Project will create the executable, in our case is under Release folder like in:


Project Properties

General

These are the general properties of the application:


C++ General

Select Additional Include Directories, to allow the application to find hashDigester.h header file. On our case it is located at "C:\Program Files\DiceLock Security\HashDigester\include" directory:


C++ Compiler Command Line

The compiler command line will look like this:


The compiler command line options are:

 
/GL /I "C:\Program Files\DiceLock Security\HashDigester\include" /D "WIN32" /D "NDEBUG" /D "_UNICODE" /D "UNICODE" /FD /EHa /MD /Yu"stdafx.h" /Fp"Release\UsingHashDigester.pch" /Fo"Release\\" /Fd"Release\vc90.pdb" /W3 /nologo /c /Zi /clr /TP /errorReport:prompt /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.XML.dll"
 

Linker General

In the Linker General Section add the directory where HashDigester.lib is located in the Additional Library Directories option. In our case the directory is "C:\Program Files\DiceLock Security\HashDigester\lib".


Linker Input

Once the previous options have been included, go to Linker Input Section and insert in Additional Dependencies the proper library, HashDigester.lib.


Linker Command Line

The linker command line will look like this:


The linker command line options are:

 
/OUT:"C:\Users\Administrador\Desktop\Projects\DifferentTests\UsingHashDigester\Release\UsingHashDigester.exe" /INCREMENTAL:NO /NOLOGO /LIBPATH:"C:\Program Files\DiceLock Security\HashDigester\lib" /MANIFEST /MANIFESTFILE:"Release\UsingHashDigester.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"c:\Users\Administrador\Desktop\Projects\DifferentTests\UsingHashDigester\Release\UsingHashDigester.pdb" /LTCG /DYNAMICBASE /FIXED:No /NXCOMPAT /MACHINE:X86 /ERRORREPORT:PROMPT HashDigester.lib
 


Execution

Once all previous steps have been completed, select Debug option, Start Without Debugging, and the application will be compiled, linked and executed.

The command line application executed will look like the following screenshot where you will be able to verify that Ripemd160 class performs as expected.

 



Close Me  
Get FREE Random Number Test Windows DLL !
Get FREE Hash Algorithms Windows DLL !