Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add checked SignaturePublicKey constructor #92

Merged
merged 1 commit into from
Apr 15, 2024
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
2 changes: 2 additions & 0 deletions openmls_rust_crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ hmac = { version = "0.12" }
ed25519-dalek = { version = "2.0.0-rc.3", features = ["rand_core"] }
p256 = { version = "0.13" }
p384 = { version = "0.13" }
p521 = "0.13"
hkdf = { version = "0.12" }
rand_core = "0.6"
rand_chacha = { version = "0.3" }
tls_codec = { workspace = true }
zeroize = { version = "1.6", features = ["derive"] }
signature = "2.1"
thiserror = "1.0"
generic-array = "0.14"

[dependencies.hpke]
git = "https://github.com/wireapp/rust-hpke.git"
Expand Down
17 changes: 17 additions & 0 deletions openmls_rust_crypto/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,23 @@ impl OpenMlsCrypto for RustCrypto {
}
}

fn signature_public_key_len(&self, alg: SignatureScheme) -> usize {
use generic_array::typenum::Unsigned;
match alg {
SignatureScheme::ECDSA_SECP256R1_SHA256 => {
<p256::NistP256 as p256::elliptic_curve::Curve>::FieldBytesSize::to_usize()
}
SignatureScheme::ECDSA_SECP384R1_SHA384 => {
<p384::NistP384 as p384::elliptic_curve::Curve>::FieldBytesSize::to_usize()
}
SignatureScheme::ECDSA_SECP521R1_SHA512 => {
<p521::NistP521 as p521::elliptic_curve::Curve>::FieldBytesSize::to_usize()
}
SignatureScheme::ED25519 => ed25519_dalek::PUBLIC_KEY_LENGTH,
SignatureScheme::ED448 => 57,
}
}

fn verify_signature(
&self,
alg: openmls_traits::types::SignatureScheme,
Expand Down
11 changes: 11 additions & 0 deletions traits/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ pub trait OpenMlsCrypto {
/// generation fails.
fn signature_key_gen(&self, alg: SignatureScheme) -> Result<(Vec<u8>, Vec<u8>), CryptoError>;

/// Gives the length of a signature public key, in bytes
fn signature_public_key_len(&self, alg: SignatureScheme) -> usize;

/// Parses and validate a signature public key
fn validate_signature_key(&self, alg: SignatureScheme, key: &[u8]) -> Result<(), CryptoError> {
if self.signature_public_key_len(alg) != key.len() {
return Err(CryptoError::InvalidKey);
}
Ok(())
}

/// Verify the signature
///
/// Returns an error if the [`SignatureScheme`] is not supported or the
Expand Down
Loading