diff --git a/native/cpp/CommonCpp/CryptoTools/opaque-ke-cxx/src/lib.rs b/native/cpp/CommonCpp/CryptoTools/opaque-ke-cxx/src/lib.rs --- a/native/cpp/CommonCpp/CryptoTools/opaque-ke-cxx/src/lib.rs +++ b/native/cpp/CommonCpp/CryptoTools/opaque-ke-cxx/src/lib.rs @@ -12,6 +12,7 @@ RegistrationResponse, }; use rand::rngs::OsRng; +use std::ops::Deref; struct Cipher; @@ -51,6 +52,11 @@ session: Vec, } + struct ServerKeyPair { + public: Vec, + private: Vec, + } + extern "Rust" { fn client_register_cxx(password: String) -> Result; fn client_register_finish_cxx( @@ -62,6 +68,7 @@ client_login_state: Vec, server_message: Vec, ) -> Result; + fn server_kp() -> ServerKeyPair; } } @@ -155,6 +162,17 @@ client_login_state.finish(server_message, ClientLoginFinishParameters::default()) } +fn server_kp() -> ffi::ServerKeyPair { + let mut rng = OsRng; + let keypair = Cipher::generate_random_keypair(&mut rng); + let public_key = keypair.public().deref().to_vec(); + let private_key = keypair.private().deref().to_vec(); + ffi::ServerKeyPair { + public: public_key, + private: private_key, + } +} + #[cfg(test)] mod tests { use super::*; @@ -364,4 +382,11 @@ Err(ProtocolError::VerificationError(_)) ); } + + #[test] + fn test_server_kp_ok() { + let keys = server_kp(); + assert_eq!(keys.public.len(), 32); + assert_eq!(keys.private.len(), 32); + } }