diff --git a/rust/pv/src/crypto.rs b/rust/pv/src/crypto.rs index edd2692d..da743066 100644 --- a/rust/pv/src/crypto.rs +++ b/rust/pv/src/crypto.rs @@ -156,13 +156,13 @@ pub fn random_array() -> Result<[u8; COUNT]> { Ok(rand) } -/// Generate a new random EC-SECP521R1 key. +/// Generate a new random EC key. /// /// # Errors /// /// This function will return an error if the key could not be generated by OpenSSL. -pub(crate) fn gen_ec_key() -> Result> { - let group = EcGroup::from_curve_name(Nid::SECP521R1)?; +pub fn gen_ec_key(nid: Nid) -> Result> { + let group = EcGroup::from_curve_name(nid)?; let key: EcKey = EcKey::generate(&group)?; PKey::from_ec_key(key).map_err(Error::Crypto) } diff --git a/rust/pv/src/lib.rs b/rust/pv/src/lib.rs index 02d797f9..1adcb3c1 100644 --- a/rust/pv/src/lib.rs +++ b/rust/pv/src/lib.rs @@ -92,7 +92,7 @@ pub use pv_core::{FileAccessErrorType, FileIoErrorType}; /// Functionalities to build UV requests pub mod request { pub use crate::brcb::BootHdrTags; - pub use crate::crypto::{derive_aes256_gcm_key, random_array, SymKey, SymKeyType}; + pub use crate::crypto::{derive_aes256_gcm_key, gen_ec_key, random_array, SymKey, SymKeyType}; pub use crate::req::{EcPubKeyCoord, Keyslot, ReqEncrCtx, Request}; pub use crate::verify::{CertVerifier, HkdVerifier, NoVerifyHkd}; diff --git a/rust/pv/src/req.rs b/rust/pv/src/req.rs index 65884c89..294f21af 100644 --- a/rust/pv/src/req.rs +++ b/rust/pv/src/req.rs @@ -145,7 +145,7 @@ impl ReqEncrCtx { S: Into>, { let iv = iv.into().unwrap_or(random_array()?); - let priv_key = priv_key.into().unwrap_or(gen_ec_key()?); + let priv_key = priv_key.into().unwrap_or(gen_ec_key(Nid::SECP521R1)?); let prot_key = prot_key .into() .unwrap_or(SymKey::random(SymKeyType::Aes256)?);