#![cfg(feature = "spake2")]
use spake2::{Ed25519Group, Identity, Password, SPAKE2};
pub struct Spake2Result {
pub key: Vec<u8>,
pub transcript_piece: Vec<u8>,
}
pub enum SpakeRole { A, B }
pub fn run_spake2(code: &str, role: SpakeRole) -> Spake2Result {
let password = Password::from(code.as_bytes());
match role {
SpakeRole::A => {
let (msg_a, state_a) = SPAKE2::<Ed25519Group>::start_a(&password, &Identity::new(&[]), &Identity::new(&[]));
let mut t = Vec::new();
t.extend_from_slice(msg_a.as_bytes());
Spake2Result { key: Vec::new(), transcript_piece: t }
}
SpakeRole::B => {
let (msg_b, state_b) = SPAKE2::<Ed25519Group>::start_b(&password, &Identity::new(&[]), &Identity::new(&[]));
let mut t = Vec::new();
t.extend_from_slice(msg_b.as_bytes());
Spake2Result { key: Vec::new(), transcript_piece: t }
}
}
}