Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crypto++ giving a compiler error in algparam.h

Tags:

c++

crypto++

I have the following lines in a rather large file:

#include <sha.h>
#include <hex.h>

Which, when compiled, throws this compiler error:

1>d:\work\app\tools\cryptopp\algparam.h(322): error C2061: syntax error : identifier 'buffer'
1>          d:\work\app\tools\cryptopp\algparam.h(321) : while compiling class template member function 'void CryptoPP::AlgorithmParametersTemplate<T>::MoveInto(void *) const'
1>          with
1>          [
1>              T=bool
1>          ]
1>          d:\work\app\tools\cryptopp\algparam.h(329) : see reference to class template instantiation 'CryptoPP::AlgorithmParametersTemplate<T>' being compiled
1>          with
1>          [
1>              T=bool
1>          ]

I'm pretty sure I'm forgetting something, but I'm not sure what. If I don't include hex.h, I don't have any problems and I get a SHA256 hash just fine, but when I do include hex.h, the error pops up.

Edit

In case anyone wonders, from algparam.h of Crypto++ toolkit:

void MoveInto(void *buffer) const //<=== line 320
{
    AlgorithmParametersTemplate<T>* p = new(buffer)
    AlgorithmParametersTemplate<T>(*this);
}

CRYPTOPP_DLL_TEMPLATE_CLASS AlgorithmParametersTemplate<bool>; // <== line 329

Edit: Removed unrelated code

like image 814
Codecat Avatar asked Mar 04 '13 14:03

Codecat


2 Answers

I fixed the problem by temporarily undefining new, which was defined as a macro to some extra debugging code.

#pragma push_macro("new")
#undef new
/* #includes for Crypto++ go here */
#pragma pop_macro("new")
like image 146
Codecat Avatar answered Oct 16 '22 17:10

Codecat


If you're including Crypto++ in a Visual Studio project with MFC support, this error might be caused by this line:

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

Make sure to remove it or comment it out.

like image 30
c00000fd Avatar answered Oct 16 '22 18:10

c00000fd