Skip to content

Context randomization tracking issue #388

Open
@apoelstra

Description

@apoelstra

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:

  1. We remove the global-context-less-secure feature; global-context enables the global context, and we rerandomize it on first use if rand is also enabled.
  2. Similarly we randomize all signing contexts on creation, if rand is enabled
  3. We also change sign() and sign_schnorr to rerandomize the context after each signing operation. We add a sign_no_rerandomize method to opt out of this
    1. 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
    2. This would also force the signing API to take a &mut pointer to the context object, which really sucks.
  4. 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 add sign_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.)

cc @TheBlueMatt @tcharding

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions