From b6bcca989986242883f6f96e34495c7eef928597 Mon Sep 17 00:00:00 2001 From: j-berman Date: Fri, 9 Aug 2024 16:29:31 -0700 Subject: [PATCH] Remove ringct dep in fcmp_pp, impl in fcmp_pp_crypto --- src/fcmp_pp/CMakeLists.txt | 2 +- src/fcmp_pp/curve_trees.cpp | 14 ++++++++------ src/ringct/rctOps.cpp | 25 ------------------------- src/ringct/rctOps.h | 4 ---- tests/unit_tests/curve_trees.cpp | 3 ++- 5 files changed, 11 insertions(+), 37 deletions(-) diff --git a/src/fcmp_pp/CMakeLists.txt b/src/fcmp_pp/CMakeLists.txt index 50dbb567f..849b09593 100644 --- a/src/fcmp_pp/CMakeLists.txt +++ b/src/fcmp_pp/CMakeLists.txt @@ -28,6 +28,7 @@ set(fcmp_pp_sources curve_trees.cpp + fcmp_pp_crypto.cpp tower_cycle.cpp) monero_find_all_headers(fcmp_pp_headers "${CMAKE_CURRENT_SOURCE_DIR}") @@ -52,7 +53,6 @@ target_link_libraries(fcmp_pp cncrypto cryptonote_basic epee - ringct_basic PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/fcmp_pp_rust/libfcmp_pp_rust.a ${EXTRA_LIBRARIES} diff --git a/src/fcmp_pp/curve_trees.cpp b/src/fcmp_pp/curve_trees.cpp index 3873b0cbc..85c9a42a5 100644 --- a/src/fcmp_pp/curve_trees.cpp +++ b/src/fcmp_pp/curve_trees.cpp @@ -26,8 +26,10 @@ // 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. -#include "cryptonote_basic/cryptonote_format_utils.h" #include "curve_trees.h" + +#include "cryptonote_basic/cryptonote_format_utils.h" +#include "fcmp_pp_crypto.h" #include "ringct/rctOps.h" @@ -705,9 +707,9 @@ CurveTrees::LeafTuple CurveTrees::leaf_tuple( const rct::key &commitment = output_pair.commitment; rct::key O, C; - if (!rct::clear_torsion(rct::pk2rct(output_pubkey), O)) + if (!fcmp_pp::clear_torsion(rct::pk2rct(output_pubkey), O)) throw std::runtime_error("output pubkey is invalid"); - if (!rct::clear_torsion(commitment, C)) + if (!fcmp_pp::clear_torsion(commitment, C)) throw std::runtime_error("commitment is invalid"); if (O == rct::I) @@ -722,11 +724,11 @@ CurveTrees::LeafTuple CurveTrees::leaf_tuple( crypto::derive_key_image_generator(output_pubkey, I); rct::key O_x, I_x, C_x; - if (!rct::point_to_wei_x(O, O_x)) + if (!fcmp_pp::point_to_wei_x(O, O_x)) throw std::runtime_error("failed to get wei x scalar from O"); - if (!rct::point_to_wei_x(rct::pt2rct(I), I_x)) + if (!fcmp_pp::point_to_wei_x(rct::pt2rct(I), I_x)) throw std::runtime_error("failed to get wei x scalar from I"); - if (!rct::point_to_wei_x(C, C_x)) + if (!fcmp_pp::point_to_wei_x(C, C_x)) throw std::runtime_error("failed to get wei x scalar from C"); return LeafTuple{ diff --git a/src/ringct/rctOps.cpp b/src/ringct/rctOps.cpp index e865f4398..0e18cb461 100644 --- a/src/ringct/rctOps.cpp +++ b/src/ringct/rctOps.cpp @@ -725,29 +725,4 @@ namespace rct { sc_sub(masked.amount.bytes, masked.amount.bytes, sharedSec2.bytes); } } - - bool clear_torsion(const key &k, key &k_out) { - ge_p3 point; - if (ge_frombytes_vartime(&point, k.bytes) != 0) - return false; - // mul by inv 8, then mul by 8 - ge_p2 point_inv_8; - ge_scalarmult(&point_inv_8, INV_EIGHT.bytes, &point); - ge_p1p1 point_inv_8_mul_8; - ge_mul8(&point_inv_8_mul_8, &point_inv_8); - ge_p3 torsion_cleared_point; - ge_p1p1_to_p3(&torsion_cleared_point, &point_inv_8_mul_8); - ge_p3_tobytes(k_out.bytes, &torsion_cleared_point); - return true; - } - - bool point_to_wei_x(const key &pub, key &wei_x) { - if (pub == I) - return false; - fe y; - if (fe_frombytes_vartime(y, pub.bytes) != 0) - return false; - fe_ed_y_to_wei_x(wei_x.bytes, y); - return true; - } } diff --git a/src/ringct/rctOps.h b/src/ringct/rctOps.h index 2a3c1f678..0edd0308c 100644 --- a/src/ringct/rctOps.h +++ b/src/ringct/rctOps.h @@ -188,9 +188,5 @@ namespace rct { key genCommitmentMask(const key &sk); void ecdhEncode(ecdhTuple & unmasked, const key & sharedSec, bool v2); void ecdhDecode(ecdhTuple & masked, const key & sharedSec, bool v2); - - // TODO: tests for these functions specifically - bool clear_torsion(const key &k, key &k_out); - bool point_to_wei_x(const key &pub, key &wei_x); } #endif /* RCTOPS_H */ diff --git a/tests/unit_tests/curve_trees.cpp b/tests/unit_tests/curve_trees.cpp index 2e4575859..86769b60f 100644 --- a/tests/unit_tests/curve_trees.cpp +++ b/tests/unit_tests/curve_trees.cpp @@ -30,6 +30,7 @@ #include "cryptonote_basic/cryptonote_format_utils.h" #include "curve_trees.h" +#include "fcmp_pp/fcmp_pp_crypto.h" #include "misc_log_ex.h" #include "ringct/rctOps.h" #include "unit_tests_utils.h" @@ -777,7 +778,7 @@ static const Selene::Scalar generate_random_selene_scalar() crypto::generate_keys(S, s, s, false); rct::key S_x; - CHECK_AND_ASSERT_THROW_MES(rct::point_to_wei_x(rct::pk2rct(S), S_x), "failed to convert to wei x"); + CHECK_AND_ASSERT_THROW_MES(fcmp_pp::point_to_wei_x(rct::pk2rct(S), S_x), "failed to convert to wei x"); return fcmp_pp::tower_cycle::selene_scalar_from_bytes(S_x); } //----------------------------------------------------------------------------------------------------------------------