@@ -305,6 +305,7 @@ pub enum ErrorCode {
305305 PageAttributesMismatch = 19 ,
306306 PageNotModifiable = 20 ,
307307 PageNotDebuggable = 21 ,
308+ InvalidReportMacStruct = 28 ,
308309 InvalidCpusvn = 32 ,
309310 InvalidIsvsvn = 64 ,
310311 UnmaskedEvent = 128 ,
@@ -702,7 +703,7 @@ impl Report {
702703 /// implementation of the verifying function.
703704 ///
704705 /// Care should be taken that `check_mac` prevents timing attacks,
705- /// in particular that the comparison happens in constant time.
706+ /// in particular that the comparison happens in constant time.
706707 #[ cfg( target_env = "sgx" ) ]
707708 pub fn verify < F , R > ( & self , check_mac : F ) -> R
708709 where
@@ -808,6 +809,100 @@ impl Default for Keypolicy {
808809 }
809810}
810811
812+ struct_def ! {
813+ /// Rust definition of `REPORTTYPE` from `REPORTMACSTRUCT`.
814+ ///
815+ /// Ref: Intel® Trust Domain CPU Architectural Extensions, table 2-4.
816+ /// Version: 343754-002US, MAY 2021
817+ /// Link: <https://cdrdv2.intel.com/v1/dl/getContent/733582>
818+ #[ repr( C , align( 4 ) ) ]
819+ #[ derive( Clone , Debug , Default , Eq , PartialEq ) ]
820+ pub struct TeeReportType {
821+ /// Trusted Execution Environment(TEE) type:
822+ /// 0x00: SGX Legacy REPORT TYPE
823+ /// 0x7F-0x01: Reserved
824+ /// 0x80: Reserved
825+ /// 0x81: TEE Report type 2
826+ /// 0xFF-0x82: Reserved
827+ pub report_type: u8 ,
828+ /// TYPE-specific subtype, Stage1: value is 0
829+ pub subtype: u8 ,
830+ /// TYPE-specific version, Stage1: value is 0
831+ pub version: u8 ,
832+ pub reserved: u8 ,
833+ }
834+ }
835+
836+ impl TeeReportType {
837+ pub const UNPADDED_SIZE : usize = 4 ;
838+ }
839+
840+ /// SHA384 hash size in bytes
841+ pub const HASH_384_SIZE : usize = 48 ;
842+ /// SHA384 hash
843+ pub type Sha384Hash = [ u8 ; HASH_384_SIZE ] ;
844+
845+ pub const CPU_SVN_SIZE : usize = 16 ;
846+ pub const REPORT_MAC_STRUCT_SIZE : usize = 256 ;
847+ pub const REPORT_MAC_STRUCT_RESERVED1_BYTES : usize = 12 ;
848+ pub const REPORT_MAC_STRUCT_RESERVED2_BYTES : usize = 32 ;
849+ pub const REPORT_DATA_SIZE : usize = 64 ;
850+
851+ /// Message SHA 256 HASH Code - 32 bytes
852+ pub const TEE_MAC_SIZE : usize = 32 ;
853+
854+
855+ struct_def ! {
856+ /// Rust definition of `REPORTMACSTRUCT`, used by TDX `TDREPORT_STRUCT`
857+ /// and the future 256BITSGX
858+ ///
859+ /// Ref: Intel® Trust Domain CPU Architectural Extensions, table 2-5.
860+ /// Version: 343754-002US, MAY 2021
861+ /// Link TDX: <https://cdrdv2.intel.com/v1/dl/getContent/733582>
862+ /// Link 256BITSGX: <https://cdrdv2-public.intel.com/851355/319433-057-architecture-instruction-set-extensions-programming-reference.pdf>
863+ #[ repr( C , align( 256 ) ) ]
864+ #[ cfg_attr(
865+ feature = "large_array_derive" ,
866+ derive( Clone , Debug , Eq , PartialEq )
867+ ) ]
868+ pub struct ReportMac {
869+ /// ( 0) TEE Report type
870+ pub report_type: TeeReportType ,
871+ /// ( 4) Reserved, must be zero
872+ pub reserved1: [ u8 ; REPORT_MAC_STRUCT_RESERVED1_BYTES ] ,
873+ /// ( 16) Security Version of the CPU
874+ pub cpu_svn: [ u8 ; CPU_SVN_SIZE ] ,
875+ /// ( 32) SHA384 of TEE_TCB_INFO for TEEs
876+ pub tee_tcb_info_hash: Sha384Hash ,
877+ /// ( 80) SHA384 of TEE_INFO
878+ pub tee_info_hash: Sha384Hash ,
879+ /// (128) Data provided by the user
880+ pub report_data: [ u8 ; REPORT_DATA_SIZE ] ,
881+ /// (192) Reserved, must be zero
882+ pub reserved2: [ u8 ; REPORT_MAC_STRUCT_RESERVED2_BYTES ] ,
883+ /// (224) The Message Authentication Code over this structure
884+ pub mac: [ u8 ; TEE_MAC_SIZE ] ,
885+ }
886+ }
887+
888+ impl ReportMac {
889+ pub const UNPADDED_SIZE : usize = 256 ;
890+
891+ #[ cfg( target_env = "sgx" ) ]
892+ pub fn verify ( & self ) -> Result < ( ) , ErrorCode > {
893+ arch:: everifyreport2 ( self . as_ref ( ) )
894+ // Same as `egetkey` reasoning: unwrap is okay here
895+ . map_err ( |e| ErrorCode :: try_from ( e) . unwrap ( ) )
896+ }
897+ }
898+
899+ #[ cfg( target_env = "sgx" ) ]
900+ impl AsRef < arch:: Align256 < [ u8 ; ReportMac :: UNPADDED_SIZE ] > > for ReportMac {
901+ fn as_ref ( & self ) -> & arch:: Align256 < [ u8 ; Self :: UNPADDED_SIZE ] > {
902+ unsafe { & * ( self as * const _ as * const _ ) }
903+ }
904+ }
905+
811906#[ test]
812907fn test_eq ( ) {
813908 let mut a = Keyrequest :: default ( ) ;
0 commit comments