0
votes

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

This is the debugger output

1
Can you introduce a check if the __ptr_ is not NULL before calling delete I feel ~ is freeing the memory allocated to this __ptr_ - Vinay Shukla
where to check this condition ,I have written only this much code, rest of the code is present in crptopp library? - SandeepAggarwal
I think the problem maybe with signature string which isn't initialized that you are passing. Is signature an input parameter or output parameter - Vinay Shukla
signature is an output parameter - SandeepAggarwal
Sandeep, how about giving more details so that people know exactly how to reproduce your problem? Where did you download the library from? Where did the example code come from? How are you compiling it and running it? What is this "log" and are there any other messages in the log? These details should have been in the original question, but it's not too late to edit it. - David Grayson

1 Answers

0
votes

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)));