use crate::{certs::sev::sev::Certificate, launch::sev::*};
use std::{
marker::PhantomData,
mem::{size_of_val, MaybeUninit},
};
#[repr(C)]
pub struct Init;
#[repr(C)]
pub struct EsInit;
#[derive(Clone, Copy)]
#[repr(transparent)]
pub struct Handle(u32);
impl From<LaunchStart<'_>> for Handle {
fn from(ls: LaunchStart) -> Self {
ls.handle
}
}
#[repr(C)]
pub struct LaunchStart<'a> {
handle: Handle,
policy: Policy,
dh_addr: u64,
dh_len: u32,
session_addr: u64,
session_len: u32,
_phantom: PhantomData<&'a ()>,
}
impl<'a> LaunchStart<'a> {
pub fn new(policy: &'a Policy, dh: &'a Certificate, session: &'a Session) -> Self {
Self {
handle: Handle(0),
policy: *policy,
dh_addr: dh as *const _ as _,
dh_len: size_of_val(dh) as _,
session_addr: session as *const _ as _,
session_len: size_of_val(session) as _,
_phantom: PhantomData,
}
}
}
#[repr(C)]
pub struct LaunchUpdateData<'a> {
addr: u64,
len: u32,
_phantom: PhantomData<&'a ()>,
}
impl<'a> LaunchUpdateData<'a> {
pub fn new(data: &'a [u8]) -> Self {
Self {
addr: data.as_ptr() as _,
len: data.len() as _,
_phantom: PhantomData,
}
}
}
#[repr(C)]
pub struct LaunchUpdateVmsa;
impl LaunchUpdateVmsa {
pub fn new() -> Self {
Self
}
}
#[repr(C)]
pub struct LaunchSecret<'a> {
hdr_addr: u64,
hdr_len: u32,
guest_addr: u64,
guest_len: u32,
trans_addr: u64,
trans_len: u32,
_phantom: PhantomData<&'a ()>,
}
impl<'a> LaunchSecret<'a> {
pub fn new(header: &'a Header, guest: usize, trans: &'a [u8]) -> Self {
Self {
hdr_addr: header as *const _ as _,
hdr_len: size_of_val(header) as _,
guest_addr: guest as _,
guest_len: trans.len() as _,
trans_addr: trans.as_ptr() as _,
trans_len: trans.len() as _,
_phantom: PhantomData,
}
}
}
#[repr(C)]
pub struct LaunchMeasure<'a> {
addr: u64,
len: u32,
_phantom: PhantomData<&'a Measurement>,
}
impl<'a> LaunchMeasure<'a> {
pub fn new(measurement: &'a mut MaybeUninit<Measurement>) -> Self {
Self {
addr: measurement.as_mut_ptr() as _,
len: size_of_val(measurement) as _,
_phantom: PhantomData,
}
}
}
#[repr(C)]
pub struct LaunchFinish;
#[derive(Default)]
#[repr(C)]
pub struct LaunchAttestation<'a> {
mnonce: [u8; 16],
addr: u64,
pub len: u32,
_phantom: PhantomData<&'a mut Vec<u8>>,
}
impl<'a> LaunchAttestation<'a> {
pub fn new(mnonce: [u8; 16], bytes: &'a mut Vec<u8>) -> Self {
Self {
mnonce,
addr: bytes.as_mut_ptr() as _,
len: bytes.capacity() as _,
_phantom: PhantomData,
}
}
}