pub fn secret(
        &self,
        flags: launch::sev::HeaderFlags,
        data: &[u8],
    ) -> Result<launch::sev::Secret> {
        let mut iv = [0u8; 16];
        rand::rand_bytes(&mut iv)?;

        let ciphertext = symm::encrypt(symm::Cipher::aes_128_ctr(), &*self.tek, Some(&iv), data)?;

        let key = pkey::PKey::hmac(&*self.tik)?;
        let mut sig = sign::Signer::new(hash::MessageDigest::sha256(), &key)?;

        sig.update(&[0x01u8])?;
        sig.update(&unsafe { std::mem::transmute::<_, [u8; 4]>(flags) })?;
        sig.update(&iv)?;
        sig.update(&(data.len() as u32).to_le_bytes())?;
        sig.update(&(ciphertext.len() as u32).to_le_bytes())?;
        sig.update(&ciphertext)?;
        sig.update(&self.data.0.measure)?;

        let mut mac = [0u8; 32];
        sig.sign(&mut mac)?;

        Ok(launch::sev::Secret {
            header: launch::sev::Header { flags, iv, mac },
            ciphertext,
        })
    }
/// Creates a packet for a secret to be injected into the guest.
Creates a packet for a secret to be injected into the guest.
Creates a packet for a secret to be injected into the guest .
pub fn secret(
        &self,
        flags: launch::sev::HeaderFlags,
        data: &[u8],
    ) -> Result<launch::sev::Secret> {
        let mut iv = [0u8; 16];
        rand::rand_bytes(&mut iv)?;
        let ciphertext = symm::encrypt(symm::Cipher::aes_128_ctr(), &*self.tek, Some(&iv), data)?;
        let key = pkey::PKey::hmac(&*self.tik)?;
        let mut sig = sign::Signer::new(hash::MessageDigest::sha256(), &key)?;
        sig.update(&[0x01u8])?;
        sig.update(&unsafe { std::mem::transmute::<_, [u8; 4]>(flags) })?;
        sig.update(&iv)?;
        sig.update(&(data.len() as u32).to_le_bytes())?;
        sig.update(&(ciphertext.len() as u32).to_le_bytes())?;
        sig.update(&ciphertext)?;
        sig.update(&self.data.0.measure)?;
        let mut mac = [0u8; 32];
        sig.sign(&mut mac)?;
        Ok(launch::sev::Secret {
            header: launch::sev::Header { flags, iv, mac },
            ciphertext,
        })
    }
pub fn secret ( & self , flags : launch :: sev :: HeaderFlags , data : & [ u8 ] , ) -> Result < launch :: sev :: Secret > { let mut iv = [ 0u8 ; 16 ] ; rand :: rand_bytes ( & mut iv ) ? ; let ciphertext = symm :: encrypt ( symm :: Cipher :: aes_128_ctr ( ) , & * self . tek , Some ( & iv ) , data ) ? ; let key = pkey :: PKey :: hmac ( & * self . tik ) ? ; let mut sig = sign :: Signer :: new ( hash :: MessageDigest :: sha256 ( ) , & key ) ? ; sig . update ( & [ 0x01u8 ] ) ? ; sig . update ( & unsafe { std :: mem :: transmute :: < _ , [ u8 ; 4 ] > ( flags ) } ) ? ; sig . update ( & iv ) ? ; sig . update ( & ( data . len ( ) as u32 ) . to_le_bytes ( ) ) ? ; sig . update ( & ( ciphertext . len ( ) as u32 ) . to_le_bytes ( ) ) ? ; sig . update ( & ciphertext ) ? ; sig . update ( & self . data . 0 . measure ) ? ; let mut mac = [ 0u8 ; 32 ] ; sig . sign ( & mut mac ) ? ; Ok ( launch :: sev :: Secret { header : launch :: sev :: Header { flags , iv , mac } , ciphertext , } ) }
Creates a packet for a secret to be injected into the guest.
Creates a packet for a secret to be injected into the guest .
&self
flags
launch::sev::HeaderFlags
data
&[u8]
&self
flags
launch::sev::HeaderFlags
data
&[u8]