mirror of
https://github.com/wownero/wownero.git
synced 2026-11-22 00:23:59 +01:00
+3









j-berman
jeffro256
Luke Parker
Lee *!* Clagett
SyntheticBird45
jeetrex17
UkoeHB
MrCyjaneK
tobtoht
selsta
Thomas
navidR
Boog900
a9145f9d38
Co-authored-by: jeffro256 <jeffro256@tutanota.com> Co-authored-by: Luke Parker <lukeparker5132@gmail.com> Co-authored-by: Lee *!* Clagett <code@leeclagett.com> Co-authored-by: SyntheticBird45 <someoneelse.is_on.github.rio7x@simplelogin.com> Co-authored-by: jeetrex17 <jeetrex@tutamail.com> Co-authored-by: UkoeHB <ukoehb@users.noreply.github.com> Co-authored-by: MrCyjaneK Co-authored-by: tobtoht Co-authored-by: selsta Co-authored-by: Thomas <thomas.giudici@proton.me> Co-authored-by: navidR Co-authored-by: Boog900 <boog900@tutanota.com>
112 lines
4.8 KiB
C++
112 lines
4.8 KiB
C++
// Copyright (c) 2024, The Monero Project
|
|
//
|
|
// All rights reserved.
|
|
//
|
|
// Redistribution and use in source and binary forms, with or without modification, are
|
|
// permitted provided that the following conditions are met:
|
|
//
|
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
// conditions and the following disclaimer.
|
|
//
|
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
// of conditions and the following disclaimer in the documentation and/or other
|
|
// materials provided with the distribution.
|
|
//
|
|
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
|
// used to endorse or promote products derived from this software without specific
|
|
// prior written permission.
|
|
//
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//paired header
|
|
#include "address_utils.h"
|
|
|
|
//local headers
|
|
#include "address_device.h"
|
|
#include "carrot_impl/subaddress_index.h"
|
|
#include "cryptonote_config.h"
|
|
#include "int-util.h"
|
|
|
|
//third party headers
|
|
|
|
//standard headers
|
|
|
|
#undef MONERO_DEFAULT_LOG_CATEGORY
|
|
#define MONERO_DEFAULT_LOG_CATEGORY "carrot_impl.address_utils"
|
|
|
|
namespace carrot
|
|
{
|
|
//-------------------------------------------------------------------------------------------------------------------
|
|
void make_legacy_subaddress_extension(const crypto::secret_key &k_view,
|
|
const std::uint32_t major_index,
|
|
const std::uint32_t minor_index,
|
|
crypto::secret_key &legacy_subaddress_extension_out)
|
|
{
|
|
if (!major_index && !minor_index)
|
|
{
|
|
memset(legacy_subaddress_extension_out.data, 0, sizeof(legacy_subaddress_extension_out));
|
|
return;
|
|
}
|
|
|
|
char data[sizeof(config::HASH_KEY_SUBADDRESS) + sizeof(crypto::secret_key) + 2 * sizeof(uint32_t)];
|
|
|
|
// "Subaddr" || IntToBytes(0)
|
|
memcpy(data, config::HASH_KEY_SUBADDRESS, sizeof(config::HASH_KEY_SUBADDRESS));
|
|
|
|
// ... || k_v
|
|
memcpy(data + sizeof(config::HASH_KEY_SUBADDRESS), &k_view, sizeof(crypto::secret_key));
|
|
|
|
// ... || IntToBytes32(j_major)
|
|
uint32_t idx = SWAP32LE(major_index);
|
|
memcpy(data + sizeof(config::HASH_KEY_SUBADDRESS) + sizeof(crypto::secret_key), &idx, sizeof(uint32_t));
|
|
|
|
// ... || IntToBytes32(j_minor)
|
|
idx = SWAP32LE(minor_index);
|
|
memcpy(data + sizeof(config::HASH_KEY_SUBADDRESS) + sizeof(crypto::secret_key) + sizeof(uint32_t),
|
|
&idx,
|
|
sizeof(uint32_t));
|
|
|
|
// k^j_subext = ScalarDeriveLegacy("SubAddr" || IntToBytes8(0) || k_v || IntToBytes32(j_major) || IntToBytes32(j_minor))
|
|
crypto::hash_to_scalar(data, sizeof(data), legacy_subaddress_extension_out);
|
|
}
|
|
//-------------------------------------------------------------------------------------------------------------------
|
|
std::size_t get_all_main_address_spend_pubkeys(const address_device &addr_dev,
|
|
crypto::public_key main_address_spend_pubkeys_out[2])
|
|
{
|
|
memset(main_address_spend_pubkeys_out, 0, 2*sizeof(main_address_spend_pubkeys_out[0]));
|
|
|
|
std::size_t n_main_addrs = 0;
|
|
if (addr_dev.supports_address_derive_type(AddressDeriveType::PreCarrot))
|
|
{
|
|
addr_dev.get_address_spend_pubkey({{}, AddressDeriveType::PreCarrot},
|
|
main_address_spend_pubkeys_out[n_main_addrs]);
|
|
++n_main_addrs;
|
|
}
|
|
if (addr_dev.supports_address_derive_type(AddressDeriveType::Carrot))
|
|
{
|
|
addr_dev.get_address_spend_pubkey({{}, AddressDeriveType::Carrot},
|
|
main_address_spend_pubkeys_out[n_main_addrs]);
|
|
++n_main_addrs;
|
|
}
|
|
|
|
return n_main_addrs;
|
|
}
|
|
//-------------------------------------------------------------------------------------------------------------------
|
|
epee::span<const crypto::public_key> get_all_main_address_spend_pubkeys_span(
|
|
const address_device &addr_dev,
|
|
crypto::public_key main_address_spend_pubkeys_out[2])
|
|
{
|
|
const std::size_t n_main_addrs = get_all_main_address_spend_pubkeys(addr_dev, main_address_spend_pubkeys_out);
|
|
return {main_address_spend_pubkeys_out, n_main_addrs};
|
|
}
|
|
//-------------------------------------------------------------------------------------------------------------------
|
|
} //namespace carrot
|