Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

elliptic-curve: ScalarBytes::from_uint #651

Merged
merged 1 commit into from
Jun 5, 2021
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: 8 additions & 2 deletions elliptic-curve/src/scalar/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ where
/// Create new [`ScalarBytes`], checking that the given input is within
/// range of the [`Curve::ORDER`].
pub fn new(bytes: FieldBytes<C>) -> CtOption<Self> {
let is_some = C::UInt::from_be_byte_array(&bytes).ct_lt(&C::ORDER);
CtOption::new(Self { inner: bytes }, is_some)
Self::from_uint(&C::UInt::from_be_byte_array(&bytes))
}

/// Create [`ScalarBytes`] from the provided `C::UInt`.
pub fn from_uint(uint: &C::UInt) -> CtOption<Self> {
let inner = uint.to_be_byte_array();
let in_range = uint.ct_lt(&C::ORDER);
CtOption::new(Self { inner }, in_range)
}

/// Convert from a [`Scalar`] type for this curve.
Expand Down