diff options
author | Brian Warner <warner@lothar.com> | 2017-05-17 13:30:42 -0700 |
---|---|---|
committer | Brian Warner <warner@lothar.com> | 2017-05-17 13:30:42 -0700 |
commit | 57a38426b5e4716f6f14e639e5b3b923ca7e3319 (patch) | |
tree | 5e1f7c4cb054ae2036a2ca150b46704d8b4c14c2 | |
parent | 48fa27649f1cfeb27a1beffd2d28b8a746b4c558 (diff) | |
download | PAKEs-57a38426b5e4716f6f14e639e5b3b923ca7e3319.tar.xz |
more sketches, help from manishearth
-rw-r--r-- | Cargo.toml | 3 | ||||
-rw-r--r-- | src/lib.rs | 3 | ||||
-rw-r--r-- | src/spake2.rs | 70 |
3 files changed, 62 insertions, 14 deletions
@@ -5,4 +5,5 @@ authors = ["Brian Warner <warner@lothar.com>"] [dependencies] #rust-crypto = "^0.2" -curve25519-dalek = "0.2.0" +curve25519-dalek = "0.6.0" +rand = "0.3.0" @@ -1,4 +1,7 @@ +extern crate rand; +extern crate curve25519_dalek; + pub mod spake2; //use spake2::*; diff --git a/src/spake2.rs b/src/spake2.rs index 7d813d9..ab9ee86 100644 --- a/src/spake2.rs +++ b/src/spake2.rs @@ -1,44 +1,88 @@ -pub fn foo() -> u8 { - 1 -} - +use curve25519_dalek::scalar::Scalar as c2_Scalar; +use curve25519_dalek::curve::ExtendedPoint as c2_Element; +use curve25519_dalek::curve::BasepointMult; +use curve25519_dalek::curve::ScalarMult; +use rand::OsRng; trait Group { type Scalar; type Element; - pub fn scalarmult(s: Scalar) -> Element; - pub fn scalar_from_integer(u8) -> Scalar; + // const element_length: usize; // in unstable, or u8 + //type ElementBytes : Index<usize, Output=u8>+IndexMut<usize>; // later + fn random_scalar() -> Self::Scalar; + fn basepoint_mult(s: &Self::Scalar) -> Self::Element; + fn scalarmult(e: &Self::Element, s: &Self::Scalar) -> Self::Element; + fn add(a: &Self::Element, b: &Self::Element) -> Self::Element; +} + +struct Ed25519Group; + +impl Group for Ed25519Group { + type Scalar = c2_Scalar; + type Element = c2_Element; + //type ElementBytes = Vec<u8>; + //type ElementBytes = [u8; 32]; + //type ScalarBytes + + fn random_scalar() -> c2_Scalar { + let mut cspring: OsRng = OsRng::new().unwrap(); + c2_Scalar::random(&mut cspring) + } + fn basepoint_mult(s: &c2_Scalar) -> c2_Element { + c2_Element::basepoint_mult(s) + } + fn scalarmult(e: &c2_Element, s: &c2_Scalar) -> c2_Element { + e.scalar_mult(s) + } + fn add(a: &c2_Element, b: &c2_Element) -> c2_Element { + a.add(b) + } } +/* "session type pattern" */ + struct SPAKE2<G: Group> { x: G::Scalar, password: Vec<u8>, idA: Vec<u8>, idB: Vec<u8>, + msg1: Vec<u8>, pw: G::Scalar, } -impl<G> for SPAKE2 { - pub fn new<G>(password: &[u8], idA: &[u8], idB: &[u8]) -> SPAKE2<G> { +impl<G: Group> SPAKE2<G> { + pub fn new(password: &[u8], idA: &[u8], idB: &[u8]) -> (SPAKE2<G>, Vec<u8>) { let pw: G::Scalar = hash_to_scalar::<G::Scalar>(password); let x: G::Scalar = random_scalar::<G::Scalar>; - let M1 G::Element = MAGIC(); - let msg1 = ... + let M1: G::Element = unimplemented!(); + let msg1 = unimplemented!(); // M1 to bytes let mut pv = Vec::new(); pv.extend_from_slice(password); - (SPAKE2 {x: x, password: pv, ... }, msg1) + let mut idA_copy = Vec::new(); + idA_copy.extend_from_slice(idA); + let mut idB_copy = Vec::new(); + idB_copy.extend_from_slice(idB); + (SPAKE2 {x: x, + password: pv, + idA: idA_copy, + idB: idB_copy, + msg1: msg1.clone(), + pw: unimplemented!(), + }, msg1) } - - pub fn finish(self, msg2: &[u8]) -> Result<Key, SPAKEErr> { + + pub fn finish(self, msg2: &[u8]) -> Result<Vec<u8>, SPAKEErr> { } } +/* { let (mut s, msg1) = SPAKE2::<Ed25519>(&password, &idA, &idB); //let msg1 = s.msg1; let key = s.finish(msg2); } +*/ |