2 use curve25519_dalek::scalar::Scalar as c2_Scalar;
3 use curve25519_dalek::curve::ExtendedPoint as c2_Element;
4 use curve25519_dalek::curve::BasepointMult;
5 use curve25519_dalek::curve::ScalarMult;
11 // const element_length: usize; // in unstable, or u8
12 //type ElementBytes : Index<usize, Output=u8>+IndexMut<usize>; // later
13 fn random_scalar() -> Self::Scalar;
14 fn basepoint_mult(s: &Self::Scalar) -> Self::Element;
15 fn scalarmult(e: &Self::Element, s: &Self::Scalar) -> Self::Element;
16 fn add(a: &Self::Element, b: &Self::Element) -> Self::Element;
21 impl Group for Ed25519Group {
22 type Scalar = c2_Scalar;
23 type Element = c2_Element;
24 //type ElementBytes = Vec<u8>;
25 //type ElementBytes = [u8; 32];
28 fn random_scalar() -> c2_Scalar {
29 let mut cspring: OsRng = OsRng::new().unwrap();
30 c2_Scalar::random(&mut cspring)
32 fn basepoint_mult(s: &c2_Scalar) -> c2_Element {
33 c2_Element::basepoint_mult(s)
35 fn scalarmult(e: &c2_Element, s: &c2_Scalar) -> c2_Element {
38 fn add(a: &c2_Element, b: &c2_Element) -> c2_Element {
44 /* "session type pattern" */
46 struct SPAKE2<G: Group> {
55 impl<G: Group> SPAKE2<G> {
56 pub fn new(password: &[u8], idA: &[u8], idB: &[u8]) -> (SPAKE2<G>, Vec<u8>) {
57 let pw: G::Scalar = hash_to_scalar::<G::Scalar>(password);
58 let x: G::Scalar = random_scalar::<G::Scalar>;
60 let M1: G::Element = unimplemented!();
61 let msg1 = unimplemented!(); // M1 to bytes
62 let mut pv = Vec::new();
63 pv.extend_from_slice(password);
64 let mut idA_copy = Vec::new();
65 idA_copy.extend_from_slice(idA);
66 let mut idB_copy = Vec::new();
67 idB_copy.extend_from_slice(idB);
77 pub fn finish(self, msg2: &[u8]) -> Result<Vec<u8>, SPAKEErr> {
84 let (mut s, msg1) = SPAKE2::<Ed25519>(&password, &idA, &idB);
86 let key = s.finish(msg2);