Skip to content

Commit

Permalink
Merge pull request #30 from xmtp/np/make-psk-number-public
Browse files Browse the repository at this point in the history
Pull upstream to expose PSKs
  • Loading branch information
nplasterer authored Jun 7, 2024
2 parents 606bf92 + 8a86797 commit 99b2d5e
Show file tree
Hide file tree
Showing 15 changed files with 850 additions and 245 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/interop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ jobs:
make run-go || echo "Build despite errors."
cd test-runner
# TODO(#1366)
go get -u google.golang.org/grpc
go mod tidy -e
patch main.go main.go.patch
go build
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- [#1506](https://github.com/openmls/openmls/pull/1506): Add `StagedWelcome` and `StagedCoreWelcome` to make joining a group staged in order to inspect the `Welcome` message. This was followed up with PR [#1533](https://github.com/openmls/openmls/pull/1533) to adjust the API.
- [#1516](https://github.com/openmls/openmls/pull/1516): Add `MlsGroup::clear_pending_proposals` to the public API; this allows users to clear a group's internal `ProposalStore`
- [#1565](https://github.com/openmls/openmls/pull/1565): Add new `StorageProvider` trait to the `openmls_traits` crate.

### Changed

Expand All @@ -27,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#1548](https://github.com/openmls/openmls/pull/1548): CryptoConfig is now replaced by just Ciphersuite.
- [#1542](https://github.com/openmls/openmls/pull/1542): Add support for custom proposals. ProposalType::Unknown is now called ProposalType::Other. Proposal::Unknown is now called Proposal::Other.
- [#1559](https://github.com/openmls/openmls/pull/1559): Remove the `PartialEq` type constraint on the error type of both the `OpenMlsRand` and `OpenMlsKeyStore` traits. Additionally, remove the `Clone` type constraint on the error type of the `OpenMlsRand` trait.
- [#1565](https://github.com/openmls/openmls/pull/1565): Removed `OpenMlsKeyStore` and replace it with a new `StorageProvider` trait in the `openmls_traits` crate.

### Fixed

Expand Down
242 changes: 238 additions & 4 deletions openmls/benches/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ extern crate rand;
use criterion::Criterion;
use openmls::prelude::*;
use openmls_basic_credential::SignatureKeyPair;
use openmls_rust_crypto::OpenMlsRustCrypto;
use openmls_traits::{crypto::OpenMlsCrypto, OpenMlsProvider};

pub type OpenMlsRustCrypto = openmls_rust_crypto::OpenMlsRustCrypto;

fn criterion_kp_bundle(c: &mut Criterion, provider: &impl OpenMlsProvider) {
fn criterion_key_package(c: &mut Criterion, provider: &impl OpenMlsProvider) {
for &ciphersuite in provider.crypto().supported_ciphersuites().iter() {
c.bench_function(
&format!("KeyPackage create bundle with ciphersuite: {ciphersuite:?}"),
Expand Down Expand Up @@ -38,14 +37,249 @@ fn criterion_kp_bundle(c: &mut Criterion, provider: &impl OpenMlsProvider) {
}
}

fn create_welcome(c: &mut Criterion, provider: &impl OpenMlsProvider) {
for &ciphersuite in provider.crypto().supported_ciphersuites().iter() {
c.bench_function(
&format!("Create a welcome message with ciphersuite: {ciphersuite:?}"),
move |b| {
b.iter_with_setup(
|| {
let alice_credential = BasicCredential::new("Alice".into());
let alice_signer =
SignatureKeyPair::new(ciphersuite.signature_algorithm()).unwrap();
let alice_credential_with_key = CredentialWithKey {
credential: alice_credential.into(),
signature_key: alice_signer.to_public_vec().into(),
};

let bob_credential = BasicCredential::new("Bob".into());
let bob_signer =
SignatureKeyPair::new(ciphersuite.signature_algorithm()).unwrap();
let bob_credential_with_key = CredentialWithKey {
credential: bob_credential.into(),
signature_key: bob_signer.to_public_vec().into(),
};
let bob_key_package = KeyPackage::builder()
.build(
ciphersuite,
provider,
&bob_signer,
bob_credential_with_key.clone(),
)
.expect("An unexpected error occurred.");

let mls_group_create_config = MlsGroupCreateConfig::builder()
.wire_format_policy(PURE_PLAINTEXT_WIRE_FORMAT_POLICY)
.ciphersuite(ciphersuite)
.build();

// === Alice creates a group ===
let alice_group = MlsGroup::new(
provider,
&alice_signer,
&mls_group_create_config,
alice_credential_with_key.clone(),
)
.expect("An unexpected error occurred.");

(alice_signer, alice_group, bob_key_package)
},
|(alice_signer, mut alice_group, bob_key_package)| {
let _welcome = match alice_group.add_members(
provider,
&alice_signer,
&[bob_key_package.key_package().clone()],
) {
Ok((_, welcome, _)) => welcome,
Err(e) => panic!("Could not add member to group: {e:?}"),
};
},
);
},
);
}
}

fn join_group(c: &mut Criterion, provider: &impl OpenMlsProvider) {
for &ciphersuite in provider.crypto().supported_ciphersuites().iter() {
c.bench_function(
&format!("Join a group with ciphersuite: {ciphersuite:?}"),
move |b| {
b.iter_with_setup(
|| {
let alice_credential = BasicCredential::new("Alice".into());
let alice_signer =
SignatureKeyPair::new(ciphersuite.signature_algorithm()).unwrap();
let alice_credential_with_key = CredentialWithKey {
credential: alice_credential.into(),
signature_key: alice_signer.to_public_vec().into(),
};

let bob_credential = BasicCredential::new("Bob".into());
let bob_signer =
SignatureKeyPair::new(ciphersuite.signature_algorithm()).unwrap();
let bob_credential_with_key = CredentialWithKey {
credential: bob_credential.into(),
signature_key: bob_signer.to_public_vec().into(),
};
let bob_key_package = KeyPackage::builder()
.build(
ciphersuite,
provider,
&bob_signer,
bob_credential_with_key.clone(),
)
.expect("An unexpected error occurred.");

let mls_group_create_config = MlsGroupCreateConfig::builder()
.wire_format_policy(PURE_PLAINTEXT_WIRE_FORMAT_POLICY)
.ciphersuite(ciphersuite)
.build();

// === Alice creates a group ===
let mut alice_group = MlsGroup::new(
provider,
&alice_signer,
&mls_group_create_config,
alice_credential_with_key.clone(),
)
.expect("An unexpected error occurred.");

let welcome = match alice_group.add_members(
provider,
&alice_signer,
&[bob_key_package.key_package().clone()],
) {
Ok((_, welcome, _)) => welcome,
Err(e) => panic!("Could not add member to group: {e:?}"),
};

alice_group
.merge_pending_commit(provider)
.expect("error merging pending commit");

(alice_group, mls_group_create_config, welcome)
},
|(alice_group, mls_group_create_config, welcome)| {
let welcome: MlsMessageIn = welcome.into();
let welcome = welcome
.into_welcome()
.expect("expected the message to be a welcome message");
let _bob_group = StagedWelcome::new_from_welcome(
provider,
mls_group_create_config.join_config(),
welcome,
Some(alice_group.export_ratchet_tree().into()),
)
.unwrap()
.into_group(provider);
},
);
},
);
}
}

fn create_commit(c: &mut Criterion, provider: &impl OpenMlsProvider) {
for &ciphersuite in provider.crypto().supported_ciphersuites().iter() {
c.bench_function(
&format!("Create a commit with ciphersuite: {ciphersuite:?}"),
move |b| {
b.iter_with_setup(
|| {
let alice_credential = BasicCredential::new("Alice".into());
let alice_signer =
SignatureKeyPair::new(ciphersuite.signature_algorithm()).unwrap();
let alice_credential_with_key = CredentialWithKey {
credential: alice_credential.into(),
signature_key: alice_signer.to_public_vec().into(),
};

let bob_credential = BasicCredential::new("Bob".into());
let bob_signer =
SignatureKeyPair::new(ciphersuite.signature_algorithm()).unwrap();
let bob_credential_with_key = CredentialWithKey {
credential: bob_credential.into(),
signature_key: bob_signer.to_public_vec().into(),
};
let bob_key_package = KeyPackage::builder()
.build(
ciphersuite,
provider,
&bob_signer,
bob_credential_with_key.clone(),
)
.expect("An unexpected error occurred.");

let mls_group_create_config = MlsGroupCreateConfig::builder()
.wire_format_policy(PURE_PLAINTEXT_WIRE_FORMAT_POLICY)
.ciphersuite(ciphersuite)
.build();

// === Alice creates a group ===
let mut alice_group = MlsGroup::new(
provider,
&alice_signer,
&mls_group_create_config,
alice_credential_with_key.clone(),
)
.expect("An unexpected error occurred.");

let welcome = match alice_group.add_members(
provider,
&alice_signer,
&[bob_key_package.key_package().clone()],
) {
Ok((_, welcome, _)) => welcome,
Err(e) => panic!("Could not add member to group: {e:?}"),
};

alice_group
.merge_pending_commit(provider)
.expect("error merging pending commit");

let welcome: MlsMessageIn = welcome.into();
let welcome = welcome
.into_welcome()
.expect("expected the message to be a welcome message");
let bob_group = StagedWelcome::new_from_welcome(
provider,
mls_group_create_config.join_config(),
welcome,
Some(alice_group.export_ratchet_tree().into()),
)
.unwrap()
.into_group(provider)
.unwrap();

(bob_group, bob_signer)
},
|(mut bob_group, bob_signer)| {
let (queued_message, welcome_option, _group_info) =
bob_group.self_update(provider, &bob_signer).unwrap();

bob_group
.merge_pending_commit(provider)
.expect("error merging pending commit");
},
);
},
);
}
}

fn kp_bundle_rust_crypto(c: &mut Criterion) {
let provider = &OpenMlsRustCrypto::default();
println!("provider: RustCrypto");
criterion_kp_bundle(c, provider);
criterion_key_package(c, provider);
}

fn criterion_benchmark(c: &mut Criterion) {
kp_bundle_rust_crypto(c);
criterion_key_package(c, &openmls_libcrux_crypto::Provider::default());
create_welcome(c, &openmls_libcrux_crypto::Provider::default());
join_group(c, &openmls_libcrux_crypto::Provider::default());
create_commit(c, &openmls_libcrux_crypto::Provider::default());
}

criterion_group!(benches, criterion_benchmark);
Expand Down
2 changes: 1 addition & 1 deletion openmls/src/group/core_group/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! error, will still return a `Result` since they may throw a `LibraryError`.

// Private
mod new_from_welcome;
pub(super) mod new_from_welcome;

// Crate
pub(crate) mod create_commit_params;
Expand Down
Loading

0 comments on commit 99b2d5e

Please sign in to comment.