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

Better constraint that Output is ProjectivePoint #906

Merged
merged 1 commit into from
Jan 19, 2022

Conversation

daxpedda
Copy link
Contributor

I encountered quiet the issue:

fn test<C: GroupDigest>() {
    let var: ProjectivePoint<C> =
        C::hash_from_bytes::<ExpandMsgXmd<sha2::Sha256>>(&[b"test"], b"test");
}
Gives the following error
error[E0308]: mismatched types
  --> src/group/elliptic_curve.rs:34:9
   |
33 |     let var: ProjectivePoint<C> =
   |              ------------------ expected due to this
34 |         C::hash_from_bytes::<ExpandMsgXmd<sha2::Sha256>>(&[b"test"], b"test");
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found enum `core::result::Result`
   |
   = note: expected associated type `<C as GroupDigest>::Output`
                         found enum `core::result::Result<<C as GroupDigest>::Output, elliptic_curve::Error>`
help: consider constraining the associated type `<C as GroupDigest>::Output` to `core::result::Result<<C as GroupDigest>::Output, elliptic_curve::Error>`
   |
32 | fn test<C: GroupDigest<Output = core::result::Result<<C as GroupDigest>::Output, elliptic_curve::Error>>>() {
   |                       ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

For more information about this error, try `rustc --explain E0308`.

Doing this:

fn test<C>()
where
    C: GroupDigest<Output = ProjectivePoint<C>>,
{
    let var: ProjectivePoint<C> =
        C::hash_from_bytes::<ExpandMsgXmd<sha2::Sha256>>(&[b"test"], b"test");
}
Doesn't help either
error[E0275]: overflow evaluating the requirement `<C as ProjectiveArithmetic>::ProjectivePoint == _`
  --> src/group/elliptic_curve.rs:32:1
   |
32 | / fn test<C>()
33 | | where
34 | |     C: GroupDigest<Output = ProjectivePoint<C>>,
   | |________________________________________________^

For more information about this error, try `rustc --explain E0275`.

I couldn't find any other solution to this then removing the associated type Output and adding a where-clause to constraint ProjectivePoint to CofactorGroup.

Alternatively I would suggest adding clear_cofactor to some other trait required by ProjectivePoint or require CofactorGroup for ProjectivePoint.

CC @tarcieri @mikelodder7

Copy link
Member

@tarcieri tarcieri left a comment

Choose a reason for hiding this comment

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

Seems fine to me. @mikelodder7 any thoughts?

@mikelodder7
Copy link
Contributor

Seems fine to me. This whole thing is complex unfortunately.

@tarcieri tarcieri merged commit 30cdb2e into RustCrypto:master Jan 19, 2022
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.

3 participants