Files
opaque-vx/src/lib.rs
T

477 lines
21 KiB
Rust
Raw Normal View History

2020-06-05 09:35:14 -07:00
// Copyright (c) Facebook, Inc. and its affiliates.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
//! An implementation of the OPAQUE asymmetric password authentication key exchange protocol
//!
2020-12-12 21:53:33 -08:00
//! Note: This implementation is in sync with [draft-irtf-cfrg-opaque-01](https://www.ietf.org/archive/id/draft-irtf-cfrg-opaque-01.html),
2020-06-09 15:13:42 -07:00
//! but this specification is subject to change, until the final version published by the IETF.
//!
2020-06-05 09:35:14 -07:00
//! # Overview
//!
//! OPAQUE is a protocol between a client and a server. They must first agree on a collection of primitives
//! to be kept consistent throughout protocol execution. These include:
//! * a finite cyclic group along with a point representation,
2020-07-13 15:23:29 -07:00
//! * a keypair type,
2020-07-27 15:25:04 -07:00
//! * a key exchange protocol,
//! * a hashing function, and
//! * a slow hashing function.
2020-06-05 09:35:14 -07:00
//!
//! We will use the following choices in this example:
//! ```
//! use opaque_ke::ciphersuite::CipherSuite;
//! struct Default;
//! impl CipherSuite for Default {
//! type Group = curve25519_dalek::ristretto::RistrettoPoint;
//! type KeyFormat = opaque_ke::keypair::X25519KeyPair;
2020-07-13 15:23:29 -07:00
//! type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
2020-07-27 15:25:04 -07:00
//! type Hash = sha2::Sha256;
//! type SlowHash = opaque_ke::slow_hash::NoOpHash;
//! }
2020-06-05 09:35:14 -07:00
//! ```
//!
2020-06-08 21:02:01 -07:00
//! Note that our choice of slow hashing function in this example, `NoOpHash`, is selected only to ensure
2020-12-12 21:53:33 -08:00
//! that the tests execute quickly. A real application should use an actual slow hashing function, such as `scrypt`,
//! which can be enabled through the `slow-hash` feature.
2020-06-05 09:35:14 -07:00
//!
//! ## Setup
2020-12-12 21:53:33 -08:00
//! To set up the protocol, the server begins by generating a static keypair:
2020-06-05 09:35:14 -07:00
//! ```
2020-11-03 21:44:00 +00:00
//! # use opaque_ke::keypair::{KeyPair, X25519KeyPair};
2020-06-05 09:35:14 -07:00
//! # use opaque_ke::errors::ProtocolError;
//! # use opaque_ke::ciphersuite::CipherSuite;
//! # struct Default;
//! # impl CipherSuite for Default {
//! # type Group = curve25519_dalek::ristretto::RistrettoPoint;
//! # type KeyFormat = opaque_ke::keypair::X25519KeyPair;
2020-07-13 15:23:29 -07:00
//! # type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
2020-07-27 15:25:04 -07:00
//! # type Hash = sha2::Sha256;
//! # type SlowHash = opaque_ke::slow_hash::NoOpHash;
//! # }
2020-06-05 09:35:14 -07:00
//! use rand_core::{OsRng, RngCore};
//! let mut rng = OsRng;
//! let server_kp = Default::generate_random_keypair(&mut rng)?;
2020-06-05 09:35:14 -07:00
//! # Ok::<(), ProtocolError>(())
//! ```
//! The server must persist this keypair for the registration and login steps, where the public component will be
//! used by the client during both registration and login, and the private component will be used by the server during login.
//!
//! ## Registration
2020-12-12 21:53:33 -08:00
//! The registration protocol between the client and server consists of four steps along with three messages:
//! [RegistrationRequest], [RegistrationResponse], and [RegistrationUpload]. A successful execution of the registration protocol results in the
//! server producing a password file corresponding to the password provided by
2020-06-05 09:35:14 -07:00
//! the client. This password file is typically stored server-side, and retrieved upon future login attempts made by the client.
//!
2020-12-12 21:53:33 -08:00
//! ### Client Registration Start
//! In the first step of registration, the client chooses as input a registration password. The client runs [ClientRegistration::start]
//! to produce an output consisting of a [RegistrationRequest] to be sent to the server, and
//! a [ClientRegistration] which must be persisted on the client for the final step of client registration.
2020-06-05 09:35:14 -07:00
//! ```
2020-06-08 21:02:01 -07:00
//! # use opaque_ke::{
//! # errors::ProtocolError,
2020-11-16 14:05:43 -08:00
//! # ServerRegistration,
2020-11-03 21:44:00 +00:00
//! # keypair::{KeyPair, X25519KeyPair},
2020-06-08 21:02:01 -07:00
//! # slow_hash::NoOpHash,
//! # };
//! # use opaque_ke::ciphersuite::CipherSuite;
//! # struct Default;
//! # impl CipherSuite for Default {
//! # type Group = curve25519_dalek::ristretto::RistrettoPoint;
//! # type KeyFormat = opaque_ke::keypair::X25519KeyPair;
2020-07-13 15:23:29 -07:00
//! # type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
2020-07-27 15:25:04 -07:00
//! # type Hash = sha2::Sha256;
//! # type SlowHash = opaque_ke::slow_hash::NoOpHash;
//! # }
2020-11-16 14:05:43 -08:00
//! use opaque_ke::{ClientRegistration, ClientRegistrationStartParameters};
2020-06-05 09:35:14 -07:00
//! use rand_core::{OsRng, RngCore};
//! let mut client_rng = OsRng;
2020-12-12 21:53:33 -08:00
//! let client_registration_start_result = ClientRegistration::<Default>::start(
//! &mut client_rng,
2020-06-05 09:35:14 -07:00
//! b"password",
2020-11-16 14:05:43 -08:00
//! ClientRegistrationStartParameters::default(),
2020-06-05 09:35:14 -07:00
//! )?;
//! # Ok::<(), ProtocolError>(())
//! ```
//!
2020-12-12 21:53:33 -08:00
//! ### Server Registration Start
//! In the second step of registration, the server takes as input the instance of [RegistrationRequest] from the client, and
//! the server's public key `server_kp.public()`.
//! The server runs [ServerRegistration::start] to produce an output consisting of
//! a [RegistrationResponse] to be returned to the client, and
//! a [ServerRegistration] which must be persisted on the server for the final step of server registration.
2020-06-05 09:35:14 -07:00
//! ```
2020-06-08 21:02:01 -07:00
//! # use opaque_ke::{
//! # errors::ProtocolError,
2020-11-16 14:05:43 -08:00
//! # ClientRegistration, ClientRegistrationStartParameters,
2020-11-03 21:44:00 +00:00
//! # keypair::{KeyPair, X25519KeyPair},
2020-06-08 21:02:01 -07:00
//! # slow_hash::NoOpHash,
//! # };
//! # use opaque_ke::ciphersuite::CipherSuite;
//! # struct Default;
//! # impl CipherSuite for Default {
//! # type Group = curve25519_dalek::ristretto::RistrettoPoint;
//! # type KeyFormat = opaque_ke::keypair::X25519KeyPair;
2020-07-13 15:23:29 -07:00
//! # type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
2020-07-27 15:25:04 -07:00
//! # type Hash = sha2::Sha256;
//! # type SlowHash = opaque_ke::slow_hash::NoOpHash;
//! # }
2020-06-05 09:35:14 -07:00
//! # use rand_core::{OsRng, RngCore};
//! # let mut client_rng = OsRng;
2020-12-12 21:53:33 -08:00
//! # let client_registration_start_result = ClientRegistration::<Default>::start(
//! # &mut client_rng,
2020-06-05 09:35:14 -07:00
//! # b"password",
2020-11-16 14:05:43 -08:00
//! # ClientRegistrationStartParameters::default(),
2020-06-05 09:35:14 -07:00
//! # )?;
2020-11-16 14:05:43 -08:00
//! use opaque_ke::ServerRegistration;
2020-06-05 09:35:14 -07:00
//! let mut server_rng = OsRng;
2020-11-16 14:05:43 -08:00
//! let server_kp = Default::generate_random_keypair(&mut server_rng)?;
2020-12-12 21:53:33 -08:00
//! let server_registration_start_result = ServerRegistration::<Default>::start(
//! &mut server_rng,
//! client_registration_start_result.message,
//! server_kp.public(),
//! )?;
2020-06-05 09:35:14 -07:00
//! # Ok::<(), ProtocolError>(())
//! ```
//!
2020-12-12 21:53:33 -08:00
//! ### Client Registration Finish
//! In the third step of registration, the client takes as input
//! a [RegistrationResponse] from the server, and
//! a [ClientRegistration] from the first step of registration.
//! The client runs [ClientRegistration::finish] to produce an output consisting of a [RegistrationUpload]
//! to be sent to the server.
2020-06-05 09:35:14 -07:00
//! ```
2020-06-08 21:02:01 -07:00
//! # use opaque_ke::{
//! # errors::ProtocolError,
2020-11-16 14:05:43 -08:00
//! # ClientRegistration, ClientRegistrationStartParameters, ServerRegistration,
2020-11-03 21:44:00 +00:00
//! # keypair::{KeyPair, X25519KeyPair},
2020-06-08 21:02:01 -07:00
//! # slow_hash::NoOpHash,
//! # };
//! # use opaque_ke::ciphersuite::CipherSuite;
//! # struct Default;
//! # impl CipherSuite for Default {
//! # type Group = curve25519_dalek::ristretto::RistrettoPoint;
//! # type KeyFormat = opaque_ke::keypair::X25519KeyPair;
2020-07-13 15:23:29 -07:00
//! # type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
2020-07-27 15:25:04 -07:00
//! # type Hash = sha2::Sha256;
//! # type SlowHash = opaque_ke::slow_hash::NoOpHash;
//! # }
2020-06-05 09:35:14 -07:00
//! # use rand_core::{OsRng, RngCore};
//! # let mut client_rng = OsRng;
2020-12-12 21:53:33 -08:00
//! # let client_registration_start_result = ClientRegistration::<Default>::start(
//! # &mut client_rng,
2020-06-05 09:35:14 -07:00
//! # b"password",
2020-11-16 14:05:43 -08:00
//! # ClientRegistrationStartParameters::default(),
2020-06-05 09:35:14 -07:00
//! # )?;
//! # let mut server_rng = OsRng;
//! # let server_kp = Default::generate_random_keypair(&mut server_rng)?;
2020-12-12 21:53:33 -08:00
//! # let server_registration_start_result = ServerRegistration::<Default>::start(&mut server_rng, client_registration_start_result.message, server_kp.public())?;
//! let client_registration_finish_result = client_registration_start_result.state.finish(
//! &mut client_rng,
//! server_registration_start_result.message,
//! )?;
2020-06-05 09:35:14 -07:00
//! # Ok::<(), ProtocolError>(())
//! ```
//!
2020-12-12 21:53:33 -08:00
//! ### Server Registration Finish
//! In the fourth step of registration, the server takes as input
//! a [RegistrationUpload] from the client, and
//! a [ServerRegistration] from the second step.
//! The server runs [ServerRegistration::finish] to produce a finalized [ServerRegistration].
//! At this point, the client can be considered as successfully registered, and the server can invoke
//! [ServerRegistration::to_bytes] to store the password file for use during the login protocol.
2020-06-05 09:35:14 -07:00
//! ```
2020-06-08 21:02:01 -07:00
//! # use opaque_ke::{
//! # errors::ProtocolError,
2020-11-16 14:05:43 -08:00
//! # ClientRegistration, ClientRegistrationStartParameters, ServerRegistration,
2020-11-03 21:44:00 +00:00
//! # keypair::{KeyPair, X25519KeyPair},
2020-06-08 21:02:01 -07:00
//! # slow_hash::NoOpHash,
//! # };
//! # use opaque_ke::ciphersuite::CipherSuite;
//! # struct Default;
//! # impl CipherSuite for Default {
//! # type Group = curve25519_dalek::ristretto::RistrettoPoint;
//! # type KeyFormat = opaque_ke::keypair::X25519KeyPair;
2020-07-13 15:23:29 -07:00
//! # type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
2020-07-27 15:25:04 -07:00
//! # type Hash = sha2::Sha256;
//! # type SlowHash = opaque_ke::slow_hash::NoOpHash;
//! # }
2020-06-05 09:35:14 -07:00
//! # use rand_core::{OsRng, RngCore};
//! # let mut client_rng = OsRng;
2020-12-12 21:53:33 -08:00
//! # let client_registration_start_result = ClientRegistration::<Default>::start(
//! # &mut client_rng,
2020-06-05 09:35:14 -07:00
//! # b"password",
2020-11-16 14:05:43 -08:00
//! # ClientRegistrationStartParameters::default(),
2020-06-05 09:35:14 -07:00
//! # )?;
//! # let mut server_rng = OsRng;
//! # let server_kp = Default::generate_random_keypair(&mut server_rng)?;
2020-12-12 21:53:33 -08:00
//! # let server_registration_start_result = ServerRegistration::<Default>::start(&mut server_rng, client_registration_start_result.message, server_kp.public())?;
//! # let client_registration_finish_result = client_registration_start_result.state.finish(&mut client_rng, server_registration_start_result.message)?;
//! let password_file = server_registration_start_result.state.finish(
//! client_registration_finish_result.message,
//! )?;
2020-06-05 09:35:14 -07:00
//! # Ok::<(), ProtocolError>(())
//! ```
//!
//! ## Login
2020-12-12 21:53:33 -08:00
//! The login protocol between a client and server also consists of four steps along with three messages:
//! [CredentialRequest], [CredentialResponse], [CredentialFinalization]. The server is expected to have access to the password file
//! corresponding to an output of the registration phase. The login protocol will execute successfully only if the same password
//! was used in the registration phase that produced the password file that the server is testing against.
2020-06-05 09:35:14 -07:00
//!
2020-12-12 21:53:33 -08:00
//! ### Client Login Start
//! In the first step of login, the client chooses as input a login password.
//! The client runs [ClientLogin::start] to produce an output consisting of
//! a [CredentialRequest] to be sent to the server, and
//! a [ClientLogin] which must be persisted on the client for the final step of client login.
2020-06-05 09:35:14 -07:00
//! ```
2020-06-08 21:02:01 -07:00
//! # use opaque_ke::{
//! # errors::ProtocolError,
2020-12-12 21:53:33 -08:00
//! # ClientRegistration, ServerRegistration, ServerLogin, CredentialFinalization,
2020-11-03 21:44:00 +00:00
//! # keypair::{KeyPair, X25519KeyPair},
2020-06-08 21:02:01 -07:00
//! # slow_hash::NoOpHash,
//! # };
//! # use opaque_ke::ciphersuite::CipherSuite;
//! # struct Default;
//! # impl CipherSuite for Default {
//! # type Group = curve25519_dalek::ristretto::RistrettoPoint;
//! # type KeyFormat = opaque_ke::keypair::X25519KeyPair;
2020-07-13 15:23:29 -07:00
//! # type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
2020-07-27 15:25:04 -07:00
//! # type Hash = sha2::Sha256;
//! # type SlowHash = opaque_ke::slow_hash::NoOpHash;
//! # }
2020-06-05 09:35:14 -07:00
//! # use rand_core::{OsRng, RngCore};
2020-11-16 14:05:43 -08:00
//! use opaque_ke::{ClientLogin, ClientLoginStartParameters};
2020-06-05 09:35:14 -07:00
//! let mut client_rng = OsRng;
2020-11-16 14:05:43 -08:00
//! let client_login_start_result = ClientLogin::<Default>::start(
2020-06-05 09:35:14 -07:00
//! &mut client_rng,
2020-12-12 21:53:33 -08:00
//! b"password",
2020-11-16 14:05:43 -08:00
//! ClientLoginStartParameters::default(),
2020-06-05 09:35:14 -07:00
//! )?;
//! # Ok::<(), ProtocolError>(())
//! ```
//!
2020-12-12 21:53:33 -08:00
//! ### Server Login Start
//! In the second step of login, the server takes as input
//! a [CredentialRequest] from the client,
//! the server's private key `server_kp.private()`, and
//! the password file output from registration.
//! The server runs [ServerLogin::start] to produce an output consisting of
//! a [CredentialResponse] which is returned to the client, and
//! a [ServerLogin] which must be persisted on the server for the final step of login.
2020-06-05 09:35:14 -07:00
//! ```
2020-06-08 21:02:01 -07:00
//! # use opaque_ke::{
//! # errors::ProtocolError,
2020-12-12 21:53:33 -08:00
//! # ClientRegistration, ClientRegistrationStartParameters, ServerRegistration, ClientLogin, ClientLoginStartParameters, CredentialFinalization,
2020-11-03 21:44:00 +00:00
//! # keypair::{KeyPair, X25519KeyPair},
2020-06-08 21:02:01 -07:00
//! # slow_hash::NoOpHash,
//! # };
//! # use opaque_ke::ciphersuite::CipherSuite;
//! # struct Default;
//! # impl CipherSuite for Default {
//! # type Group = curve25519_dalek::ristretto::RistrettoPoint;
//! # type KeyFormat = opaque_ke::keypair::X25519KeyPair;
2020-07-13 15:23:29 -07:00
//! # type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
2020-07-27 15:25:04 -07:00
//! # type Hash = sha2::Sha256;
//! # type SlowHash = opaque_ke::slow_hash::NoOpHash;
//! # }
2020-06-05 09:35:14 -07:00
//! # use rand_core::{OsRng, RngCore};
//! # let mut client_rng = OsRng;
2020-12-12 21:53:33 -08:00
//! # let client_registration_start_result = ClientRegistration::<Default>::start(
//! # &mut client_rng,
2020-06-05 09:35:14 -07:00
//! # b"password",
2020-11-16 14:05:43 -08:00
//! # ClientRegistrationStartParameters::default(),
2020-06-05 09:35:14 -07:00
//! # )?;
//! # let mut server_rng = OsRng;
//! # let server_kp = Default::generate_random_keypair(&mut server_rng)?;
2020-12-12 21:53:33 -08:00
//! # let server_registration_start_result = ServerRegistration::<Default>::start(&mut server_rng, client_registration_start_result.message, server_kp.public())?;
//! # let client_registration_finish_result = client_registration_start_result.state.finish(&mut client_rng, server_registration_start_result.message)?;
//! # let password_file_bytes = server_registration_start_result.state.finish(client_registration_finish_result.message)?.to_bytes();
2020-11-16 14:05:43 -08:00
//! # let client_login_start_result = ClientLogin::<Default>::start(
2020-06-05 09:35:14 -07:00
//! # &mut client_rng,
2020-12-12 21:53:33 -08:00
//! # b"password",
2020-11-16 14:05:43 -08:00
//! # ClientLoginStartParameters::default(),
2020-06-05 09:35:14 -07:00
//! # )?;
2020-11-16 14:05:43 -08:00
//! use opaque_ke::{ServerLogin, ServerLoginStartParameters};
2020-06-05 09:35:14 -07:00
//! use std::convert::TryFrom;
//! let password_file = ServerRegistration::<Default>::try_from(&password_file_bytes[..])?;
2020-06-05 09:35:14 -07:00
//! let mut server_rng = OsRng;
2020-12-12 21:53:33 -08:00
//! let server_login_start_result = ServerLogin::start(
//! &mut server_rng,
//! password_file,
//! &server_kp.private(),
//! client_login_start_result.message,
//! ServerLoginStartParameters::default(),
//! )?;
2020-06-05 09:35:14 -07:00
//! # Ok::<(), ProtocolError>(())
//! ```
//!
2020-12-12 21:53:33 -08:00
//! ### Client Login Finish
//! In the third step of login, the client takes as input a [CredentialResponse] from the server.
//! The client runs [ClientLogin::finish] and produces an output consisting of
//! a [CredentialFinalization] to be sent to the server to complete the protocol,
//! the `shared_secret` sequence of bytes which will match the server's shared secret upon a successful login.
2020-06-05 09:35:14 -07:00
//! ```
2020-06-08 21:02:01 -07:00
//! # use opaque_ke::{
//! # errors::ProtocolError,
2020-12-12 21:53:33 -08:00
//! # ClientRegistration, ClientRegistrationStartParameters, ServerRegistration, ClientLogin, ClientLoginStartParameters, ClientLoginFinishParameters, ServerLogin, ServerLoginStartParameters, CredentialFinalization,
2020-11-03 21:44:00 +00:00
//! # keypair::{KeyPair, X25519KeyPair},
2020-06-08 21:02:01 -07:00
//! # slow_hash::NoOpHash,
//! # };
//! # use opaque_ke::ciphersuite::CipherSuite;
//! # struct Default;
//! # impl CipherSuite for Default {
//! # type Group = curve25519_dalek::ristretto::RistrettoPoint;
//! # type KeyFormat = opaque_ke::keypair::X25519KeyPair;
2020-07-13 15:23:29 -07:00
//! # type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
2020-07-27 15:25:04 -07:00
//! # type Hash = sha2::Sha256;
//! # type SlowHash = opaque_ke::slow_hash::NoOpHash;
//! # }
2020-06-05 09:35:14 -07:00
//! # use rand_core::{OsRng, RngCore};
//! # let mut client_rng = OsRng;
2020-12-12 21:53:33 -08:00
//! # let client_registration_start_result = ClientRegistration::<Default>::start(
//! # &mut client_rng,
2020-06-05 09:35:14 -07:00
//! # b"password",
2020-11-16 14:05:43 -08:00
//! # ClientRegistrationStartParameters::default(),
2020-06-05 09:35:14 -07:00
//! # )?;
//! # let mut server_rng = OsRng;
//! # let server_kp = Default::generate_random_keypair(&mut server_rng)?;
2020-12-12 21:53:33 -08:00
//! # let server_registration_start_result = ServerRegistration::<Default>::start(&mut server_rng, client_registration_start_result.message, server_kp.public())?;
//! # let client_registration_finish_result = client_registration_start_result.state.finish(&mut client_rng, server_registration_start_result.message)?;
//! # let password_file_bytes = server_registration_start_result.state.finish(client_registration_finish_result.message)?.to_bytes();
2020-11-16 14:05:43 -08:00
//! # let client_login_start_result = ClientLogin::<Default>::start(
2020-12-12 21:53:33 -08:00
//! # &mut client_rng,
//! # b"password",
//! # ClientLoginStartParameters::default(),
2020-06-05 09:35:14 -07:00
//! # )?;
//! # use std::convert::TryFrom;
//! # let password_file =
//! # ServerRegistration::<Default>::try_from(
2020-06-05 09:35:14 -07:00
//! # &password_file_bytes[..],
//! # )?;
2020-11-16 14:05:43 -08:00
//! # let server_login_start_result =
2020-12-12 21:53:33 -08:00
//! # ServerLogin::start(&mut server_rng, password_file, &server_kp.private(), client_login_start_result.message, ServerLoginStartParameters::default())?;
//! let client_login_finish_result = client_login_start_result.state.finish(
//! server_login_start_result.message,
2020-11-16 14:05:43 -08:00
//! ClientLoginFinishParameters::default(),
2020-06-05 09:35:14 -07:00
//! )?;
2020-12-12 21:53:33 -08:00
//! assert_eq!(
//! client_registration_finish_result.export_key,
//! client_login_finish_result.export_key,
//! );
2020-06-05 09:35:14 -07:00
//! # Ok::<(), ProtocolError>(())
//! ```
//!
2020-12-12 21:53:33 -08:00
//! ### Server Login Finish
//! In the fourth step of login, the server takes as input a [CredentialFinalization] from the client and runs [ServerLogin::finish] to
//! produce an output consisting of the `shared_secret` sequence of bytes which will match the client's shared secret upon a successful login.
2020-06-05 09:35:14 -07:00
//! ```
2020-06-08 21:02:01 -07:00
//! # use opaque_ke::{
//! # errors::ProtocolError,
2020-12-12 21:53:33 -08:00
//! # ClientRegistration, ClientRegistrationStartParameters, ServerRegistration, ClientLogin, ClientLoginStartParameters, ClientLoginFinishParameters, ServerLogin, ServerLoginStartParameters, CredentialFinalization,
2020-11-03 21:44:00 +00:00
//! # keypair::{KeyPair, X25519KeyPair},
2020-06-08 21:02:01 -07:00
//! # slow_hash::NoOpHash,
//! # };
//! # use opaque_ke::ciphersuite::CipherSuite;
//! # struct Default;
//! # impl CipherSuite for Default {
//! # type Group = curve25519_dalek::ristretto::RistrettoPoint;
//! # type KeyFormat = opaque_ke::keypair::X25519KeyPair;
2020-07-13 15:23:29 -07:00
//! # type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
2020-07-27 15:25:04 -07:00
//! # type Hash = sha2::Sha256;
//! # type SlowHash = opaque_ke::slow_hash::NoOpHash;
//! # }
2020-06-05 09:35:14 -07:00
//! # use rand_core::{OsRng, RngCore};
//! # let mut client_rng = OsRng;
2020-12-12 21:53:33 -08:00
//! # let client_registration_start_result = ClientRegistration::<Default>::start(
//! # &mut client_rng,
2020-06-05 09:35:14 -07:00
//! # b"password",
2020-11-16 14:05:43 -08:00
//! # ClientRegistrationStartParameters::default(),
2020-06-05 09:35:14 -07:00
//! # )?;
//! # let mut server_rng = OsRng;
//! # let server_kp = Default::generate_random_keypair(&mut server_rng)?;
2020-12-12 21:53:33 -08:00
//! # let server_registration_start_result = ServerRegistration::<Default>::start(&mut server_rng, client_registration_start_result.message, server_kp.public())?;
//! # let client_registration_finish_result = client_registration_start_result.state.finish(&mut client_rng, server_registration_start_result.message)?;
//! # let password_file_bytes = server_registration_start_result.state.finish(client_registration_finish_result.message)?.to_bytes();
2020-11-16 14:05:43 -08:00
//! # let client_login_start_result = ClientLogin::<Default>::start(
2020-06-05 09:35:14 -07:00
//! # &mut client_rng,
2020-12-12 21:53:33 -08:00
//! # b"password",
2020-11-16 14:05:43 -08:00
//! # ClientLoginStartParameters::default(),
2020-06-05 09:35:14 -07:00
//! # )?;
//! # use std::convert::TryFrom;
//! # let password_file =
//! # ServerRegistration::<Default>::try_from(
2020-06-05 09:35:14 -07:00
//! # &password_file_bytes[..],
//! # )?;
2020-11-16 14:05:43 -08:00
//! # let server_login_start_result =
2020-12-12 21:53:33 -08:00
//! # ServerLogin::start(&mut server_rng, password_file, &server_kp.private(), client_login_start_result.message, ServerLoginStartParameters::default())?;
//! # let client_login_finish_result = client_login_start_result.state.finish(
//! # server_login_start_result.message,
2020-11-16 14:05:43 -08:00
//! # ClientLoginFinishParameters::default(),
2020-06-05 09:35:14 -07:00
//! # )?;
2020-12-12 21:53:33 -08:00
//! let server_login_finish_result = server_login_start_result.state.finish(
//! client_login_finish_result.message,
//! )?;
//! assert_eq!(
//! client_login_finish_result.shared_secret,
//! server_login_finish_result.shared_secret,
//! );
2020-06-05 09:35:14 -07:00
//! # Ok::<(), ProtocolError>(())
//! ```
2020-12-12 21:53:33 -08:00
//! If the protocol completes successfully, then the server obtains a `server_login_finish_result.shared_secret` which is guaranteed to
//! match `client_login_finish_result.shared_secret`. Otherwise, on failure, the [ServerLogin::finish] algorithm outputs the error [InvalidLoginError](errors::PakeError::InvalidLoginError).
2020-06-05 09:35:14 -07:00
//!
#![cfg_attr(not(feature = "bench"), deny(missing_docs))]
#![deny(unsafe_code)]
#[cfg(not(any(feature = "u64_backend", feature = "u32_backend",)))]
compile_error!(
"no dalek arithmetic backend cargo feature enabled! \
please enable one of: u64_backend, u32_backend"
);
2020-06-05 09:35:14 -07:00
// Error types
pub mod errors;
2020-06-05 09:35:14 -07:00
// High-level API
2020-11-16 14:05:43 -08:00
mod opaque;
mod messages;
2020-06-05 09:35:14 -07:00
pub mod ciphersuite;
mod envelope;
2020-10-21 18:20:43 -04:00
pub mod hash;
2020-09-02 15:06:24 -04:00
mod elligator;
2020-07-22 11:58:00 -04:00
pub mod group;
2020-09-02 15:06:24 -04:00
2020-07-22 11:58:00 -04:00
pub mod map_to_curve;
2020-07-13 15:23:29 -07:00
pub mod key_exchange;
2020-06-05 09:35:14 -07:00
pub mod keypair;
#[cfg(feature = "bench")]
pub mod oprf;
#[cfg(not(feature = "bench"))]
2020-06-05 09:35:14 -07:00
mod oprf;
2020-06-08 21:02:01 -07:00
pub mod slow_hash;
2020-06-05 09:35:14 -07:00
mod serialization;
2020-06-05 09:35:14 -07:00
#[cfg(test)]
mod tests;
2020-11-16 14:05:43 -08:00
// Exports
pub use crate::messages::{
2020-12-12 21:53:33 -08:00
CredentialFinalization, CredentialRequest, CredentialResponse, RegistrationRequest,
RegistrationResponse, RegistrationUpload,
2020-11-16 14:05:43 -08:00
};
pub use crate::opaque::{ClientLogin, ClientRegistration, ServerLogin, ServerRegistration};
pub use crate::opaque::{
ClientLoginFinishParameters, ClientLoginStartParameters, ClientRegistrationStartParameters,
ServerLoginStartParameters,
};