Skip to content

Commit 2136b5e

Browse files
committed
refactor: swap meaning of Ciphersuite vs MlsCiphersuite
Previously `MlsCiphersuite` was defined in core-crypto, and `Ciphersuite` was defined in openmls, which was insane. This commit adjusts such that `Ciphersuite` is defined in core-crypto, and `MlsCiphersuite` is a module-level import alias for the definition in openmls.
1 parent 2084922 commit 2136b5e

File tree

28 files changed

+113
-118
lines changed

28 files changed

+113
-118
lines changed

crypto-ffi/src/ciphersuite.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! it doesn't work on newtypes around external enums. We therefore redefine the ciphersuites enum
55
//! here with appropriate annotations such that it gets exported to all relevant bindings.
66
7-
use core_crypto::{CiphersuiteName, MlsCiphersuite};
7+
use core_crypto::{Ciphersuite, CiphersuiteName};
88
#[cfg(target_family = "wasm")]
99
use wasm_bindgen::prelude::*;
1010

@@ -60,16 +60,16 @@ impl From<CiphersuiteName> for Ciphersuite {
6060
}
6161
}
6262

63-
impl From<Ciphersuite> for MlsCiphersuite {
63+
impl From<Ciphersuite> for Ciphersuite {
6464
#[inline]
6565
fn from(value: Ciphersuite) -> Self {
6666
CiphersuiteName::from(value).into()
6767
}
6868
}
6969

70-
impl From<MlsCiphersuite> for Ciphersuite {
70+
impl From<Ciphersuite> for Ciphersuite {
7171
#[inline]
72-
fn from(value: MlsCiphersuite) -> Self {
72+
fn from(value: Ciphersuite) -> Self {
7373
CiphersuiteName::from(value).into()
7474
}
7575
}

crypto-ffi/src/core_crypto/e2ei/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl CoreCryptoFfi {
1717

1818
/// See [core_crypto::Session::e2ei_is_enabled]
1919
pub async fn e2ei_is_enabled(&self, ciphersuite: Ciphersuite) -> CoreCryptoResult<bool> {
20-
let signature_scheme = core_crypto::MlsCiphersuite::from(ciphersuite).signature_algorithm();
20+
let signature_scheme = core_crypto::Ciphersuite::from(ciphersuite).signature_algorithm();
2121
self.inner
2222
.e2ei_is_enabled(signature_scheme)
2323
.await

crypto-ffi/src/core_crypto_context/e2ei.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl CoreCryptoContext {
198198

199199
/// See [core_crypto::Session::e2ei_is_enabled]
200200
pub async fn e2ei_is_enabled(&self, ciphersuite: Ciphersuite) -> CoreCryptoResult<bool> {
201-
let sc = core_crypto::MlsCiphersuite::from(ciphersuite).signature_algorithm();
201+
let sc = core_crypto::Ciphersuite::from(ciphersuite).signature_algorithm();
202202
self.inner
203203
.e2ei_is_enabled(sc)
204204
.await

crypto-ffi/src/core_crypto_context/mls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use core_crypto::{
2-
ClientIdentifier, KeyPackageIn, MlsCiphersuite, MlsConversationConfiguration, RecursiveError, VerifiableGroupInfo,
2+
Ciphersuite, ClientIdentifier, KeyPackageIn, MlsConversationConfiguration, RecursiveError, VerifiableGroupInfo,
33
mls::conversation::Conversation as _, transaction_context::Error as TransactionError,
44
};
55
use tls_codec::{Deserialize as _, Serialize as _};
@@ -60,7 +60,7 @@ impl CoreCryptoContext {
6060
self.inner
6161
.mls_init(
6262
ClientIdentifier::Basic(client_id.as_cc()),
63-
&ciphersuites.into_iter().map(MlsCiphersuite::from).collect::<Vec<_>>(),
63+
&ciphersuites.into_iter().map(Ciphersuite::from).collect::<Vec<_>>(),
6464
)
6565
.await?;
6666
Ok(())

crypto/benches/utils/mls.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use std::{
55

66
use async_lock::RwLock;
77
use core_crypto::{
8-
CertificateBundle, ClientId, ConnectionType, ConversationId, CoreCrypto, Database, DatabaseKey, HistorySecret,
9-
MlsCiphersuite, MlsCommitBundle, MlsConversationConfiguration, MlsCredentialType, MlsCustomConfiguration,
8+
CertificateBundle, Ciphersuite, ClientId, ConnectionType, ConversationId, CoreCrypto, Database, DatabaseKey,
9+
HistorySecret, MlsCommitBundle, MlsConversationConfiguration, MlsCredentialType, MlsCustomConfiguration,
1010
MlsGroupInfoBundle, MlsTransport, MlsTransportData, MlsTransportResponse, Session, SessionConfig,
1111
};
1212
use criterion::BenchmarkId;
@@ -35,7 +35,7 @@ pub enum MlsTestCase {
3535
}
3636

3737
impl MlsTestCase {
38-
pub fn get(&self) -> (Self, MlsCiphersuite, Option<CertificateBundle>) {
38+
pub fn get(&self) -> (Self, Ciphersuite, Option<CertificateBundle>) {
3939
match self {
4040
MlsTestCase::Basic_Ciphersuite1 => (
4141
*self,
@@ -59,7 +59,7 @@ impl MlsTestCase {
5959
}
6060
}
6161

62-
pub fn values() -> impl Iterator<Item = (Self, MlsCiphersuite, Option<CertificateBundle>, bool)> {
62+
pub fn values() -> impl Iterator<Item = (Self, Ciphersuite, Option<CertificateBundle>, bool)> {
6363
[
6464
MlsTestCase::Basic_Ciphersuite1,
6565
#[cfg(feature = "test-all-cipher")]
@@ -121,7 +121,7 @@ impl Display for MlsTestCase {
121121
}
122122

123123
pub async fn setup_mls(
124-
ciphersuite: MlsCiphersuite,
124+
ciphersuite: Ciphersuite,
125125
credential: Option<&CertificateBundle>,
126126
in_memory: bool,
127127
) -> (CoreCrypto, ConversationId, Arc<dyn MlsTransportTestExt>) {
@@ -146,7 +146,7 @@ pub async fn setup_mls(
146146
}
147147

148148
pub async fn new_central(
149-
ciphersuite: MlsCiphersuite,
149+
ciphersuite: Ciphersuite,
150150
// TODO: always None for the moment. Need to update the benches with some realistic certificates. Tracking issue: WPB-9589
151151
_credential: Option<&CertificateBundle>,
152152
in_memory: bool,
@@ -190,7 +190,7 @@ pub fn conversation_id() -> ConversationId {
190190
pub async fn add_clients(
191191
central: &mut Session,
192192
id: &ConversationId,
193-
ciphersuite: MlsCiphersuite,
193+
ciphersuite: Ciphersuite,
194194
nb_clients: usize,
195195
main_client_delivery_service: Arc<dyn MlsTransportTestExt>,
196196
) -> (Vec<ClientId>, VerifiableGroupInfo) {
@@ -225,7 +225,7 @@ pub async fn add_clients(
225225
}
226226

227227
pub async fn setup_mls_and_add_clients(
228-
cipher_suite: MlsCiphersuite,
228+
cipher_suite: Ciphersuite,
229229
credential: Option<&CertificateBundle>,
230230
in_memory: bool,
231231
client_count: usize,
@@ -253,7 +253,7 @@ fn create_signature_keypair(backend: &MlsCryptoProvider, ciphersuite: Ciphersuit
253253
SignatureKeyPair::new(ciphersuite.signature_algorithm(), &mut *rng).unwrap()
254254
}
255255

256-
pub async fn rand_key_package(ciphersuite: MlsCiphersuite) -> (KeyPackage, ClientId) {
256+
pub async fn rand_key_package(ciphersuite: Ciphersuite) -> (KeyPackage, ClientId) {
257257
let client_id = Alphanumeric
258258
.sample_string(&mut rand::thread_rng(), 16)
259259
.as_bytes()
@@ -286,7 +286,7 @@ pub async fn invite(
286286
from: &mut Session,
287287
other: &mut Session,
288288
id: &ConversationId,
289-
ciphersuite: MlsCiphersuite,
289+
ciphersuite: Ciphersuite,
290290
delivery_service: Arc<dyn MlsTransportTestExt>,
291291
) {
292292
let core_crypto = CoreCrypto::from(from.clone());

crypto/src/e2e_identity/crypto.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
use mls_crypto_provider::PkiKeypair;
22
use openmls_basic_credential::SignatureKeyPair as OpenMlsSignatureKeyPair;
3-
use openmls_traits::types::{Ciphersuite, SignatureScheme};
3+
use openmls_traits::types::{Ciphersuite as MlsCiphersuite, SignatureScheme};
44
use wire_e2e_identity::prelude::JwsAlgorithm;
55
use zeroize::Zeroize;
66

77
use super::error::*;
8-
use crate::{MlsCiphersuite, MlsError};
8+
use crate::{Ciphersuite, MlsError};
99

10-
impl TryFrom<MlsCiphersuite> for JwsAlgorithm {
10+
impl TryFrom<Ciphersuite> for JwsAlgorithm {
1111
type Error = Error;
1212

13-
fn try_from(cs: MlsCiphersuite) -> Result<Self> {
14-
let cs = openmls_traits::types::Ciphersuite::from(cs);
13+
fn try_from(cs: Ciphersuite) -> Result<Self> {
14+
let cs = MlsCiphersuite::from(cs);
1515
Ok(match cs {
16-
Ciphersuite::MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519
17-
| Ciphersuite::MLS_128_DHKEMX25519_CHACHA20POLY1305_SHA256_Ed25519 => JwsAlgorithm::Ed25519,
18-
Ciphersuite::MLS_128_DHKEMP256_AES128GCM_SHA256_P256 => JwsAlgorithm::P256,
19-
Ciphersuite::MLS_256_DHKEMP384_AES256GCM_SHA384_P384 => JwsAlgorithm::P384,
20-
Ciphersuite::MLS_256_DHKEMP521_AES256GCM_SHA512_P521 => JwsAlgorithm::P521,
21-
Ciphersuite::MLS_256_DHKEMX448_AES256GCM_SHA512_Ed448
22-
| Ciphersuite::MLS_256_DHKEMX448_CHACHA20POLY1305_SHA512_Ed448 => return Err(Error::NotYetSupported),
16+
MlsCiphersuite::MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519
17+
| MlsCiphersuite::MLS_128_DHKEMX25519_CHACHA20POLY1305_SHA256_Ed25519 => JwsAlgorithm::Ed25519,
18+
MlsCiphersuite::MLS_128_DHKEMP256_AES128GCM_SHA256_P256 => JwsAlgorithm::P256,
19+
MlsCiphersuite::MLS_256_DHKEMP384_AES256GCM_SHA384_P384 => JwsAlgorithm::P384,
20+
MlsCiphersuite::MLS_256_DHKEMP521_AES256GCM_SHA512_P521 => JwsAlgorithm::P521,
21+
MlsCiphersuite::MLS_256_DHKEMX448_AES256GCM_SHA512_Ed448
22+
| MlsCiphersuite::MLS_256_DHKEMX448_CHACHA20POLY1305_SHA512_Ed448 => return Err(Error::NotYetSupported),
2323
})
2424
}
2525
}

crypto/src/e2e_identity/enrollment/crypto.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@ use openmls::prelude::SignatureScheme;
33
use openmls_traits::crypto::OpenMlsCrypto as _;
44

55
use super::{Error, Result};
6-
use crate::{MlsCiphersuite, MlsError, e2e_identity::crypto::E2eiSignatureKeypair};
6+
use crate::{Ciphersuite, MlsError, e2e_identity::crypto::E2eiSignatureKeypair};
77

88
impl super::E2eiEnrollment {
9-
pub(crate) fn new_sign_key(
10-
ciphersuite: MlsCiphersuite,
11-
backend: &MlsCryptoProvider,
12-
) -> Result<E2eiSignatureKeypair> {
9+
pub(crate) fn new_sign_key(ciphersuite: Ciphersuite, backend: &MlsCryptoProvider) -> Result<E2eiSignatureKeypair> {
1310
let (sk, _) = backend
1411
.signature_key_gen(ciphersuite.signature_algorithm())
1512
.map_err(MlsError::wrap("performing signature keygen"))?;

crypto/src/e2e_identity/enrollment/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use wire_e2e_identity::{RustyE2eIdentity, prelude::E2eiAcmeAuthorization};
99
use zeroize::Zeroize as _;
1010

1111
use super::{EnrollmentHandle, Error, Json, Result, crypto::E2eiSignatureKeypair, id::QualifiedE2eiClientId, types};
12-
use crate::{ClientId, KeystoreError, MlsCiphersuite, MlsError};
12+
use crate::{Ciphersuite, ClientId, KeystoreError, MlsError};
1313

1414
/// Wire end to end identity solution for fetching a x509 certificate which identifies a client.
1515
#[derive(Debug, serde::Serialize, serde::Deserialize)]
@@ -27,7 +27,7 @@ pub struct E2eiEnrollment {
2727
device_authz: Option<E2eiAcmeAuthorization>,
2828
valid_order: Option<wire_e2e_identity::prelude::E2eiAcmeOrder>,
2929
finalize: Option<wire_e2e_identity::prelude::E2eiAcmeFinalize>,
30-
pub(super) ciphersuite: MlsCiphersuite,
30+
pub(super) ciphersuite: Ciphersuite,
3131
has_called_new_oidc_challenge_request: bool,
3232
}
3333

@@ -56,7 +56,7 @@ impl E2eiEnrollment {
5656
team: Option<String>,
5757
expiry_sec: u32,
5858
backend: &MlsCryptoProvider,
59-
ciphersuite: MlsCiphersuite,
59+
ciphersuite: Ciphersuite,
6060
sign_keypair: Option<E2eiSignatureKeypair>,
6161
has_called_new_oidc_challenge_request: bool,
6262
) -> Result<Self> {
@@ -88,7 +88,7 @@ impl E2eiEnrollment {
8888
})
8989
}
9090

91-
pub(crate) fn ciphersuite(&self) -> &MlsCiphersuite {
91+
pub(crate) fn ciphersuite(&self) -> &Ciphersuite {
9292
&self.ciphersuite
9393
}
9494

crypto/src/ephemeral.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use obfuscate::{Obfuscate, Obfuscated};
2727
use openmls::prelude::KeyPackageSecretEncapsulation;
2828

2929
use crate::{
30-
ClientId, ClientIdentifier, CoreCrypto, Error, MlsCiphersuite, MlsCredentialType, MlsError, RecursiveError, Result,
30+
Ciphersuite, ClientId, ClientIdentifier, CoreCrypto, Error, MlsCredentialType, MlsError, RecursiveError, Result,
3131
Session, SessionConfig,
3232
};
3333

@@ -56,7 +56,7 @@ impl Obfuscate for HistorySecret {
5656
/// Create a new [`CoreCrypto`] with an **uninitialized** mls session.
5757
///
5858
/// You must initialize the session yourself before using this!
59-
async fn in_memory_cc_with_ciphersuite(ciphersuite: impl Into<MlsCiphersuite>) -> Result<CoreCrypto> {
59+
async fn in_memory_cc_with_ciphersuite(ciphersuite: impl Into<Ciphersuite>) -> Result<CoreCrypto> {
6060
let db = Database::open(ConnectionType::InMemory, &DatabaseKey::generate())
6161
.await
6262
.unwrap();
@@ -85,7 +85,7 @@ async fn in_memory_cc_with_ciphersuite(ciphersuite: impl Into<MlsCiphersuite>) -
8585
/// Note that this is a crate-private function; the public interface for this feature is
8686
/// [`Conversation::generate_history_secret`][core_crypto::mls::conversation::Conversation::generate_history_secret].
8787
/// This implementation lives here instead of there for organizational reasons.
88-
pub(crate) async fn generate_history_secret(ciphersuite: MlsCiphersuite) -> Result<HistorySecret> {
88+
pub(crate) async fn generate_history_secret(ciphersuite: Ciphersuite) -> Result<HistorySecret> {
8989
// generate a new completely arbitrary client id
9090
let client_id = uuid::Uuid::new_v4();
9191
let client_id = format!("{HISTORY_CLIENT_ID_PREFIX}-{client_id}");

crypto/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub use crate::{
5454
RecursiveError, Result, ToRecursiveError,
5555
},
5656
mls::{
57-
ciphersuite::MlsCiphersuite,
57+
ciphersuite::Ciphersuite,
5858
conversation::{
5959
ConversationId, MlsConversation,
6060
commit::MlsCommitBundle,

0 commit comments

Comments
 (0)