Skip to content

Commit

Permalink
Cleanup 'use' statements
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth committed Jan 27, 2025
1 parent 6faca35 commit 924f5dd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
13 changes: 6 additions & 7 deletions aws-lc-rs/src/agreement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@
mod ephemeral;

use crate::ec::encoding;
use crate::ec::encoding::sec1::{marshal_sec1_private_key, parse_sec1_private_bn};
use crate::ec::encoding::sec1::{
marshal_sec1_private_key, marshal_sec1_public_point, marshal_sec1_public_point_into_buffer,
parse_sec1_private_bn,
};
use crate::ec::evp_key_generate;
use crate::error::KeyRejected;
use crate::error::Unspecified;
Expand Down Expand Up @@ -394,11 +397,7 @@ impl PrivateKey {
| KeyInner::ECDH_P384(evp_pkey)
| KeyInner::ECDH_P521(evp_pkey) => {
let mut public_key = [0u8; MAX_PUBLIC_KEY_LEN];
let len = encoding::sec1::marshal_sec1_public_point_into_buffer(
&mut public_key,
evp_pkey,
false,
)?;
let len = marshal_sec1_public_point_into_buffer(&mut public_key, evp_pkey, false)?;
Ok(PublicKey {
inner_key: self.inner_key.clone(),
public_key,
Expand Down Expand Up @@ -579,7 +578,7 @@ impl AsBigEndian<EcPublicKeyCompressedBin<'static>> for PublicKey {
| KeyInner::ECDH_P521(evp_pkey) => evp_pkey,
KeyInner::X25519(_) => return Err(Unspecified),
};
let pub_point = encoding::sec1::marshal_sec1_public_point(evp_pkey, true)?;
let pub_point = marshal_sec1_public_point(evp_pkey, true)?;
Ok(EcPublicKeyCompressedBin::new(pub_point))
}
}
Expand Down
3 changes: 2 additions & 1 deletion aws-lc-rs/src/ec/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0 OR ISC

use crate::aws_lc::{EVP_PKEY, EVP_PKEY_EC};
use crate::ec::encoding::sec1::parse_sec1_public_point;
use crate::ec::validate_evp_key;

use crate::error::KeyRejected;
Expand Down Expand Up @@ -251,6 +252,6 @@ pub(crate) fn parse_ec_public_key(
expected_curve_nid: i32,
) -> Result<LcPtr<EVP_PKEY>, KeyRejected> {
LcPtr::<EVP_PKEY>::parse_rfc5280_public_key(key_bytes, EVP_PKEY_EC)
.or(sec1::parse_sec1_public_point(key_bytes, expected_curve_nid))
.or(parse_sec1_public_point(key_bytes, expected_curve_nid))
.and_then(|key| validate_evp_key(&key.as_const(), expected_curve_nid).map(|()| key))
}
16 changes: 10 additions & 6 deletions aws-lc-rs/src/ec/key_pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ use core::ptr::{null, null_mut};
use crate::aws_lc::{EVP_DigestSign, EVP_DigestSignInit, EVP_PKEY_cmp, EVP_PKEY, EVP_PKEY_EC};

use crate::digest::digest_ctx::DigestContext;
use crate::ec::evp_key_generate;
use crate::ec::signature::{EcdsaSignatureFormat, EcdsaSigningAlgorithm, PublicKey};
#[cfg(feature = "fips")]
use crate::ec::validate_evp_key;
#[cfg(not(feature = "fips"))]
use crate::ec::verify_evp_key_nid;
use crate::ec::{encoding, evp_key_generate};

use crate::ec::encoding::rfc5915::{marshal_rfc5915_private_key, parse_rfc5915_private_key};
use crate::ec::encoding::sec1::{
marshal_sec1_private_key, parse_sec1_private_bn, parse_sec1_public_point,
};
use crate::encoding::{AsBigEndian, AsDer, EcPrivateKeyBin, EcPrivateKeyRfc5915Der};
use crate::error::{KeyRejected, Unspecified};
use crate::fips::indicator_check;
Expand Down Expand Up @@ -156,8 +160,8 @@ impl EcdsaKeyPair {
private_key: &[u8],
public_key: &[u8],
) -> Result<Self, KeyRejected> {
let priv_evp_pkey = ec::encoding::sec1::parse_sec1_private_bn(private_key, alg.id.nid())?;
let pub_evp_pkey = ec::encoding::sec1::parse_sec1_public_point(public_key, alg.id.nid())?;
let priv_evp_pkey = parse_sec1_private_bn(private_key, alg.id.nid())?;
let pub_evp_pkey = parse_sec1_public_point(public_key, alg.id.nid())?;
// EVP_PKEY_cmp only compare params and public key
if 1 != unsafe { EVP_PKEY_cmp(*priv_evp_pkey.as_const(), *pub_evp_pkey.as_const()) } {
return Err(KeyRejected::inconsistent_components());
Expand All @@ -183,7 +187,7 @@ impl EcdsaKeyPair {
alg: &'static EcdsaSigningAlgorithm,
private_key: &[u8],
) -> Result<Self, KeyRejected> {
let evp_pkey = ec::encoding::rfc5915::parse_rfc5915_private_key(private_key, alg.id.nid())?;
let evp_pkey = parse_rfc5915_private_key(private_key, alg.id.nid())?;

Ok(Self::new(alg, evp_pkey)?)
}
Expand Down Expand Up @@ -301,7 +305,7 @@ impl AsBigEndian<EcPrivateKeyBin<'static>> for PrivateKey<'_> {
/// # Errors
/// `error::Unspecified` if serialization failed.
fn as_be_bytes(&self) -> Result<EcPrivateKeyBin<'static>, Unspecified> {
let buffer = encoding::sec1::marshal_sec1_private_key(&self.0.evp_pkey)?;
let buffer = marshal_sec1_private_key(&self.0.evp_pkey)?;
Ok(EcPrivateKeyBin::new(buffer))
}
}
Expand All @@ -312,7 +316,7 @@ impl AsDer<EcPrivateKeyRfc5915Der<'static>> for PrivateKey<'_> {
/// # Errors
/// `error::Unspecified` if serialization failed.
fn as_der(&self) -> Result<EcPrivateKeyRfc5915Der<'static>, Unspecified> {
let bytes = encoding::rfc5915::marshal_rfc5915_private_key(&self.0.evp_pkey)?;
let bytes = marshal_rfc5915_private_key(&self.0.evp_pkey)?;
Ok(EcPrivateKeyRfc5915Der::new(bytes))
}
}
7 changes: 4 additions & 3 deletions aws-lc-rs/src/ec/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ use crate::aws_lc::{
use crate::digest::digest_ctx::DigestContext;
use crate::ec::compressed_public_key_size_bytes;
use crate::ec::encoding::parse_ec_public_key;
use crate::ec::encoding::sec1::marshal_sec1_public_point;
use crate::encoding::{
AsBigEndian, AsDer, EcPublicKeyCompressedBin, EcPublicKeyUncompressedBin, PublicKeyX509Der,
};
use crate::error::Unspecified;
use crate::fips::indicator_check;
use crate::ptr::{DetachableLcPtr, LcPtr};
use crate::signature::VerificationAlgorithm;
use crate::{digest, ec, sealed};
use crate::{digest, sealed};
use core::fmt;
use core::fmt::{Debug, Formatter};
use std::mem::MaybeUninit;
Expand Down Expand Up @@ -107,7 +108,7 @@ pub(crate) fn public_key_from_evp_pkey(
evp_pkey: &LcPtr<EVP_PKEY>,
algorithm: &'static EcdsaSigningAlgorithm,
) -> Result<PublicKey, Unspecified> {
let pub_key_bytes = ec::encoding::sec1::marshal_sec1_public_point(evp_pkey, false)?;
let pub_key_bytes = marshal_sec1_public_point(evp_pkey, false)?;

Ok(PublicKey {
evp_pkey: evp_pkey.clone(),
Expand All @@ -131,7 +132,7 @@ impl AsBigEndian<EcPublicKeyCompressedBin<'static>> for PublicKey {
/// # Errors
/// Returns an error if the public key fails to marshal.
fn as_be_bytes(&self) -> Result<EcPublicKeyCompressedBin<'static>, crate::error::Unspecified> {
let pub_point = ec::encoding::sec1::marshal_sec1_public_point(&self.evp_pkey, true)?;
let pub_point = marshal_sec1_public_point(&self.evp_pkey, true)?;
Ok(EcPublicKeyCompressedBin::new(pub_point))
}
}
Expand Down

0 comments on commit 924f5dd

Please sign in to comment.