From cfd01e80fe14b57379770da10d8cde901ae472a2 Mon Sep 17 00:00:00 2001 From: sowle Date: Sun, 26 Mar 2023 22:36:15 +0200 Subject: [PATCH] BGE proof: WIP --- src/crypto/one_out_of_many_proofs.cpp | 35 +++++++++++++++++++++++++-- src/crypto/one_out_of_many_proofs.h | 10 ++++---- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/crypto/one_out_of_many_proofs.cpp b/src/crypto/one_out_of_many_proofs.cpp index f9025ab0..72dda1c8 100644 --- a/src/crypto/one_out_of_many_proofs.cpp +++ b/src/crypto/one_out_of_many_proofs.cpp @@ -19,12 +19,43 @@ namespace crypto { + static const size_t N_max = 256; + static const size_t mn_max = 16; + + const point_t& get_BGE_generator(size_t index, bool& ok) + { + static std::vector precalculated_generators; + if (precalculated_generators.empty()) + { + precalculated_generators.resize(mn_max * 2); + + scalar_t hash_buf[2] = { hash_helper_t::hs("Zano BGE generator"), 0 }; + + for(size_t i = 0; i < precalculated_generators.size(); ++i) + { + hash_buf[1].m_u64[0] = i; + precalculated_generators[i] = hash_helper_t::hp(&hash_buf, sizeof hash_buf); + } + } + + if (index >= mn_max * 2) + { + ok = false; + return c_point_0; + } + + ok = true; + return precalculated_generators[index]; + } + + + #define CHECK_AND_FAIL_WITH_ERROR_IF_FALSE(cond, err_code) \ if (!(cond)) { LOG_PRINT_RED("generate_BGE_proof: \"" << #cond << "\" is false at " << LOCATION_SS << ENDL << "error code = " << (int)err_code, LOG_LEVEL_3); \ if (p_err) { *p_err = err_code; } return false; } - bool generate_BGE_proof(const hash& m, const std::vector& ring, const scalar_t& secret, const size_t secret_index, BGE_proof& result, uint8_t* p_err /* = nullptr */) + bool generate_BGE_proof(const hash& context_hash, const std::vector& ring, const scalar_t& secret, const size_t secret_index, BGE_proof& result, uint8_t* p_err /* = nullptr */) { DBG_PRINT(" - - - generate_BGE_proof - - -"); size_t N = ring.size(); @@ -39,7 +70,7 @@ namespace crypto } - bool verify_BGE_proof(const hash& m, const std::vector& ring, BGE_proof& result, uint8_t* p_err /* = nullptr */) + bool verify_BGE_proof(const hash& context_hash, const std::vector& ring, BGE_proof& result, uint8_t* p_err /* = nullptr */) { return false; } diff --git a/src/crypto/one_out_of_many_proofs.h b/src/crypto/one_out_of_many_proofs.h index d6d9aafe..fe8b3713 100644 --- a/src/crypto/one_out_of_many_proofs.h +++ b/src/crypto/one_out_of_many_proofs.h @@ -22,18 +22,18 @@ namespace crypto struct BGE_proof { - point_t A; - point_t B; - std::vector Pk; + public_key A; // premultiplied by 1/8 + public_key B; // premultiplied by 1/8 + std::vector Pk; // premultiplied by 1/8 scalar_vec_t f; scalar_t y; scalar_t z; }; - bool generate_BGE_proof(const hash& m, const std::vector& ring, const scalar_t& secret, const size_t secret_index, BGE_proof& result, uint8_t* p_err = nullptr); + bool generate_BGE_proof(const hash& context_hash, const std::vector& ring, const scalar_t& secret, const size_t secret_index, BGE_proof& result, uint8_t* p_err = nullptr); - bool verify_BGE_proof(const hash& m, const std::vector& ring, BGE_proof& result, uint8_t* p_err = nullptr); + bool verify_BGE_proof(const hash& context_hash, const std::vector& ring, BGE_proof& result, uint8_t* p_err = nullptr); } // namespace crypto