diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2024-04-16 14:06:22 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2024-04-16 15:02:37 +0200 |
commit | cc699ad1f6c25f10d76176a233cf91683a23c398 (patch) | |
tree | e5ff015b484ad8f3f7b1c40ba9bdcfe6aafb1b69 | |
parent | b90569922125b249492531e7205d37ddf953cd02 (diff) |
openpgp: Refactor imports.
-rw-r--r-- | openpgp/src/crypto/backend/rust/asymmetric.rs | 36 | ||||
-rw-r--r-- | openpgp/src/crypto/backend/rust/ecdh.rs | 15 |
2 files changed, 19 insertions, 32 deletions
diff --git a/openpgp/src/crypto/backend/rust/asymmetric.rs b/openpgp/src/crypto/backend/rust/asymmetric.rs index 7df6ecf6..a07a760c 100644 --- a/openpgp/src/crypto/backend/rust/asymmetric.rs +++ b/openpgp/src/crypto/backend/rust/asymmetric.rs @@ -11,6 +11,16 @@ use num_bigint_dig::{traits::ModInverse, BigUint}; use rsa::traits::{PrivateKeyParts, PublicKeyParts}; use rsa::{Pkcs1v15Encrypt, RsaPublicKey, RsaPrivateKey, Pkcs1v15Sign}; +use ecdsa::{ + EncodedPoint, + hazmat::{SignPrimitive, VerifyPrimitive}, +}; +use p256::elliptic_curve::{ + generic_array::GenericArray as GA, + ops::Reduce, + sec1::FromEncodedPoint, +}; + use crate::{Error, Result}; use crate::crypto::asymmetric::KeyPair; use crate::crypto::backend::interface::Asymmetric; @@ -264,18 +274,9 @@ impl KeyPair { mpi::SecretKeyMaterial::ECDSA { scalar }) => match curve { Curve::NistP256 => { - use p256::{ - elliptic_curve::{ - generic_array::GenericArray as GA, - ops::Reduce, - }, - Scalar, - }; - use ecdsa::{ - hazmat::SignPrimitive, - }; - + use p256::Scalar; const LEN: usize = 32; + let key = scalar.value_padded(LEN); let key = Scalar::reduce_bytes(GA::try_from_slice(&key)?); let dig = pad_truncating(digest, LEN); @@ -430,18 +431,7 @@ impl<P: key::KeyParts, R: key::KeyRole> Key<P, R> { mpi::Signature::ECDSA { r, s }) => match curve { Curve::NistP256 => { - use p256::{ - AffinePoint, - ecdsa::Signature, - elliptic_curve::{ - generic_array::GenericArray as GA, - sec1::FromEncodedPoint, - }, - }; - use ecdsa::{ - EncodedPoint, - hazmat::VerifyPrimitive, - }; + use p256::{AffinePoint, ecdsa::Signature}; const LEN: usize = 32; let key = AffinePoint::from_encoded_point( diff --git a/openpgp/src/crypto/backend/rust/ecdh.rs b/openpgp/src/crypto/backend/rust/ecdh.rs index 119ca537..56e4357b 100644 --- a/openpgp/src/crypto/backend/rust/ecdh.rs +++ b/openpgp/src/crypto/backend/rust/ecdh.rs @@ -2,6 +2,11 @@ use std::convert::TryInto; +use p256::elliptic_curve::{ + ecdh::diffie_hellman, + generic_array::GenericArray as GA, +}; + use crate::{Error, Result}; use crate::crypto::SessionKey; use crate::crypto::mem::Protected; @@ -116,15 +121,7 @@ pub fn decrypt<R>(recipient: &Key<key::PublicParts, R>, Vec::from(secret.to_bytes()).into() }, Curve::NistP256 => { - use p256::{ - SecretKey, - PublicKey, - elliptic_curve::{ - ecdh::diffie_hellman, - generic_array::GenericArray as GA, - }, - }; - + use p256::{SecretKey, PublicKey}; const NISTP256_SIZE: usize = 32; // Get the public part V of the ephemeral key. |