Skip to content

Commit

Permalink
Make Scalar::from_bits a const fn.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
plotskogwq authored and rubdos committed May 28, 2020
1 parent 62af577 commit 022685d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl Scalar {
/// This function is intended for applications like X25519 which
/// require specific bit-patterns when performing scalar
/// multiplication.
pub fn from_bits(bytes: [u8; 32]) -> Scalar {
pub const fn from_bits(bytes: [u8; 32]) -> Scalar {
let mut s = Scalar{bytes};
// Ensure that s < 2^255 by masking the high bit
s.bytes[31] &= 0b0111_1111;
Expand Down

0 comments on commit 022685d

Please sign in to comment.