1
0
Fork 0
forked from lthn/blockchain

BGE proof: WIP

This commit is contained in:
sowle 2023-03-26 22:36:15 +02:00
parent fdc1ceea62
commit cfd01e80fe
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
2 changed files with 38 additions and 7 deletions

View file

@ -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<point_t> 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<point_t>& 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<point_t>& 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<const public_key*>& ring, BGE_proof& result, uint8_t* p_err /* = nullptr */)
bool verify_BGE_proof(const hash& context_hash, const std::vector<const public_key*>& ring, BGE_proof& result, uint8_t* p_err /* = nullptr */)
{
return false;
}

View file

@ -22,18 +22,18 @@ namespace crypto
struct BGE_proof
{
point_t A;
point_t B;
std::vector<point_t> Pk;
public_key A; // premultiplied by 1/8
public_key B; // premultiplied by 1/8
std::vector<public_key> 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<point_t>& 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<point_t>& 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<const public_key*>& ring, BGE_proof& result, uint8_t* p_err = nullptr);
bool verify_BGE_proof(const hash& context_hash, const std::vector<const public_key*>& ring, BGE_proof& result, uint8_t* p_err = nullptr);
} // namespace crypto