Move PrivateKey from CipherSuite to ServerSetup

This commit is contained in:
daxpedda
2021-07-23 15:23:10 -07:00
committed by Kevin Lewi
parent 124d64c9ca
commit 3d01a605df
8 changed files with 18 additions and 45 deletions
-2
View File
@@ -32,7 +32,6 @@ use std::process::exit;
use opaque_ke::{
ciphersuite::CipherSuite,
keypair::PrivateKey,
rand::{rngs::OsRng, RngCore},
ClientLogin, ClientLoginFinishParameters, ClientRegistration,
ClientRegistrationFinishParameters, CredentialFinalization, CredentialRequest,
@@ -49,7 +48,6 @@ impl CipherSuite for Default {
type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
type Hash = sha2::Sha512;
type SlowHash = opaque_ke::slow_hash::NoOpHash;
type PrivateKey = PrivateKey<Self::Group>;
}
struct Locker {
+4 -6
View File
@@ -26,11 +26,10 @@ use std::collections::HashMap;
use std::process::exit;
use opaque_ke::{
ciphersuite::CipherSuite, keypair::PrivateKey, rand::rngs::OsRng, ClientLogin,
ClientLoginFinishParameters, ClientRegistration, ClientRegistrationFinishParameters,
CredentialFinalization, CredentialRequest, CredentialResponse, RegistrationRequest,
RegistrationResponse, RegistrationUpload, ServerLogin, ServerLoginStartParameters,
ServerRegistration, ServerSetup,
ciphersuite::CipherSuite, rand::rngs::OsRng, ClientLogin, ClientLoginFinishParameters,
ClientRegistration, ClientRegistrationFinishParameters, CredentialFinalization,
CredentialRequest, CredentialResponse, RegistrationRequest, RegistrationResponse,
RegistrationUpload, ServerLogin, ServerLoginStartParameters, ServerRegistration, ServerSetup,
};
// The ciphersuite trait allows to specify the underlying primitives
@@ -42,7 +41,6 @@ impl CipherSuite for Default {
type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
type Hash = sha2::Sha512;
type SlowHash = opaque_ke::slow_hash::NoOpHash;
type PrivateKey = PrivateKey<Self::Group>;
}
// Password-based registration between a client and server
+2 -4
View File
@@ -6,8 +6,8 @@
//! Defines the CipherSuite trait to specify the underlying primitives for OPAQUE
use crate::{
hash::Hash, key_exchange::traits::KeyExchange, keypair::SecretKey,
map_to_curve::GroupWithMapToCurve, slow_hash::SlowHash,
hash::Hash, key_exchange::traits::KeyExchange, map_to_curve::GroupWithMapToCurve,
slow_hash::SlowHash,
};
use digest::Digest;
@@ -31,6 +31,4 @@ pub trait CipherSuite {
type Hash: Hash;
/// A slow hashing function, typically used for password hashing
type SlowHash: SlowHash<Self::Hash>;
/// A private key container, allows remote key implementations
type PrivateKey: SecretKey<Self::Group>;
}
-15
View File
@@ -26,7 +26,6 @@
//! type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
//! type Hash = sha2::Sha512;
//! type SlowHash = opaque_ke::slow_hash::NoOpHash;
//! type PrivateKey = opaque_ke::keypair::PrivateKey<Self::Group>;
//! }
//! ```
//! See [examples/simple_login.rs](https://github.com/novifinancial/opaque-ke/blob/master/examples/simple_login.rs)
@@ -48,7 +47,6 @@
//! # type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
//! # type Hash = sha2::Sha512;
//! # type SlowHash = opaque_ke::slow_hash::NoOpHash;
//! # type PrivateKey = opaque_ke::keypair::PrivateKey<Self::Group>;
//! # }
//! use rand::{rngs::OsRng, RngCore};
//! let mut rng = OsRng;
@@ -81,7 +79,6 @@
//! # type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
//! # type Hash = sha2::Sha512;
//! # type SlowHash = opaque_ke::slow_hash::NoOpHash;
//! # type PrivateKey = opaque_ke::keypair::PrivateKey<Self::Group>;
//! # }
//! use opaque_ke::ClientRegistration;
//! use rand::{rngs::OsRng, RngCore};
@@ -112,7 +109,6 @@
//! # type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
//! # type Hash = sha2::Sha512;
//! # type SlowHash = opaque_ke::slow_hash::NoOpHash;
//! # type PrivateKey = opaque_ke::keypair::PrivateKey<Self::Group>;
//! # }
//! # use rand::{rngs::OsRng, RngCore};
//! # let mut client_rng = OsRng;
@@ -150,7 +146,6 @@
//! # type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
//! # type Hash = sha2::Sha512;
//! # type SlowHash = opaque_ke::slow_hash::NoOpHash;
//! # type PrivateKey = opaque_ke::keypair::PrivateKey<Self::Group>;
//! # }
//! # use rand::{rngs::OsRng, RngCore};
//! # let mut client_rng = OsRng;
@@ -189,7 +184,6 @@
//! # type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
//! # type Hash = sha2::Sha512;
//! # type SlowHash = opaque_ke::slow_hash::NoOpHash;
//! # type PrivateKey = opaque_ke::keypair::PrivateKey<Self::Group>;
//! # }
//! # use rand::{rngs::OsRng, RngCore};
//! # let mut client_rng = OsRng;
@@ -232,7 +226,6 @@
//! # type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
//! # type Hash = sha2::Sha512;
//! # type SlowHash = opaque_ke::slow_hash::NoOpHash;
//! # type PrivateKey = opaque_ke::keypair::PrivateKey<Self::Group>;
//! # }
//! # use rand::{rngs::OsRng, RngCore};
//! use opaque_ke::ClientLogin;
@@ -266,7 +259,6 @@
//! # type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
//! # type Hash = sha2::Sha512;
//! # type SlowHash = opaque_ke::slow_hash::NoOpHash;
//! # type PrivateKey = opaque_ke::keypair::PrivateKey<Self::Group>;
//! # }
//! # use rand::{rngs::OsRng, RngCore};
//! # let mut client_rng = OsRng;
@@ -320,7 +312,6 @@
//! # type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
//! # type Hash = sha2::Sha512;
//! # type SlowHash = opaque_ke::slow_hash::NoOpHash;
//! # type PrivateKey = opaque_ke::keypair::PrivateKey<Self::Group>;
//! # }
//! # use rand::{rngs::OsRng, RngCore};
//! # let mut client_rng = OsRng;
@@ -366,7 +357,6 @@
//! # type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
//! # type Hash = sha2::Sha512;
//! # type SlowHash = opaque_ke::slow_hash::NoOpHash;
//! # type PrivateKey = opaque_ke::keypair::PrivateKey<Self::Group>;
//! # }
//! # use rand::{rngs::OsRng, RngCore};
//! # let mut client_rng = OsRng;
@@ -442,7 +432,6 @@
//! # type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
//! # type Hash = sha2::Sha512;
//! # type SlowHash = opaque_ke::slow_hash::NoOpHash;
//! # type PrivateKey = opaque_ke::keypair::PrivateKey<Self::Group>;
//! # }
//! # use rand::{rngs::OsRng, RngCore};
//! # let mut client_rng = OsRng;
@@ -520,7 +509,6 @@
//! # type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
//! # type Hash = sha2::Sha512;
//! # type SlowHash = opaque_ke::slow_hash::NoOpHash;
//! # type PrivateKey = opaque_ke::keypair::PrivateKey<Self::Group>;
//! # }
//! # use rand::{rngs::OsRng, RngCore};
//! # let mut client_rng = OsRng;
@@ -586,7 +574,6 @@
//! # type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
//! # type Hash = sha2::Sha512;
//! # type SlowHash = opaque_ke::slow_hash::NoOpHash;
//! # type PrivateKey = opaque_ke::keypair::PrivateKey<Self::Group>;
//! # }
//! # use rand::{rngs::OsRng, RngCore};
//! # let mut client_rng = OsRng;
@@ -624,7 +611,6 @@
//! # type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
//! # type Hash = sha2::Sha512;
//! # type SlowHash = opaque_ke::slow_hash::NoOpHash;
//! # type PrivateKey = opaque_ke::keypair::PrivateKey<Self::Group>;
//! # }
//! # use rand::{rngs::OsRng, RngCore};
//! # let mut client_rng = OsRng;
@@ -674,7 +660,6 @@
//! # type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
//! # type Hash = sha2::Sha512;
//! # type SlowHash = opaque_ke::slow_hash::NoOpHash;
//! # type PrivateKey = opaque_ke::keypair::PrivateKey<Self::Group>;
//! # }
//! # use rand::{rngs::OsRng, RngCore};
//! # let mut client_rng = OsRng;
+10 -13
View File
@@ -41,23 +41,20 @@ const STR_OPAQUE_DERIVE_KEY_PAIR: &[u8] = b"OPAQUE-DeriveKeyPair";
feature = "serialize",
derive(serde::Deserialize, serde::Serialize),
serde(bound(
deserialize = "KeyPair<CS::Group, CS::PrivateKey>: serde::Deserialize<'de>",
serialize = "KeyPair<CS::Group, CS::PrivateKey>: serde::Serialize"
deserialize = "KeyPair<CS::Group, S>: serde::Deserialize<'de>",
serialize = "KeyPair<CS::Group, S>: serde::Serialize"
))
)]
pub struct ServerSetup<CS: CipherSuite> {
pub struct ServerSetup<
CS: CipherSuite,
S: SecretKey<CS::Group> = PrivateKey<<CS as CipherSuite>::Group>,
> {
oprf_seed: GenericArray<u8, <CS::Hash as Digest>::OutputSize>,
keypair: KeyPair<CS::Group, CS::PrivateKey>,
keypair: KeyPair<CS::Group, S>,
pub(crate) fake_keypair: KeyPair<CS::Group>,
}
impl<
CS: CipherSuite<Group = G, PrivateKey = PrivateKey<G>>,
G: Group + GroupWithMapToCurve<UniformBytesLen = <CS::Hash as Digest>::OutputSize>,
> ServerSetup<CS>
where
<CS as CipherSuite>::KeyExchange: KeyExchange<<CS as CipherSuite>::Hash, G>,
{
impl<CS: CipherSuite> ServerSetup<CS, PrivateKey<CS::Group>> {
/// Generate a new instance of server setup
pub fn new<R: CryptoRng + RngCore>(rng: &mut R) -> Self {
let mut seed = vec![0u8; <CS::Hash as Digest>::OutputSize::to_usize()];
@@ -71,7 +68,7 @@ where
}
}
impl<CS: CipherSuite> ServerSetup<CS> {
impl<CS: CipherSuite, S: SecretKey<CS::Group>> ServerSetup<CS, S> {
/// Serialization into bytes
pub fn serialize(&self) -> Vec<u8> {
[
@@ -96,7 +93,7 @@ impl<CS: CipherSuite> ServerSetup<CS> {
}
/// Returns the keypair
pub fn keypair(&self) -> &KeyPair<CS::Group, CS::PrivateKey> {
pub fn keypair(&self) -> &KeyPair<CS::Group, S> {
&self.keypair
}
}
+1 -2
View File
@@ -12,7 +12,7 @@ use crate::{
traits::{FromBytes, KeyExchange, ToBytes},
tripledh::{NonceLen, TripleDH},
},
keypair::{KeyPair, PrivateKey, PublicKey},
keypair::{KeyPair, PublicKey},
serialization::{i2osp, os2ip, serialize},
*,
};
@@ -31,7 +31,6 @@ impl CipherSuite for Default {
type KeyExchange = TripleDH;
type Hash = sha2::Sha512;
type SlowHash = crate::slow_hash::NoOpHash;
type PrivateKey = PrivateKey<RistrettoPoint>;
}
const HASH_SIZE: usize = 64; // Because of SHA512
+1 -2
View File
@@ -10,7 +10,7 @@ use crate::{
errors::*,
group::Group,
key_exchange::tripledh::{NonceLen, TripleDH},
keypair::{KeyPair, PrivateKey},
keypair::KeyPair,
opaque::*,
slow_hash::NoOpHash,
tests::mock_rng::CycleRng,
@@ -33,7 +33,6 @@ impl CipherSuite for RistrettoSha5123dhNoSlowHash {
type KeyExchange = TripleDH;
type Hash = sha2::Sha512;
type SlowHash = NoOpHash;
type PrivateKey = PrivateKey<RistrettoPoint>;
}
pub struct TestVectorParameters {
-1
View File
@@ -21,7 +21,6 @@ impl CipherSuite for Ristretto255Sha512NoSlowHash {
type KeyExchange = TripleDH;
type Hash = sha2::Sha512;
type SlowHash = NoOpHash;
type PrivateKey = PrivateKey<RistrettoPoint>;
}
#[derive(PartialEq)]