General improvements (#250)
* Remove unnecessary constraints on hash * Remove unnecessary `Result` on `KeyPair::generate_random` * Fix de-serialization issue on `Ke1State` * Fix rustfmt * Remove allocations in `envelope` * Run Clippy for tests and rustdoc lints too * Fix `Debug` implementation * Fix missing constraints on `ClientRegistration` * Fix de-serialization * Pin temporary dependency * Update dependencies * Replace macro with derive-where * Remove unnecessary installation of Rust components * Improve macro naming * Implement `Copy`, `Debug`, `Ord` and `PartialOrd` for high-level items * Add `rust-version` field to `Cargo.toml` * Remove unnecessary allocations * Fix MSRV * Fix no_std * Remove unnecessary allocations * Remove unnecessary allocations * Not importing items from voprf helps readability * Fix rustdoc * Remove unnecessary allocations * Remove unnecessary allocations * Replace `Vec` from `diffie_hellman` with `GenericArray` * Remove unnecessary allocations * Remove unnecessary allocations * Remove `cfg(feature = bench)` guard for `missing_docs` * Fix documentation * Remove all remaining allocations from `KeyExchange` * Improve type-safety * Remove all remaining allocations in `keypair` * Remove last remaining allocations except `NonVerifiableClient` input * Remove base64 encoding in Serde implementation * Remove unnecessary Serde `alloc` feature * Make curve25519-dalek optional * Rename `serialize` crate feature to `serde` * Switch `KeGroup` implementations to higher-level libraries - Fixes missing clamping in X25519 - X25519 is now a separate crate feature * Fix typo
This commit is contained in:
Regular → Executable
+46
-23
@@ -12,7 +12,8 @@ use crate::{
|
||||
hash::Hash,
|
||||
keypair::{PrivateKey, PublicKey, SecretKey},
|
||||
};
|
||||
use alloc::vec::Vec;
|
||||
use digest::Digest;
|
||||
use generic_array::{ArrayLength, GenericArray};
|
||||
use rand::{CryptoRng, RngCore};
|
||||
use zeroize::Zeroize;
|
||||
|
||||
@@ -25,23 +26,26 @@ pub type GenerateKe2Result<K, D, G> = (
|
||||
pub type GenerateKe2Result<K, D, G> = (
|
||||
<K as KeyExchange<D, G>>::KE2State,
|
||||
<K as KeyExchange<D, G>>::KE2Message,
|
||||
Vec<u8>,
|
||||
generic_array::GenericArray<u8, <D as digest::Digest>::OutputSize>,
|
||||
GenericArray<u8, <D as Digest>::OutputSize>,
|
||||
GenericArray<u8, <D as Digest>::OutputSize>,
|
||||
);
|
||||
#[cfg(not(test))]
|
||||
pub type GenerateKe3Result<K, D, G> = (Vec<u8>, <K as KeyExchange<D, G>>::KE3Message);
|
||||
pub type GenerateKe3Result<K, D, G> = (
|
||||
GenericArray<u8, <D as Digest>::OutputSize>,
|
||||
<K as KeyExchange<D, G>>::KE3Message,
|
||||
);
|
||||
#[cfg(test)]
|
||||
pub type GenerateKe3Result<K, D, G> = (
|
||||
Vec<u8>,
|
||||
GenericArray<u8, <D as Digest>::OutputSize>,
|
||||
<K as KeyExchange<D, G>>::KE3Message,
|
||||
Vec<u8>,
|
||||
generic_array::GenericArray<u8, <D as digest::Digest>::OutputSize>,
|
||||
GenericArray<u8, <D as Digest>::OutputSize>,
|
||||
GenericArray<u8, <D as Digest>::OutputSize>,
|
||||
);
|
||||
|
||||
pub trait KeyExchange<D: Hash, G: KeGroup> {
|
||||
type KE1State: FromBytes + ToBytes + Zeroize + Clone;
|
||||
type KE2State: FromBytes + ToBytes + Zeroize + Clone;
|
||||
type KE1Message: FromBytes + ToBytes + Clone;
|
||||
type KE1Message: FromBytes + ToBytes + Zeroize + Clone;
|
||||
type KE2Message: FromBytes + ToBytes + Clone;
|
||||
type KE3Message: FromBytes + ToBytes + Clone;
|
||||
|
||||
@@ -50,44 +54,63 @@ pub trait KeyExchange<D: Hash, G: KeGroup> {
|
||||
) -> Result<(Self::KE1State, Self::KE1Message), ProtocolError>;
|
||||
|
||||
#[allow(clippy::too_many_arguments, clippy::type_complexity)]
|
||||
fn generate_ke2<R: RngCore + CryptoRng, S: SecretKey<G>>(
|
||||
fn generate_ke2<'a, 'b, 'c, 'd, R: RngCore + CryptoRng, S: SecretKey<G>>(
|
||||
rng: &mut R,
|
||||
l1_bytes: Vec<u8>,
|
||||
l2_bytes: Vec<u8>,
|
||||
l1_bytes: impl Iterator<Item = &'a [u8]>,
|
||||
l2_bytes: impl Iterator<Item = &'b [u8]>,
|
||||
ke1_message: Self::KE1Message,
|
||||
client_s_pk: PublicKey<G>,
|
||||
server_s_sk: S,
|
||||
id_u: Vec<u8>,
|
||||
id_s: Vec<u8>,
|
||||
context: Vec<u8>,
|
||||
id_u: impl Iterator<Item = &'c [u8]>,
|
||||
id_s: impl Iterator<Item = &'d [u8]>,
|
||||
context: &[u8],
|
||||
) -> Result<GenerateKe2Result<Self, D, G>, ProtocolError<S::Error>>;
|
||||
|
||||
#[allow(clippy::too_many_arguments, clippy::type_complexity)]
|
||||
fn generate_ke3(
|
||||
l2_component: Vec<u8>,
|
||||
fn generate_ke3<'a, 'b, 'c, 'd>(
|
||||
l2_component: impl Iterator<Item = &'a [u8]>,
|
||||
ke2_message: Self::KE2Message,
|
||||
ke1_state: &Self::KE1State,
|
||||
serialized_credential_request: &[u8],
|
||||
serialized_credential_request: impl Iterator<Item = &'b [u8]>,
|
||||
server_s_pk: PublicKey<G>,
|
||||
client_s_sk: PrivateKey<G>,
|
||||
id_u: Vec<u8>,
|
||||
id_s: Vec<u8>,
|
||||
context: Vec<u8>,
|
||||
id_u: impl Iterator<Item = &'c [u8]>,
|
||||
id_s: impl Iterator<Item = &'d [u8]>,
|
||||
context: &[u8],
|
||||
) -> Result<GenerateKe3Result<Self, D, G>, ProtocolError>;
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn finish_ke(
|
||||
ke3_message: Self::KE3Message,
|
||||
ke2_state: &Self::KE2State,
|
||||
) -> Result<Vec<u8>, ProtocolError>;
|
||||
) -> Result<GenericArray<u8, D::OutputSize>, ProtocolError>;
|
||||
|
||||
fn ke2_message_size() -> usize;
|
||||
}
|
||||
|
||||
pub trait FromBytes: Sized {
|
||||
fn from_bytes<CS: CipherSuite>(input: &[u8]) -> Result<Self, ProtocolError>;
|
||||
fn from_bytes(input: &[u8]) -> Result<Self, ProtocolError>;
|
||||
}
|
||||
|
||||
pub trait ToBytes {
|
||||
fn to_bytes(&self) -> Vec<u8>;
|
||||
type Len: ArrayLength<u8>;
|
||||
|
||||
fn to_bytes(&self) -> GenericArray<u8, Self::Len>;
|
||||
}
|
||||
|
||||
#[allow(dead_code, type_alias_bounds)]
|
||||
pub type Ke1StateLen<CS: CipherSuite> =
|
||||
<<CS::KeyExchange as KeyExchange<CS::Hash, CS::KeGroup>>::KE1State as ToBytes>::Len;
|
||||
#[allow(type_alias_bounds)]
|
||||
pub type Ke1MessageLen<CS: CipherSuite> =
|
||||
<<CS::KeyExchange as KeyExchange<CS::Hash, CS::KeGroup>>::KE1Message as ToBytes>::Len;
|
||||
#[allow(type_alias_bounds)]
|
||||
#[allow(type_alias_bounds)]
|
||||
pub type Ke2StateLen<CS: CipherSuite> =
|
||||
<<CS::KeyExchange as KeyExchange<CS::Hash, CS::KeGroup>>::KE2State as ToBytes>::Len;
|
||||
#[allow(type_alias_bounds)]
|
||||
pub type Ke2MessageLen<CS: CipherSuite> =
|
||||
<<CS::KeyExchange as KeyExchange<CS::Hash, CS::KeGroup>>::KE2Message as ToBytes>::Len;
|
||||
#[allow(type_alias_bounds)]
|
||||
pub type Ke3MessageLen<CS: CipherSuite> =
|
||||
<<CS::KeyExchange as KeyExchange<CS::Hash, CS::KeGroup>>::KE3Message as ToBytes>::Len;
|
||||
|
||||
Reference in New Issue
Block a user