Description
Consolidating discussion from #385 #386 #387. Tobin is proposing to re-randomize contexts, not just the global one, when they are created -- though naturally only if the rand
feature is enabled. Our current situation is kinda weird -- for users of global contexts, we require they "opt out" of rerandomization by choosing the global-context-less-secure
feature vs the global-context
flag, while ordinary users must "opt in" by creating a context then explicitly calling randomize()
on it.
A bit of context (hah):
- re-randomization is not free: it takes about as long as a signing operation (around 50us on a desktop computer)
- on the other hand, context generation is extremely expensive (multiple milliseconds on a desktop computer) so this is fine during context creation; but on the third hand, now that we are moving toward pre-computing all the tables, context creation will be nearly free, so the re-randomization would then be the bulk of the "create context" operation
- re-randomization of verification contexts is a no-op. This discussion is only about signing contexts
Here is my proposal:
- We remove the
global-context-less-secure
feature;global-context
enables the global context, and we rerandomize it on first use ifrand
is also enabled. - Similarly we randomize all signing contexts on creation, if
rand
is enabled - We also change
sign()
andsign_schnorr
to rerandomize the context after each signing operation. We add asign_no_rerandomize
method to opt out of this- This would nearly double signing time, although sipa points out that there is a theoretical way, with help from upstream, we could make the rerandomization 99%+ faster, by essentially only doing one bit of re-randomization per signature
- This would also force the signing API to take a
&mut
pointer to the context object, which really sucks.
- We leave the
rerandomize()
methods in place but document that users have basically no reason to call them manually.
Alternate proposals:
- Leave the
sign
methods alone but addsign_randomize
ones which also do the re-randomization - Embed a mutex in our
Context
objects so that re-randomization can be done with normal non-mutable references. (May be OK with "fast re-randomization", almost certainly not with full re-randomization, which would basically cause parallel signing operations to be force-serialized.)
See also bitcoin-core/secp256k1#881 (which is not the "one-bit rerandomization" idea, but is similar and has a similar effect).
See also bitcoin-core/secp256k1#1058 which will affect upstream's blinding logic.