Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions basic_credential/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ async-trait = { workspace = true }
serde = "1.0"

# Rust Crypto
ed25519-dalek = { version = "2.0.0-rc.3", features = ["rand_core"] }
p256 = "0.13"
p384 = "0.13"
p521 = "0.13"
ed25519-dalek = { version = "3.0", features = ["rand_core"] }
elliptic-curve = "0.14"
p256 = "0.14"
p384 = "0.14"
p521 = "0.14"
secrecy = { version = "0.8", features = ["serde"] }
rand_core = "0.6"
getrandom = { version = "0.2", features = ["js"] }
rand_core = "0.10"
getrandom = { version = "0.4", features = ["wasm_js"] }

[dev-dependencies]
rand = "0.8"
rand = "0.10"

[features]
clonable = [] # Make the keys clonable
Expand Down
19 changes: 10 additions & 9 deletions basic_credential/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//!
//! For now this credential uses only RustCrypto.

use elliptic_curve::Generate as _;
use secrecy::{ExposeSecret, SecretVec};
use std::fmt::Debug;

Expand Down Expand Up @@ -108,23 +109,23 @@ impl SignatureKeyPair {
/// Generates a fresh signature keypair using the [`SignatureScheme`].
pub fn new(
signature_scheme: SignatureScheme,
csprng: &mut impl rand_core::CryptoRngCore,
csprng: &mut impl rand_core::CryptoRng,
) -> Result<Self, CryptoError> {
let (private, public): (SecretVec<u8>, Vec<u8>) = match signature_scheme {
SignatureScheme::ECDSA_SECP256R1_SHA256 => {
let sk = p256::ecdsa::SigningKey::random(csprng);
let pk = sk.verifying_key().to_encoded_point(false).to_bytes().into();
let sk = p256::ecdsa::SigningKey::generate_from_rng(csprng);
let pk = sk.verifying_key().to_sec1_point(false).to_bytes().into();
(sk.to_bytes().to_vec().into(), pk)
}
SignatureScheme::ECDSA_SECP384R1_SHA384 => {
let sk = p384::ecdsa::SigningKey::random(csprng);
let pk = sk.verifying_key().to_encoded_point(false).to_bytes().into();
let sk = p384::ecdsa::SigningKey::generate_from_rng(csprng);
let pk = sk.verifying_key().to_sec1_point(false).to_bytes().into();
(sk.to_bytes().to_vec().into(), pk)
}
SignatureScheme::ECDSA_SECP521R1_SHA512 => {
let sk = p521::ecdsa::SigningKey::random(csprng);
let sk = p521::ecdsa::SigningKey::generate_from_rng(csprng);
let pk = p521::ecdsa::VerifyingKey::from(&sk)
.to_encoded_point(false)
.to_sec1_point(false)
.to_bytes()
.into();
(sk.to_bytes().to_vec().into(), pk)
Expand Down Expand Up @@ -202,7 +203,7 @@ impl SignatureKeyPair {
.map_err(|_| CryptoError::InvalidKey)?;
let sk_pk = p521::ecdsa::VerifyingKey::from(&sk);

if sk_pk.to_encoded_point(false) != pk.to_encoded_point(false) {
if sk_pk.to_sec1_point(false) != pk.to_sec1_point(false) {
return Err(CryptoError::MismatchKeypair);
}
}
Expand Down Expand Up @@ -263,7 +264,7 @@ pub mod tests {
SignatureScheme::ECDSA_SECP521R1_SHA512,
];
for scheme in schemes {
let kp = SignatureKeyPair::new(scheme, &mut rand::thread_rng()).unwrap();
let kp = SignatureKeyPair::new(scheme, &mut rand::rng()).unwrap();
let sk = kp.private.expose_secret().clone();
let pk = kp.public.clone();
SignatureKeyPair::try_from_raw(scheme, sk, pk).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion openmls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ indexmap = "2.0"
itertools = "0.12"

# Only required for tests.
rand = { version = "0.8", optional = true, features = ["getrandom"] }
rand = { version = "0.10", optional = true }
getrandom = { version = "0.2", optional = true, features = ["js"] }
serde_json = { version = "1.0", optional = true }
# Crypto backends required for KAT and testing - "test-utils" feature
Expand Down
44 changes: 11 additions & 33 deletions openmls/src/binary_tree/test_binary_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,17 @@ fn test_tree_basics() {
assert_eq!(tree1.tree_size(), TreeSize::new(3));
assert_eq!(tree1.leaf_count(), 2);

// Test tree creation: Too many nodes (only in cases where usize is 64 bit).
#[cfg(target_pointer_width = "64")]
// We allow uninitialized vectors because we don't want to allocate so much memory
#[allow(clippy::uninit_vec)]
unsafe {
let len = u32::MAX as usize + 2;
let mut nodes: Vec<TreeNode<u32, u32>> = Vec::new();

nodes.set_len(len);

assert_eq!(
MlsBinaryTree::new(nodes).expect_err("No error while creating too large tree."),
MlsBinaryTreeError::OutOfRange
)
}
// // Test tree creation: Too many nodes (only in cases where usize is 64 bit).
// #[cfg(target_pointer_width = "64")]
// {
// let len = u32::MAX as usize + 2;
// let nodes: Vec<TreeNode<u32, u32>> = Vec::with_capacity(len);

// assert_eq!(
// MlsBinaryTree::new(nodes).expect_err("No error while creating too large tree."),
// MlsBinaryTreeError::InvalidNumberOfNodes
// )
// }

// Node access
assert_eq!(&1, tree1.leaf_by_index(LeafNodeIndex::new(0)));
Expand Down Expand Up @@ -157,24 +153,6 @@ fn test_diff_merging() {
assert_eq!(tree, original_tree);
}

#[test]
#[wasm_bindgen_test::wasm_bindgen_test]
fn test_new_tree_error() {
// Let's test what happens when the tree is getting too large.
let mut nodes: Vec<TreeNode<u32, u32>> = Vec::new();

// We allow uninitialized vectors because we don't want to allocate so much memory
#[allow(clippy::uninit_vec)]
unsafe {
nodes.set_len(u32::MAX as usize);

assert_eq!(
MlsBinaryTree::new(nodes).expect_err("no error adding beyond TREE_MAX"),
MlsBinaryTreeError::OutOfRange
)
}
}

#[test]
#[wasm_bindgen_test::wasm_bindgen_test]
fn test_diff_iter() {
Expand Down
2 changes: 1 addition & 1 deletion openmls/src/extensions/external_sender_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ mod test {

#[apply(ciphersuites)]
async fn test_serialize_deserialize(ciphersuite: Ciphersuite) {
let mut rng = rand::thread_rng();
let mut rng = rand::rng();
let tests = {
let mut external_sender_extensions = Vec::new();

Expand Down
Loading
Loading