2020-06-14 23:25:31 -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.
|
2020-06-11 14:46:46 -07:00
|
|
|
|
2020-06-14 23:25:31 -07:00
|
|
|
//! Defines the CipherSuite trait to specify the underlying primitives for OPAQUE
|
|
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
|
errors::InternalPakeError,
|
|
|
|
|
group::Group,
|
|
|
|
|
keypair::{Key, KeyPair},
|
2020-07-03 18:28:33 -04:00
|
|
|
oprf::HkdfDigest,
|
2020-06-14 23:25:31 -07:00
|
|
|
slow_hash::SlowHash,
|
|
|
|
|
};
|
2020-07-03 18:28:33 -04:00
|
|
|
use digest::FixedOutput;
|
|
|
|
|
use generic_array::typenum::{U32};
|
2020-06-14 23:25:31 -07:00
|
|
|
use rand_core::{CryptoRng, RngCore};
|
|
|
|
|
|
|
|
|
|
/// Configures the underlying primitives used in OPAQUE
|
2020-07-03 18:28:33 -04:00
|
|
|
/// * `Digest`: a digest suitable for use in an Hkdf, with an output length equal
|
|
|
|
|
/// to the input of the hash-to-curve function of the `Group` parameter.
|
|
|
|
|
/// * `Group`: a finite cyclic group along with a point representation
|
|
|
|
|
/// * `KeyFormat`: a keypair type composed of public and private components
|
|
|
|
|
/// * `SlowHash`: a slow hashing function, typically used for password hashing
|
2020-06-11 14:46:46 -07:00
|
|
|
pub trait CipherSuite {
|
2020-07-03 18:28:33 -04:00
|
|
|
type Digest: HkdfDigest;
|
|
|
|
|
type Group: Group<ScalarLen = U32, UniformBytesLen = <Self::Digest as FixedOutput>::OutputSize>;
|
2020-06-14 23:25:31 -07:00
|
|
|
type KeyFormat: KeyPair<Repr = Key> + PartialEq;
|
|
|
|
|
type SlowHash: SlowHash;
|
|
|
|
|
|
|
|
|
|
/// Generating a random key pair given a cryptographic rng
|
|
|
|
|
fn generate_random_keypair<R: RngCore + CryptoRng>(
|
|
|
|
|
rng: &mut R,
|
|
|
|
|
) -> Result<Self::KeyFormat, InternalPakeError> {
|
|
|
|
|
Self::KeyFormat::generate_random(rng)
|
|
|
|
|
}
|
2020-06-11 14:46:46 -07:00
|
|
|
}
|