Module secp256kfun::op
source · [−]Expand description
Operations in the secp256k1 group.
The purpose of this module is to hold all the operations that can be done
with secp256k1 Points
and Scalars
. Usually, you shouldn’t call
these directly but instead use the group g!
and scalar s!
expression
macros which compile your expressions into (potentially more efficient)
calls to these functions.
Most of the functions here are specialized
so the compiler may be able to
choose a faster algorithm depending on the arguments. For example scalar
multiplications are faster points marked BasePoint
like G
, so in the
following snippet computing X1
will be computed faster than X2
even
though the same function is being called.
use secp256kfun::{marker::*, op, Scalar, G};
let x = Scalar::random(&mut rand::thread_rng());
let X1 = op::scalar_mul_point(&x, G); // fast
let H = &G.clone().mark::<Normal>(); // scrub `BasePoint` marker
let X2 = op::scalar_mul_point(&x, &H); // slow
assert_eq!(X1, X2);
Functions
Computes x * A + y * B
more efficiently than calling scalar_mul_point
twice.
Does a linear combination of points
Adds two points together
Subtracts one point from another
Adds two scalars together (modulo the curve order)
Multiplies two scalars together (modulo the curve order)
Computes multiplies the point P
by the scalar x
.
Subtracts one scalar from another