Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BoxedUint: add cond_map and cond_and_then #352

Merged
merged 1 commit into from
Nov 29, 2023

Conversation

tarcieri
Copy link
Member

Unfortunately BoxedUint can't impl subtle::ConditionallySelectable due to a supertrait bound on Copy. See dalek-cryptography/subtle#94

This bound is required by CtOption::map and CtOption::and_then which are important for writing constant-time code.

As a workaround which makes it still possible to leverate CtOption, this adds special BoxedUint-specialized combinators that are able to work around this issue by generating a placeholder (zero) value to pass to the provided callbacks in the event CtOption is none.

This requires branching on the output of CtOption (which is unavoidable without an upstream fix in subtle itself), but still ensures that the provided callback function is called with a BoxedUint of a matching number of limbs regardless of whether the CtOption is some or none, which is the best we can do for now (and really quite close to what subtle is doing under the hood anyway).

Unfortunately `BoxedUint` can't impl `subtle::ConditionallySelectable`
due to a supertrait bound on `Copy`. See dalek-cryptography/subtle#94

This bound is required by `CtOption::map` and `CtOption::and_then` which
are important for writing constant-time code.

As a workaround which makes it still possible to leverate `CtOption`,
this adds special `BoxedUint`-specialized combinators that are able to
work around this issue by generating a placeholder (zero) value to pass
to the provided callbacks in the event `CtOption` is none.

This requires branching on the output of `CtOption` (which is
unavoidable without an upstream fix in `subtle` itself), but still
ensures that the provided callback function is called with a `BoxedUint`
of a matching number of limbs regardless of whether the `CtOption` is
some or none, which is the best we can do for now (and really quite
close to what `subtle` is doing under the hood anyway).
@tarcieri tarcieri merged commit 4e061ef into master Nov 29, 2023
16 checks passed
@tarcieri tarcieri deleted the boxed-uint/ct-combinators branch November 29, 2023 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant