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

reduce boilerplate implementing comparisons for user-defined types #6

Closed

Conversation

cosmicexplorer
Copy link

@cosmicexplorer cosmicexplorer commented Jun 30, 2022

Problem

In signalapp/libsignal#469, we discussed having to hand-roll a constant-time comparison function for a public key with a slice of bytes and an enum tag. After seeing dalek-cryptography#78 where we implement ConstantTimeEq for slices, I realized we could extend this method of iterated constant-time computation to make it more fluent to implement comparison operations for structs with multiple fields.

Proposed Solution

  1. Introduce IteratedOperation and IteratedEq to modularize the approach used in the existing ConstantTimeEq impl for slices.
    • Add a doctest demonstrating how to apply this to user structs with multiple fields.
  2. Develop a novel method to calculate ConstantTimeGreater over a collection of elements as IteratedGreater.
    • Implement ConstantTimeGreater for slices using IteratedGreater.
  3. Expose a Convertible trait which implements ConstantTime{Eq,Greater,Less} for structs which can be cheaply converted into a constant-time comparable type.

Result

@cosmicexplorer cosmicexplorer force-pushed the expand-constant-time-cmp branch 2 times, most recently from 3bb8d59 to eb31e20 Compare June 30, 2022 07:34
@cosmicexplorer cosmicexplorer changed the title impl ConstantTime{Less,Greater} for slices introduce IteratedOperation to apply comparisons lexicographically Jul 1, 2022
/// impl ConstantTimeGreater for S {
/// fn ct_gt(&self, other: &Self) -> Choice {
/// let mut x = IteratedGreater::initiate();
/// x.apply_gt(&(self.len as u64), &(other.len as u64));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When #7 is merged, this can just be:

Suggested change
/// x.apply_gt(&(self.len as u64), &(other.len as u64));
/// x.apply_gt(&self.len, &other.len);

@cosmicexplorer cosmicexplorer changed the title introduce IteratedOperation to apply comparisons lexicographically introduce tools to enable constant-time comparisons for user-defined aggregate data types Jul 1, 2022
@cosmicexplorer cosmicexplorer changed the title introduce tools to enable constant-time comparisons for user-defined aggregate data types introduce tools to extend constant-time comparisons to user-defined aggregate data types Jul 1, 2022
@cosmicexplorer cosmicexplorer changed the title introduce tools to extend constant-time comparisons to user-defined aggregate data types make it easier to extend constant-time comparisons to user-defined aggregate data types Jul 1, 2022
@cosmicexplorer cosmicexplorer changed the title make it easier to extend constant-time comparisons to user-defined aggregate data types reduce boilerplate implementing comparisons for user-defined aggregate data types Jul 1, 2022
@cosmicexplorer cosmicexplorer changed the title reduce boilerplate implementing comparisons for user-defined aggregate data types reduce boilerplate implementing comparisons for user-defined types Jul 1, 2022
@cosmicexplorer cosmicexplorer force-pushed the expand-constant-time-cmp branch 3 times, most recently from 138437d to c0a3e55 Compare July 1, 2022 10:58
@cosmicexplorer cosmicexplorer force-pushed the expand-constant-time-cmp branch from c0a3e55 to 8533dce Compare July 1, 2022 11:04
@cosmicexplorer
Copy link
Author

This repo is unmaintained, use the original instead: https://github.com/dalek-cryptography/subtle.

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