Crypto++ in C++ Builder XE ?

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 2497 Views - Last Post: 19 May 2013 - 11:01 AM Rate Topic: -----

#1 Latias  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 28-June 12

Crypto++ in C++ Builder XE ?

Posted 16 May 2013 - 11:13 PM

Hey people

Im comfortable with C++ Builder XE1/2/3. So i want to use the Crypto++ library(no other library but specify Crypto++).

Just a note that the latest version of Crypto++ is only compatible with C++ Builder 2010. But i guess it will work too for later versions like XE3.

So,
1. Downloaded the Crypto++ library, extracted in a folder called "CryptoPP562" at desktop.
2. Launched C++ Builder XE3 and created a new VCL form.
3. Goes to Tools>Options>C++ Options>Paths and directories, and located to the "CryptoPP562" folder at desktop and added this to the "include" & "Library"-path.
4. Added the line #include "sha.h" to project.cpp.
5. Saved the project at desktop.

So i took a look at the Crypto++ wiki and created the first line for the sha256 function, which is: CryptoPP::SHA256 hash;.
I moved this line in the onclick event from a created vcl button.

So after this all i was executing the ide debugger of C++ Builder to test it so far, but got a lot of errors. Seems to be linking errors but im sure i did everything correcly in the steps above.

So why i get these errors? Because i did something from like including the Crypto library, or just simply because that library supports only C++ Builder 2010 as the homepage said.

Quote

Checking project dependencies...
Compiling Project1.cbproj (Debug, Win32)
ilink32 command line
c:\program files (x86)\embarcadero\rad studio\10.0\bin\ilink32.exe -L.\Win32\Debug;"c:\program files (x86)\embarcadero\rad
studio\10.0\lib\Win32\debug";"c:\program files (x86)\embarcadero\rad studio\10.0\lib\win32\release";"c:\program files (x86)\embarcadero\rad
studio\10.0\lib\win32\release\psdk";C:\Users\S\Desktop\CryptoPP562;"C:\Users\Public\Documents\RAD Studio\10.0\DCP" -j.\Win32\Debug;"c:\program files
(x86)\embarcadero\rad studio\10.0\lib\Win32\debug";"c:\program files (x86)\embarcadero\rad studio\10.0\lib\win32\release";"c:\program files
(x86)\embarcadero\rad studio\10.0\lib\win32\release\psdk";C:\Users\S\Desktop\CryptoPP562;"C:\Users\Public\Documents\RAD Studio\10.0\DCP"
-l.\Win32\Debug -v -GA"C:\Users\S\AppData\Local\Temp\vfs37F8.tmp"="C:\Users\S\Desktop\project.dfm" -aa -V5.0 -G8 -Tpe c0w32 rtl.bpi vcl.bpi
(...)
[ilink32 Error] Error: Unresolved external 'CryptoPP::SHA256::InitState(unsigned int *)' referenced from C:\USERS\S\DESKTOP\WIN32\DEBUG\PROJECT.OBJ
[ilink32 Error] Error: Unresolved external 'CryptoPP::SHA256::Transform(unsigned int *, const unsigned int *)' referenced from C:\USERS\S\DESKTOP\WIN32\DEBUG\PROJECT.OBJ
[ilink32 Error] Error: Unable to perform link
Failed
Elapsed time: 00:00:00.1


Is This A Good Question/Topic? 0
  • +

Replies To: Crypto++ in C++ Builder XE ?

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3485
  • View blog
  • Posts: 10,742
  • Joined: 05-May 12

Re: Crypto++ in C++ Builder XE ?

Posted 17 May 2013 - 05:53 AM

I don't use C++ Builder, but on step 3, I see that you added the path to the Crypto library. I don't see a step where you actually added the library to be linked in. So basically all you did was tell the linker where it can find some libraries, but you didn't actually instruct the linker to link in a particular library.
Was This Post Helpful? 1
  • +
  • -

#3 Latias  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 28-June 12

Re: Crypto++ in C++ Builder XE ?

Posted 17 May 2013 - 07:52 AM

well there is no *.lib in the package which i downloaded from the Crypto++ homepage...

This post has been edited by Latias: 17 May 2013 - 07:58 AM

Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3485
  • View blog
  • Posts: 10,742
  • Joined: 05-May 12

Re: Crypto++ in C++ Builder XE ?

Posted 17 May 2013 - 08:02 AM

Then you'll probably have to compile the .cpp files along with your project.

Sent from my T-Mobile G2 using Tapatalk 2
Was This Post Helpful? 1
  • +
  • -

#5 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1312
  • View blog
  • Posts: 4,512
  • Joined: 19-February 09

Re: Crypto++ in C++ Builder XE ?

Posted 17 May 2013 - 03:31 PM

A Readme.txt file is supposedly included in the zip file, so should have been extracted to the directory.
Was This Post Helpful? 2
  • +
  • -

