pub struct NonZero<T>(/* private fields */);Implementations§
Source§impl<T> NonZero<T>
impl<T> NonZero<T>
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Returns wrapped value
Source§impl<E: Curve> NonZero<Point<E>>
impl<E: Curve> NonZero<Point<E>>
Sourcepub fn from_point(point: Point<E>) -> Option<Self>
pub fn from_point(point: Point<E>) -> Option<Self>
Constructs non-zero point
Returns None if point is zero
Sourcepub fn ct_from_point(point: Point<E>) -> CtOption<Self>
pub fn ct_from_point(point: Point<E>) -> CtOption<Self>
Constructs non-zero point (constant time)
Returns None if point is zero
Source§impl<E: Curve> NonZero<Scalar<E>>
impl<E: Curve> NonZero<Scalar<E>>
Sourcepub fn random<R: RngCore>(rng: &mut R) -> Self
pub fn random<R: RngCore>(rng: &mut R) -> Self
Generates random non-zero scalar
§Guarantees
- Uniform distribution
Output scalar is uniformly distributed (given that provided PRNG outputs uniformly distributed bytes), with possible negligible bias respective to curve target security level - Constant-time
Random generation algorithm does not branch on input randomness, and in particular, it does not use rejection-sampling strategy (might not be the case with negligible probability respective to the curve target security level1) - Reproducible
When random generation algorithm is given the same PRNG with the same seed, it always outputs the same scalar on all platforms
If you don’t need constant-time/reproducibility properties, you can use random_vartime instead which is typically faster.
§Panics
Panics if randomness source returned 100 zero scalars in a row. It happens with negligible probability, e.g. for secp256k1 curve it’s about $2^{-25600}$, which practically means that randomness source is broken.
we use rejection-sampling strategy in case if a zero scalar is generated, however, probability of that happening is negligible ↩
Sourcepub fn random_vartime<R: RngCore>(rng: &mut R) -> Self
pub fn random_vartime<R: RngCore>(rng: &mut R) -> Self
Generates random non-zero scalar using variable time algorithm
§Guarantees
- Uniform distribution
Output scalar is uniformly distributed (given that provided PRNG outputs uniformly distributed bytes), with possible negligible bias respective to curve target security level
Unlike random method, this one is not constant-time nor reproducible, but
often it’s faster.
§Panics
Panics if randomness source returned 100 zero scalars in a row. It happens with negligible probability, e.g. for secp256k1 curve it’s about $2^{-25600}$, which practically means that randomness source is broken.
Sourcepub fn from_hash<D: Digest>(data: &impl Digestable) -> Self
Available on crate feature hash-to-scalar only.
pub fn from_hash<D: Digest>(data: &impl Digestable) -> Self
hash-to-scalar only.Hashes the input and outputs scalar
Input can be any structured data that implements Digestable
trait (see udigest crate).
§How it works
It works by instantiating HashRng CSPRNG seeded from provided data.
Then it’s used to derive the scalar.
§Security considerations
It’s not constant time. It doesn’t follow any existing standards for hash to scalar primitive.
§Example
use generic_ec::{Scalar, NonZero, curves::Secp256k1};
use sha2::Sha256;
#[derive(udigest::Digestable)]
struct Data<'a> {
nonce: &'a [u8],
param_a: &'a str,
param_b: u128,
// ...
}
let scalar = NonZero::<Scalar<Secp256k1>>::from_hash::<Sha256>(&Data {
nonce: b"some data",
param_a: "some other data",
param_b: 12345,
// ...
});Sourcepub fn from_scalar(scalar: Scalar<E>) -> Option<Self>
pub fn from_scalar(scalar: Scalar<E>) -> Option<Self>
Constructs non-zero scalar
Returns None if scalar is zero
Sourcepub fn ct_from_scalar(scalar: Scalar<E>) -> CtOption<Self>
pub fn ct_from_scalar(scalar: Scalar<E>) -> CtOption<Self>
Constructs non-zero scalar (constant time)
Returns None if scalar is zero
Sourcepub fn invert(&self) -> NonZero<Scalar<E>>
pub fn invert(&self) -> NonZero<Scalar<E>>
Returns scalar inverse $S^{-1}$
Similar to Scalar::invert, but this function is always defined as inverse is defined for all non-zero scalars
Sourcepub fn into_secret(self) -> NonZero<SecretScalar<E>>
pub fn into_secret(self) -> NonZero<SecretScalar<E>>
Upgrades the non-zero scalar into non-zero SecretScalar
Source§impl<E: Curve> NonZero<SecretScalar<E>>
impl<E: Curve> NonZero<SecretScalar<E>>
Sourcepub fn random<R: RngCore + CryptoRng>(rng: &mut R) -> Self
pub fn random<R: RngCore + CryptoRng>(rng: &mut R) -> Self
Generates random non-zero scalar
§Guarantees
- Uniform distribution
Output scalar is uniformly distributed (given that provided PRNG outputs uniformly distributed bytes), with possible negligible bias respective to curve target security level - Constant-time
Random generation algorithm does not branch on input randomness, and in particular, it does not use rejection-sampling strategy (might not be the case with negligible probability respective to the curve target security level1) - Reproducible
When random generation algorithm is given the same PRNG with the same seed, it always outputs the same scalar on all platforms
If you don’t need constant-time/reproducibility properties, you can use random_vartime instead which is typically faster.
§Panics
Panics if randomness source returned 100 zero scalars in a row. It happens with negligible probability, e.g. for secp256k1 curve it’s about $2^{-25600}$, which practically means that randomness source is broken.
we use rejection-sampling strategy in case if a zero scalar is generated, however, probability of that happening is negligible ↩
Sourcepub fn random_vartime<R: RngCore + CryptoRng>(rng: &mut R) -> Self
pub fn random_vartime<R: RngCore + CryptoRng>(rng: &mut R) -> Self
Generates random non-zero scalar using variable time algorithm
§Guarantees
- Uniform distribution
Output scalar is uniformly distributed (given that provided PRNG outputs uniformly distributed bytes), with possible negligible bias respective to curve target security level
Unlike random method, this one is not constant-time nor reproducible, but
often it’s faster.
§Panics
Panics if randomness source returned 100 zero scalars in a row. It happens with negligible probability, e.g. for secp256k1 curve it’s about $2^{-25600}$, which practically means that randomness source is broken.
Sourcepub fn from_secret_scalar(scalar: SecretScalar<E>) -> Option<Self>
pub fn from_secret_scalar(scalar: SecretScalar<E>) -> Option<Self>
Constructs non-zero scalar
Returns None if scalar is zero
Sourcepub fn ct_from_secret_scalar(secret_scalar: SecretScalar<E>) -> CtOption<Self>
pub fn ct_from_secret_scalar(secret_scalar: SecretScalar<E>) -> CtOption<Self>
Constructs non-zero scalar (constant time)
Returns None if scalar is zero
Sourcepub fn invert(&self) -> NonZero<SecretScalar<E>>
pub fn invert(&self) -> NonZero<SecretScalar<E>>
Returns scalar inverse $S^{-1}$
Similar to SecretScalar::invert, but this function is always defined as inverse is defined for all non-zero scalars
Trait Implementations§
Source§impl<E: Curve> Add<&NonZero<SecretScalar<E>>> for &NonZero<SecretScalar<E>>
impl<E: Curve> Add<&NonZero<SecretScalar<E>>> for &NonZero<SecretScalar<E>>
Source§impl<E: Curve> Add<&NonZero<SecretScalar<E>>> for &SecretScalar<E>
impl<E: Curve> Add<&NonZero<SecretScalar<E>>> for &SecretScalar<E>
Source§impl<E: Curve> Add<&NonZero<SecretScalar<E>>> for NonZero<SecretScalar<E>>
impl<E: Curve> Add<&NonZero<SecretScalar<E>>> for NonZero<SecretScalar<E>>
Source§impl<E: Curve> Add<&NonZero<SecretScalar<E>>> for SecretScalar<E>
impl<E: Curve> Add<&NonZero<SecretScalar<E>>> for SecretScalar<E>
Source§impl<E: Curve> Add<&SecretScalar<E>> for &NonZero<SecretScalar<E>>
impl<E: Curve> Add<&SecretScalar<E>> for &NonZero<SecretScalar<E>>
Source§impl<E: Curve> Add<&SecretScalar<E>> for NonZero<SecretScalar<E>>
impl<E: Curve> Add<&SecretScalar<E>> for NonZero<SecretScalar<E>>
Source§impl<E: Curve> Add<NonZero<SecretScalar<E>>> for &NonZero<SecretScalar<E>>
impl<E: Curve> Add<NonZero<SecretScalar<E>>> for &NonZero<SecretScalar<E>>
Source§impl<E: Curve> Add<NonZero<SecretScalar<E>>> for &SecretScalar<E>
impl<E: Curve> Add<NonZero<SecretScalar<E>>> for &SecretScalar<E>
Source§impl<E: Curve> Add<NonZero<SecretScalar<E>>> for SecretScalar<E>
impl<E: Curve> Add<NonZero<SecretScalar<E>>> for SecretScalar<E>
Source§impl<E: Curve> Add<SecretScalar<E>> for &NonZero<SecretScalar<E>>
impl<E: Curve> Add<SecretScalar<E>> for &NonZero<SecretScalar<E>>
Source§impl<E: Curve> Add<SecretScalar<E>> for NonZero<SecretScalar<E>>
impl<E: Curve> Add<SecretScalar<E>> for NonZero<SecretScalar<E>>
Source§impl<E: Curve> AddAssign<&NonZero<SecretScalar<E>>> for Scalar<E>
impl<E: Curve> AddAssign<&NonZero<SecretScalar<E>>> for Scalar<E>
Source§fn add_assign(&mut self, rhs: &NonZero<SecretScalar<E>>)
fn add_assign(&mut self, rhs: &NonZero<SecretScalar<E>>)
+= operation. Read moreSource§impl<E: Curve> AddAssign<NonZero<SecretScalar<E>>> for Scalar<E>
impl<E: Curve> AddAssign<NonZero<SecretScalar<E>>> for Scalar<E>
Source§fn add_assign(&mut self, rhs: NonZero<SecretScalar<E>>)
fn add_assign(&mut self, rhs: NonZero<SecretScalar<E>>)
+= operation. Read moreSource§impl<E: Curve> AlwaysHasAffineX<E> for NonZero<Point<E>>where
Point<E>: HasAffineX<E>,
impl<E: Curve> AlwaysHasAffineX<E> for NonZero<Point<E>>where
Point<E>: HasAffineX<E>,
Source§fn x(&self) -> Coordinate<E>
fn x(&self) -> Coordinate<E>
Source§impl<E: Curve> AlwaysHasAffineXY<E> for NonZero<Point<E>>where
Point<E>: HasAffineXY<E>,
impl<E: Curve> AlwaysHasAffineXY<E> for NonZero<Point<E>>where
Point<E>: HasAffineXY<E>,
Source§fn from_coords(coords: &Coordinates<E>) -> Option<Self>
fn from_coords(coords: &Coordinates<E>) -> Option<Self>
Source§impl<E: Curve> AlwaysHasAffineY<E> for NonZero<Point<E>>where
Point<E>: HasAffineY<E>,
impl<E: Curve> AlwaysHasAffineY<E> for NonZero<Point<E>>where
Point<E>: HasAffineY<E>,
Source§fn y(&self) -> Coordinate<E>
fn y(&self) -> Coordinate<E>
Source§impl<T: ConstantTimeEq> ConstantTimeEq for NonZero<T>
impl<T: ConstantTimeEq> ConstantTimeEq for NonZero<T>
Source§impl<'de, T> Deserialize<'de> for NonZero<T>
impl<'de, T> Deserialize<'de> for NonZero<T>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<'de, T> DeserializeAs<'de, NonZero<T>> for Compact
Available on crate feature serde only.
impl<'de, T> DeserializeAs<'de, NonZero<T>> for Compact
serde only.Source§fn deserialize_as<D>(deserializer: D) -> Result<NonZero<T>, D::Error>where
D: Deserializer<'de>,
fn deserialize_as<D>(deserializer: D) -> Result<NonZero<T>, D::Error>where
D: Deserializer<'de>,
Source§impl<T> Digestable for NonZero<T>where
T: Digestable,
impl<T> Digestable for NonZero<T>where
T: Digestable,
Source§fn unambiguously_encode<B>(&self, encoder: EncodeValue<'_, B>)where
B: Buffer,
fn unambiguously_encode<B>(&self, encoder: EncodeValue<'_, B>)where
B: Buffer,
Source§impl<E: Curve> From<NonZero<SecretScalar<E>>> for SecretScalar<E>
impl<E: Curve> From<NonZero<SecretScalar<E>>> for SecretScalar<E>
Source§fn from(secret_scalar: NonZero<SecretScalar<E>>) -> Self
fn from(secret_scalar: NonZero<SecretScalar<E>>) -> Self
Source§impl<E: Curve> Mul<&NonZero<SecretScalar<E>>> for &NonZero<SecretScalar<E>>
impl<E: Curve> Mul<&NonZero<SecretScalar<E>>> for &NonZero<SecretScalar<E>>
Source§impl<E: Curve> Mul<&NonZero<SecretScalar<E>>> for NonZero<SecretScalar<E>>
impl<E: Curve> Mul<&NonZero<SecretScalar<E>>> for NonZero<SecretScalar<E>>
Source§impl<E: Curve> Mul<NonZero<SecretScalar<E>>> for &NonZero<SecretScalar<E>>
impl<E: Curve> Mul<NonZero<SecretScalar<E>>> for &NonZero<SecretScalar<E>>
Source§impl<E: Curve> MulAssign<&NonZero<SecretScalar<E>>> for NonZero<Point<E>>
impl<E: Curve> MulAssign<&NonZero<SecretScalar<E>>> for NonZero<Point<E>>
Source§fn mul_assign(&mut self, rhs: &NonZero<SecretScalar<E>>)
fn mul_assign(&mut self, rhs: &NonZero<SecretScalar<E>>)
*= operation. Read moreSource§impl<E: Curve> MulAssign<&NonZero<SecretScalar<E>>> for NonZero<Scalar<E>>
impl<E: Curve> MulAssign<&NonZero<SecretScalar<E>>> for NonZero<Scalar<E>>
Source§fn mul_assign(&mut self, rhs: &NonZero<SecretScalar<E>>)
fn mul_assign(&mut self, rhs: &NonZero<SecretScalar<E>>)
*= operation. Read moreSource§impl<E: Curve> MulAssign<&NonZero<SecretScalar<E>>> for Point<E>
impl<E: Curve> MulAssign<&NonZero<SecretScalar<E>>> for Point<E>
Source§fn mul_assign(&mut self, rhs: &NonZero<SecretScalar<E>>)
fn mul_assign(&mut self, rhs: &NonZero<SecretScalar<E>>)
*= operation. Read moreSource§impl<E: Curve> MulAssign<&NonZero<SecretScalar<E>>> for Scalar<E>
impl<E: Curve> MulAssign<&NonZero<SecretScalar<E>>> for Scalar<E>
Source§fn mul_assign(&mut self, rhs: &NonZero<SecretScalar<E>>)
fn mul_assign(&mut self, rhs: &NonZero<SecretScalar<E>>)
*= operation. Read moreSource§impl<E: Curve> MulAssign<NonZero<SecretScalar<E>>> for NonZero<Point<E>>
impl<E: Curve> MulAssign<NonZero<SecretScalar<E>>> for NonZero<Point<E>>
Source§fn mul_assign(&mut self, rhs: NonZero<SecretScalar<E>>)
fn mul_assign(&mut self, rhs: NonZero<SecretScalar<E>>)
*= operation. Read moreSource§impl<E: Curve> MulAssign<NonZero<SecretScalar<E>>> for NonZero<Scalar<E>>
impl<E: Curve> MulAssign<NonZero<SecretScalar<E>>> for NonZero<Scalar<E>>
Source§fn mul_assign(&mut self, rhs: NonZero<SecretScalar<E>>)
fn mul_assign(&mut self, rhs: NonZero<SecretScalar<E>>)
*= operation. Read moreSource§impl<E: Curve> MulAssign<NonZero<SecretScalar<E>>> for Point<E>
impl<E: Curve> MulAssign<NonZero<SecretScalar<E>>> for Point<E>
Source§fn mul_assign(&mut self, rhs: NonZero<SecretScalar<E>>)
fn mul_assign(&mut self, rhs: NonZero<SecretScalar<E>>)
*= operation. Read moreSource§impl<E: Curve> MulAssign<NonZero<SecretScalar<E>>> for Scalar<E>
impl<E: Curve> MulAssign<NonZero<SecretScalar<E>>> for Scalar<E>
Source§fn mul_assign(&mut self, rhs: NonZero<SecretScalar<E>>)
fn mul_assign(&mut self, rhs: NonZero<SecretScalar<E>>)
*= operation. Read moreSource§impl<T: Ord> Ord for NonZero<T>
impl<T: Ord> Ord for NonZero<T>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<E: Curve> PartialOrd<NonZero<Point<E>>> for Point<E>
impl<E: Curve> PartialOrd<NonZero<Point<E>>> for Point<E>
Source§impl<E: Curve> PartialOrd<NonZero<Scalar<E>>> for Scalar<E>
impl<E: Curve> PartialOrd<NonZero<Scalar<E>>> for Scalar<E>
Source§impl<T> PartialOrd<T> for NonZero<T>where
T: PartialOrd,
impl<T> PartialOrd<T> for NonZero<T>where
T: PartialOrd,
Source§impl<T: PartialOrd> PartialOrd for NonZero<T>
impl<T: PartialOrd> PartialOrd for NonZero<T>
Source§impl<'s, E: Curve> Product<&'s NonZero<SecretScalar<E>>> for NonZero<SecretScalar<E>>
impl<'s, E: Curve> Product<&'s NonZero<SecretScalar<E>>> for NonZero<SecretScalar<E>>
Source§impl<E: Curve> Samplable for NonZero<Scalar<E>>
impl<E: Curve> Samplable for NonZero<Scalar<E>>
Source§impl<E: Curve> Samplable for NonZero<SecretScalar<E>>
impl<E: Curve> Samplable for NonZero<SecretScalar<E>>
Source§impl<T> SerializeAs<NonZero<T>> for Compactwhere
Compact: SerializeAs<T>,
Available on crate feature serde only.
impl<T> SerializeAs<NonZero<T>> for Compactwhere
Compact: SerializeAs<T>,
serde only.Source§fn serialize_as<S>(
source: &NonZero<T>,
serializer: S,
) -> Result<S::Ok, S::Error>where
S: Serializer,
fn serialize_as<S>(
source: &NonZero<T>,
serializer: S,
) -> Result<S::Ok, S::Error>where
S: Serializer,
Source§impl<E: Curve> Sub<&NonZero<SecretScalar<E>>> for &NonZero<SecretScalar<E>>
impl<E: Curve> Sub<&NonZero<SecretScalar<E>>> for &NonZero<SecretScalar<E>>
Source§impl<E: Curve> Sub<&NonZero<SecretScalar<E>>> for &SecretScalar<E>
impl<E: Curve> Sub<&NonZero<SecretScalar<E>>> for &SecretScalar<E>
Source§impl<E: Curve> Sub<&NonZero<SecretScalar<E>>> for NonZero<SecretScalar<E>>
impl<E: Curve> Sub<&NonZero<SecretScalar<E>>> for NonZero<SecretScalar<E>>
Source§impl<E: Curve> Sub<&NonZero<SecretScalar<E>>> for SecretScalar<E>
impl<E: Curve> Sub<&NonZero<SecretScalar<E>>> for SecretScalar<E>
Source§impl<E: Curve> Sub<&SecretScalar<E>> for &NonZero<SecretScalar<E>>
impl<E: Curve> Sub<&SecretScalar<E>> for &NonZero<SecretScalar<E>>
Source§impl<E: Curve> Sub<&SecretScalar<E>> for NonZero<SecretScalar<E>>
impl<E: Curve> Sub<&SecretScalar<E>> for NonZero<SecretScalar<E>>
Source§impl<E: Curve> Sub<NonZero<SecretScalar<E>>> for &NonZero<SecretScalar<E>>
impl<E: Curve> Sub<NonZero<SecretScalar<E>>> for &NonZero<SecretScalar<E>>
Source§impl<E: Curve> Sub<NonZero<SecretScalar<E>>> for &SecretScalar<E>
impl<E: Curve> Sub<NonZero<SecretScalar<E>>> for &SecretScalar<E>
Source§impl<E: Curve> Sub<NonZero<SecretScalar<E>>> for SecretScalar<E>
impl<E: Curve> Sub<NonZero<SecretScalar<E>>> for SecretScalar<E>
Source§impl<E: Curve> Sub<SecretScalar<E>> for &NonZero<SecretScalar<E>>
impl<E: Curve> Sub<SecretScalar<E>> for &NonZero<SecretScalar<E>>
Source§impl<E: Curve> Sub<SecretScalar<E>> for NonZero<SecretScalar<E>>
impl<E: Curve> Sub<SecretScalar<E>> for NonZero<SecretScalar<E>>
Source§impl<E: Curve> SubAssign<&NonZero<SecretScalar<E>>> for Scalar<E>
impl<E: Curve> SubAssign<&NonZero<SecretScalar<E>>> for Scalar<E>
Source§fn sub_assign(&mut self, rhs: &NonZero<SecretScalar<E>>)
fn sub_assign(&mut self, rhs: &NonZero<SecretScalar<E>>)
-= operation. Read moreSource§impl<E: Curve> SubAssign<NonZero<SecretScalar<E>>> for Scalar<E>
impl<E: Curve> SubAssign<NonZero<SecretScalar<E>>> for Scalar<E>
Source§fn sub_assign(&mut self, rhs: NonZero<SecretScalar<E>>)
fn sub_assign(&mut self, rhs: NonZero<SecretScalar<E>>)
-= operation. Read more