diff --git a/src/keypair.rs b/src/keypair.rs index f86ff0f..0cf2b3e 100644 --- a/src/keypair.rs +++ b/src/keypair.rs @@ -115,7 +115,11 @@ impl> KeyPair { /// Obtains a KeyPair from a slice representing the private key pub fn from_private_key_slice(input: &[u8]) -> Result> { - let sk = S::deserialize(input)?; + Self::from_private_key(S::deserialize(input)?) + } + + /// Obtains a KeyPair from a private key + pub fn from_private_key(sk: S) -> Result> { let pk = sk.public_key()?; Ok(Self { pk, sk }) } diff --git a/src/opaque.rs b/src/opaque.rs index ebd559b..77d8f56 100644 --- a/src/opaque.rs +++ b/src/opaque.rs @@ -57,18 +57,27 @@ pub struct ServerSetup< impl ServerSetup> { /// Generate a new instance of server setup pub fn new(rng: &mut R) -> Self { + let keypair = KeyPair::::generate_random(rng); + Self::new_with_key(rng, keypair) + } +} + +impl> ServerSetup { + /// Create [`ServerSetup`] with the given keypair + pub fn new_with_key( + rng: &mut R, + keypair: KeyPair, + ) -> Self { let mut seed = vec![0u8; ::OutputSize::to_usize()]; rng.fill_bytes(&mut seed); Self { oprf_seed: GenericArray::clone_from_slice(&seed[..]), - keypair: KeyPair::::generate_random(rng), + keypair, fake_keypair: KeyPair::::generate_random(rng), } } -} -impl> ServerSetup { /// Serialization into bytes pub fn serialize(&self) -> Vec { [ @@ -375,8 +384,8 @@ impl ServerRegistration { /// From the client's "blinded" password, returns a response to be /// sent back to the client, as well as a ServerRegistration - pub fn start( - server_setup: &ServerSetup, + pub fn start>( + server_setup: &ServerSetup, message: RegistrationRequest, credential_identifier: &[u8], ) -> Result, ProtocolError> {