在Xcode下使用Crypto ++ ECDSA签名消息时,应用程序崩溃?

时间:2019-10-11 10:08:59

标签: xcode macos crypto++ ecdsa

我正在使用Crypto ++在Mac OS上执行ECDSA签名。命令行可以,但是在Xcode EXC_BAD_ACCESS下,签名消息发生错误。

在命令行中cryptest.exe中的测试通过了。 cryptest.exe是图书馆的验证程序。

我曾尝试使用clang ++和libc ++来构建库,并使用XCode来构建它,所有这些都有这个问题。

clang++ -DNDEBUG -g2 -O2 -stdlib=libc++ -DCRYPTOPP_DISABLE_MIXED_ASM -fPIC -pthread -pipe -c 

这是代码。

AutoSeededRandomPool prng;

ECDSA<ECP, SHA256>::PrivateKey k1;   
k1.Initialize( prng, ASN1::secp256r1() );

ECDSA<ECP, SHA256>::PublicKey pKey;
k1.MakePublicKey( pKey );

const ECP::Point& q = pKey.GetPublicElement();    
const Integer& qx = q.x;
const Integer& qy = q.y;

std::cout << "x: " << std::hex << qx << std::endl;    
std::cout << "y: " << std::hex << qy << std::endl;

const Integer& x = k1.GetPrivateExponent();
std::cout << "K1: " << std::hex << x << std::endl;

ByteQueue queue;
k1.Save(queue);

ECDSA<ECP, SHA256>::Signer signer(k1);

std::string message = "Do or do not. There is no try.";
size_t siglen = signer.MaxSignatureLength();
std::string signature(siglen, 0x00);

siglen = signer.SignMessage( prng, (const byte*)&message[0], message.size(), (byte*)&signature[0] );
signature.resize(siglen);

我在下面附加堆栈跟踪:

* thread #1: tid = 0x15fc20, 0x00007fff910a9d26 libsystem_platform.dylib`_platform_bzero$VARIANT$Merom + 22, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  frame #0: 0x00007fff910a9d26 libsystem_platform.dylib`_platform_bzero$VARIANT$Merom + 22  
* frame #1: 0x00000001000ccc23 testCrypto`CryptoPP::DL_SignatureMessageEncodingMethod_DSA::ComputeMessageRepresentative(this=<unavailable>, rng=<unavailable>, recoverableMessage=<unavailable>,   
  recoverableMessageLength=<unavailable>, hash=0x0000000104e7df30, hashIdentifier=<unavailable>, messageEmpty=false, representative=0x0000000000000000, representativeBitLength=<unavailable>) const + 83 at gfpcrypt.cpp:96  
  frame #2: 0x0000000100019ae8 testCrypto`CryptoPP::DL_VerifierBase<CryptoPP::EC2NPoint>::VerifyAndRestart(this=0x00007fff5fbfdab8, messageAccumulator=0x0000000104e7de40) const + 568 at pubkey.h:1693 
  frame #3: 0x0000000100034c1e testCrypto`CryptoPP::PK_Verifier::VerifyMessage(this=0x00007fff5fbfdab8, message=<unavailable>, messageLen=<unavailable>, signature=<unavailable>, signatureLen=<unavailable>) const + 94 at cryptlib.cpp:942
  frame #4: 0x000000010000464a testCrypto`ValidateECDSA() + 2762 at main.cpp:257
  frame #5: 0x0000000100004a35 testCrypto`main(argc=1, argv=0x00007fff5fbff9e0) + 53 at main.cpp:272
  frame #6: 0x00007fff8fec95c9 libdyld.dylib`start + 1

1 个答案:

答案 0 :(得分:0)

我使用Xcode构建项目以创建一个库,然后可以无错误地调用该库。