LCOV - code coverage report
Current view: top level - src - pubkey.cpp (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 227 299 75.9 %
Date: 2023-09-07 14:00:19 Functions: 22 22 100.0 %
Legend: Modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed

Not modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed
Branches: 71 114 62.3 %

           Branch data     Line data    Source code
#       1                 :            : // Copyright (c) 2009-2022 The Bitcoin Core developers
#       2                 :            : // Copyright (c) 2017 The Zcash developers
#       3                 :            : // Distributed under the MIT software license, see the accompanying
#       4                 :            : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#       5                 :            : 
#       6                 :            : #include <pubkey.h>
#       7                 :            : 
#       8                 :            : #include <hash.h>
#       9                 :            : #include <secp256k1.h>
#      10                 :            : #include <secp256k1_ellswift.h>
#      11                 :            : #include <secp256k1_extrakeys.h>
#      12                 :            : #include <secp256k1_recovery.h>
#      13                 :            : #include <secp256k1_schnorrsig.h>
#      14                 :            : #include <span.h>
#      15                 :            : #include <uint256.h>
#      16                 :            : 
#      17                 :            : #include <algorithm>
#      18                 :            : #include <cassert>
#      19                 :            : 
#      20                 :            : namespace {
#      21                 :            : 
#      22                 :            : struct Secp256k1SelfTester
#      23                 :            : {
#      24                 :        830 :     Secp256k1SelfTester() {
#      25                 :            :         /* Run libsecp256k1 self-test before using the secp256k1_context_static. */
#      26                 :        830 :         secp256k1_selftest();
#      27                 :        830 :     }
#      28                 :            : } SECP256K1_SELFTESTER;
#      29                 :            : 
#      30                 :            : } // namespace
#      31                 :            : 
#      32                 :            : /** This function is taken from the libsecp256k1 distribution and implements
#      33                 :            :  *  DER parsing for ECDSA signatures, while supporting an arbitrary subset of
#      34                 :            :  *  format violations.
#      35                 :            :  *
#      36                 :            :  *  Supported violations include negative integers, excessive padding, garbage
#      37                 :            :  *  at the end, and overly long length descriptors. This is safe to use in
#      38                 :            :  *  Bitcoin because since the activation of BIP66, signatures are verified to be
#      39                 :            :  *  strict DER before being passed to this module, and we know it supports all
#      40                 :            :  *  violations present in the blockchain before that point.
#      41                 :            :  */
#      42                 :     209003 : int ecdsa_signature_parse_der_lax(secp256k1_ecdsa_signature* sig, const unsigned char *input, size_t inputlen) {
#      43                 :     209003 :     size_t rpos, rlen, spos, slen;
#      44                 :     209003 :     size_t pos = 0;
#      45                 :     209003 :     size_t lenbyte;
#      46                 :     209003 :     unsigned char tmpsig[64] = {0};
#      47                 :     209003 :     int overflow = 0;
#      48                 :            : 
#      49                 :            :     /* Hack to initialize sig with a correctly-parsed but invalid signature. */
#      50                 :     209003 :     secp256k1_ecdsa_signature_parse_compact(secp256k1_context_static, sig, tmpsig);
#      51                 :            : 
#      52                 :            :     /* Sequence tag byte */
#      53 [ +  + ][ +  + ]:     209823 :     if (pos == inputlen || input[pos] != 0x30) {
#      54                 :         96 :         return 0;
#      55                 :         96 :     }
#      56                 :     208907 :     pos++;
#      57                 :            : 
#      58                 :            :     /* Sequence length bytes */
#      59         [ -  + ]:     208907 :     if (pos == inputlen) {
#      60                 :          0 :         return 0;
#      61                 :          0 :     }
#      62                 :     208907 :     lenbyte = input[pos++];
#      63         [ -  + ]:     208907 :     if (lenbyte & 0x80) {
#      64                 :          0 :         lenbyte -= 0x80;
#      65         [ #  # ]:          0 :         if (lenbyte > inputlen - pos) {
#      66                 :          0 :             return 0;
#      67                 :          0 :         }
#      68                 :          0 :         pos += lenbyte;
#      69                 :          0 :     }
#      70                 :            : 
#      71                 :            :     /* Integer tag byte for R */
#      72 [ +  + ][ +  + ]:     209817 :     if (pos == inputlen || input[pos] != 0x02) {
#      73                 :          0 :         return 0;
#      74                 :          0 :     }
#      75                 :     208907 :     pos++;
#      76                 :            : 
#      77                 :            :     /* Integer length for R */
#      78         [ -  + ]:     208907 :     if (pos == inputlen) {
#      79                 :          0 :         return 0;
#      80                 :          0 :     }
#      81                 :     208907 :     lenbyte = input[pos++];
#      82         [ -  + ]:     208907 :     if (lenbyte & 0x80) {
#      83                 :          0 :         lenbyte -= 0x80;
#      84         [ #  # ]:          0 :         if (lenbyte > inputlen - pos) {
#      85                 :          0 :             return 0;
#      86                 :          0 :         }
#      87 [ #  # ][ #  # ]:          0 :         while (lenbyte > 0 && input[pos] == 0) {
#      88                 :          0 :             pos++;
#      89                 :          0 :             lenbyte--;
#      90                 :          0 :         }
#      91                 :          0 :         static_assert(sizeof(size_t) >= 4, "size_t too small");
#      92         [ #  # ]:          0 :         if (lenbyte >= 4) {
#      93                 :          0 :             return 0;
#      94                 :          0 :         }
#      95                 :          0 :         rlen = 0;
#      96         [ #  # ]:          0 :         while (lenbyte > 0) {
#      97                 :          0 :             rlen = (rlen << 8) + input[pos];
#      98                 :          0 :             pos++;
#      99                 :          0 :             lenbyte--;
#     100                 :          0 :         }
#     101                 :     208907 :     } else {
#     102                 :     208907 :         rlen = lenbyte;
#     103                 :     208907 :     }
#     104         [ -  + ]:     208907 :     if (rlen > inputlen - pos) {
#     105                 :          0 :         return 0;
#     106                 :          0 :     }
#     107                 :     208907 :     rpos = pos;
#     108                 :     208907 :     pos += rlen;
#     109                 :            : 
#     110                 :            :     /* Integer tag byte for S */
#     111 [ +  + ][ +  + ]:     209779 :     if (pos == inputlen || input[pos] != 0x02) {
#     112                 :          0 :         return 0;
#     113                 :          0 :     }
#     114                 :     208907 :     pos++;
#     115                 :            : 
#     116                 :            :     /* Integer length for S */
#     117         [ -  + ]:     208907 :     if (pos == inputlen) {
#     118                 :          0 :         return 0;
#     119                 :          0 :     }
#     120                 :     208907 :     lenbyte = input[pos++];
#     121         [ -  + ]:     208907 :     if (lenbyte & 0x80) {
#     122                 :          0 :         lenbyte -= 0x80;
#     123         [ #  # ]:          0 :         if (lenbyte > inputlen - pos) {
#     124                 :          0 :             return 0;
#     125                 :          0 :         }
#     126 [ #  # ][ #  # ]:          0 :         while (lenbyte > 0 && input[pos] == 0) {
#     127                 :          0 :             pos++;
#     128                 :          0 :             lenbyte--;
#     129                 :          0 :         }
#     130                 :          0 :         static_assert(sizeof(size_t) >= 4, "size_t too small");
#     131         [ #  # ]:          0 :         if (lenbyte >= 4) {
#     132                 :          0 :             return 0;
#     133                 :          0 :         }
#     134                 :          0 :         slen = 0;
#     135         [ #  # ]:          0 :         while (lenbyte > 0) {
#     136                 :          0 :             slen = (slen << 8) + input[pos];
#     137                 :          0 :             pos++;
#     138                 :          0 :             lenbyte--;
#     139                 :          0 :         }
#     140                 :     208907 :     } else {
#     141                 :     208907 :         slen = lenbyte;
#     142                 :     208907 :     }
#     143         [ -  + ]:     208907 :     if (slen > inputlen - pos) {
#     144                 :          0 :         return 0;
#     145                 :          0 :     }
#     146                 :     208907 :     spos = pos;
#     147                 :            : 
#     148                 :            :     /* Ignore leading zeroes in R */
#     149 [ +  + ][ +  + ]:     241337 :     while (rlen > 0 && input[rpos] == 0) {
#     150                 :      31647 :         rlen--;
#     151                 :      31647 :         rpos++;
#     152                 :      31647 :     }
#     153                 :            :     /* Copy R value */
#     154         [ +  + ]:     208907 :     if (rlen > 32) {
#     155                 :          1 :         overflow = 1;
#     156                 :     208906 :     } else {
#     157                 :     208906 :         memcpy(tmpsig + 32 - rlen, input + rpos, rlen);
#     158                 :     208906 :     }
#     159                 :            : 
#     160                 :            :     /* Ignore leading zeroes in S */
#     161 [ +  + ][ +  + ]:     213207 :     while (slen > 0 && input[spos] == 0) {
#     162                 :       3544 :         slen--;
#     163                 :       3544 :         spos++;
#     164                 :       3544 :     }
#     165                 :            :     /* Copy S value */
#     166         [ -  + ]:     208907 :     if (slen > 32) {
#     167                 :          0 :         overflow = 1;
#     168                 :     208907 :     } else {
#     169                 :     208907 :         memcpy(tmpsig + 64 - slen, input + spos, slen);
#     170                 :     208907 :     }
#     171                 :            : 
#     172         [ +  + ]:     209648 :     if (!overflow) {
#     173                 :     209648 :         overflow = !secp256k1_ecdsa_signature_parse_compact(secp256k1_context_static, sig, tmpsig);
#     174                 :     209648 :     }
#     175         [ +  + ]:     208907 :     if (overflow) {
#     176                 :            :         /* Overwrite the result again with a correctly-parsed but invalid
#     177                 :            :            signature if parsing failed. */
#     178                 :          1 :         memset(tmpsig, 0, 64);
#     179                 :          1 :         secp256k1_ecdsa_signature_parse_compact(secp256k1_context_static, sig, tmpsig);
#     180                 :          1 :     }
#     181                 :     208907 :     return 1;
#     182                 :     208907 : }
#     183                 :            : 
#     184                 :            : XOnlyPubKey::XOnlyPubKey(Span<const unsigned char> bytes)
#     185                 :    1484536 : {
#     186                 :    1484536 :     assert(bytes.size() == 32);
#     187                 :    1484537 :     std::copy(bytes.begin(), bytes.end(), m_keydata.begin());
#     188                 :    1484537 : }
#     189                 :            : 
#     190                 :            : std::vector<CKeyID> XOnlyPubKey::GetKeyIDs() const
#     191                 :     331145 : {
#     192                 :     331145 :     std::vector<CKeyID> out;
#     193                 :            :     // For now, use the old full pubkey-based key derivation logic. As it is indexed by
#     194                 :            :     // Hash160(full pubkey), we need to return both a version prefixed with 0x02, and one
#     195                 :            :     // with 0x03.
#     196                 :     331145 :     unsigned char b[33] = {0x02};
#     197                 :     331145 :     std::copy(m_keydata.begin(), m_keydata.end(), b + 1);
#     198                 :     331145 :     CPubKey fullpubkey;
#     199                 :     331145 :     fullpubkey.Set(b, b + 33);
#     200                 :     331145 :     out.push_back(fullpubkey.GetID());
#     201                 :     331145 :     b[0] = 0x03;
#     202                 :     331145 :     fullpubkey.Set(b, b + 33);
#     203                 :     331145 :     out.push_back(fullpubkey.GetID());
#     204                 :     331145 :     return out;
#     205                 :     331145 : }
#     206                 :            : 
#     207                 :            : bool XOnlyPubKey::IsFullyValid() const
#     208                 :     128812 : {
#     209                 :     128812 :     secp256k1_xonly_pubkey pubkey;
#     210                 :     128812 :     return secp256k1_xonly_pubkey_parse(secp256k1_context_static, &pubkey, m_keydata.data());
#     211                 :     128812 : }
#     212                 :            : 
#     213                 :            : bool XOnlyPubKey::VerifySchnorr(const uint256& msg, Span<const unsigned char> sigbytes) const
#     214                 :       6727 : {
#     215                 :       6727 :     assert(sigbytes.size() == 64);
#     216                 :       6727 :     secp256k1_xonly_pubkey pubkey;
#     217         [ +  + ]:       6727 :     if (!secp256k1_xonly_pubkey_parse(secp256k1_context_static, &pubkey, m_keydata.data())) return false;
#     218                 :       6723 :     return secp256k1_schnorrsig_verify(secp256k1_context_static, sigbytes.data(), msg.begin(), 32, &pubkey);
#     219                 :       6727 : }
#     220                 :            : 
#     221                 :            : static const HashWriter HASHER_TAPTWEAK{TaggedHash("TapTweak")};
#     222                 :            : 
#     223                 :            : uint256 XOnlyPubKey::ComputeTapTweakHash(const uint256* merkle_root) const
#     224                 :     176171 : {
#     225         [ +  + ]:     176171 :     if (merkle_root == nullptr) {
#     226                 :            :         // We have no scripts. The actual tweak does not matter, but follow BIP341 here to
#     227                 :            :         // allow for reproducible tweaking.
#     228                 :      99441 :         return (HashWriter{HASHER_TAPTWEAK} << m_keydata).GetSHA256();
#     229                 :      99441 :     } else {
#     230                 :      76730 :         return (HashWriter{HASHER_TAPTWEAK} << m_keydata << *merkle_root).GetSHA256();
#     231                 :      76730 :     }
#     232                 :     176171 : }
#     233                 :            : 
#     234                 :            : bool XOnlyPubKey::CheckTapTweak(const XOnlyPubKey& internal, const uint256& merkle_root, bool parity) const
#     235                 :      61807 : {
#     236                 :      61807 :     secp256k1_xonly_pubkey internal_key;
#     237         [ +  + ]:      61807 :     if (!secp256k1_xonly_pubkey_parse(secp256k1_context_static, &internal_key, internal.data())) return false;
#     238                 :      61805 :     uint256 tweak = internal.ComputeTapTweakHash(&merkle_root);
#     239                 :      61805 :     return secp256k1_xonly_pubkey_tweak_add_check(secp256k1_context_static, m_keydata.begin(), parity, &internal_key, tweak.begin());
#     240                 :      61807 : }
#     241                 :            : 
#     242                 :            : std::optional<std::pair<XOnlyPubKey, bool>> XOnlyPubKey::CreateTapTweak(const uint256* merkle_root) const
#     243                 :     113781 : {
#     244                 :     113781 :     secp256k1_xonly_pubkey base_point;
#     245         [ -  + ]:     113781 :     if (!secp256k1_xonly_pubkey_parse(secp256k1_context_static, &base_point, data())) return std::nullopt;
#     246                 :     113781 :     secp256k1_pubkey out;
#     247                 :     113781 :     uint256 tweak = ComputeTapTweakHash(merkle_root);
#     248         [ -  + ]:     113781 :     if (!secp256k1_xonly_pubkey_tweak_add(secp256k1_context_static, &out, &base_point, tweak.data())) return std::nullopt;
#     249                 :     113781 :     int parity = -1;
#     250                 :     113781 :     std::pair<XOnlyPubKey, bool> ret;
#     251                 :     113781 :     secp256k1_xonly_pubkey out_xonly;
#     252         [ -  + ]:     113781 :     if (!secp256k1_xonly_pubkey_from_pubkey(secp256k1_context_static, &out_xonly, &parity, &out)) return std::nullopt;
#     253                 :     113781 :     secp256k1_xonly_pubkey_serialize(secp256k1_context_static, ret.first.begin(), &out_xonly);
#     254                 :     113781 :     assert(parity == 0 || parity == 1);
#     255                 :     113781 :     ret.second = parity;
#     256                 :     113781 :     return ret;
#     257                 :     113781 : }
#     258                 :            : 
#     259                 :            : 
#     260                 :     126279 : bool CPubKey::Verify(const uint256 &hash, const std::vector<unsigned char>& vchSig) const {
#     261         [ -  + ]:     126279 :     if (!IsValid())
#     262                 :          0 :         return false;
#     263                 :     126279 :     secp256k1_pubkey pubkey;
#     264                 :     126279 :     secp256k1_ecdsa_signature sig;
#     265         [ -  + ]:     126279 :     if (!secp256k1_ec_pubkey_parse(secp256k1_context_static, &pubkey, vch, size())) {
#     266                 :          0 :         return false;
#     267                 :          0 :     }
#     268         [ +  + ]:     126279 :     if (!ecdsa_signature_parse_der_lax(&sig, vchSig.data(), vchSig.size())) {
#     269                 :         96 :         return false;
#     270                 :         96 :     }
#     271                 :            :     /* libsecp256k1's ECDSA verification requires lower-S signatures, which have
#     272                 :            :      * not historically been enforced in Bitcoin, so normalize them first. */
#     273                 :     126183 :     secp256k1_ecdsa_signature_normalize(secp256k1_context_static, &sig, &sig);
#     274                 :     126183 :     return secp256k1_ecdsa_verify(secp256k1_context_static, &sig, hash.begin(), &pubkey);
#     275                 :     126279 : }
#     276                 :            : 
#     277                 :        141 : bool CPubKey::RecoverCompact(const uint256 &hash, const std::vector<unsigned char>& vchSig) {
#     278         [ -  + ]:        141 :     if (vchSig.size() != COMPACT_SIGNATURE_SIZE)
#     279                 :          0 :         return false;
#     280                 :        141 :     int recid = (vchSig[0] - 27) & 3;
#     281                 :        141 :     bool fComp = ((vchSig[0] - 27) & 4) != 0;
#     282                 :        141 :     secp256k1_pubkey pubkey;
#     283                 :        141 :     secp256k1_ecdsa_recoverable_signature sig;
#     284         [ -  + ]:        141 :     if (!secp256k1_ecdsa_recoverable_signature_parse_compact(secp256k1_context_static, &sig, &vchSig[1], recid)) {
#     285                 :          0 :         return false;
#     286                 :          0 :     }
#     287         [ +  + ]:        141 :     if (!secp256k1_ecdsa_recover(secp256k1_context_static, &pubkey, &sig, hash.begin())) {
#     288                 :          1 :         return false;
#     289                 :          1 :     }
#     290                 :        140 :     unsigned char pub[SIZE];
#     291                 :        140 :     size_t publen = SIZE;
#     292         [ +  + ]:        140 :     secp256k1_ec_pubkey_serialize(secp256k1_context_static, pub, &publen, &pubkey, fComp ? SECP256K1_EC_COMPRESSED : SECP256K1_EC_UNCOMPRESSED);
#     293                 :        140 :     Set(pub, pub + publen);
#     294                 :        140 :     return true;
#     295                 :        141 : }
#     296                 :            : 
#     297                 :      46419 : bool CPubKey::IsFullyValid() const {
#     298         [ +  + ]:      46419 :     if (!IsValid())
#     299                 :      18512 :         return false;
#     300                 :      27907 :     secp256k1_pubkey pubkey;
#     301                 :      27907 :     return secp256k1_ec_pubkey_parse(secp256k1_context_static, &pubkey, vch, size());
#     302                 :      46419 : }
#     303                 :            : 
#     304                 :         37 : bool CPubKey::Decompress() {
#     305         [ -  + ]:         37 :     if (!IsValid())
#     306                 :          0 :         return false;
#     307                 :         37 :     secp256k1_pubkey pubkey;
#     308         [ -  + ]:         37 :     if (!secp256k1_ec_pubkey_parse(secp256k1_context_static, &pubkey, vch, size())) {
#     309                 :          0 :         return false;
#     310                 :          0 :     }
#     311                 :         37 :     unsigned char pub[SIZE];
#     312                 :         37 :     size_t publen = SIZE;
#     313                 :         37 :     secp256k1_ec_pubkey_serialize(secp256k1_context_static, pub, &publen, &pubkey, SECP256K1_EC_UNCOMPRESSED);
#     314                 :         37 :     Set(pub, pub + publen);
#     315                 :         37 :     return true;
#     316                 :         37 : }
#     317                 :            : 
#     318                 :     594973 : bool CPubKey::Derive(CPubKey& pubkeyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode& cc) const {
#     319                 :     594973 :     assert(IsValid());
#     320                 :     594973 :     assert((nChild >> 31) == 0);
#     321                 :     594973 :     assert(size() == COMPRESSED_SIZE);
#     322                 :     594973 :     unsigned char out[64];
#     323                 :     594973 :     BIP32Hash(cc, nChild, *begin(), begin()+1, out);
#     324                 :     594973 :     memcpy(ccChild.begin(), out+32, 32);
#     325                 :     594973 :     secp256k1_pubkey pubkey;
#     326         [ -  + ]:     594973 :     if (!secp256k1_ec_pubkey_parse(secp256k1_context_static, &pubkey, vch, size())) {
#     327                 :          0 :         return false;
#     328                 :          0 :     }
#     329         [ -  + ]:     594973 :     if (!secp256k1_ec_pubkey_tweak_add(secp256k1_context_static, &pubkey, out)) {
#     330                 :          0 :         return false;
#     331                 :          0 :     }
#     332                 :     594973 :     unsigned char pub[COMPRESSED_SIZE];
#     333                 :     594973 :     size_t publen = COMPRESSED_SIZE;
#     334                 :     594973 :     secp256k1_ec_pubkey_serialize(secp256k1_context_static, pub, &publen, &pubkey, SECP256K1_EC_COMPRESSED);
#     335                 :     594973 :     pubkeyChild.Set(pub, pub + publen);
#     336                 :     594973 :     return true;
#     337                 :     594973 : }
#     338                 :            : 
#     339                 :            : EllSwiftPubKey::EllSwiftPubKey(Span<const std::byte> ellswift) noexcept
#     340                 :     586964 : {
#     341                 :     586964 :     assert(ellswift.size() == SIZE);
#     342                 :     586964 :     std::copy(ellswift.begin(), ellswift.end(), m_pubkey.begin());
#     343                 :     586964 : }
#     344                 :            : 
#     345                 :            : CPubKey EllSwiftPubKey::Decode() const
#     346                 :          8 : {
#     347                 :          8 :     secp256k1_pubkey pubkey;
#     348                 :          8 :     secp256k1_ellswift_decode(secp256k1_context_static, &pubkey, UCharCast(m_pubkey.data()));
#     349                 :            : 
#     350                 :          8 :     size_t sz = CPubKey::COMPRESSED_SIZE;
#     351                 :          8 :     std::array<uint8_t, CPubKey::COMPRESSED_SIZE> vch_bytes;
#     352                 :            : 
#     353                 :          8 :     secp256k1_ec_pubkey_serialize(secp256k1_context_static, vch_bytes.data(), &sz, &pubkey, SECP256K1_EC_COMPRESSED);
#     354                 :          8 :     assert(sz == vch_bytes.size());
#     355                 :            : 
#     356                 :          8 :     return CPubKey{vch_bytes.begin(), vch_bytes.end()};
#     357                 :          8 : }
#     358                 :            : 
#     359                 :     270379 : void CExtPubKey::Encode(unsigned char code[BIP32_EXTKEY_SIZE]) const {
#     360                 :     270379 :     code[0] = nDepth;
#     361                 :     270379 :     memcpy(code+1, vchFingerprint, 4);
#     362                 :     270379 :     WriteBE32(code+5, nChild);
#     363                 :     270379 :     memcpy(code+9, chaincode.begin(), 32);
#     364                 :     270379 :     assert(pubkey.size() == CPubKey::COMPRESSED_SIZE);
#     365                 :     270379 :     memcpy(code+41, pubkey.begin(), CPubKey::COMPRESSED_SIZE);
#     366                 :     270379 : }
#     367                 :            : 
#     368                 :       7760 : void CExtPubKey::Decode(const unsigned char code[BIP32_EXTKEY_SIZE]) {
#     369                 :       7760 :     nDepth = code[0];
#     370                 :       7760 :     memcpy(vchFingerprint, code+1, 4);
#     371                 :       7760 :     nChild = ReadBE32(code+5);
#     372                 :       7760 :     memcpy(chaincode.begin(), code+9, 32);
#     373                 :       7760 :     pubkey.Set(code+41, code+BIP32_EXTKEY_SIZE);
#     374 [ +  + ][ +  + ]:       7760 :     if ((nDepth == 0 && (nChild != 0 || ReadLE32(vchFingerprint) != 0)) || !pubkey.IsFullyValid()) pubkey = CPubKey();
#         [ +  + ][ +  + ]
#     375                 :       7760 : }
#     376                 :            : 
#     377                 :            : void CExtPubKey::EncodeWithVersion(unsigned char code[BIP32_EXTKEY_WITH_VERSION_SIZE]) const
#     378                 :          3 : {
#     379                 :          3 :     memcpy(code, version, 4);
#     380                 :          3 :     Encode(&code[4]);
#     381                 :          3 : }
#     382                 :            : 
#     383                 :            : void CExtPubKey::DecodeWithVersion(const unsigned char code[BIP32_EXTKEY_WITH_VERSION_SIZE])
#     384                 :          3 : {
#     385                 :          3 :     memcpy(version, code, 4);
#     386                 :          3 :     Decode(&code[4]);
#     387                 :          3 : }
#     388                 :            : 
#     389                 :     594975 : bool CExtPubKey::Derive(CExtPubKey &out, unsigned int _nChild) const {
#     390         [ +  + ]:     594975 :     if (nDepth == std::numeric_limits<unsigned char>::max()) return false;
#     391                 :     594973 :     out.nDepth = nDepth + 1;
#     392                 :     594973 :     CKeyID id = pubkey.GetID();
#     393                 :     594973 :     memcpy(out.vchFingerprint, &id, 4);
#     394                 :     594973 :     out.nChild = _nChild;
#     395                 :     594973 :     return pubkey.Derive(out.pubkey, out.chaincode, _nChild, chaincode);
#     396                 :     594975 : }
#     397                 :            : 
#     398                 :      83579 : /* static */ bool CPubKey::CheckLowS(const std::vector<unsigned char>& vchSig) {
#     399                 :      83579 :     secp256k1_ecdsa_signature sig;
#     400         [ -  + ]:      83579 :     if (!ecdsa_signature_parse_der_lax(&sig, vchSig.data(), vchSig.size())) {
#     401                 :          0 :         return false;
#     402                 :          0 :     }
#     403                 :      83579 :     return (!secp256k1_ecdsa_signature_normalize(secp256k1_context_static, nullptr, &sig));
#     404                 :      83579 : }

Generated by: LCOV version 3.1-eol-3983-g6fec45e53af6