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.

--~--~---------~--~----~------------~-------~--~----~
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.
-~----------~----~----~----~------~----~------~--~---

Reply via email to