elliptic_curve/
scalar.rs

1//! Scalar types.
2
3use subtle::Choice;
4
5pub(crate) mod core;
6
7#[cfg(feature = "arithmetic")]
8pub(crate) mod nonzero;
9
10#[cfg(feature = "arithmetic")]
11use crate::ScalarArithmetic;
12
13/// Scalar field element for a particular elliptic curve.
14#[cfg(feature = "arithmetic")]
15#[cfg_attr(docsrs, doc(cfg(feature = "arithmetic")))]
16pub type Scalar<C> = <C as ScalarArithmetic>::Scalar;
17
18/// Bit representation of a scalar field element of a given curve.
19#[cfg(feature = "bits")]
20#[cfg_attr(docsrs, doc(cfg(feature = "bits")))]
21pub type ScalarBits<C> = ff::FieldBits<<Scalar<C> as ff::PrimeFieldBits>::ReprBits>;
22
23/// Is this scalar greater than n / 2?
24///
25/// # Returns
26///
27/// - For scalars 0 through n / 2: `Choice::from(0)`
28/// - For scalars (n / 2) + 1 through n - 1: `Choice::from(1)`
29pub trait IsHigh {
30    /// Is this scalar greater than or equal to n / 2?
31    fn is_high(&self) -> Choice;
32}