| 167 | } |
| 168 | |
| 169 | bool CKey::Sign(const uint256 &hash, std::vector<unsigned char>& vchSig, uint32_t test_case) const { |
| 170 | if (!fValid) |
| 171 | return false; |
| 172 | vchSig.resize(72); |
| 173 | size_t nSigLen = 72; |
| 174 | unsigned char extra_entropy[32] = {0}; |
| 175 | WriteLE32(extra_entropy, test_case); |
| 176 | secp256k1_ecdsa_signature sig; |
| 177 | int ret = secp256k1_ecdsa_sign(secp256k1_context_sign, &sig, hash.begin(), begin(), secp256k1_nonce_function_rfc6979, test_case ? extra_entropy : NULL); |
| 178 | assert(ret); |
| 179 | secp256k1_ecdsa_signature_serialize_der(secp256k1_context_sign, (unsigned char*)&vchSig[0], &nSigLen, &sig); |
| 180 | vchSig.resize(nSigLen); |
| 181 | return true; |
| 182 | } |
| 183 | |
| 184 | bool CKey::VerifyPubKey(const CPubKey& pubkey) const { |
| 185 | if (pubkey.IsCompressed() != fCompressed) { |