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 instance s of Scalar<E> is guaranteed to be non-negative integer modulo n: 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

Samples a random nonzero scalar

Constructs zero scalar

Checks if a scalar is zero

Converts a scalar to BigInt

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

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. 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);
}

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the - operator.

Performs the unary - operation. Read more

The resulting type after applying the - operator.

Performs the unary - operation. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Method which takes an iterator and generates Self from the elements by multiplying the items. Read more

Method which takes an iterator and generates Self from the elements by multiplying the items. Read more

Serialize this value into the given Serde serializer. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

Method which takes an iterator and generates Self from the elements by “summing up” the items. Read more

Method which takes an iterator and generates Self from the elements by “summing up” the items. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.