General cleanups and reorganizing code (#236)
This commit is contained in:
+120
-139
@@ -22,8 +22,10 @@ use digest::Digest;
|
||||
use generic_array::{typenum::Unsigned, GenericArray};
|
||||
use rand::{CryptoRng, RngCore};
|
||||
|
||||
// Messages
|
||||
// =========
|
||||
////////////////////////////
|
||||
// High-level API Structs //
|
||||
// ====================== //
|
||||
////////////////////////////
|
||||
|
||||
/// The message sent by the client to the server, to initiate registration
|
||||
pub struct RegistrationRequest<CS: CipherSuite> {
|
||||
@@ -31,24 +33,62 @@ pub struct RegistrationRequest<CS: CipherSuite> {
|
||||
pub(crate) alpha: CS::OprfGroup,
|
||||
}
|
||||
|
||||
/// The answer sent by the server to the user, upon reception of the
|
||||
/// registration attempt
|
||||
pub struct RegistrationResponse<CS: CipherSuite> {
|
||||
/// The server's oprf output
|
||||
pub(crate) beta: CS::OprfGroup,
|
||||
/// Server's static public key
|
||||
pub(crate) server_s_pk: PublicKey<CS::KeGroup>,
|
||||
}
|
||||
|
||||
/// The final message from the client, containing sealed cryptographic
|
||||
/// identifiers
|
||||
pub struct RegistrationUpload<CS: CipherSuite> {
|
||||
/// The "envelope" generated by the user, containing sealed
|
||||
/// cryptographic identifiers
|
||||
pub(crate) envelope: Envelope<CS>,
|
||||
/// The masking key used to mask the envelope
|
||||
pub(crate) masking_key: GenericArray<u8, <CS::Hash as Digest>::OutputSize>,
|
||||
/// The user's public key
|
||||
pub(crate) client_s_pk: PublicKey<CS::KeGroup>,
|
||||
}
|
||||
|
||||
/// The message sent by the user to the server, to initiate registration
|
||||
pub struct CredentialRequest<CS: CipherSuite> {
|
||||
/// blinded password information
|
||||
pub(crate) alpha: CS::OprfGroup,
|
||||
pub(crate) ke1_message: <CS::KeyExchange as KeyExchange<CS::Hash, CS::KeGroup>>::KE1Message,
|
||||
}
|
||||
|
||||
/// The answer sent by the server to the user, upon reception of the
|
||||
/// login attempt
|
||||
pub struct CredentialResponse<CS: CipherSuite> {
|
||||
/// the server's oprf output
|
||||
pub(crate) beta: CS::OprfGroup,
|
||||
pub(crate) masking_nonce: Vec<u8>,
|
||||
pub(crate) masked_response: Vec<u8>,
|
||||
pub(crate) ke2_message: <CS::KeyExchange as KeyExchange<CS::Hash, CS::KeGroup>>::KE2Message,
|
||||
}
|
||||
|
||||
/// The answer sent by the client to the server, upon reception of the
|
||||
/// sealed envelope
|
||||
pub struct CredentialFinalization<CS: CipherSuite> {
|
||||
pub(crate) ke3_message: <CS::KeyExchange as KeyExchange<CS::Hash, CS::KeGroup>>::KE3Message,
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// High-level Implementations //
|
||||
// ========================== //
|
||||
////////////////////////////////
|
||||
|
||||
impl<CS: CipherSuite> RegistrationRequest<CS> {
|
||||
/// Only used for testing purposes
|
||||
#[cfg(test)]
|
||||
pub fn get_alpha_for_testing(&self) -> CS::OprfGroup {
|
||||
self.alpha
|
||||
}
|
||||
}
|
||||
|
||||
// Cannot be derived because it would require for CS to be Clone.
|
||||
impl<CS: CipherSuite> Clone for RegistrationRequest<CS> {
|
||||
fn clone(&self) -> Self {
|
||||
Self { alpha: self.alpha }
|
||||
}
|
||||
}
|
||||
|
||||
impl_debug_eq_hash_for!(struct RegistrationRequest<CS: CipherSuite>, [alpha], [CS::OprfGroup]);
|
||||
|
||||
impl<CS: CipherSuite> RegistrationRequest<CS> {
|
||||
/// Serialization into bytes
|
||||
pub fn serialize(&self) -> Vec<u8> {
|
||||
self.alpha.to_arr().to_vec()
|
||||
@@ -71,33 +111,6 @@ impl<CS: CipherSuite> RegistrationRequest<CS> {
|
||||
}
|
||||
}
|
||||
|
||||
impl_serialize_and_deserialize_for!(RegistrationRequest);
|
||||
|
||||
/// The answer sent by the server to the user, upon reception of the
|
||||
/// registration attempt
|
||||
pub struct RegistrationResponse<CS: CipherSuite> {
|
||||
/// The server's oprf output
|
||||
pub(crate) beta: CS::OprfGroup,
|
||||
/// Server's static public key
|
||||
pub(crate) server_s_pk: PublicKey<CS::KeGroup>,
|
||||
}
|
||||
|
||||
// Cannot be derived because it would require for CS to be Clone.
|
||||
impl<CS: CipherSuite> Clone for RegistrationResponse<CS> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
beta: self.beta,
|
||||
server_s_pk: self.server_s_pk.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl_debug_eq_hash_for!(
|
||||
struct RegistrationResponse<CS: CipherSuite>,
|
||||
[beta, server_s_pk],
|
||||
[CS::OprfGroup],
|
||||
);
|
||||
|
||||
impl<CS: CipherSuite> RegistrationResponse<CS> {
|
||||
/// Serialization into bytes
|
||||
pub fn serialize(&self) -> Vec<u8> {
|
||||
@@ -140,29 +153,6 @@ impl<CS: CipherSuite> RegistrationResponse<CS> {
|
||||
}
|
||||
}
|
||||
|
||||
impl_serialize_and_deserialize_for!(RegistrationResponse);
|
||||
|
||||
/// The final message from the client, containing sealed cryptographic
|
||||
/// identifiers
|
||||
pub struct RegistrationUpload<CS: CipherSuite> {
|
||||
/// The "envelope" generated by the user, containing sealed
|
||||
/// cryptographic identifiers
|
||||
pub(crate) envelope: Envelope<CS>,
|
||||
/// The masking key used to mask the envelope
|
||||
pub(crate) masking_key: GenericArray<u8, <CS::Hash as Digest>::OutputSize>,
|
||||
/// The user's public key
|
||||
pub(crate) client_s_pk: PublicKey<CS::KeGroup>,
|
||||
}
|
||||
|
||||
impl_clone_for!(
|
||||
struct RegistrationUpload<CS: CipherSuite>,
|
||||
[envelope, masking_key, client_s_pk],
|
||||
);
|
||||
impl_debug_eq_hash_for!(
|
||||
struct RegistrationUpload<CS: CipherSuite>,
|
||||
[envelope, masking_key, client_s_pk],
|
||||
);
|
||||
|
||||
impl<CS: CipherSuite> RegistrationUpload<CS> {
|
||||
/// Serialization into bytes
|
||||
pub fn serialize(&self) -> Vec<u8> {
|
||||
@@ -208,34 +198,6 @@ impl<CS: CipherSuite> RegistrationUpload<CS> {
|
||||
}
|
||||
}
|
||||
|
||||
impl_serialize_and_deserialize_for!(RegistrationUpload);
|
||||
|
||||
/// The message sent by the user to the server, to initiate registration
|
||||
pub struct CredentialRequest<CS: CipherSuite> {
|
||||
/// blinded password information
|
||||
pub(crate) alpha: CS::OprfGroup,
|
||||
pub(crate) ke1_message: <CS::KeyExchange as KeyExchange<CS::Hash, CS::KeGroup>>::KE1Message,
|
||||
}
|
||||
|
||||
// Cannot be derived because it would require for CS to be Clone.
|
||||
impl<CS: CipherSuite> Clone for CredentialRequest<CS> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
alpha: self.alpha,
|
||||
ke1_message: self.ke1_message.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl_debug_eq_hash_for!(
|
||||
struct CredentialRequest<CS: CipherSuite>,
|
||||
[alpha, ke1_message],
|
||||
[
|
||||
CS::OprfGroup,
|
||||
<CS::KeyExchange as KeyExchange<CS::Hash, CS::KeGroup>>::KE1Message
|
||||
],
|
||||
);
|
||||
|
||||
impl<CS: CipherSuite> CredentialRequest<CS> {
|
||||
/// Serialization into bytes
|
||||
pub fn serialize(&self) -> Vec<u8> {
|
||||
@@ -273,39 +235,6 @@ impl<CS: CipherSuite> CredentialRequest<CS> {
|
||||
}
|
||||
}
|
||||
|
||||
impl_serialize_and_deserialize_for!(CredentialRequest);
|
||||
|
||||
/// The answer sent by the server to the user, upon reception of the
|
||||
/// login attempt
|
||||
pub struct CredentialResponse<CS: CipherSuite> {
|
||||
/// the server's oprf output
|
||||
pub(crate) beta: CS::OprfGroup,
|
||||
pub(crate) masking_nonce: Vec<u8>,
|
||||
pub(crate) masked_response: Vec<u8>,
|
||||
pub(crate) ke2_message: <CS::KeyExchange as KeyExchange<CS::Hash, CS::KeGroup>>::KE2Message,
|
||||
}
|
||||
|
||||
// Cannot be derived because it would require for CS to be Clone.
|
||||
impl<CS: CipherSuite> Clone for CredentialResponse<CS> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
beta: self.beta,
|
||||
masking_nonce: self.masking_nonce.clone(),
|
||||
masked_response: self.masked_response.clone(),
|
||||
ke2_message: self.ke2_message.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl_debug_eq_hash_for!(
|
||||
struct CredentialResponse<CS: CipherSuite>,
|
||||
[beta, masking_nonce, masked_response, ke2_message],
|
||||
[
|
||||
CS::OprfGroup,
|
||||
<CS::KeyExchange as KeyExchange<CS::Hash, CS::KeGroup>>::KE2Message,
|
||||
],
|
||||
);
|
||||
|
||||
impl<CS: CipherSuite> CredentialResponse<CS> {
|
||||
/// Serialization into bytes
|
||||
pub fn serialize(&self) -> Vec<u8> {
|
||||
@@ -380,21 +309,6 @@ impl<CS: CipherSuite> CredentialResponse<CS> {
|
||||
}
|
||||
}
|
||||
|
||||
impl_serialize_and_deserialize_for!(CredentialResponse);
|
||||
|
||||
/// The answer sent by the client to the server, upon reception of the
|
||||
/// sealed envelope
|
||||
pub struct CredentialFinalization<CS: CipherSuite> {
|
||||
pub(crate) ke3_message: <CS::KeyExchange as KeyExchange<CS::Hash, CS::KeGroup>>::KE3Message,
|
||||
}
|
||||
|
||||
impl_clone_for!(struct CredentialFinalization<CS: CipherSuite>, [ke3_message]);
|
||||
impl_debug_eq_hash_for!(
|
||||
struct CredentialFinalization<CS: CipherSuite>,
|
||||
[ke3_message],
|
||||
[<CS::KeyExchange as KeyExchange<CS::Hash, CS::KeGroup>>::KE3Message],
|
||||
);
|
||||
|
||||
impl<CS: CipherSuite> CredentialFinalization<CS> {
|
||||
/// Serialization into bytes
|
||||
pub fn serialize(&self) -> Vec<u8> {
|
||||
@@ -411,4 +325,71 @@ impl<CS: CipherSuite> CredentialFinalization<CS> {
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////
|
||||
// Trait Implementations //
|
||||
// ===================== //
|
||||
///////////////////////////
|
||||
|
||||
impl_clone_for!(
|
||||
struct RegistrationRequest<CS: CipherSuite>,
|
||||
[alpha],
|
||||
);
|
||||
impl_debug_eq_hash_for!(struct RegistrationRequest<CS: CipherSuite>, [alpha], [CS::OprfGroup]);
|
||||
impl_serialize_and_deserialize_for!(RegistrationRequest);
|
||||
|
||||
impl_clone_for!(
|
||||
struct RegistrationResponse<CS: CipherSuite>,
|
||||
[beta, server_s_pk],
|
||||
);
|
||||
impl_debug_eq_hash_for!(
|
||||
struct RegistrationResponse<CS: CipherSuite>,
|
||||
[beta, server_s_pk],
|
||||
[CS::OprfGroup],
|
||||
);
|
||||
impl_serialize_and_deserialize_for!(RegistrationResponse);
|
||||
|
||||
impl_clone_for!(
|
||||
struct RegistrationUpload<CS: CipherSuite>,
|
||||
[envelope, masking_key, client_s_pk],
|
||||
);
|
||||
impl_debug_eq_hash_for!(
|
||||
struct RegistrationUpload<CS: CipherSuite>,
|
||||
[envelope, masking_key, client_s_pk],
|
||||
);
|
||||
impl_serialize_and_deserialize_for!(RegistrationUpload);
|
||||
|
||||
impl_clone_for!(
|
||||
struct CredentialRequest<CS: CipherSuite>,
|
||||
[alpha, ke1_message],
|
||||
);
|
||||
impl_debug_eq_hash_for!(
|
||||
struct CredentialRequest<CS: CipherSuite>,
|
||||
[alpha, ke1_message],
|
||||
[
|
||||
CS::OprfGroup,
|
||||
<CS::KeyExchange as KeyExchange<CS::Hash, CS::KeGroup>>::KE1Message
|
||||
],
|
||||
);
|
||||
impl_serialize_and_deserialize_for!(CredentialRequest);
|
||||
|
||||
impl_clone_for!(
|
||||
struct CredentialResponse<CS: CipherSuite>,
|
||||
[beta, masking_nonce, masked_response, ke2_message],
|
||||
);
|
||||
impl_debug_eq_hash_for!(
|
||||
struct CredentialResponse<CS: CipherSuite>,
|
||||
[beta, masking_nonce, masked_response, ke2_message],
|
||||
[
|
||||
CS::OprfGroup,
|
||||
<CS::KeyExchange as KeyExchange<CS::Hash, CS::KeGroup>>::KE2Message,
|
||||
],
|
||||
);
|
||||
impl_serialize_and_deserialize_for!(CredentialResponse);
|
||||
|
||||
impl_clone_for!(struct CredentialFinalization<CS: CipherSuite>, [ke3_message]);
|
||||
impl_debug_eq_hash_for!(
|
||||
struct CredentialFinalization<CS: CipherSuite>,
|
||||
[ke3_message],
|
||||
[<CS::KeyExchange as KeyExchange<CS::Hash, CS::KeGroup>>::KE3Message],
|
||||
);
|
||||
impl_serialize_and_deserialize_for!(CredentialFinalization);
|
||||
|
||||
Reference in New Issue
Block a user