Normalize generic parameters for LoginSecondMessage

(aka use the CipherSuite just like the others)

Repair the generics in KE trait: it makes sense that generate_ke[1-3] should operate on the same key representation.
This commit is contained in:
François Garillot
2020-09-19 19:16:36 -04:00
parent 887b4577fa
commit 786bc51fdd
6 changed files with 74 additions and 97 deletions
+4 -4
View File
@@ -12,19 +12,19 @@ use rand_core::{CryptoRng, RngCore};
use std::convert::TryFrom;
pub trait KeyExchange<D: Hash> {
pub trait KeyExchange<D: Hash, KeyFormat: KeyPair<Repr = Key>> {
type KE1State: TryFrom<Vec<u8>, Error = InternalPakeError> + ToBytes;
type KE2State: TryFrom<Vec<u8>, Error = ProtocolError> + ToBytes;
type KE1Message: TryFrom<Vec<u8>, Error = InternalPakeError> + ToBytes;
type KE2Message: TryFrom<Vec<u8>, Error = ProtocolError> + ToBytes;
type KE3Message: TryFrom<Vec<u8>, Error = ProtocolError> + ToBytes;
fn generate_ke1<R: RngCore + CryptoRng, KeyFormat: KeyPair<Repr = Key>>(
fn generate_ke1<R: RngCore + CryptoRng>(
l1_component: Vec<u8>,
rng: &mut R,
) -> Result<(Self::KE1State, Self::KE1Message), ProtocolError>;
fn generate_ke2<R: RngCore + CryptoRng, KeyFormat: KeyPair<Repr = Key>>(
fn generate_ke2<R: RngCore + CryptoRng>(
rng: &mut R,
l1_bytes: Vec<u8>,
l2_bytes: Vec<u8>,
@@ -33,7 +33,7 @@ pub trait KeyExchange<D: Hash> {
server_s_sk: KeyFormat::Repr,
) -> Result<(Self::KE2State, Self::KE2Message), ProtocolError>;
fn generate_ke3<KeyFormat: KeyPair<Repr = Key>>(
fn generate_ke3(
l2_component: Vec<u8>,
ke2_message: Self::KE2Message,
ke1_state: &Self::KE1State,
+4 -4
View File
@@ -31,14 +31,14 @@ static STR_3DH: &[u8] = b"3DH keys";
/// The Triple Diffie-Hellman key exchange implementation
pub struct TripleDH;
impl<D: Hash> KeyExchange<D> for TripleDH {
impl<D: Hash, KeyFormat: KeyPair<Repr = Key>> KeyExchange<D, KeyFormat> for TripleDH {
type KE1State = KE1State<<D as FixedOutput>::OutputSize>;
type KE2State = KE2State<<D as FixedOutput>::OutputSize>;
type KE1Message = KE1Message;
type KE2Message = KE2Message<<D as FixedOutput>::OutputSize>;
type KE3Message = KE3Message<<D as FixedOutput>::OutputSize>;
fn generate_ke1<R: RngCore + CryptoRng, KeyFormat: KeyPair<Repr = Key>>(
fn generate_ke1<R: RngCore + CryptoRng>(
l1_component: Vec<u8>,
rng: &mut R,
) -> Result<(Self::KE1State, Self::KE1Message), ProtocolError> {
@@ -69,7 +69,7 @@ impl<D: Hash> KeyExchange<D> for TripleDH {
))
}
fn generate_ke2<R: RngCore + CryptoRng, KeyFormat: KeyPair<Repr = Key>>(
fn generate_ke2<R: RngCore + CryptoRng>(
rng: &mut R,
l1_bytes: Vec<u8>,
l2_bytes: Vec<u8>,
@@ -132,7 +132,7 @@ impl<D: Hash> KeyExchange<D> for TripleDH {
))
}
fn generate_ke3<KeyFormat: KeyPair<Repr = Key>>(
fn generate_ke3(
l2_component: Vec<u8>,
ke2_message: Self::KE2Message,
ke1_state: &Self::KE1State,