[][src]Module secp256kfun::op

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

double_mul

Computes x * A + y * B more efficiently than calling scalar_mul_point twice.

point_add

Adds two points together

point_sub

Subtracts one point from another

scalar_add

Adds two scalars together (modulo the curve order)

scalar_mul

Multiplies two scalars together (modulo the curve order)

scalar_mul_point

Computes multiplies the point P by the scalar x.

scalar_sub

Subtracts one scalar from another