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
The code looks OK to me.
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.
You only need one of these.
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: