Try "(HashTransformation&)SHA()" instead of "SHA()". Newer compilers follow the C++ standard more strictly, and do not allow temporary objects to be implicitly converted to non-const references.

----- Original Message ----- From: "Manik Taneja" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Tuesday, November 15, 2005 2:20 PM
Subject: Re: Could not convert 'SHA()' to 'HashTransformation&'


Hey,

I checked with cryptlib.h and making a pointer too. But, it does not
still compile saying Could not convert from SHA() to HashTransformation.
You mentioned about Update() and Final(). I think they would only come
into picture once the argument is correctly passed. Unitl then, it would
n't much matter what I am using.

Quoting Jeffrey Walton <[EMAIL PROTECTED]>:

Hi,

I think the only methods available (of interest) are Update() and
Final(). See
http://cryptopp.sourceforge.net/docs/ref521/class_hash_transformation.html

You might also try including cryptlib.h.

Finally, does a pointer make a difference? When I move amoung Random
Number Generators, I generall hold a pointer to a base class, and not
a
reference.

Jeff

>>> [EMAIL PROTECTED] 11/15/2005 3:08 PM >>>
I followed your lead but still can not figure out why its not taking
SHA() as the algorithm. Here is my complete code. Kindly see if you
couls figure something out.

// Crypto++
#include "/util/crypto++-5.2.1/hex.h"        // HexEncoder
#include "/util/crypto++-5.2.1/sha.h"        // SHA-1, SHA-256,
SHA-384,
SHA-512
#include "/util/crypto++-5.2.1/ripemd.h"     // RIPEMD160
#include "/util/crypto++-5.2.1/md5.h"        // MD5
#include "/util/crypto++-5.2.1/crc.h"        // CRC-32

// std
#include <iostream>
#include <string>
#include <fstream>
#include <vector>

std::fstream fout("hash.txt", std::ios::out | std::ios::app);

void ReadInput(std::vector<std::string>& vecText, unsigned int
nNrPlaintexts)
{
  // delare namespaces in use
  using namespace std;
  using namespace CryptoPP;

  char str[200];

  // resize vector so that it references the 0th element
  vecText.resize(0);

  // open the input file to read plaintext from
  fstream fin("plaintext.txt", ios::in);

  while (nNrPlaintexts--)
    {
      if(!fin.eof())
{// while end of file is not reached read each line of data
  fin.getline(str,200);
  vecText.push_back(str);
}
      else
{
  cout << "The file does not have sufficient data";
  break;
 }
    }

  // close the file
  fin.close();
}

void HashDump(CryptoPP::HashTransformation& hash, char const*
szModuleName, std::string const& strData)
{
  // declare namespaces in use
  using namespace std;
  using namespace CryptoPP;

  string strHash;

  // byte hashOutputBuffer[SHA::DIGESTSIZE];
  // memset(hashOutputBuffer, 0x00, SHA::DIGESTSIZE);

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

  // calculate the requisite hash
  hash.CalculateDigest(sbbDigest, (byte const*) strData.data(),
strData.size());

  // HexEncode the hash and store in a string
  StringSource(sbbDigest.begin(), true, new HexEncoder(new
StringSink(strHash)));

  // display the generated hash
  fout << szModuleName << ": " << strHash << endl;
}

int main()
{
  // declares namespaces in use
  using namespace std;
  using namespace CryptoPP;

  try
  {
    unsigned int nText = 10;
    vector<string> vecText;

    // populate vector with the plaintexts
    ReadInput(vecText, nText);

    for (unsigned int i=0; i!=nText; ++i)
      {
cout << "(" << i << ") ";
cout << vecText[i] << endl;

//  calculate SHA digest
HashDump(CryptoPP::SHA(), SHA::StaticAlgorithm, vecText[i]);

//calculate 256 bit hash digest
//HashDump(CryptoPP::SHA256(), "SHA256 ", vecText[i]);

// calculate RIPEMD digest
//HashDump(CryptoPP::RIPEMD160(), "RIPEMD160 ", vecText[i]);

//  calculate MD5 hash digest
HashDump(CryptoPP::MD5(), "MD5 ", vecText[i]);

// calculaye CRC digest
// HashDump(CryptoPP::CRC32(), "CRC32 ", vecText[i]);
      }
  }
  catch (CryptoPP::Exception const& e)
  {// catch CryptoPP exceptions
    cout << "CryptoPP::Exception caught: " << endl
     << e.what() << endl;
   return 1;
  }

  fout.close();
  return 0;
}


Quoting Cornel Maftuleac <[EMAIL PROTECTED]>:

> Manik Taneja wrote:
>
> >I am trying to write a hash program which could
> >compute the Hash for all the different types -
> >SHA1, SHA256, MD5, ....
> >
> >As such, I wrote the following function that
> >computes the hash for different algorithms
> >
> >i coded the function as -
> >
> >void HashDump(CryptoPP::HashTransformation& hash, char const*
> Module,
> >std::string const& strData)
> >{
> >....
> >...
> >....
> >...
> >
> >
> >}
> >
> >However, when I call the function as -
> >
> >HashDump(SHA(), "SHA 1", strData);
> >
> >the compiler generates an error saying -
> >
> >could not convert 'SHA()' to 'CryptoPP::HashTransformation&'
> >
> >I really wish to figure out which **interface** to use so that I
> could
> >just pass the requisite arguments and the function computes the
> >appropriate hash for me.
> >
> >
> I think CryptoPP::HashTransformation is just what you need.
> But are you sure that compiler knows what is SHA()?
> Maybe you should write CryptoPP::SHA?
> A little hint: you can replace the second hard-coded parameter by
> CryptoPP::SHA::StaticAlgorithmName(), this way you'll get the
> algorithm
> name from cryptopp inside.  ;)







=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Manik Taneja
University at Buffalo
mtaneja [at] buffalo [dot] edu



Reply via email to