mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
rust/crypto: Rename derive_key to derive_aes256_gcm_key and export it
This is currently the only key type supported, therefore rename the function to make this clear. In addition, improve the documentation of the function as function is now exported. Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com> Reviewed-by: Steffen Eiden <seiden@linux.ibm.com> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
This commit is contained in:
committed by
Steffen Eiden
parent
a0a8aa47a8
commit
eee29e0399
@@ -106,12 +106,12 @@ pub(crate) fn hkdf_rfc_5869<const COUNT: usize>(
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
/// Derive a symmetric key from a private and a public key.
|
||||
/// Derive a symmetric AES 256 GCM key from a private and a public key.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function will return an error if something went bad in OpenSSL.
|
||||
pub(crate) fn derive_key(k1: &PKeyRef<Private>, k2: &PKeyRef<Public>) -> Result<Aes256Key> {
|
||||
pub fn derive_aes256_gcm_key(k1: &PKeyRef<Private>, k2: &PKeyRef<Public>) -> Result<Aes256Key> {
|
||||
let mut der = Deriver::new(k1)?;
|
||||
der.set_peer(k2)?;
|
||||
let mut key = der.derive_to_vec()?;
|
||||
@@ -392,7 +392,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn derive_key() {
|
||||
fn derive_aes256_gcm_key() {
|
||||
let (cust_key, host_key) = get_test_keys();
|
||||
|
||||
let exp_key: Aes256Key = [
|
||||
@@ -402,7 +402,7 @@ mod tests {
|
||||
]
|
||||
.into();
|
||||
|
||||
let calc_key = super::derive_key(&cust_key, &host_key).unwrap();
|
||||
let calc_key = super::derive_aes256_gcm_key(&cust_key, &host_key).unwrap();
|
||||
|
||||
assert_eq!(&calc_key, &exp_key);
|
||||
}
|
||||
|
||||
@@ -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::{SymKey, SymKeyType};
|
||||
pub use crate::crypto::{derive_aes256_gcm_key, SymKey, SymKeyType};
|
||||
pub use crate::req::{EcPubKeyCoord, Keyslot, ReqEncrCtx, Request};
|
||||
pub use crate::verify::{CertVerifier, HkdVerifier, NoVerifyHkd};
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
use crate::assert_size;
|
||||
use crate::crypto::{
|
||||
decrypt_aes_gcm, derive_key, encrypt_aes_gcm, gen_ec_key, hash, random_array, AesGcmResult,
|
||||
SymKey, SymKeyType, AES_256_GCM_TAG_SIZE,
|
||||
decrypt_aes_gcm, derive_aes256_gcm_key, encrypt_aes_gcm, gen_ec_key, hash, random_array,
|
||||
AesGcmResult, SymKey, SymKeyType, AES_256_GCM_TAG_SIZE,
|
||||
};
|
||||
use crate::misc::to_u32;
|
||||
use crate::request::Confidential;
|
||||
@@ -106,7 +106,7 @@ impl Encrypt for Keyslot {
|
||||
priv_key: &PKeyRef<Private>,
|
||||
to: &mut Vec<u8>,
|
||||
) -> Result<()> {
|
||||
let derived_key = derive_key(priv_key, &self.0)?;
|
||||
let derived_key = derive_aes256_gcm_key(priv_key, &self.0)?;
|
||||
let mut wrpk_and_kst =
|
||||
encrypt_aes_gcm(&derived_key.into(), &[0; 12], &[], prot_key)?.data();
|
||||
let phk: EcPubKeyCoord = self.0.as_ref().try_into()?;
|
||||
|
||||
Reference in New Issue
Block a user