Reputation: 93
I have a program that initialize an ECDSA key pair and store them. That program worked, but now, I have a segmentation fault when initializing an ECDSA Private key using the Crypto++ library.
Here is what I am doing:
#include <iostream>
#include <cryptopp/eccrypto.h>
#include <cryptopp/osrng.h>
#include <cryptopp/oids.h>
#include <cryptopp/files.h>
using namespace std;
using namespace CryptoPP;
int main(int argc, char **argv)
{
if(argc < 2)
{
cout << "Usage: " << argv[0] << " key_name" << endl;
return 1;
}
ECDSA<ECP, SHA256>::PrivateKey privateKey;
AutoSeededRandomPool prng;
privateKey.Initialize(prng, ASN1::secp256r1());
bool result = privateKey.Validate(prng, 3);
if(!result)
return 2;
ECDSA<ECP, SHA256>::PublicKey publicKey;
privateKey.MakePublicKey(publicKey);
result = publicKey.Validate(prng, 3);
if(!result)
return 3;
FileSink fsppk(string(string(argv[1]) + ".ppk").c_str(), true /*binary*/);
privateKey.Save(fsppk);
fsppk.Flush(true);
FileSink fspub(string(string(argv[1]) + ".pub").c_str(), true /*binary*/);
publicKey.Save(fspub);
fspub.Flush(true);
return 0;
}
I use crypto++-8.2.0.3 and I have the segmentation fault either with clang 11.0.0 and g++ 10.2.0.
QtCreator tells me that the fault comes in the delete in this function from smartptr.h:
template <class T> value_ptr<T>& value_ptr<T>::operator=(const value_ptr<T>& rhs)
{
T *old_p = this->m_p;
this->m_p = rhs.m_p ? new T(*rhs.m_p) : NULLPTR;
delete old_p;
return *this;
}
[EDIT] The stack trace:
#0 0x00007ffff7cbd813 in CryptoPP::value_ptr<CryptoPP::ECP>::operator= (this=0x7fffffffdd88, rhs=...) at smartptr.h:95
#1 0x00007ffff7cf483e in CryptoPP::EcPrecomputation<CryptoPP::ECP>::operator= (this=0x7fffffffdd78) at ecp.h:126
#2 CryptoPP::DL_GroupParametersImpl<CryptoPP::EcPrecomputation<CryptoPP::ECP>, CryptoPP::DL_FixedBasePrecomputationImpl<CryptoPP::ECPPoint>, CryptoPP::DL_GroupParameters<CryptoPP::ECPPoint> >::operator= (this=0x7fffffffdd68) at pubkey.h:1013
#3 CryptoPP::DL_GroupParameters_EC<CryptoPP::ECP>::operator= (this=0x7fffffffdd68) at eccrypto.h:39
#4 0x00007ffff7d07272 in CryptoPP::GetValueHelperClass<CryptoPP::DL_GroupParameters_EC<CryptoPP::ECP>, CryptoPP::DL_GroupParameters<CryptoPP::ECPPoint> >::Assignable (this=0x7fffffffd260)
at algparam.h:197
#5 CryptoPP::GetValueHelperClass<CryptoPP::DL_GroupParameters_EC<CryptoPP::ECP>, CryptoPP::DL_GroupParameters<CryptoPP::ECPPoint> >::Assignable (this=0x7fffffffd260) at algparam.h:189
#6 CryptoPP::DL_GroupParameters_EC<CryptoPP::ECP>::GetVoidValue (pValue=0x7fffffffdd68, valueType=..., name=<optimized out>, this=<optimized out>) at eccrypto.cpp:510
#7 CryptoPP::DL_GroupParameters_EC<CryptoPP::ECP>::GetVoidValue (this=<optimized out>, name=<optimized out>, valueType=..., pValue=0x7fffffffdd68) at eccrypto.cpp:497
#8 0x00007ffff7cdce12 in CryptoPP::NameValuePairs::GetValue<CryptoPP::DL_GroupParameters_EC<CryptoPP::ECP> > (value=..., name=<optimized out>, this=0x7fffffffd950) at cryptlib.h:379
#9 CryptoPP::NameValuePairs::GetThisObject<CryptoPP::DL_GroupParameters_EC<CryptoPP::ECP> > (object=..., this=0x7fffffffd950) at cryptlib.h:359
#10 CryptoPP::DL_PrivateKeyImpl<CryptoPP::DL_GroupParameters_EC<CryptoPP::ECP> >::GenerateRandom (this=this@entry=0x7fffffffdd00, rng=..., params=...) at pubkey.h:1278
#11 0x00007ffff7d216ac in CryptoPP::DL_PrivateKey_WithSignaturePairwiseConsistencyTest<CryptoPP::DL_PrivateKey_EC<CryptoPP::ECP>, CryptoPP::ECDSA<CryptoPP::ECP, CryptoPP::SHA256> >::GenerateRandom (this=0x7fffffffdd00, rng=..., params=...) at pubkey.h:1321
#12 0x000055555555c5d6 in main (argc=2, argv=0x7fffffffe018) at ../../../pki/main.cpp:21
And, in QtCreator I have these messsages:
can't find linker symbol for virtual table for `CryptoPP::ECP' value
found `CryptoPP::DL_FixedBasePrecomputationImpl<CryptoPP::EC2NPoint>::~DL_FixedBasePrecomputationImpl()' instead
can't find linker symbol for virtual table for `CryptoPP::ECP' value
found `CryptoPP::DL_FixedBasePrecomputationImpl<CryptoPP::EC2NPoint>::~DL_FixedBasePrecomputationImpl()' instead
can't find linker symbol for virtual table for `CryptoPP::ECP' value
found `CryptoPP::DL_FixedBasePrecomputationImpl<CryptoPP::EC2NPoint>::~DL_FixedBasePrecomputationImpl()' instead
can't find linker symbol for virtual table for `CryptoPP::ECP' value
found `CryptoPP::DL_FixedBasePrecomputationImpl<CryptoPP::EC2NPoint>::~DL_FixedBasePrecomputationImpl()' instead
can't find linker symbol for virtual table for `CryptoPP::ECP' value
found `CryptoPP::DL_FixedBasePrecomputationImpl<CryptoPP::EC2NPoint>::~DL_FixedBasePrecomputationImpl()' instead
can't find linker symbol for virtual table for `CryptoPP::ECP' value
found `CryptoPP::DL_FixedBasePrecomputationImpl<CryptoPP::EC2NPoint>::~DL_FixedBasePrecomputationImpl()' instead
can't find linker symbol for virtual table for `CryptoPP::ECP' value
found `CryptoPP::DL_FixedBasePrecomputationImpl<CryptoPP::EC2NPoint>::~DL_FixedBasePrecomputationImpl()' instead
Upvotes: 1
Views: 312
Reputation: 31569
I have found the solution: I had two version of the crypto++ in my /usr/lib/
.
The libcryptopp.so.8 was pointing to the 8.3.0 version, by pointing to the 8.2.0 it work again.
This answer was posted as an edit to the question Crypto++ ECDSA<ECP, SHA256>::PrivateKey::Initialize make a segmentation fault [SOLVED] by the OP Bourdy Emilien under CC BY-SA 4.0.
Upvotes: 0