Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions elliptic-curve/src/secret_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -117,8 +117,12 @@ where
}

/// Create a new secret key from a scalar value.
pub fn new(scalar: ScalarPrimitive<C>) -> Self {
Self { inner: scalar }
///
/// # Returns
///
/// This will return a none if the scalar is all-zero.
pub fn new(scalar: ScalarPrimitive<C>) -> CtOption<Self> {
CtOption::new(Self { inner: scalar }, !scalar.is_zero())
}

/// Borrow the inner secret [`ScalarPrimitive`] value.
Expand Down