rust/crypto: Export gen_ec_key and open-code the SECP521R1 NID

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
This commit is contained in:
Marc Hartmayer
2024-10-22 08:24:38 +00:00
committed by Steffen Eiden
parent dec796d52f
commit 2f3c189fda
3 changed files with 5 additions and 5 deletions

View File

@@ -156,13 +156,13 @@ pub fn random_array<const COUNT: usize>() -> 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<PKey<Private>> {
let group = EcGroup::from_curve_name(Nid::SECP521R1)?;
pub fn gen_ec_key(nid: Nid) -> Result<PKey<Private>> {
let group = EcGroup::from_curve_name(nid)?;
let key: EcKey<Private> = EcKey::generate(&group)?;
PKey::from_ec_key(key).map_err(Error::Crypto)
}

View File

@@ -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};

View File

@@ -145,7 +145,7 @@ impl ReqEncrCtx {
S: Into<Option<SymKey>>,
{
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)?);