-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
 
Gary wrote:
> Hello I want to use "Cryptopp" library in my project(that is a
> smart card CSP)! First,I've tried to compile a sample code of SHA
> that is provided in "crypto++ user's guide" CHM file in section
> "HashModule" by denis bider.
>
> I only want to try SHA and SHA256,so I've deleted other algorithms
> calls in "main" function(such "MD5"),then I created "An empty win32
>  console application" in visual C++ 2008 and copy and paste the
> code below in it.
>
>
> // Crypto++ #include "sha.h"        // SHA-1, SHA-256, SHA-384,
> SHA-512 #include "hex.h"        // HexEncoder
>
> // std #include <iostream> #include <string.h> void DumpHash(
> CryptoPP::HashModule& hash, char const* szModuleName, std::string
> const& strDataPart1, std::string const& strDataPart2, std::string
> const& strDataPart3) { DumpHash_SingleStep(hash, szModuleName,
> strDataPart1 + strDataPart2 + strDataPart3);
> DumpHash_MultiStep(hash, szModuleName, strDataPart1, strDataPart2,
> strDataPart3); DumpHash_HashFilter(hash, szModuleName,
> strDataPart1, strDataPart2, strDataPart3); } void
> DumpHash_SingleStep( CryptoPP::HashModule& hash, char const*
> szModuleName, std::string const& strData) { using namespace std;
> using namespace CryptoPP;
>
> // Cannot use std::string for buffer; // its internal storage might
> not be contiguous SecByteBlock sbbDigest(hash.DigestSize());
>
> hash.CalculateDigest( sbbDigest.Begin(), (byte const*)
> strData.data(), strData.size());
>
> cout << szModuleName << " SS: "; HexEncoder(new
> FileSink(cout)).Put(sbbDigest.Begin(), sbbDigest.Size()); cout <<
> endl; } void DumpHash_MultiStep( CryptoPP::HashModule& hash, char
> const* szModuleName, std::string const& strDataPart1, std::string
> const& strDataPart2, std::string const& strDataPart3) { using
> namespace std; using namespace CryptoPP;
>
> hash.Update((byte const*) strDataPart1.data(), strDataPart1.size
> ()); hash.Update((byte const*) strDataPart2.data(),
> strDataPart2.size ()); hash.Update((byte const*)
> strDataPart3.data(), strDataPart3.size ());
>
> // Cannot use std::string for buffer; // its internal storage might
> not be contiguous SecByteBlock sbbDigest(hash.DigestSize());
>
> hash.Final(sbbDigest.Begin());
>
> cout << szModuleName << " MS: "; HexEncoder(new
> FileSink(cout)).Put(sbbDigest.Begin(), sbbDigest.Size()); cout <<
> endl; } void DumpHash_HashFilter( CryptoPP::HashModule& hash, char
> const* szModuleName, std::string const& strDataPart1, std::string
> const& strDataPart2, std::string const& strDataPart3) { using
> namespace std; using namespace CryptoPP;
>
> // Here, we are free to use std::string as the destination, //
> because StringSink uses the correct std::string interface to append
> data string strDigest; HashFilter hashFilter(hash, new
> StringSink(strDigest)); hashFilter.Put((byte const*)
> strDataPart1.data(), strDataPart1.size()); hashFilter.Put((byte
> const*) strDataPart2.data(), strDataPart2.size());
> hashFilter.Put((byte const*) strDataPart3.data(),
> strDataPart3.size()); hashFilter.MessageEnd();
>
> cout << szModuleName << " HF: "; StringSource(strDigest, true, new
> HexEncoder( new FileSink(cout))); cout << endl; }
>
> int main() { using namespace std; using namespace CryptoPP;
>
> std::string strDataPart1 = "part 1; "; std::string strDataPart2 =
> "part two; "; std::string strDataPart3 = "PART THREE.";
>
> try { DumpHash(SHA(),       "SHA      ", strDataPart1,
> strDataPart2, strDataPart3); DumpHash(SHA256(),    "SHA256   ",
> strDataPart1, strDataPart2, strDataPart3); } catch
> (CryptoPP::Exception const& e) { cout << "CryptoPP::Exception
> caught: " << endl << e.what() << endl; return 1; }
>
> return 0; }
>
>
> Then with "Tools/Options/projects and solutions/visual C++
> Directories",include "cryptopp552" folder(which contains all header
>  files of cryptopp library) to project,also I added "hex.h" and
> "sha.h" to project in "solution explorer" section. But after
> building it,I got 26 errors as below:
>
> ------ Build started: Project: cryptopp(hashmodule), Configuration:
>  Debug Win32 ------ Compiling... 1.cpp
> d:\cryptopp(hashmodule)\1.cpp(9) : error C2039: 'HashModule' : is
> not a member of 'CryptoPP'
>
> d:\cryptopp(hashmodule)\1.cpp(9) : error C2065: 'HashModule' :
> undeclared identifier
>
> d:\cryptopp(hashmodule)\1.cpp(9) : error C2065: 'hash' : undeclared
>  identifier
>
> d:\cryptopp(hashmodule)\1.cpp(10) : error C2062: type 'const char'
> unexpected
>
> d:\cryptopp(hashmodule)\1.cpp(14) : error C2143: syntax error :
> missing ';' before '{'
>
> d:\cryptopp(hashmodule)\1.cpp(14) : error C2447: '{' : missing
> function header (old-style formal list?)
>
> d:\cryptopp(hashmodule)\1.cpp(20) : error C2039: 'HashModule' : is
> not a member of 'CryptoPP'
>
> d:\cryptopp(hashmodule)\1.cpp(20) : error C2065: 'HashModule' :
> undeclared identifier
>
> d:\cryptopp(hashmodule)\1.cpp(20) : error C2065: 'hash' :
> undeclared identifier
>
> d:\cryptopp(hashmodule)\1.cpp(21) : error C2062: type 'const char'
> unexpected
>
> d:\cryptopp(hashmodule)\1.cpp(23) : error C2143: syntax error :
> missing ';' before '{'
>
> d:\cryptopp(hashmodule)\1.cpp(23) : error C2447: '{' : missing
> function header (old-style formal list?)
>
> d:\cryptopp(hashmodule)\1.cpp(41) : error C2039: 'HashModule' : is
> not a member of 'CryptoPP'
>
> d:\cryptopp(hashmodule)\1.cpp(41) : error C2065: 'HashModule' :
> undeclared identifier
>
> d:\cryptopp(hashmodule)\1.cpp(41) : error C2065: 'hash' :
> undeclared identifier
>
> d:\cryptopp(hashmodule)\1.cpp(42) : error C2062: type 'const char'
> unexpected
>
> d:\cryptopp(hashmodule)\1.cpp(46) : error C2143: syntax error :
> missing ';' before '{'
>
> d:\cryptopp(hashmodule)\1.cpp(46) : error C2447: '{' : missing
> function header (old-style formal list?)
>
> d:\cryptopp(hashmodule)\1.cpp(65) : error C2039: 'HashModule' : is
> not a member of 'CryptoPP'
>
> d:\cryptopp(hashmodule)\1.cpp(65) : error C2065: 'HashModule' :
> undeclared identifier
>
> d:\cryptopp(hashmodule)\1.cpp(65) : error C2065: 'hash' :
> undeclared identifier
>
> d:\cryptopp(hashmodule)\1.cpp(66) : error C2062: type 'const char'
> unexpected
>
> d:\cryptopp(hashmodule)\1.cpp(70) : error C2143: syntax error :
> missing ';' before '{'
>
> d:\cryptopp(hashmodule)\1.cpp(70) : error C2447: '{' : missing
> function header (old-style formal list?)
>
> d:\cryptopp(hashmodule)\1.cpp(101) : error C3861: 'DumpHash':
> identifier not found
>
> d:\cryptopp(hashmodule)\1.cpp(102) : error C3861: 'DumpHash':
> identifier not found
>
> cryptopp(hashmodule) - 26 error(s), 0 warning(s) ========== Build:
> 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
>
>
>
> Please help me what should I do to compile and build this sample
> code, correctly and will see the output provided as such:
>
> SHA       SS: 83F4A5C2778C5FC3FA4DC91BDE16203126E41D56 SHA
> MS: 83F4A5C2778C5FC3FA4DC91BDE16203126E41D56 SHA       HF:
> 83F4A5C2778C5FC3FA4DC91BDE16203126E41D56 SHA256    SS:
> 972226D00A46823E0A1FD0EB44EB7A865CA3AB981DE3927F8C1A98F4A0436AF9
> SHA256    MS:
> 972226D00A46823E0A1FD0EB44EB7A865CA3AB981DE3927F8C1A98F4A0436AF9
> SHA256    HF:
> 972226D00A46823E0A1FD0EB44EB7A865CA3AB981DE3927F8C1A98F4A0436AF9
>
>
> One other question!
>
> Should I create "cryptopp.dll" and "cryptopp.lib" myself? or there
> are these files in "cryptopp website" that I can  add them to my
> "smart card CSP" code and use from it's cryptographic functions? If
> not,how should I compile "cryptopp.c" and "cryptopp.h" in VC++ 2008
>  to produce "cryptopp.dll" and "cryptopp.lib"?
>
> Please help me as soon as possible,I have no much time! I'm so new
> to use of this library in my project and waiting your reply and
> guide Dear Friends. Best Regards.
>
> >
>
Gary,

