2022-01-21 22:52:09 +01:00
|
|
|
// Copyright (c) Facebook, Inc. and its affiliates.
|
|
|
|
|
//
|
|
|
|
|
// This source code is licensed under both the MIT license found in the
|
|
|
|
|
// LICENSE-MIT file in the root directory of this source tree and the Apache
|
|
|
|
|
// License, Version 2.0 found in the LICENSE-APACHE file in the root directory
|
|
|
|
|
// of this source tree.
|
|
|
|
|
|
|
|
|
|
//! Defines the CipherSuite trait to specify the underlying primitives for VOPRF
|
|
|
|
|
|
|
|
|
|
use digest::core_api::BlockSizeUser;
|
2023-02-08 09:18:04 +01:00
|
|
|
use digest::{FixedOutput, HashMarker, OutputSizeUser};
|
2022-01-21 22:52:09 +01:00
|
|
|
use elliptic_curve::VoprfParameters;
|
|
|
|
|
use generic_array::typenum::{IsLess, IsLessOrEqual, U256};
|
|
|
|
|
|
|
|
|
|
use crate::Group;
|
|
|
|
|
|
|
|
|
|
/// Configures the underlying primitives used in VOPRF
|
|
|
|
|
pub trait CipherSuite
|
|
|
|
|
where
|
|
|
|
|
<Self::Hash as OutputSizeUser>::OutputSize:
|
|
|
|
|
IsLess<U256> + IsLessOrEqual<<Self::Hash as BlockSizeUser>::BlockSize>,
|
|
|
|
|
{
|
|
|
|
|
/// The ciphersuite identifier as dictated by
|
2022-04-01 17:30:28 -07:00
|
|
|
/// <https://datatracker.ietf.org/doc/draft-irtf-cfrg-voprf/>
|
2023-02-08 09:18:04 +01:00
|
|
|
const ID: &'static str;
|
2022-01-21 22:52:09 +01:00
|
|
|
|
|
|
|
|
/// A finite cyclic group along with a point representation that allows some
|
|
|
|
|
/// customization on how to hash an input to a curve point. See [`Group`].
|
|
|
|
|
type Group: Group;
|
|
|
|
|
|
|
|
|
|
/// The main hash function to use (for HKDF computations and hashing
|
|
|
|
|
/// transcripts).
|
2023-02-08 09:18:04 +01:00
|
|
|
type Hash: BlockSizeUser + Default + FixedOutput + HashMarker;
|
2022-01-21 22:52:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: VoprfParameters> CipherSuite for T
|
|
|
|
|
where
|
|
|
|
|
T: Group,
|
2023-02-08 09:18:04 +01:00
|
|
|
T::Hash: BlockSizeUser + Default + FixedOutput + HashMarker,
|
2022-01-21 22:52:09 +01:00
|
|
|
<T::Hash as OutputSizeUser>::OutputSize:
|
|
|
|
|
IsLess<U256> + IsLessOrEqual<<T::Hash as BlockSizeUser>::BlockSize>,
|
|
|
|
|
{
|
2023-02-08 09:18:04 +01:00
|
|
|
const ID: &'static str = T::ID;
|
2022-01-21 22:52:09 +01:00
|
|
|
|
|
|
|
|
type Group = T;
|
|
|
|
|
|
|
|
|
|
type Hash = T::Hash;
|
|
|
|
|
}
|