Skip to content

Commit 3a61a0b

Browse files
committed
Make Scalar::from_bits a const fn.
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.
1 parent 805cdbf commit 3a61a0b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/scalar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl Scalar {
243243
/// This function is intended for applications like X25519 which
244244
/// require specific bit-patterns when performing scalar
245245
/// multiplication.
246-
pub fn from_bits(bytes: [u8; 32]) -> Scalar {
246+
pub const fn from_bits(bytes: [u8; 32]) -> Scalar {
247247
let mut s = Scalar{bytes};
248248
// Ensure that s < 2^255 by masking the high bit
249249
s.bytes[31] &= 0b0111_1111;

0 commit comments

Comments
 (0)