You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Why does ConditionallySelectable require Copy? #56
I'm working on an embedded versions of ed25519, and considering whether to use your library, or roll my own. I'd like to have more control over what is copied.
On the one hand, I think ConditionallySelectable could use Clone as trait bound, and then later in the provided method conditional_swap explicitly clone (instead of the implict copy in the derefence). AFAIK, Copy types would always implement Clone in the same way, so this would strictly extend applicability of the trait. If you agree, I can PR this, it's just two changed lines.
On the other hand, the implementation I am currently using, which is a transliteration of the TweetNaCl code, does not use any copy or clone at all:
The Copy trait is a marker that the value can be duplicated by copying bits, whereas Clone can perform arbitrary logic (a "deep copy"). We require Copy because it doesn't really make sense to do constant-time operations on non-Copyable types.
Your example does use Copy, just not explicitly (e.g., in the line let t = mask & (*pi ^ *qi)).
As you note in the edit, the provided implementations are there for implementation convenience, but implementors can override them if they wish.
Yes, it's a marker trait, but it also (when implemented e.g. on newtypes) cause the compiler to change behaviour and implicitly copy things around, eliminating compile time checks. So not just "can" but also "does". (Yes, in my example copies are also done, but of individual entries, not the entire type.)
As noted, I assume all your current use cases that are Copy implement Clone also, in exactly the same way - no deep copy. Do they?
As it stands, I have the choice of making my types Copy or not using your library. Do you have some (heuristic...) argument on why I should do the former?
Also, do you foresee actual harm in replacing the Copy with a Clone bound (given it would trivially extend the applicability of the library)?
The heuristic reason why your types should be Copy is that constant-time operations implemented using bit operations should be performed on types which are bit-copyable.
You are of course free to not use this library if it doesn't suit your needs, but I don't think we will be relaxing the Copy bound.
Activity
hdevalence commentedon Nov 15, 2019
The
Copytrait is a marker that the value can be duplicated by copying bits, whereasClonecan perform arbitrary logic (a "deep copy"). We requireCopybecause it doesn't really make sense to do constant-time operations on non-Copyable types.Your example does use
Copy, just not explicitly (e.g., in the linelet t = mask & (*pi ^ *qi)).As you note in the edit, the provided implementations are there for implementation convenience, but implementors can override them if they wish.
nickray commentedon Nov 15, 2019
Yes, it's a marker trait, but it also (when implemented e.g. on newtypes) cause the compiler to change behaviour and implicitly copy things around, eliminating compile time checks. So not just "can" but also "does". (Yes, in my example copies are also done, but of individual entries, not the entire type.)
As noted, I assume all your current use cases that are Copy implement Clone also, in exactly the same way - no deep copy. Do they?
As it stands, I have the choice of making my types
Copyor not using your library. Do you have some (heuristic...) argument on why I should do the former?Also, do you foresee actual harm in replacing the Copy with a Clone bound (given it would trivially extend the applicability of the library)?
hdevalence commentedon Nov 15, 2019
The heuristic reason why your types should be
Copyis that constant-time operations implemented using bit operations should be performed on types which are bit-copyable.You are of course free to not use this library if it doesn't suit your needs, but I don't think we will be relaxing the
Copybound.