-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Elliptic Curve Cryptography | ||
|
||
Elliptic curve cryptography takes advantage of the intractability of the elliptic curve discrete logarithm problem. | ||
|
||
Let $E$ be an elliptic curve defined over a Galois (finite) field $\mathbb{F}_q$. Point addition forms a cyclic group | ||
on $E(\mathbb{F}_q)$ with a generator point $G \in E(\mathbb{F}_q)$ and a point at infinite $\mathcal{O}$ such that: | ||
|
||
$$ | ||
\forall P, Q \in E(\mathbb{F}_q) : P + Q = R \in E(\mathbb{F}_q) | ||
\forall P \in E(\mathbb{F}_q) : P + \mathcal{O} = P | ||
\forall P \in E(\mathbb{F}_q) : P + (-P) = \mathcal{O} | ||
$$ | ||
|
||
Scalar multiplication is defined as iterative point addition such that: | ||
|
||
$$ | ||
\forall P \in E(\mathbb{F}_q), k \in \mathbb{Z} : k \times P = P_k \in E(\mathbb{F}_q) | ||
\forall P_k \in E(\mathbb{F}_q), \exists k \in \mathbb{Z} : k \times G = P_k | ||
$$ | ||
|
||
## Application | ||
|
||
The discrete logarithm problem and algebraic structure of elliptic curve point addition and scalar multiplication | ||
allows for public key cryptography schemes such as digital signatures | ||
([ECDSA](https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm)) and key exchanges | ||
([ECDH](https://en.wikipedia.org/wiki/Elliptic-curve_Diffie%E2%80%93Hellman)). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//! ECDH key exchange | ||
use self::field::prime::PlutoScalarField; | ||
use super::*; | ||
|
||
// PARAMETERS | ||
// ******************************************* | ||
// CURVE the elliptic curve field and equation used | ||
// G a point on the curve that generates a subgroup of large prime order n | ||
// n integer order of G, means that n × G = O, n must also be prime. | ||
// d_A the local private key (randomly selected) (scaler in F_n) | ||
// Q_A the local public key d_A × G = Q_A (point on the curve) | ||
// d_B the foreign private key (randomly selected) (scaler in F_n) | ||
// Q_B the foreign public key d_B × G = Q_B (point on the curve) | ||
// S the shared secret point S = d_A × Q_B = d_B × Q_A | ||
|
||
/// SHARED SECRET COMPUTATION | ||
/// ******************************************* | ||
/// 1. Compute the shared secret point S = d_A × Q_B. | ||
/// | ||
/// ## Notes: | ||
/// Elliptic Curve Diffie Hellman (ECDH) exchanges a shared secret over an insecure channel via the | ||
/// commutativity and associativity of elliptic curve point multiplication. | ||
/// | ||
/// d_A × (d_B × G) = d_B × (d_A × G) | ||
/// d_B × Q_A = d_A × Q_B | ||
pub fn compute_shared_secret( | ||
d_a: PlutoScalarField, | ||
q_b: AffinePoint<PlutoBaseCurve>, | ||
) -> AffinePoint<PlutoBaseCurve> { | ||
q_b * d_a | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_key_exchange() { | ||
// secret keys | ||
let mut rns = rand::rngs::OsRng; | ||
let d_a = PlutoScalarField::new(rand::Rng::gen_range(&mut rns, 1..=PlutoScalarField::ORDER)); | ||
let d_b = PlutoScalarField::new(rand::Rng::gen_range(&mut rns, 1..=PlutoScalarField::ORDER)); | ||
|
||
// public keys | ||
let q_a = AffinePoint::<PlutoBaseCurve>::generator() * d_a; | ||
let q_b = AffinePoint::<PlutoBaseCurve>::generator() * d_b; | ||
|
||
// shared secret | ||
let s_a = compute_shared_secret(d_a, q_b); | ||
let s_b = compute_shared_secret(d_b, q_a); | ||
|
||
println!("shared secrets = [\n\t{:?},\n\t{:?}\n]", s_a, s_b); | ||
assert_eq!(s_a, s_b); | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
//! Elliptic curve cryptography primitives | ||
use super::*; | ||
|
||
pub mod ecdh; | ||
pub mod ecdsa; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters