mirror of
https://github.com/monero-project/monero.git
synced 2025-03-27 16:58:10 -04:00
enote equality operators
This commit is contained in:
parent
ee3a8697d6
commit
2d978eaaff
@ -30,6 +30,7 @@ set(carrot_core_sources
|
||||
account_secrets.cpp
|
||||
address_utils.cpp
|
||||
carrot_enote_scan.cpp
|
||||
carrot_enote_types.cpp
|
||||
core_types.cpp
|
||||
destination.cpp
|
||||
device_ram_borrowed.cpp
|
||||
|
@ -55,7 +55,7 @@ void make_carrot_index_extension_generator(const crypto::secret_key &s_generate_
|
||||
derive_bytes_32(transcript.data(), transcript.size(), &s_generate_address, &address_generator_out);
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
void make_carrot_subaddress_scalar(const crypto::public_key &spend_pubkey,
|
||||
void make_carrot_subaddress_scalar(const crypto::public_key &account_spend_pubkey,
|
||||
const crypto::secret_key &s_address_generator,
|
||||
const std::uint32_t j_major,
|
||||
const std::uint32_t j_minor,
|
||||
@ -63,11 +63,11 @@ void make_carrot_subaddress_scalar(const crypto::public_key &spend_pubkey,
|
||||
{
|
||||
// k^j_subscal = H_n(K_s, j_major, j_minor, s^j_gen)
|
||||
const auto transcript = sp::make_fixed_transcript<CARROT_DOMAIN_SEP_SUBADDRESS_SCALAR>(
|
||||
spend_pubkey, j_major, j_minor);
|
||||
account_spend_pubkey, j_major, j_minor);
|
||||
derive_scalar(transcript.data(), transcript.size(), &s_address_generator, subaddress_scalar_out.data);
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
void make_carrot_address_spend_pubkey(const crypto::public_key &spend_pubkey,
|
||||
void make_carrot_address_spend_pubkey(const crypto::public_key &account_spend_pubkey,
|
||||
const crypto::secret_key &s_generate_address,
|
||||
const std::uint32_t j_major,
|
||||
const std::uint32_t j_minor,
|
||||
@ -75,11 +75,11 @@ void make_carrot_address_spend_pubkey(const crypto::public_key &spend_pubkey,
|
||||
{
|
||||
// k^j_subscal = H_n(K_s, j_major, j_minor, s^j_gen)
|
||||
crypto::secret_key subaddress_scalar;
|
||||
make_carrot_subaddress_scalar(spend_pubkey, s_generate_address, j_major, j_minor, subaddress_scalar);
|
||||
make_carrot_subaddress_scalar(account_spend_pubkey, s_generate_address, j_major, j_minor, subaddress_scalar);
|
||||
|
||||
// K^j_s = k^j_subscal * K_s
|
||||
address_spend_pubkey_out = rct::rct2pk(rct::scalarmultKey(
|
||||
rct::pk2rct(spend_pubkey), rct::sk2rct(subaddress_scalar)));
|
||||
rct::pk2rct(account_spend_pubkey), rct::sk2rct(subaddress_scalar)));
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
} //namespace carrot
|
||||
|
@ -66,13 +66,13 @@ void make_carrot_index_extension_generator(const crypto::secret_key &s_generate_
|
||||
/**
|
||||
* brief: make_carrot_address_privkey - d^j_a
|
||||
* k^j_subscal = H_n(K_s, j_major, j_minor, s^j_gen)
|
||||
* param: spend_pubkey - K_s = k_vb X + k_m U
|
||||
* param: account_spend_pubkey - K_s = k_vb X + k_m U
|
||||
* param: s_address_generator - s^j_gen
|
||||
* param: j_major -
|
||||
* param: j_minor -
|
||||
* outparam: subaddress_scalar_out - k^j_subscal
|
||||
*/
|
||||
void make_carrot_subaddress_scalar(const crypto::public_key &spend_pubkey,
|
||||
void make_carrot_subaddress_scalar(const crypto::public_key &account_spend_pubkey,
|
||||
const crypto::secret_key &s_address_generator,
|
||||
const std::uint32_t j_major,
|
||||
const std::uint32_t j_minor,
|
||||
@ -80,13 +80,13 @@ void make_carrot_subaddress_scalar(const crypto::public_key &spend_pubkey,
|
||||
/**
|
||||
* brief: make_carrot_address_spend_pubkey - K^j_s
|
||||
* K^j_s = k^j_subscal * K_s
|
||||
* param: spend_pubkey - K_s = k_gi G + k_ps U
|
||||
* param: account_spend_pubkey - K_s = k_gi G + k_ps U
|
||||
* param: s_generate_address - s_ga
|
||||
* param: j_major -
|
||||
* param: j_minor -
|
||||
* outparam: address_spend_pubkey_out - K^j_s
|
||||
*/
|
||||
void make_carrot_address_spend_pubkey(const crypto::public_key &spend_pubkey,
|
||||
void make_carrot_address_spend_pubkey(const crypto::public_key &account_spend_pubkey,
|
||||
const crypto::secret_key &s_generate_address,
|
||||
const std::uint32_t j_major,
|
||||
const std::uint32_t j_minor,
|
||||
|
73
src/carrot_core/carrot_enote_types.cpp
Normal file
73
src/carrot_core/carrot_enote_types.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
// 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.
|
||||
|
||||
// Utilities for scanning carrot enotes
|
||||
|
||||
//paired header
|
||||
#include "carrot_enote_types.h"
|
||||
|
||||
//local headers
|
||||
|
||||
//third party headers
|
||||
|
||||
//standard headers
|
||||
|
||||
/*
|
||||
onetime address
|
||||
// - amount commitment
|
||||
// - encrypted amount
|
||||
// - encrypted janus anchor
|
||||
// - view tag
|
||||
// - ephemeral pubkey
|
||||
// - tx first key image*/
|
||||
|
||||
namespace carrot
|
||||
{
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
bool operator==(const CarrotEnoteV1 &a, const CarrotEnoteV1 &b)
|
||||
{
|
||||
return a.onetime_address == b.onetime_address &&
|
||||
a.amount_commitment == b.amount_commitment &&
|
||||
a.amount_enc == b.amount_enc &&
|
||||
a.anchor_enc == b.anchor_enc &&
|
||||
a.view_tag == b.view_tag &&
|
||||
a.tx_first_key_image == b.tx_first_key_image &&
|
||||
memcmp(a.enote_ephemeral_pubkey.data, b.enote_ephemeral_pubkey.data, sizeof(mx25519_pubkey)) == 0;
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
bool operator==(const CarrotCoinbaseEnoteV1 &a, const CarrotCoinbaseEnoteV1 &b)
|
||||
{
|
||||
return a.onetime_address == b.onetime_address &&
|
||||
a.amount == b.amount &&
|
||||
a.anchor_enc == b.anchor_enc &&
|
||||
a.view_tag == b.view_tag &&
|
||||
a.block_index == b.block_index &&
|
||||
memcmp(a.enote_ephemeral_pubkey.data, b.enote_ephemeral_pubkey.data, sizeof(mx25519_pubkey)) == 0;
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
} //namespace carrot
|
@ -52,6 +52,8 @@ namespace carrot
|
||||
// - encrypted amount
|
||||
// - encrypted janus anchor
|
||||
// - view tag
|
||||
// - ephemeral pubkey
|
||||
// - tx first key image
|
||||
///
|
||||
struct CarrotEnoteV1 final
|
||||
{
|
||||
@ -71,12 +73,18 @@ struct CarrotEnoteV1 final
|
||||
crypto::key_image tx_first_key_image;
|
||||
};
|
||||
|
||||
/// equality operators
|
||||
bool operator==(const CarrotEnoteV1 &a, const CarrotEnoteV1 &b);
|
||||
static inline bool operator!=(const CarrotEnoteV1 &a, const CarrotEnoteV1 &b) { return !(a == b); }
|
||||
|
||||
////
|
||||
// CarrotCoinbaseEnoteV1
|
||||
// - onetime address
|
||||
// - cleartext amount
|
||||
// - encrypted janus anchor
|
||||
// - view tag
|
||||
// - ephemeral pubkey
|
||||
// - block index
|
||||
///
|
||||
struct CarrotCoinbaseEnoteV1 final
|
||||
{
|
||||
@ -94,13 +102,8 @@ struct CarrotCoinbaseEnoteV1 final
|
||||
std::uint64_t block_index;
|
||||
};
|
||||
|
||||
/**
|
||||
* brief: gen_carrot_enote_v1() - generate a carrot v1 enote (all random)
|
||||
*/
|
||||
CarrotEnoteV1 gen_carrot_enote_v1();
|
||||
/**
|
||||
* brief: gen_carrot_coinbase_enote_v1() - generate a carrot coinbase v1 enote (all random)
|
||||
*/
|
||||
CarrotCoinbaseEnoteV1 gen_carrot_coinbase_enote_v1();
|
||||
/// equality operators
|
||||
bool operator==(const CarrotCoinbaseEnoteV1 &a, const CarrotCoinbaseEnoteV1 &b);
|
||||
static inline bool operator!=(const CarrotCoinbaseEnoteV1 &a, const CarrotCoinbaseEnoteV1 &b) { return !(a == b); }
|
||||
|
||||
} //namespace carrot
|
||||
|
Loading…
x
Reference in New Issue
Block a user