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

Make Scalar::from_bits a const fn. #325

Merged

Conversation

rubdos
Copy link
Contributor

@rubdos rubdos commented May 28, 2020

const_fn is stable since Rust 1.31 (rust-lang/rust#54835) and enables calling Scalar::from_bits(..) from other const fn contexts, potentially saving some overhead here and there.

Especially useful in contexts where constants are being built from a bit pattern.


My use case is a constructor for a certain large number, where I'd rather start from a slice and set the correct bits that just hardcode in all 32 bytes at once.

I'm not 100% sure about the compatibility guarantees when switching an existing function to const, but I imagine it shouldn't interfere anywhere, since the whole test suite still passes.

The other constructors use a call to .reduce(), so I didn't bother looking deeper whether they can be made const too.

const_fn is stable since Rust 1.31
(rust-lang/rust#54835) and enables calling
`Scalar::from_bits(..)` from other const fn contexts, potentially
saving some overhead here and there.

Especially useful in contexts where constants are being built from a bit
pattern.
@hdevalence
Copy link
Contributor

Sounds good to me, thanks for the PR!

@hdevalence hdevalence merged commit e342f25 into dalek-cryptography:master May 29, 2020
@hdevalence
Copy link
Contributor

@rubdos This change is published in 2.1.0

@rubdos
Copy link
Contributor Author

rubdos commented May 29, 2020

@rubdos This change is published in 2.1.0

We're mostly running against git/develop anyway, doesn't matter too much to me at this time. Thanks for the feedback! EDIT, nvm, we're running bulletproofs against develop, not this :-)

@rubdos rubdos deleted the const_fn_for_scalar_from_bits branch May 29, 2020 20:37
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.

None yet

2 participants