Struct curv::elliptic::curves::Scalar [−][src]
#[repr(transparent)]pub struct Scalar<E: Curve> { /* fields omitted */ }
Expand description
Scalar value in a prime field
Guarantees
-
Modulus group order
Denoting group order as
n
, any instances
ofScalar<E>
is guaranteed to be non-negative integer modulon
:0 <= s < n
Arithmetics
Supported operations:
- Unary: you can invert and negate a scalar
- Binary: you can add, subtract, and multiply two scalars
Example
fn expression(
a: &Scalar<Secp256k1>,
b: &Scalar<Secp256k1>,
c: &Scalar<Secp256k1>
) -> Scalar<Secp256k1> {
a + b * c
}
Implementations
Ensures that self
is not zero, returns Err(_)
otherwise
Constructs a scalar n % curve_order
from given n
Serializes a scalar to bytes
Constructs a scalar from bytes
Returns an order of generator point
Returns inversion self^-1 mod group_order
, or None if self
is zero
Constructs a Scalar<E>
from low-level ECScalar implementor
Typically, you don’t need to use this constructor. See random,
from_bigint constructors, and From<T>
, TryFrom<T>
traits implemented
for Scalar<E>
.
Returns a reference to low-level scalar implementation
Typically, you don’t need to work with ECScalar
trait directly. Scalar<E>
wraps ECScalar
and provides convenient utilities around it: it implements arithmetic operators, (de)serialization
traits, etc. If you believe that some functionality is missing, please
open an issue.
Converts a scalar into inner low-level scalar implementation
Typically, you don’t need to work with ECScalar
trait directly. Scalar<E>
wraps ECScalar
and provides convenient utilities around it: it implements arithmetic operators, (de)serialization
traits, etc. If you believe that some functionality is missing, please
open an issue.
Trait Implementations
Deserialize this value from the given Serde deserializer. Read more
Multiplies polynomial f(x)
at scalar s
, returning resulting polynomial g(x) = s * f(x)
Example
use curv::elliptic::curves::{Secp256k1, Scalar};
let f = Polynomial::<Secp256k1>::sample_exact(3);
let s = Scalar::<Secp256k1>::random();
let g = &f * &s;
for (f_coef, g_coef) in f.coefficients().iter().zip(g.coefficients()) {
assert_eq!(&(f_coef * &s), g_coef);
}
Auto Trait Implementations
impl<E> RefUnwindSafe for Scalar<E> where
<E as Curve>::Scalar: RefUnwindSafe,
impl<E> UnwindSafe for Scalar<E> where
<E as Curve>::Scalar: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more