#6 Latias  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 28-June 12

Re: Crypto++ in C++ Builder XE ?

Posted 18 May 2013 - 02:32 AM

When compiling the cpp file it got serveral errors.

in the readme there is nothing what works.

I followed the tutorial at youtube: Compiling Crypto++ library into the Microsoft Visual C++
also this didnt work for my MS visual studio 2010 express. Crypto++ Project is too old i got as error message
Was This Post Helpful? 0
  • +
  • -

#7 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 765
  • View blog
  • Posts: 2,227
  • Joined: 20-March 10

Re: Crypto++ in C++ Builder XE ?

Posted 18 May 2013 - 06:39 AM

In the readme.txt

It tells you to build cryptest.sln

in MSVC 2010 . I have done this and the project builds fine with no errors.

It builds cryptlib.lib in Win32\Output\Debug or Release
(depending on whether you built as Debug or Release.)

Regards

Snoopy.
Was This Post Helpful? 2
  • +
  • -

#8 Latias  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 28-June 12

Re: Crypto++ in C++ Builder XE ?

Posted 18 May 2013 - 12:20 PM

Ok, let me explain better why it still does not work for me for Windows 7 Home Premium 64 bit.

1. I succesfully downloaded and installed Microsoft Visual C++ 2010 Express, downloaded from go.microsoft.com/?linkid=9709949
2. I started C++ 2010 Express and created a new project: File>New>Win32 project.
3. I entered "project1" as name and it saved the project in: c:\users\x\documents\visual studio 2010\Projects.
4. Then the application wizard pops automatically.

5. I extracted the latest Crypto++ Files into a folder at destop called "cryptopp".
6. Then I close my created "project1" and locate and open the "cryptest.sln" from the "cryptopp" folder.
7. At this point I got the "Visual Studio Conversion Wizard".

So after trying to convert it, it says "convertion error". So i have no chance to compile and build the "cryptlib.lib".

This post has been edited by Latias: 18 May 2013 - 10:55 PM

Was This Post Helpful? 0
  • +
  • -

#9 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 765
  • View blog
  • Posts: 2,227
  • Joined: 20-March 10

Re: Crypto++ in C++ Builder XE ?

Posted 18 May 2013 - 01:01 PM

Well,

What exactly is your error as I get no errors building this ?

In the meantime I have uploaded a Release version of this it might get you

through till you can build your own version of the Library

download link
https://www.box.com/...242qg9s5qbttpdn

Regards

Snoopy.
Was This Post Helpful? 1
  • +
  • -

#10 Latias  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 28-June 12

Re: Crypto++ in C++ Builder XE ?

Posted 18 May 2013 - 01:24 PM

Thanks you very much! I will test your file and see if i can use md5 with it.

i made a screenshot of the error

Posted Image
Was This Post Helpful? 0
  • +
  • -

#11 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 765
  • View blog
  • Posts: 2,227
  • Joined: 20-March 10

Re: Crypto++ in C++ Builder XE ?

Posted 18 May 2013 - 01:40 PM

Hi,

I must admit I dont know what that error is

Are you sure you extracted the files properly as it is saying the files are corrupt ?

and the system error code is not one I recognise.

Perhaps one of the Mentors can help.

Snoopy.
Was This Post Helpful? 1
  • +
  • -

#12 Latias  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 28-June 12

Re: Crypto++ in C++ Builder XE ?

Posted 18 May 2013 - 02:45 PM

yes i did everything correct :)

But so now im using your generated library for a md5 string hash.
but the problem is there are no examples of a md5 string hash for Win32 C++.
So maybe you do know how to do a md5 hash with crypto++?
Was This Post Helpful? 0
  • +
  • -

#13 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1312
  • View blog
  • Posts: 4,512
  • Joined: 19-February 09

Re: Crypto++ in C++ Builder XE ?

Posted 18 May 2013 - 05:50 PM

Hash Functions


Quick sha1sum with Crypto++
Was This Post Helpful? 0
  • +
  • -

#14 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 765
  • View blog
  • Posts: 2,227
  • Joined: 20-March 10

Re: Crypto++ in C++ Builder XE ?

Posted 18 May 2013 - 06:00 PM

I wouldnt even bother with a library as there is a perfectly good C
implementation on the Rosetta Code of the MD5 hash algorithm

Adjusted code from the Rosetta Code Project

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <conio.h>

typedef union uwb {
	unsigned w;
	unsigned char b[4];
} WBunion;

typedef unsigned Digest[4];

unsigned f0( unsigned abcd[] ){
	return ( abcd[1] & abcd[2]) | (~abcd[1] & abcd[3]);}

unsigned f1( unsigned abcd[] ){
	return ( abcd[3] & abcd[1]) | (~abcd[3] & abcd[2]);}

