herumi / mcl

a portable and fast pairing-based cryptography library
BSD 3-Clause "New" or "Revised" License
450 stars 152 forks source link

Question about aggregate addition #116

Closed UndeadRat22 closed 3 years ago

UndeadRat22 commented 3 years ago

maybe I missed it, but is there a function which does something like this:

public MCL.G1 Commit(MCL.G1[] g1Points)
{
    return Coefficients.Zip(g1Points)
        .Aggregate(new MCL.G1(), (acc, val) => acc + val.Second * val.First);
}

the rough idea is like this:

Frs: [a0, a1, ... an]
*
G1s: [g0, g1, ... gn]
=
G1s: [g0 * a0, g1 * a1, g2 * a2 ... gn * an]

return sum of ([g0 * a0, g1 * a1, g2 * a2 ... gn * an]);

If not, maybe it would make sense to add such a function to the mcl library?

afaik, there's a method which does the first part, mclBnG1_mulVec, but not sure about the aggregation of the multiplication results, would be nice to have an optimized version of that.

UndeadRat22 commented 3 years ago

Yikes, my bad, that function does exactly that, misread the signature. Sorry for the trouble 🙏