diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2017-11-04 10:39:17 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2017-12-17 16:12:32 +0000 |
commit | e36f5b6021eb541d72fee4b2d5643ba42fd4d9dd (patch) | |
tree | e9ba527083a6e99dc8ed2739ca478dc20a77f6cb /src/wallet | |
parent | wallet2: fix slow multisig unit tests with subaddress patch (diff) | |
download | monero-e36f5b6021eb541d72fee4b2d5643ba42fd4d9dd.tar.xz |
Match surae's recommendation to derive multisig keys
Diffstat (limited to 'src/wallet')
-rw-r--r-- | src/wallet/wallet2.cpp | 31 | ||||
-rw-r--r-- | src/wallet/wallet_rpc_server.cpp | 6 |
2 files changed, 19 insertions, 18 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 013ad6a75..29ca3dd2f 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2830,8 +2830,6 @@ std::string wallet2::make_multisig(const epee::wipeable_string &password, // We need an extra step, so we package all the composite public keys // we know about, and make a signed string out of them std::string data; - const crypto::public_key &pkey = get_account().get_keys().m_account_address.m_spend_public_key; - data += std::string((const char *)&pkey, sizeof(crypto::public_key)); const crypto::public_key signer = get_multisig_signer_public_key(rct::rct2sk(spend_skey)); data += std::string((const char *)&signer, sizeof(crypto::public_key)); @@ -2844,7 +2842,7 @@ std::string wallet2::make_multisig(const epee::wipeable_string &password, data.resize(data.size() + sizeof(crypto::signature)); crypto::cn_fast_hash(data.data(), data.size() - sizeof(signature), hash); crypto::signature &signature = *(crypto::signature*)&data[data.size() - sizeof(crypto::signature)]; - crypto::generate_signature(hash, pkey, get_account().get_keys().m_spend_secret_key, signature); + crypto::generate_signature(hash, signer, get_multisig_blinded_secret_key(rct::rct2sk(spend_skey)), signature); extra_multisig_info = std::string("MultisigxV1") + tools::base58::encode(data); } @@ -2958,19 +2956,18 @@ bool wallet2::finalize_multisig(const epee::wipeable_string &password, const std std::string wallet2::get_multisig_info() const { // It's a signed package of private view key and public spend key - const crypto::secret_key &skey = get_account().get_keys().m_view_secret_key; - const crypto::public_key &pkey = get_account().get_keys().m_account_address.m_spend_public_key; + const crypto::secret_key skey = cryptonote::get_multisig_blinded_secret_key(get_account().get_keys().m_view_secret_key); + const crypto::public_key pkey = get_multisig_signer_public_key(get_account().get_keys().m_spend_secret_key); crypto::hash hash; std::string data; - crypto::cn_fast_hash(&skey, sizeof(crypto::secret_key), hash); - data += std::string((const char *)&hash, sizeof(crypto::hash)); + data += std::string((const char *)&skey, sizeof(crypto::secret_key)); data += std::string((const char *)&pkey, sizeof(crypto::public_key)); data.resize(data.size() + sizeof(crypto::signature)); crypto::cn_fast_hash(data.data(), data.size() - sizeof(signature), hash); crypto::signature &signature = *(crypto::signature*)&data[data.size() - sizeof(crypto::signature)]; - crypto::generate_signature(hash, pkey, get_account().get_keys().m_spend_secret_key, signature); + crypto::generate_signature(hash, pkey, get_multisig_blinded_secret_key(get_account().get_keys().m_spend_secret_key), signature); return std::string("MultisigV1") + tools::base58::encode(data); } @@ -3027,28 +3024,26 @@ bool wallet2::verify_extra_multisig_info(const std::string &data, std::unordered MERROR("Multisig info decoding error"); return false; } - if (decoded.size() < sizeof(crypto::public_key) + sizeof(crypto::public_key) + sizeof(crypto::signature)) + if (decoded.size() < sizeof(crypto::public_key) + sizeof(crypto::signature)) { MERROR("Multisig info is corrupt"); return false; } - if ((decoded.size() - (sizeof(crypto::public_key) + sizeof(crypto::public_key) + sizeof(crypto::signature))) % sizeof(crypto::public_key)) + if ((decoded.size() - (sizeof(crypto::public_key) + sizeof(crypto::signature))) % sizeof(crypto::public_key)) { MERROR("Multisig info is corrupt"); return false; } - const size_t n_keys = (decoded.size() - (sizeof(crypto::public_key) + sizeof(crypto::public_key) + sizeof(crypto::signature))) / sizeof(crypto::public_key); + const size_t n_keys = (decoded.size() - (sizeof(crypto::public_key) + sizeof(crypto::signature))) / sizeof(crypto::public_key); size_t offset = 0; - const crypto::public_key &pkey = *(const crypto::public_key*)(decoded.data() + offset); - offset += sizeof(pkey); signer = *(const crypto::public_key*)(decoded.data() + offset); offset += sizeof(signer); const crypto::signature &signature = *(const crypto::signature*)(decoded.data() + offset + n_keys * sizeof(crypto::public_key)); crypto::hash hash; crypto::cn_fast_hash(decoded.data(), decoded.size() - sizeof(signature), hash); - if (!crypto::check_signature(hash, pkey, signature)) + if (!crypto::check_signature(hash, signer, signature)) { MERROR("Multisig info signature is invalid"); return false; @@ -8313,13 +8308,19 @@ size_t wallet2::import_outputs(const std::vector<tools::wallet2::transfer_detail crypto::public_key wallet2::get_multisig_signer_public_key(const crypto::secret_key &spend_skey) const { crypto::public_key pkey; - crypto::secret_key_to_public_key(spend_skey, pkey); + crypto::secret_key_to_public_key(get_multisig_blinded_secret_key(spend_skey), pkey); return pkey; } //---------------------------------------------------------------------------------------------------- crypto::public_key wallet2::get_multisig_signer_public_key() const { CHECK_AND_ASSERT_THROW_MES(m_multisig, "Wallet is not multisig"); + if (m_multisig_threshold == m_multisig_signers.size()) + { + crypto::public_key signer; + CHECK_AND_ASSERT_THROW_MES(crypto::secret_key_to_public_key(get_account().get_keys().m_spend_secret_key, signer), "Failed to generate signer public key"); + return signer; + } return get_multisig_signer_public_key(get_account().get_keys().m_spend_secret_key); } //---------------------------------------------------------------------------------------------------- diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 043890fd1..e6e5445b2 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -41,6 +41,7 @@ using namespace epee; #include "common/i18n.h" #include "cryptonote_basic/cryptonote_format_utils.h" #include "cryptonote_basic/account.h" +#include "multisig/multisig.h" #include "wallet_rpc_server_commands_defs.h" #include "misc_language.h" #include "string_coding.h" @@ -2424,11 +2425,10 @@ namespace tools } // people may include their own, weed it out - crypto::hash hash; - crypto::cn_fast_hash(&m_wallet->get_account().get_keys().m_view_secret_key, sizeof(crypto::secret_key), hash); + crypto::secret_key local_skey = cryptonote::get_multisig_blinded_secret_key(m_wallet->get_account().get_keys().m_view_secret_key); for (size_t i = 0; i < secret_keys.size(); ++i) { - if (rct::sk2rct(secret_keys[i]) == rct::hash2rct(hash)) + if (rct::sk2rct(secret_keys[i]) == rct::sk2rct(local_skey)) { secret_keys[i] = secret_keys.back(); public_keys[i] = public_keys.back(); |