Merge pull request #4379

607301bf rct: avoid repeated unnecessary conversions when accummulating (moneromooo-monero)
This commit is contained in:
Riccardo Spagni 2018-09-21 20:42:41 +02:00
commit 4a652d6b52
No known key found for this signature in database
GPG Key ID: 55432DF31CCD4FCD
3 changed files with 25 additions and 7 deletions

View File

@ -252,6 +252,25 @@ namespace rct {
return k; return k;
} }
rct::key addKeys(const keyV &A) {
if (A.empty())
return rct::identity();
ge_p3 p3, tmp;
CHECK_AND_ASSERT_THROW_MES_L1(ge_frombytes_vartime(&p3, A[0].bytes) == 0, "ge_frombytes_vartime failed at "+boost::lexical_cast<std::string>(__LINE__));
for (size_t i = 1; i < A.size(); ++i)
{
CHECK_AND_ASSERT_THROW_MES_L1(ge_frombytes_vartime(&tmp, A[i].bytes) == 0, "ge_frombytes_vartime failed at "+boost::lexical_cast<std::string>(__LINE__));
ge_cached p2;
ge_p3_to_cached(&p2, &tmp);
ge_p1p1 p1;
ge_add(&p1, &p3, &p2);
ge_p1p1_to_p3(&p3, &p1);
}
rct::key res;
ge_p3_tobytes(res.bytes, &p3);
return res;
}
//addKeys1 //addKeys1
//aGB = aG + B where a is a scalar, G is the basepoint, and B is a point //aGB = aG + B where a is a scalar, G is the basepoint, and B is a point
void addKeys1(key &aGB, const key &a, const key & B) { void addKeys1(key &aGB, const key &a, const key & B) {

View File

@ -132,6 +132,7 @@ namespace rct {
//for curve points: AB = A + B //for curve points: AB = A + B
void addKeys(key &AB, const key &A, const key &B); void addKeys(key &AB, const key &A, const key &B);
rct::key addKeys(const key &A, const key &B); rct::key addKeys(const key &A, const key &B);
rct::key addKeys(const keyV &A);
//aGB = aG + B where a is a scalar, G is the basepoint, and B is a point //aGB = aG + B where a is a scalar, G is the basepoint, and B is a point
void addKeys1(key &aGB, const key &a, const key & B); void addKeys1(key &aGB, const key &a, const key & B);
//aGbB = aG + bB where a, b are scalars, G is the basepoint and B is a point //aGbB = aG + bB where a, b are scalars, G is the basepoint and B is a point

View File

@ -963,18 +963,16 @@ namespace rct {
const bool bulletproof = is_rct_bulletproof(rv.type); const bool bulletproof = is_rct_bulletproof(rv.type);
const keyV &pseudoOuts = bulletproof ? rv.p.pseudoOuts : rv.pseudoOuts; const keyV &pseudoOuts = bulletproof ? rv.p.pseudoOuts : rv.pseudoOuts;
key sumOutpks = identity(); rct::keyV masks(rv.outPk.size());
for (size_t i = 0; i < rv.outPk.size(); i++) { for (size_t i = 0; i < rv.outPk.size(); i++) {
addKeys(sumOutpks, sumOutpks, rv.outPk[i].mask); masks[i] = rv.outPk[i].mask;
} }
key sumOutpks = addKeys(masks);
DP(sumOutpks); DP(sumOutpks);
key txnFeeKey = scalarmultH(d2h(rv.txnFee)); const key txnFeeKey = scalarmultH(d2h(rv.txnFee));
addKeys(sumOutpks, txnFeeKey, sumOutpks); addKeys(sumOutpks, txnFeeKey, sumOutpks);
key sumPseudoOuts = identity(); key sumPseudoOuts = addKeys(pseudoOuts);
for (size_t i = 0 ; i < pseudoOuts.size() ; i++) {
addKeys(sumPseudoOuts, sumPseudoOuts, pseudoOuts[i]);
}
DP(sumPseudoOuts); DP(sumPseudoOuts);
//check pseudoOuts vs Outs.. //check pseudoOuts vs Outs..