eccoxide/
lib.rs

1//! Elliptic Curve Cryptography
2//!
3//! Provide arithmetic functions to deal with
4//! elliptic curve mathematics, from the finite field
5//! arithmetics abstractions to point representation on
6//! curves.
7//!
8//! It also provide those operations on multiples
9//! standard curves, and use when possible
10//! constant-time operations.
11//!
12//! Currently most lowlevel arithmetics is provided by
13//! the fiat-crypto project
14//!
15//! Example to do basic arithmetic operation with this crate:
16//!
17//! ```
18//! // use p256r1 for this example, but other curve available in sec2 module
19//! // or future other hierarchy
20//! use eccoxide::curve::sec2::p256r1::{FieldElement, Point};
21//!
22//! // addition in the underlying Field
23//! let two = FieldElement::one() + FieldElement::one();
24//!
25//! // Get the generator and add the point at infinity
26//! let generator = Point::generator();
27//! let same_generator = &generator + Point::infinity();
28//!
29//! // transform the point to affine coordinate
30//! let point = generator.to_affine().unwrap();
31//! let (x, y) = point.to_coordinate();
32//! ```
33//!
34//! Using
35//!
36//! ```
37//! // use p521r1 for this example
38//! use eccoxide::curve::sec2::p521r1::{FieldElement, Scalar, Point};
39//! use eccoxide::curve::Sign;
40//!
41//! // this is just unsecure example, but here it could be loading some secret from disk
42//! let bytes : [u8;66] = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];
43//!
44//! let secret_key = Scalar::from_bytes(&bytes).unwrap();
45//! let public_key = &Point::generator() * &secret_key;
46//!
47//! // serialize the public key to a standard-ish compress format for p521r1
48//! let public_affine = public_key.to_affine().unwrap();
49//! let (x, ysign) = public_affine.compress();
50//! let format_byte : u8 = match ysign {
51//!     Sign::Positive => 0x2,
52//!     Sign::Negative => 0x3,
53//! };
54//!
55//! let mut public_key_bytes = Vec::new();
56//! public_key_bytes.push(format_byte);
57//! public_key_bytes.extend_from_slice(&x.to_bytes());
58//! ```
59
60#[macro_use]
61extern crate lazy_static;
62
63pub mod curve;
64pub(crate) mod mp;
65pub mod params;
66
67#[cfg(test)]
68mod tests;