Skip to content

[DO NOT MERGE] Attempt at making a constant-time PartialOrd impl #79

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

Conversation

isislovecruft
Copy link
Member

I don't actually like this approach because there's no way to get the integration with all of Rust's functionality through the Ordering::{Less,Equal,Greater} enum without branching on whether the value is -1, 0, or 1. Because Ordering is implemented internally with i8s:

    pub enum Ordering {
        Less = -1,
        Equal = 0,
        Greater = 1,
    }

I assumed we could just construct an Ordering like so:

    let x = -1;
    let cmp = Ordering(x);

    assert!(::std::matches!(cmp, Ordering::Less {..} ));

But that turns out to not be the case? If it is, then I don't see a clear way to make this constant-time.

A default implementation is provided for any type which implements
ConstantTimeGreaterThan + ConstantTimeEq.
I don't actually like this approach because there's no way to get the
integration with all of Rust's functionality through the
Ordering::{Less,Equal,Greater} enum without branching on whether the value is
-1, 0, or 1.  Because Ordering is implemented internally with i8s:

    pub enum Ordering {
        Less = -1,
        Equal = 0,
        Greater = 1,
    }

I assumed we could just construct an Ordering like so:

    let x = -1;
    let cmp = Ordering(x);

    assert!(::std::matches!(cmp, Ordering::Less {..} ));

But that turns out to not be the case?  If it is, then I don't see a clear way
to make this constant-time.
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