2023-05-22 23:04:39 -07:00
|
|
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
2022-01-21 22:52:09 +01:00
|
|
|
//
|
2023-05-22 23:04:39 -07:00
|
|
|
// This source code is dual-licensed under either the MIT license found in the
|
|
|
|
|
// LICENSE-MIT file in the root directory of this source tree or the Apache
|
2022-01-21 22:52:09 +01:00
|
|
|
// License, Version 2.0 found in the LICENSE-APACHE file in the root directory
|
2023-05-22 23:04:39 -07:00
|
|
|
// of this source tree. You may select, at your option, one of the above-listed
|
|
|
|
|
// licenses.
|
2022-01-21 22:52:09 +01:00
|
|
|
|
|
|
|
|
//! Defines the CipherSuite trait to specify the underlying primitives for VOPRF
|
|
|
|
|
|
|
|
|
|
use crate::Group;
|
2026-06-27 17:04:58 +02:00
|
|
|
use digest::block_api::BlockSizeUser;
|
|
|
|
|
use digest::typenum::{IsLess, IsLessOrEqual, U256};
|
2026-06-29 11:32:17 +02:00
|
|
|
use digest::{FixedOutput, HashMarker, OutputSizeUser};
|
|
|
|
|
use hash2curve::{ExpandMsg, GroupDigest, MapToCurve, OprfParameters};
|
2026-06-27 17:04:58 +02:00
|
|
|
use hybrid_array::ArraySize;
|
|
|
|
|
use hybrid_array::typenum::{IsGreaterOrEqual, Prod, True, U2};
|
2022-01-21 22:52:09 +01:00
|
|
|
|
|
|
|
|
/// Configures the underlying primitives used in VOPRF
|
|
|
|
|
pub trait CipherSuite
|
|
|
|
|
where
|
2026-06-27 17:04:58 +02:00
|
|
|
<Self::Hash as OutputSizeUser>::OutputSize: ArraySize
|
|
|
|
|
+ IsLess<U256>
|
|
|
|
|
+ IsLessOrEqual<<Self::Hash as BlockSizeUser>::BlockSize, Output = True>
|
|
|
|
|
+ IsGreaterOrEqual<Prod<<Self::Group as Group>::SecurityLevel, U2>, Output = True>,
|
2022-01-21 22:52:09 +01:00
|
|
|
{
|
|
|
|
|
/// The ciphersuite identifier as dictated by
|
2024-01-11 11:58:36 -08:00
|
|
|
/// <https://www.rfc-editor.org/rfc/rfc9497>
|
2026-06-27 17:04:58 +02:00
|
|
|
const ID: &'static [u8];
|
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).
|
2026-06-29 11:32:17 +02:00
|
|
|
type Hash: BlockSizeUser + Default + FixedOutput + HashMarker;
|
2022-01-21 22:52:09 +01:00
|
|
|
}
|
2026-06-28 13:14:48 +02:00
|
|
|
|
2026-06-29 11:32:17 +02:00
|
|
|
/// The hash function associated with a curve's OPRF `expand_message` implementation.
|
|
|
|
|
type OprfHash<T> =
|
|
|
|
|
<<T as GroupDigest>::ExpandMsg as ExpandMsg<<T as MapToCurve>::SecurityLevel>>::Hash;
|
2026-06-28 13:14:48 +02:00
|
|
|
|
2026-06-29 11:32:17 +02:00
|
|
|
impl<T: OprfParameters> CipherSuite for T
|
2026-06-28 13:14:48 +02:00
|
|
|
where
|
2026-06-28 18:16:42 +02:00
|
|
|
T: Group,
|
2026-06-29 11:32:17 +02:00
|
|
|
OprfHash<T>: BlockSizeUser + Default + FixedOutput + HashMarker,
|
|
|
|
|
<OprfHash<T> as OutputSizeUser>::OutputSize: ArraySize
|
2026-06-28 13:14:48 +02:00
|
|
|
+ IsLess<U256>
|
2026-06-29 11:32:17 +02:00
|
|
|
+ IsLessOrEqual<<OprfHash<T> as BlockSizeUser>::BlockSize, Output = True>
|
2026-06-28 18:16:42 +02:00
|
|
|
+ IsGreaterOrEqual<Prod<<T as Group>::SecurityLevel, U2>, Output = True>,
|
2026-06-28 13:14:48 +02:00
|
|
|
{
|
2026-06-28 18:16:42 +02:00
|
|
|
const ID: &'static [u8] = T::ID;
|
|
|
|
|
type Group = T;
|
2026-06-29 11:32:17 +02:00
|
|
|
type Hash = OprfHash<T>;
|
2026-06-28 13:14:48 +02:00
|
|
|
}
|