openhcl_attestation_protocol/
vmgs.rs1use zerocopy::FromBytes;
7use zerocopy::Immutable;
8use zerocopy::IntoBytes;
9use zerocopy::KnownLayout;
10
11pub const NUMBER_KP: usize = 2;
14
15pub const DEK_BUFFER_SIZE: usize = 512;
17
18pub const GSP_BUFFER_SIZE: usize = 512;
20
21pub const KEY_PROTECTOR_SIZE: usize = size_of::<KeyProtector>();
23
24#[repr(C)]
26#[derive(Debug, IntoBytes, Immutable, KnownLayout, FromBytes)]
27pub struct DekKp {
28 pub dek_buffer: [u8; DEK_BUFFER_SIZE],
30}
31
32#[repr(C)]
34#[derive(Debug, IntoBytes, Immutable, KnownLayout, FromBytes)]
35pub struct GspKp {
36 pub gsp_length: u32,
38 pub gsp_buffer: [u8; GSP_BUFFER_SIZE],
40}
41
42#[repr(C)]
44#[derive(Debug, IntoBytes, Immutable, KnownLayout, FromBytes)]
45pub struct KeyProtector {
46 pub dek: [DekKp; NUMBER_KP],
48 pub gsp: [GspKp; NUMBER_KP],
50 pub active_kp: u32,
52}
53
54#[repr(C)]
56#[derive(Debug, IntoBytes, Immutable, KnownLayout, FromBytes)]
57pub struct KeyProtectorById {
58 pub id_guid: guid::Guid,
60 pub ported: u8,
62 pub pad: [u8; 3],
64}
65
66pub const AGENT_DATA_MAX_SIZE: usize = 2048;
68
69#[repr(C)]
71#[derive(Debug, IntoBytes, Immutable, KnownLayout, FromBytes)]
72pub struct SecurityProfile {
73 pub agent_data: [u8; AGENT_DATA_MAX_SIZE],
75}
76
77pub const HW_KEY_VERSION: u32 = 1; pub const HW_KEY_PROTECTOR_SIZE: usize = size_of::<HardwareKeyProtector>();
85
86pub const AES_GCM_KEY_LENGTH: usize = 32;
88
89pub const AES_CBC_KEY_LENGTH: usize = AES_GCM_KEY_LENGTH;
91
92pub const AES_CBC_IV_LENGTH: usize = 16;
94
95pub const HMAC_SHA_256_KEY_LENGTH: usize = 32;
97
98#[repr(C)]
100#[derive(Debug, IntoBytes, Immutable, KnownLayout, FromBytes)]
101pub struct HardwareKeyProtectorHeader {
102 pub version: u32,
104 pub length: u32,
106 pub tcb_version: u64,
108 pub _reserved: [u8; 8],
110}
111
112impl HardwareKeyProtectorHeader {
113 pub fn new(version: u32, length: u32, tcb_version: u64) -> Self {
115 Self {
116 version,
117 length,
118 tcb_version,
119 _reserved: [0u8; 8],
120 }
121 }
122}
123
124#[repr(C)]
126#[derive(Debug, IntoBytes, Immutable, KnownLayout, FromBytes)]
127pub struct HardwareKeyProtector {
128 pub header: HardwareKeyProtectorHeader,
130 pub iv: [u8; AES_CBC_IV_LENGTH],
132 pub ciphertext: [u8; AES_GCM_KEY_LENGTH],
134 pub hmac: [u8; HMAC_SHA_256_KEY_LENGTH],
136}
137
138pub const GUEST_SECRET_KEY_MAX_SIZE: usize = 2048;
140
141#[repr(C)]
143#[derive(Debug, IntoBytes, Immutable, KnownLayout, FromBytes)]
144pub struct GuestSecretKey {
145 pub guest_secret_key: [u8; GUEST_SECRET_KEY_MAX_SIZE],
147}