openmls/ciphersuite/
mod.rs

1//! # Ciphersuites for MLS
2//!
3//! This module defines the API for interacting with MLS ciphersuites. For
4//! implementation details, refer to `codec.rs` and `ciphersuites.rs`.
5
6use ::tls_codec::{TlsDeserialize, TlsDeserializeBytes, TlsSerialize, TlsSize, VLBytes};
7use openmls_traits::{
8    crypto::OpenMlsCrypto,
9    random::OpenMlsRand,
10    types::{AeadType, Ciphersuite, CryptoError, SignatureScheme},
11};
12use signable::SignedStruct;
13
14use std::hash::Hash;
15
16mod aead;
17mod codec;
18pub(crate) mod hpke;
19mod kdf_label;
20mod mac;
21mod reuse_guard;
22mod secret;
23
24// Public
25pub mod hash_ref;
26pub mod signable;
27pub mod signature;
28#[cfg(feature = "extensions-draft-08")]
29pub use hpke::{
30    safe_decrypt_with_label, safe_encrypt_with_label, Error as HpkeError, SafeEncryptionContext,
31};
32
33// Crate
34pub(crate) use aead::*;
35pub(crate) use mac::*;
36pub(crate) use reuse_guard::*;
37pub(crate) use secret::*;
38pub(crate) use signature::*;
39
40pub(crate) use serde::{Deserialize, Serialize};
41
42#[cfg(test)]
43mod tests_and_kats;
44
45const LABEL_PREFIX: &str = "MLS 1.0 ";
46
47/// A simple type for HPKE public keys using [`VLBytes`] for (de)serializing.
48pub type HpkePublicKey = VLBytes;
49pub use openmls_traits::types::HpkePrivateKey;
50
51/// Compare two byte slices in a way that's hopefully not optimised out by the
52/// compiler.
53#[inline(never)]
54fn equal_ct(a: &[u8], b: &[u8]) -> bool {
55    let mut diff = 0u8;
56    for (l, r) in a.iter().zip(b.iter()) {
57        diff |= l ^ r;
58    }
59    diff == 0
60}