66
77#include " eccryptoverify.h"
88
9- #ifdef USE_SECP256K1
10- #include < secp256k1.h>
11- #else
129#include " ecwrapper.h"
13- #endif
1410
1511bool CPubKey::Verify (const uint256 &hash, const std::vector<unsigned char >& vchSig) const {
1612 if (!IsValid ())
1713 return false ;
18- #ifdef USE_SECP256K1
19- if (secp256k1_ecdsa_verify ((const unsigned char *)&hash, &vchSig[0 ], vchSig.size (), begin (), size ()) != 1 )
20- return false ;
21- #else
2214 CECKey key;
2315 if (!key.SetPubKey (begin (), size ()))
2416 return false ;
2517 if (!key.Verify (hash, vchSig))
2618 return false ;
27- #endif
2819 return true ;
2920}
3021
@@ -33,52 +24,33 @@ bool CPubKey::RecoverCompact(const uint256 &hash, const std::vector<unsigned cha
3324 return false ;
3425 int recid = (vchSig[0 ] - 27 ) & 3 ;
3526 bool fComp = ((vchSig[0 ] - 27 ) & 4 ) != 0 ;
36- #ifdef USE_SECP256K1
37- int pubkeylen = 65 ;
38- if (!secp256k1_ecdsa_recover_compact ((const unsigned char *)&hash, &vchSig[1 ], (unsigned char *)begin (), &pubkeylen, fComp , recid))
39- return false ;
40- assert ((int )size () == pubkeylen);
41- #else
4227 CECKey key;
4328 if (!key.Recover (hash, &vchSig[1 ], recid))
4429 return false ;
4530 std::vector<unsigned char > pubkey;
4631 key.GetPubKey (pubkey, fComp );
4732 Set (pubkey.begin (), pubkey.end ());
48- #endif
4933 return true ;
5034}
5135
5236bool CPubKey::IsFullyValid () const {
5337 if (!IsValid ())
5438 return false ;
55- #ifdef USE_SECP256K1
56- if (!secp256k1_ecdsa_pubkey_verify (begin (), size ()))
57- return false ;
58- #else
5939 CECKey key;
6040 if (!key.SetPubKey (begin (), size ()))
6141 return false ;
62- #endif
6342 return true ;
6443}
6544
6645bool CPubKey::Decompress () {
6746 if (!IsValid ())
6847 return false ;
69- #ifdef USE_SECP256K1
70- int clen = size ();
71- int ret = secp256k1_ecdsa_pubkey_decompress ((unsigned char *)begin (), &clen);
72- assert (ret);
73- assert (clen == (int )size ());
74- #else
7548 CECKey key;
7649 if (!key.SetPubKey (begin (), size ()))
7750 return false ;
7851 std::vector<unsigned char > pubkey;
7952 key.GetPubKey (pubkey, false );
8053 Set (pubkey.begin (), pubkey.end ());
81- #endif
8254 return true ;
8355}
8456
@@ -89,17 +61,12 @@ bool CPubKey::Derive(CPubKey& pubkeyChild, unsigned char ccChild[32], unsigned i
8961 unsigned char out[64 ];
9062 BIP32Hash (cc, nChild, *begin (), begin ()+1 , out);
9163 memcpy (ccChild, out+32 , 32 );
92- #ifdef USE_SECP256K1
93- pubkeyChild = *this ;
94- bool ret = secp256k1_ecdsa_pubkey_tweak_add ((unsigned char *)pubkeyChild.begin (), pubkeyChild.size (), out);
95- #else
9664 CECKey key;
9765 bool ret = key.SetPubKey (begin (), size ());
9866 ret &= key.TweakPublic (out);
9967 std::vector<unsigned char > pubkey;
10068 key.GetPubKey (pubkey, true );
10169 pubkeyChild.Set (pubkey.begin (), pubkey.end ());
102- #endif
10370 return ret;
10471}
10572
0 commit comments