nucypher / goUmbral

Umbral implementation in Golang
GNU General Public License v3.0
41 stars 6 forks source link

Expand arithmetic API arguments #16

Closed tuxxy closed 6 years ago

tuxxy commented 6 years ago

What this does:

  1. Prevents the arithmetic API from modifying the class it's called with.[0]
  2. Makes GetNewPoint to return a null ECPoint if a nil point is passed.
  3. Makes GetNewModBN return a ModBigNum with a nil BIGNUM.
  4. Adds a test for ModBigNum.Neg.

What this needs:

  1. Blackbox tests need to be fixed to comply with these API changes.

[0] -- The reason for this can be demonstrated in the following example. Let's imagine that we need to generate a pubkey.

With the way the API is before this PR, it was as follows (somewhat pseudocode):

G := GetCurveGenerator(SECP256K1)
privkey := GenRand(SECP256K1)
G.Mul(privkey)

This can be fixed by doing pubkey := G.Copy(), but I don't think this is preferable.

This PR allows for the following (same scenario):

G := GetCurveGenerator(SECP256K1)
privkey := GenRand(SECP256K1)
pubkey := GetNewPoint(nil, curve)
pubkey.Mul(privkey, G)

Apologies for not catching this in review before @Karce. When looking at the logic between Python and Go, it made sense and looked similar. However, the bugs weren't apparent at the time until I tried to make some demo code. So, again, apologies for not catching this earlier. :(