]> git.lizzy.rs Git - PAKEs.git/commitdiff
more sketches, help from manishearth
authorBrian Warner <warner@lothar.com>
Wed, 17 May 2017 20:30:42 +0000 (13:30 -0700)
committerBrian Warner <warner@lothar.com>
Wed, 17 May 2017 20:30:42 +0000 (13:30 -0700)
Cargo.toml
src/lib.rs
src/spake2.rs

index f470646754c5581fe7eb642df7013b6694818055..c08f92f08c3f638b529928744a656df7d7bb53d7 100644 (file)
@@ -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"
index abab8b1a72d392a997099357b61d0612c15d7782..b972f4bfdd5a71061afada4539024872ddff23c5 100644 (file)
@@ -1,4 +1,7 @@
 
+extern crate rand;
+extern crate curve25519_dalek;
+
 pub mod spake2;
 //use spake2::*;
 
index 7d813d93e84a790ec6d64723bcd6cb54f2f17511..ab9ee86c97c975b960a0c24b1b93adc71b0fe00f 100644 (file)
@@ -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);
 }
+*/