diff --git a/elliptic-curve/src/secret_key.rs b/elliptic-curve/src/secret_key.rs index 1c15dc797..f1559c8c4 100644 --- a/elliptic-curve/src/secret_key.rs +++ b/elliptic-curve/src/secret_key.rs @@ -11,7 +11,7 @@ mod pkcs8; use crate::{Curve, Error, FieldBytes, Result, ScalarPrimitive}; use core::fmt::{self, Debug}; use hybrid_array::typenum::Unsigned; -use subtle::{Choice, ConstantTimeEq}; +use subtle::{Choice, ConstantTimeEq, CtOption}; use zeroize::{Zeroize, ZeroizeOnDrop, Zeroizing}; #[cfg(feature = "arithmetic")] @@ -117,8 +117,12 @@ where } /// Create a new secret key from a scalar value. - pub fn new(scalar: ScalarPrimitive) -> Self { - Self { inner: scalar } + /// + /// # Returns + /// + /// This will return a none if the scalar is all-zero. + pub fn new(scalar: ScalarPrimitive) -> CtOption { + CtOption::new(Self { inner: scalar }, !scalar.is_zero()) } /// Borrow the inner secret [`ScalarPrimitive`] value.