| 49 | std::map<std::vector<unsigned char>, std::vector<unsigned char>> hash160_preimages; |
| 50 | |
| 51 | TestData() |
| 52 | { |
| 53 | // All our signatures sign (and are required to sign) this constant message. |
| 54 | constexpr uint256 MESSAGE_HASH{"0000000000000000f5cd94e18b6fe77dd7aca9e35c2b0c9cbd86356c80a71065"}; |
| 55 | // We don't pass additional randomness when creating a schnorr signature. |
| 56 | const auto EMPTY_AUX{uint256::ZERO}; |
| 57 | |
| 58 | // We generate 255 public keys and 255 hashes of each type. |
| 59 | for (int i = 1; i <= 255; ++i) { |
| 60 | // This 32-byte array functions as both private key data and hash preimage (31 zero bytes plus any nonzero byte). |
| 61 | unsigned char keydata[32] = {0}; |
| 62 | keydata[31] = i; |
| 63 | |
| 64 | // Compute CPubkey and CKeyID |
| 65 | CKey key; |
| 66 | key.Set(keydata, keydata + 32, true); |
| 67 | CPubKey pubkey = key.GetPubKey(); |
| 68 | CKeyID keyid = pubkey.GetID(); |
| 69 | pubkeys.push_back(pubkey); |
| 70 | pkhashes.emplace(pubkey, keyid); |
| 71 | pkmap.emplace(keyid, pubkey); |
| 72 | XOnlyPubKey xonly_pubkey{pubkey}; |
| 73 | uint160 xonly_hash{Hash160(xonly_pubkey)}; |
| 74 | xonly_pkhashes.emplace(xonly_pubkey, xonly_hash); |
| 75 | pkmap.emplace(xonly_hash, pubkey); |
| 76 | |
| 77 | // Compute ECDSA signatures on MESSAGE_HASH with the private keys. |
| 78 | std::vector<unsigned char> sig, schnorr_sig(64); |
| 79 | BOOST_CHECK(key.Sign(MESSAGE_HASH, sig)); |
| 80 | sig.push_back(1); // sighash byte |
| 81 | signatures.emplace(pubkey, sig); |
| 82 | BOOST_CHECK(key.SignSchnorr(MESSAGE_HASH, schnorr_sig, nullptr, EMPTY_AUX)); |
| 83 | schnorr_sig.push_back(1); // Maximally sized Schnorr sigs have a sighash byte. |
| 84 | schnorr_signatures.emplace(XOnlyPubKey{pubkey}, schnorr_sig); |
| 85 | |
| 86 | // Compute various hashes |
| 87 | std::vector<unsigned char> hash; |
| 88 | hash.resize(32); |
| 89 | CSHA256().Write(keydata, 32).Finalize(hash.data()); |
| 90 | sha256.push_back(hash); |
| 91 | sha256_preimages[hash] = std::vector<unsigned char>(keydata, keydata + 32); |
| 92 | CHash256().Write(keydata).Finalize(hash); |
| 93 | hash256.push_back(hash); |
| 94 | hash256_preimages[hash] = std::vector<unsigned char>(keydata, keydata + 32); |
| 95 | hash.resize(20); |
| 96 | CRIPEMD160().Write(keydata, 32).Finalize(hash.data()); |
| 97 | ripemd160.push_back(hash); |
| 98 | ripemd160_preimages[hash] = std::vector<unsigned char>(keydata, keydata + 32); |
| 99 | CHash160().Write(keydata).Finalize(hash); |
| 100 | hash160.push_back(hash); |
| 101 | hash160_preimages[hash] = std::vector<unsigned char>(keydata, keydata + 32); |
| 102 | } |
| 103 | } |
| 104 | }; |
| 105 | |
| 106 | //! Global TestData object |
nothing calls this directly
no test coverage detected