unsigned f2( unsigned abcd[] ){
	return  abcd[1] ^ abcd[2] ^ abcd[3];}

unsigned f3( unsigned abcd[] ){
	return abcd[2] ^ (abcd[1] |~ abcd[3]);}

typedef unsigned (*DgstFctn)(unsigned a[]);

unsigned *calcKs( unsigned *k)
{
	double s, pwr;
	int i;

	pwr = pow( 2.0, 32);
	for (i=0; i<64; i++) {
		s = fabs(sin(1.0+i));
		k[i] = (unsigned)( s * pwr );
	}
	return k;
}

// ROtate v Left by amt bits
unsigned rol( unsigned v, short amt )
{
	unsigned  msk1 = (1<<amt) -1;
	return ((v>>(32-amt)) & msk1) | ((v<<amt) & ~msk1);
}

unsigned *md5( const char *msg, int mlen) 
{
	static Digest h0 = { 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476 };
	//    static Digest h0 = { 0x01234567, 0x89ABCDEF, 0xFEDCBA98, 0x76543210 };
	static DgstFctn ff[] = { &f0, &f1, &f2, &f3 };
	static short M[] = { 1, 5, 3, 7 };
	static short O[] = { 0, 1, 5, 0 };
	static short rot0[] = { 7,12,17,22};
	static short rot1[] = { 5, 9,14,20};
	static short rot2[] = { 4,11,16,23};
	static short rot3[] = { 6,10,15,21};
	static short *rots[] = {rot0, rot1, rot2, rot3 };
	static unsigned kspace[64];
	static unsigned *k;

	static Digest h;
	Digest abcd;
	DgstFctn fctn;
	short m, o, g;
	unsigned f;
	short *rotn;
	union {
		unsigned w[16];
		char     b[64];
	}mm;
	int os = 0;
	int grp, grps, q, p;
	unsigned char *msg2;

	if (k==NULL) k= calcKs(kspace);

	for (q=0; q<4; q++) h[q] = h0[q];   // initialize

	{
		grps  = 1 + (mlen+8)/64;
		msg2 = (unsigned char*) malloc( 64*grps);
		memcpy( msg2, msg, mlen);
		msg2[mlen] = (unsigned char)0x80;  
		q = mlen + 1;
		while (q < 64*grps){ msg2[q] = 0; q++ ; }
		{
			//            unsigned char t;
			WBunion u;
			u.w = 8*mlen;
			//            t = u.b[0]; u.b[0] = u.b[3]; u.b[3] = t;
			//            t = u.b[1]; u.b[1] = u.b[2]; u.b[2] = t;
			q -= 8;
			memcpy(msg2+q, &u.w, 4 );
		}
	}

	for (grp=0; grp<grps; grp++)
	{
		memcpy( mm.b, msg2+os, 64);
		for(q=0;q<4;q++) abcd[q] = h[q];
		for (p = 0; p<4; p++) {
			fctn = ff[p];
			rotn = rots[p];
			m = M[p]; o= O[p];
			for (q=0; q<16; q++) {
				g = (m*q + o) % 16;
				f = abcd[1] + rol( abcd[0]+ fctn(abcd) + k[q+16*p] + mm.w[g], rotn[q%4]);

				abcd[0] = abcd[3];
				abcd[3] = abcd[2];
				abcd[2] = abcd[1];
				abcd[1] = f;
			}
		}
		for (p=0; p<4; p++)
			h[p] += abcd[p];
		os += 64;
	}
	return h;
}    


int main()
{
	int j,k;
	const char *msg = "The quick brown fox jumps over the lazy dog.";
	unsigned *d = md5(msg, strlen(msg));
	WBunion u;

	printf("MD5 Encrypted Message = ");
	for (j=0;j<4; j++){
		u.w = d[j];
		for (k=0;k<4;k++) printf("%02x",u.b[k]);
	}
	printf("\n");

	_getch(); //used to hold window open replace as you see fit
	return 0;
}



http://rosettacode.org/wiki/MD5#C

Relevant RFC

http://tools.ietf.org/html/rfc1321
Was This Post Helpful? 2
  • +
  • -

#15 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3485
  • View blog
  • Posts: 10,742
  • Joined: 05-May 12

Re: Crypto++ in C++ Builder XE ?

Posted 18 May 2013 - 08:02 PM

Migrating the Crypto++ libraries to VS2010 worked just fine for me as well. It also worked well starting with a clean copy and migrating to VS2012.

Can you post the .vcproj files and I can take a peek to see if there is anything obviously wrong.

As snoopy11 mentioned, are you sure that the files were not corrupted at extraction time? What AV software are you using? Some AV software just do not work well with developer tools like compilers and linkers.

BTW, unlike VS2008, you don't have to run VS2010 as an Administrator.
Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2