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

Bump hybrid-array dependency to v0.2.0-rc.9 #243

Merged
merged 1 commit into from
Jul 16, 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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ssh-cipher/src/chacha20poly1305.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl ChaCha20Poly1305 {

// TODO(tarcieri): support for using both keys
let (k_2, _k_1) = key.split_at(KEY_SIZE);
let key = Key::from_slice(k_2);
let key = Key::try_from(k_2).map_err(|_| Error::KeySize)?;

let nonce = if nonce.is_empty() {
// For key encryption
Expand All @@ -55,7 +55,7 @@ impl ChaCha20Poly1305 {
Nonce::try_from(nonce).map_err(|_| Error::IvSize)?
};

let mut cipher = ChaCha20::new(key, &nonce.into());
let mut cipher = ChaCha20::new(&key, &nonce.into());
let mut poly1305_key = poly1305::Key::default();
cipher.apply_keystream(&mut poly1305_key);

Expand Down
36 changes: 12 additions & 24 deletions ssh-key/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,19 +534,15 @@ impl TryFrom<&Signature> for p256::ecdsa::Signature {
}
#[cfg(feature = "p256")]
fn p256_signature_from_openssh_bytes(mut signature_bytes: &[u8]) -> Result<p256::ecdsa::Signature> {
const FIELD_SIZE: usize = 32;

let reader = &mut signature_bytes;
let r = Mpint::decode(reader)?;
let s = Mpint::decode(reader)?;

match (r.as_positive_bytes(), s.as_positive_bytes()) {
(Some(r), Some(s)) if r.len() == FIELD_SIZE && s.len() == FIELD_SIZE => {
Ok(p256::ecdsa::Signature::from_scalars(
*p256::FieldBytes::from_slice(r),
*p256::FieldBytes::from_slice(s),
)?)
}
(Some(r), Some(s)) => Ok(p256::ecdsa::Signature::from_scalars(
p256::FieldBytes::try_from(r).map_err(|_| Error::Crypto)?,
p256::FieldBytes::try_from(s).map_err(|_| Error::Crypto)?,
)?),
_ => Err(Error::Crypto),
}
}
Expand All @@ -556,8 +552,6 @@ impl TryFrom<&Signature> for p384::ecdsa::Signature {
type Error = Error;

fn try_from(signature: &Signature) -> Result<p384::ecdsa::Signature> {
const FIELD_SIZE: usize = 48;

match signature.algorithm {
Algorithm::Ecdsa {
curve: EcdsaCurve::NistP384,
Expand All @@ -567,12 +561,10 @@ impl TryFrom<&Signature> for p384::ecdsa::Signature {
let s = Mpint::decode(reader)?;

match (r.as_positive_bytes(), s.as_positive_bytes()) {
(Some(r), Some(s)) if r.len() == FIELD_SIZE && s.len() == FIELD_SIZE => {
Ok(p384::ecdsa::Signature::from_scalars(
*p384::FieldBytes::from_slice(r),
*p384::FieldBytes::from_slice(s),
)?)
}
(Some(r), Some(s)) => Ok(p384::ecdsa::Signature::from_scalars(
p384::FieldBytes::try_from(r).map_err(|_| Error::Crypto)?,
p384::FieldBytes::try_from(s).map_err(|_| Error::Crypto)?,
)?),
_ => Err(Error::Crypto),
}
}
Expand All @@ -586,8 +578,6 @@ impl TryFrom<&Signature> for p521::ecdsa::Signature {
type Error = Error;

fn try_from(signature: &Signature) -> Result<p521::ecdsa::Signature> {
const FIELD_SIZE: usize = 66;

match signature.algorithm {
Algorithm::Ecdsa {
curve: EcdsaCurve::NistP521,
Expand All @@ -597,12 +587,10 @@ impl TryFrom<&Signature> for p521::ecdsa::Signature {
let s = Mpint::decode(reader)?;

match (r.as_positive_bytes(), s.as_positive_bytes()) {
(Some(r), Some(s)) if r.len() == FIELD_SIZE && s.len() == FIELD_SIZE => {
Ok(p521::ecdsa::Signature::from_scalars(
*p521::FieldBytes::from_slice(r),
*p521::FieldBytes::from_slice(s),
)?)
}
(Some(r), Some(s)) => Ok(p521::ecdsa::Signature::from_scalars(
p521::FieldBytes::try_from(r).map_err(|_| Error::Crypto)?,
p521::FieldBytes::try_from(s).map_err(|_| Error::Crypto)?,
)?),
_ => Err(Error::Crypto),
}
}
Expand Down
Loading