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

Add traits to connect integers and residue represenations #431

Merged
merged 6 commits into from
Dec 20, 2023

Conversation

fjarri
Copy link
Contributor

@fjarri fjarri commented Dec 15, 2023

A part of #348
Fixes #448

All the naming is up for debate (see also #351)

  • add Monty associated type to Integer linking it to the corresponding Montgomery form
  • add Monty trait with an associated type linking back to the corresponding Integer and a bunch of bounds (similar to Integer)
  • remove the bound on Square which made it hard to make Square a bound to other traits. This means that there's no default implementation anymore.
  • add SquareAssign trait.

I will make a separate PR adding div_by_2() to Monty after #436 is merged

@fjarri fjarri marked this pull request as ready for review December 15, 2023 00:24
@tarcieri
Copy link
Member

Elsewhere *Repr is used for serialized bytestrings.

It might be good to consider the naming for these traits in conjunction with #351

@tarcieri
Copy link
Member

Instead of HasResidueRepr I think we can just add an associated type to Integer.

@fjarri
Copy link
Contributor Author

fjarri commented Dec 19, 2023

I wasn't sure if bundling everything into one trait is a good idea. But I don't insist on it.

@tarcieri
Copy link
Member

Well, if we do end up putting it in its own trait, it seems like a good trait for Integer to bound on, anyway

@fjarri fjarri changed the title Add HasResidueRepr and ResidueRepr traits to connect integers and residue represenations Add traits to connect integers and residue represenations Dec 20, 2023
src/traits.rs Outdated Show resolved Hide resolved
@fjarri fjarri changed the title Add traits to connect integers and residue represenations [WIP] Add traits to connect integers and residue represenations Dec 20, 2023
@fjarri
Copy link
Contributor Author

fjarri commented Dec 20, 2023

Can't make it a draft, but I'm still working on it: adding trait bounds to the Montgomery trait to make it more like Integer.

One problem not sure how to solve: the current trait bound on Square makes it difficult to use it as a bound. Maybe just remove it? It's only needed for the default implementation which is trivial.

@tarcieri
Copy link
Member

Sure, you can remove Square and just add it as a trait method elsewhere

@fjarri
Copy link
Contributor Author

fjarri commented Dec 20, 2023

No, I meant remove the bound but keep the trait. That should be enough.

@fjarri
Copy link
Contributor Author

fjarri commented Dec 20, 2023

Ok this should be ready for review now.

@tarcieri
Copy link
Member

Will look if you want to remove [WIP]

@fjarri fjarri changed the title [WIP] Add traits to connect integers and residue represenations Add traits to connect integers and residue represenations Dec 20, 2023
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.

One suggestion but this looks fine

@tarcieri tarcieri merged commit 8416c24 into RustCrypto:master Dec 20, 2023
16 checks passed
@fjarri fjarri deleted the residue-traits branch December 20, 2023 21:32
@tarcieri tarcieri mentioned this pull request Jan 22, 2025
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.

Trait for *Residue / Montgomery form
2 participants