Skip to main content

opaque_vx/
ciphersuite.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2// Copyright (c) VexaHub and contributors.
3// Copyright (c) Meta Platforms, Inc. and affiliates.
4
5//! Defines the [`CipherSuite`] trait to specify the underlying primitives for
6//! OPAQUE
7
8use core::ops::Add;
9
10use digest::block_api::{CoreProxy, EagerHash, SmallBlockSizeUser};
11use generic_array::ArrayLength;
12use generic_array::typenum::{IsLess, Le, NonZero, Sum, U256};
13
14use crate::envelope::NonceLen;
15use crate::hash::{Hash, OutputSize, ProxyHash};
16use crate::key_exchange::KeyExchange;
17use crate::key_exchange::group::Group;
18use crate::ksf::Ksf;
19use crate::opaque::MaskedResponseLen;
20
21/// Configures the underlying primitives used in OPAQUE
22/// * `OprfCs`: A VOPRF ciphersuite, see [`voprf::CipherSuite`].
23/// * `KeGroup`: A `Group` used for the `KeyExchange`.
24/// * `KeyExchange`: The key exchange protocol to use in the login step
25/// * `Hash`: The main hashing function to use
26/// * `Ksf`: A key stretching function, typically used for password hashing
27pub trait CipherSuite
28where
29    OprfHash<Self>: Hash + EagerHash,
30    <OprfHash<Self> as CoreProxy>::Core: ProxyHash,
31    <<OprfHash<Self> as CoreProxy>::Core as SmallBlockSizeUser>::_BlockSize: IsLess<U256>,
32    Le<<<OprfHash<Self> as CoreProxy>::Core as SmallBlockSizeUser>::_BlockSize, U256>: NonZero,
33    // Envelope: Nonce + Hash
34    // MaskedResponse: (Nonce + Hash) + KePk
35    // TODO: migrate fully to after hybrid-array v0.5 releases
36    // https://github.com/RustCrypto/hybrid-array/issues/66
37    OutputSize<OprfHash<Self>>: Add<NonceLen> + ArrayLength,
38    Sum<OutputSize<OprfHash<Self>>, NonceLen>: ArrayLength + Add<<KeGroup<Self> as Group>::PkLen>,
39    MaskedResponseLen<Self>: ArrayLength,
40    // hybrid-array interop bounds
41    <OprfGroup<Self> as voprf::Group>::ScalarLen: ArrayLength,
42    <OprfGroup<Self> as voprf::Group>::ElemLen: ArrayLength,
43{
44    /// A VOPRF ciphersuite, see [`voprf::CipherSuite`].
45    type OprfCs: voprf::CipherSuite;
46    /// A key exchange protocol
47    type KeyExchange: KeyExchange;
48    /// A key stretching function, typically used for password hashing
49    type Ksf: Ksf;
50}
51
52pub(crate) type OprfGroup<CS: CipherSuite> = <CS::OprfCs as voprf::CipherSuite>::Group;
53pub(crate) type OprfHash<CS: CipherSuite> = <CS::OprfCs as voprf::CipherSuite>::Hash;
54pub(crate) type KeGroup<CS: CipherSuite> = <CS::KeyExchange as KeyExchange>::Group;
55pub(crate) type KeHash<CS: CipherSuite> = <CS::KeyExchange as KeyExchange>::Hash;