BAD_ACCESS (code=EXC_I386_GPFLT) when signing with ECDSA

馋奶兔 提交于 2019-12-12 02:58:24

问题


I am trying to use Crypto++ on iOS. I downloaded a prebuilt version of the library from Marek Kotewicz's GitHub.

I am struggling hard to run this sample code from the Crypto++ wiki.

ECDSA<ECP, CryptoPP::SHA256>::PrivateKey privateKey;
ECDSA<ECP, CryptoPP::SHA256>::PublicKey publicKey;

AutoSeededRandomPool prng, rrng;

privateKey.Initialize(prng, CryptoPP::ASN1::secp256k1());    
privateKey.MakePublicKey(publicKey);

string signature;       
string message = "Do or do not. There is no try.";

StringSource s(message, true,
             new SignerFilter(rrng,
                              ECDSA<ECP, CryptoPP::SHA256>::Signer(privateKey),
                              new StringSink(signature)));

Its crashing with the following. Its showing up in Xcode output window:

BAD_ACCESS (code=EXC_I386_GPFLT)  

This is the code snippet from memory.h of c++ file where it is pointing the BAD_ACCESS

 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}

I am getting BAD_ACCESS(code=1 , address=0x0) error pointing to this line of code of library

 ->  0x1065dfa8d <+85>:  movq   -0x58(%rbp), %rdi


回答1:


Its crashing with the following. Its showing up in Xcode output window:

BAD_ACCESS(code=EXC_I386_GPFLT)  

The code looks OK to me.


I am trying to use Crypto++ on iOS. I downloaded a prebuilt version of the library from Marek Kotewicz's GitHub.

I'm just taking a stab in the dark. It presumes the code you showed above is really all you are doing in, say, a test ViewController.

The precompiled library appears to be using GNU's Standard C++ library. I would switch to LLVM's Standard C++ library by building Crypto++ with -stdlib=c++ (and not GNU's -stdlib=stdc++). Apple switched to it years ago, and Xcode uses it by default.

You can find a GitHub with the fat library using LLVM Standard C++ at noloader/cryptopp-5.6.2-ios.

Or, you can build the fat library yourself. For that, see iOS (Command Line) on the Crypto++ wiki. The prebuilt library at cryptopp-5.6.2-ios uses those instructions.


AutoSeededRandomPool prng, rrng;

You only need one of these.


StringSource s(message, true,
               new SignerFilter(rrng,
                   ECDSA<ECP, CryptoPP::SHA256>::Signer(privateKey),
                       new StringSink(signature)));

Over the years, I've come to wonder about the temporary signer created for the pipeline. I've changed the Crypto++ wiki to stop using them. Use this code instead:

ECDSA<ECP, CryptoPP::SHA256>::PrivateKey privateKey;
...
ECDSA<ECP, CryptoPP::SHA256>::Signer signer(privateKey);
...

StringSource s(message, true,
               new SignerFilter(prng, signer,
                   new StringSink(signature)));


来源:https://stackoverflow.com/questions/30950856/bad-access-code-exc-i386-gpflt-when-signing-with-ecdsa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!