I looked at the code and you will need to use
CryptoPP::HashTransformation instead of the old CryptoPP::HashModule
which is defined in cryptlib.h it was a predecessor to
HashTransformation in Crypto++ 4.2. I believe you are using Wei's
latest Crypto++ 5.5.2 build in which HashModule has been deprecated.
You mentioned in your email that your using Crypto++ 5.5.2 with Visual
Studio so that kind of explains why your getting errors during the
build process. I also see a class reference to FileSink you will need
the proper include which is #include "files.h". As for compiling the
libs,
yes, I would suggest you compile the cryptlibd and cryptlib for your
release and debug builds.

Reference to HashTransformation:
http://www.cryptopp.com/docs/ref/class_hash_transformation.html

In response to another question posted on the group in which this
topic came up.

http://www.mail-archive.com/[email protected]/msg00101.html


void DumpHash_SingleStep(CryptoPP::HashTransformation& hash, char
const* szModuleName, std::string const& strData) { // Code }

Moreover, the syntax errors are pretty straightforward.

HexEncoder(new FileSink(cout)).Put(sbbDigest.Begin(), // sbbDigest.begin()


See these topics and see if they  help, I was able to compile this
code using the proper version of the Crypto++ 4.2

http://www.linuxdiyf.com/viewarticle.php?id=109184

http://blog.csdn.net/violetfeeling/archive/2008/09/19/2949701.aspx

I'm sure Mr. Dai will have more insightful information regarding
HashModule and HashTransformation.

Regards,

Dillon Beresford
The Komodo PGMP project
http://code.google.com/p/komodopgmp/
http://sourceforge.net/projects/komodopgmp/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
 
iD8DBQFJhNRoRnxC5lZRuuERAtFBAJ9OrROS9XvLhBfNP1ZpGSkJaiBylQCeI/xj
hh7dvN8927jYs0hCHyw6Oy8=
=eJQl
-----END PGP SIGNATURE-----


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
-~----------~----~----~----~------~----~------~--~---

//codes in userguide, cryptlib.h, DumpHashes.cpp

#include "./cryptlib/hex.h"
#include "./cryptlib/files.h"
#include "./cryptlib/cryptlib.h"
#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1

#include <iostream>
#include <string.h>

using namespace std;
using namespace CryptoPP;

void DumpHash_SingleStep(CryptoPP::HashTransformation& hash, char const* 
szModuleName, std::string const& strData) {
//Can't use std::string for buffer;
// its internal storage might not be contiguous
SecByteBlock sbbDigest(hash.DigestSize());

hash.CalculateDigest(sbbDigest.begin(), (byte const*) strData.data(), 
strData.size());

cout << szModuleName << "SS:";
HexEncoder(new FileSink(cout)).Put(sbbDigest.begin(), sbbDigest.size());
cout << endl;
}

void DumpHash_MultiStep(CryptoPP::HashTransformation& hash, char const* 
szModuleName, std::string const& strDataPart1, std::string const& strDataPart2, 
std::string const& strDataPart3){
hash.Update((byte const*) strDataPart1.data(), strDataPart1.size());
hash.Update((byte const*) strDataPart2.data(), strDataPart2.size());
hash.Update((byte const*) strDataPart3.data(), strDataPart3.size());

//can't use std::string for buffer;
//its internal storage might not be contiguous
SecByteBlock sbbDigest(hash.DigestSize());

hash.Final(sbbDigest.begin());

cout << szModuleName << "MS";
HexEncoder(new FileSink(cout)).Put(sbbDigest.begin(), sbbDigest.size());
cout << endl;
}

void DumpHash_HashFilter(CryptoPP::HashTransformation& hash, char const* 
szModuleName, std::string const& strDataPart1, std::string const& strDataPart2, 
std::string const& strDataPart3){
//Here, we are free to use std::string as the destination,
//because StringSink uses the correct std::string interface to append data
string strDigest;
HashFilter hashFilter(hash, new StringSink(strDigest));
hashFilter.Put((byte const*) strDataPart1.data(), strDataPart1.size());
hashFilter.Put((byte const*) strDataPart2.data(), strDataPart2.size());
hashFilter.Put((byte const*) strDataPart3.data(), strDataPart3.size());
hashFilter.MessageEnd();

cout << szModuleName << "HF:";
StringSource(strDigest, true, new HexEncoder(new FileSink(cout)));
cout << endl;
}

void DumpHash(CryptoPP::HashTransformation& hash, char const* szModuleName, 
std::string const& strDataPart1, std::string const& strDataPart2, std::string 
const& strDataPart3){
DumpHash_SingleStep(hash, szModuleName, strDataPart1 + strDataPart2 + 
strDataPart3);
DumpHash_MultiStep(hash, szModuleName, strDataPart1, strDataPart2, 
strDataPart3);
DumpHash_HashFilter(hash, szModuleName, strDataPart1, strDataPart2, 
strDataPart3);
}

//Crypto++
#include "./cryptlib/sha.h"
#include "./cryptlib/ripemd.h"
#include "./cryptlib/md5.h"
#include "./cryptlib/crc.h"

int main(){
using namespace std;
using namespace CryptoPP;

SHA sha;
SHA256 sha256;
RIPEMD160 ripemd160;
Weak::MD5 md5;
CRC32 crc32;

std::string strDataPart1 = "part 1;";
std::string strDataPart2 = "part two;";
std::string strDataPart3 = "PART THREE;";

try{
DumpHash(sha, "SHA", strDataPart1, strDataPart2, strDataPart3);
DumpHash(sha256, "SHA256", strDataPart1, strDataPart2, strDataPart3);
DumpHash(ripemd160, "RIPEMD160", strDataPart1, strDataPart2, strDataPart3);
DumpHash(md5, "MD5", strDataPart1, strDataPart2, strDataPart3);
DumpHash(crc32, "CRC32", strDataPart1, strDataPart2, strDataPart3);
}
catch(CryptoPP::Exception const& e){
cout << "CryptoPP::Exception caught:" << endl
<< e.what() << endl;
return 1;
}
}

Attachment: pgpkeys.asc
Description: application/pgp-keys

Reply via email to