User Guide
Installation
dlog-group is published on crates.io. Add via Cargo:
cargo add dlog-group --features p256
Or add entries manually to your Cargo.toml (replace the version with the latest on crates.io):
[dependencies]
dlog-group = { version = "x.y.z", features = ["p256"] }
Available feature flags include: "ristretto", "p256", "k256" and "p384".
Usage
Once a group is selected (following standard elliptic-curve conventions, is considered an additive group), we can distinguish two main components:
-
Points: Elements of . If , then as well. Operations on points (e.g. addition, scalar multiplication) are typically more expensive than on scalars.
-
Scalars: Elements of , where is the order of the group . Scalars represent integer multipliers. For example, multiplying a point by (i.e., ) is defined as , and more generally represents the sum of added to itself -times.
These two structures support standard algebraic operations and are the basis for cryptographic schemes like Diffie–Hellman and digital signatures.
Example
First, we import a backend implementation (in this case, RistrettoGroup) as well as the traits GroupPoint and GroupScalar, which provide operations over points and scalars, respectively:
use dlog_group::{
ristretto::{RistrettoGroup},
group::{GroupPoint, GroupScalar}
};
We additionally import the rand crate to generate a random seed (rng) which we are going to use to generate a scalar r.
use rand;
let mut rng = rand::thread_rng();
Finally, let’s use the standard generator of the RistrettoGroup, perform some basic operations, and verify that the following holds:
let G = RistrettoGroup::generator();
let r = RistrettoGroup::scalar_random(&mut rng);
let r_G = G * &r;
let r1_G = G + &r_G;
assert_eq!(r1_G - &r_G, G);