scgbckbone/python-secp256k1

Context handling

Opened this issue · 1 comments

In current implementation both contexts (sign/verify) are created when library is initialized. They are also randomized during this phase. Then they are used all the time (without further randomization). Is this approach correct? Or should at least context_sign be randomized more frequently?

I secp256k1 all function take context as first argument. Here context cannot be passed to function as it will use the ones created at initialization phase. Should this be reworked?

If one needs to randomize (for reasons not know to me at the moment) you can import default context that is used throughout the library and randomize it:

from pysecp256k1 import context_randomize, secp256k1_context_sign
context_randomize(secp256k1_context_sign)

context_randomize was adjusted to randomize default sign context (secp256k1_context_sign) if provided with no ctx argument.

from pysecp256k1 import context_randomize
context_randomize()  # this will randomize secp256k1_context_sign with 32 byte randomness from PRNG (os.urandom)
# in case you wan to to pass your own randomness
context_randomize(seed32=<32 bytes of randomness>)