From 3a61a0b70ce77a67658a007f0ffa00029de249b0 Mon Sep 17 00:00:00 2001 From: Ruben De Smet Date: Thu, 28 May 2020 10:28:28 +0200 Subject: [PATCH] Make Scalar::from_bits a const fn. const_fn is stable since Rust 1.31 (https://github.com/rust-lang/rust/pull/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. --- src/scalar.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scalar.rs b/src/scalar.rs index d365d25f1..95493c247 100644 --- a/src/scalar.rs +++ b/src/scalar.rs @@ -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;