commit 8e686faf83e8b4480aff2e26c013305e53dd650d Author: Jeff Hodges Date: Tue Mar 3 11:18:23 2020 -0800 copy sgx_sdk_ffi from SVR to here We're moving this crate out to make it easier for CDS to use it. (There's been some cargo bugs causing this crate to not be picked up in SVR.) The version being copied over is from commit 5725cc27c061dac688feb1ff31ec6027dead718f. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fbc9a58 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea +target +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..79e918f --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,3 @@ +[workspace] + +members = ["sgx_sdk_ffi"] diff --git a/sgx_sdk_ffi/Cargo.toml b/sgx_sdk_ffi/Cargo.toml new file mode 100644 index 0000000..e7686aa --- /dev/null +++ b/sgx_sdk_ffi/Cargo.toml @@ -0,0 +1,11 @@ +[package] +authors = ["Open Whisper Systems"] +name = "sgx_sdk_ffi" +version = "0.1.0" +license = "AGPL-3.0-or-later" +description = "Intel SGX SDK bindings" +edition = "2018" + +[dependencies] +num-derive = "0.3" +num-traits = "0.2" diff --git a/sgx_sdk_ffi/src/bindgen_wrapper.h b/sgx_sdk_ffi/src/bindgen_wrapper.h new file mode 100644 index 0000000..9df4b9a --- /dev/null +++ b/sgx_sdk_ffi/src/bindgen_wrapper.h @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2019 Open Whisper Systems + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include "sgx_uae_service.h" +#include "sgx_urts.h" diff --git a/sgx_sdk_ffi/src/bindgen_wrapper.rs b/sgx_sdk_ffi/src/bindgen_wrapper.rs new file mode 100644 index 0000000..683c69f --- /dev/null +++ b/sgx_sdk_ffi/src/bindgen_wrapper.rs @@ -0,0 +1,1617 @@ +/* automatically generated by rust-bindgen */ + +#[repr(C)] +#[derive(Default)] +pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); +impl __IncompleteArrayField { + #[inline] + pub const fn new() -> Self { + __IncompleteArrayField(::std::marker::PhantomData, []) + } + #[inline] + pub fn as_ptr(&self) -> *const T { + self as *const _ as *const T + } + #[inline] + pub fn as_mut_ptr(&mut self) -> *mut T { + self as *mut _ as *mut T + } + #[inline] + pub unsafe fn as_slice(&self, len: usize) -> &[T] { + ::std::slice::from_raw_parts(self.as_ptr(), len) + } + #[inline] + pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + } +} +impl ::std::fmt::Debug for __IncompleteArrayField { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + fmt.write_str("__IncompleteArrayField") + } +} +pub const true_: u32 = 1; +pub const false_: u32 = 0; +pub const __bool_true_false_are_defined: u32 = 1; +pub const _STDINT_H: u32 = 1; +pub const _FEATURES_H: u32 = 1; +pub const _DEFAULT_SOURCE: u32 = 1; +pub const __USE_ISOC11: u32 = 1; +pub const __USE_ISOC99: u32 = 1; +pub const __USE_ISOC95: u32 = 1; +pub const __USE_POSIX_IMPLICITLY: u32 = 1; +pub const _POSIX_SOURCE: u32 = 1; +pub const _POSIX_C_SOURCE: u32 = 200809; +pub const __USE_POSIX: u32 = 1; +pub const __USE_POSIX2: u32 = 1; +pub const __USE_POSIX199309: u32 = 1; +pub const __USE_POSIX199506: u32 = 1; +pub const __USE_XOPEN2K: u32 = 1; +pub const __USE_XOPEN2K8: u32 = 1; +pub const _ATFILE_SOURCE: u32 = 1; +pub const __USE_MISC: u32 = 1; +pub const __USE_ATFILE: u32 = 1; +pub const __USE_FORTIFY_LEVEL: u32 = 0; +pub const __GLIBC_USE_DEPRECATED_GETS: u32 = 0; +pub const _STDC_PREDEF_H: u32 = 1; +pub const __STDC_IEC_559__: u32 = 1; +pub const __STDC_IEC_559_COMPLEX__: u32 = 1; +pub const __STDC_ISO_10646__: u32 = 201706; +pub const __STDC_NO_THREADS__: u32 = 1; +pub const __GNU_LIBRARY__: u32 = 6; +pub const __GLIBC__: u32 = 2; +pub const __GLIBC_MINOR__: u32 = 27; +pub const _SYS_CDEFS_H: u32 = 1; +pub const __glibc_c99_flexarr_available: u32 = 1; +pub const __WORDSIZE: u32 = 64; +pub const __WORDSIZE_TIME64_COMPAT32: u32 = 1; +pub const __SYSCALL_WORDSIZE: u32 = 64; +pub const __HAVE_GENERIC_SELECTION: u32 = 1; +pub const __GLIBC_USE_LIB_EXT2: u32 = 0; +pub const __GLIBC_USE_IEC_60559_BFP_EXT: u32 = 0; +pub const __GLIBC_USE_IEC_60559_FUNCS_EXT: u32 = 0; +pub const __GLIBC_USE_IEC_60559_TYPES_EXT: u32 = 0; +pub const _BITS_TYPES_H: u32 = 1; +pub const _BITS_TYPESIZES_H: u32 = 1; +pub const __OFF_T_MATCHES_OFF64_T: u32 = 1; +pub const __INO_T_MATCHES_INO64_T: u32 = 1; +pub const __RLIM_T_MATCHES_RLIM64_T: u32 = 1; +pub const __FD_SETSIZE: u32 = 1024; +pub const _BITS_WCHAR_H: u32 = 1; +pub const _BITS_STDINT_INTN_H: u32 = 1; +pub const _BITS_STDINT_UINTN_H: u32 = 1; +pub const INT8_MIN: i32 = -128; +pub const INT16_MIN: i32 = -32768; +pub const INT32_MIN: i32 = -2147483648; +pub const INT8_MAX: u32 = 127; +pub const INT16_MAX: u32 = 32767; +pub const INT32_MAX: u32 = 2147483647; +pub const UINT8_MAX: u32 = 255; +pub const UINT16_MAX: u32 = 65535; +pub const UINT32_MAX: u32 = 4294967295; +pub const INT_LEAST8_MIN: i32 = -128; +pub const INT_LEAST16_MIN: i32 = -32768; +pub const INT_LEAST32_MIN: i32 = -2147483648; +pub const INT_LEAST8_MAX: u32 = 127; +pub const INT_LEAST16_MAX: u32 = 32767; +pub const INT_LEAST32_MAX: u32 = 2147483647; +pub const UINT_LEAST8_MAX: u32 = 255; +pub const UINT_LEAST16_MAX: u32 = 65535; +pub const UINT_LEAST32_MAX: u32 = 4294967295; +pub const INT_FAST8_MIN: i32 = -128; +pub const INT_FAST16_MIN: i64 = -9223372036854775808; +pub const INT_FAST32_MIN: i64 = -9223372036854775808; +pub const INT_FAST8_MAX: u32 = 127; +pub const INT_FAST16_MAX: u64 = 9223372036854775807; +pub const INT_FAST32_MAX: u64 = 9223372036854775807; +pub const UINT_FAST8_MAX: u32 = 255; +pub const UINT_FAST16_MAX: i32 = -1; +pub const UINT_FAST32_MAX: i32 = -1; +pub const INTPTR_MIN: i64 = -9223372036854775808; +pub const INTPTR_MAX: u64 = 9223372036854775807; +pub const UINTPTR_MAX: i32 = -1; +pub const PTRDIFF_MIN: i64 = -9223372036854775808; +pub const PTRDIFF_MAX: u64 = 9223372036854775807; +pub const SIG_ATOMIC_MIN: i32 = -2147483648; +pub const SIG_ATOMIC_MAX: u32 = 2147483647; +pub const SIZE_MAX: i32 = -1; +pub const WINT_MIN: u32 = 0; +pub const WINT_MAX: u32 = 4294967295; +pub const SGX_FLAGS_INITTED: u32 = 1; +pub const SGX_FLAGS_DEBUG: u32 = 2; +pub const SGX_FLAGS_MODE64BIT: u32 = 4; +pub const SGX_FLAGS_PROVISION_KEY: u32 = 16; +pub const SGX_FLAGS_EINITTOKEN_KEY: u32 = 32; +pub const SGX_FLAGS_KSS: u32 = 128; +pub const SGX_XFRM_LEGACY: u32 = 3; +pub const SGX_XFRM_AVX: u32 = 6; +pub const SGX_XFRM_AVX512: u32 = 230; +pub const SGX_XFRM_MPX: u32 = 24; +pub const SGX_XFRM_RESERVED: i32 = -232; +pub const SGX_KEYSELECT_EINITTOKEN: u32 = 0; +pub const SGX_KEYSELECT_PROVISION: u32 = 1; +pub const SGX_KEYSELECT_PROVISION_SEAL: u32 = 2; +pub const SGX_KEYSELECT_REPORT: u32 = 3; +pub const SGX_KEYSELECT_SEAL: u32 = 4; +pub const SGX_KEYPOLICY_MRENCLAVE: u32 = 1; +pub const SGX_KEYPOLICY_MRSIGNER: u32 = 2; +pub const SGX_KEYPOLICY_NOISVPRODID: u32 = 4; +pub const SGX_KEYPOLICY_CONFIGID: u32 = 8; +pub const SGX_KEYPOLICY_ISVFAMILYID: u32 = 16; +pub const SGX_KEYPOLICY_ISVEXTPRODID: u32 = 32; +pub const SGX_KEYID_SIZE: u32 = 32; +pub const SGX_CPUSVN_SIZE: u32 = 16; +pub const SGX_CONFIGID_SIZE: u32 = 64; +pub const SGX_KEY_REQUEST_RESERVED2_BYTES: u32 = 434; +pub const SGX_HASH_SIZE: u32 = 32; +pub const SGX_MAC_SIZE: u32 = 16; +pub const SGX_REPORT_DATA_SIZE: u32 = 64; +pub const SGX_ISVEXT_PROD_ID_SIZE: u32 = 16; +pub const SGX_ISV_FAMILY_ID_SIZE: u32 = 16; +pub const SGX_TARGET_INFO_RESERVED1_BYTES: u32 = 2; +pub const SGX_TARGET_INFO_RESERVED2_BYTES: u32 = 8; +pub const SGX_TARGET_INFO_RESERVED3_BYTES: u32 = 384; +pub const SGX_PLATFORM_INFO_SIZE: u32 = 101; +pub const MAX_EX_FEATURES_COUNT: u32 = 32; +pub const SGX_CREATE_ENCLAVE_EX_PCL_BIT_IDX: u32 = 0; +pub const SGX_CREATE_ENCLAVE_EX_PCL: u32 = 1; +pub const SGX_CREATE_ENCLAVE_EX_SWITCHLESS_BIT_IDX: u32 = 1; +pub const SGX_CREATE_ENCLAVE_EX_SWITCHLESS: u32 = 2; +pub const SGX_CREATE_ENCLAVE_EX_KSS_BIT_IDX: u32 = 2; +pub const SGX_CREATE_ENCLAVE_EX_KSS: u32 = 4; +pub const _SGX_LAST_EX_FEATURE_IDX_: u32 = 2; +pub const SGX_DEBUG_FLAG: u32 = 1; +pub const PS_CAP_TRUSTED_TIME: u32 = 1; +pub const PS_CAP_MONOTONIC_COUNTER: u32 = 2; +pub type __u_char = ::std::os::raw::c_uchar; +pub type __u_short = ::std::os::raw::c_ushort; +pub type __u_int = ::std::os::raw::c_uint; +pub type __u_long = ::std::os::raw::c_ulong; +pub type __int8_t = ::std::os::raw::c_schar; +pub type __uint8_t = ::std::os::raw::c_uchar; +pub type __int16_t = ::std::os::raw::c_short; +pub type __uint16_t = ::std::os::raw::c_ushort; +pub type __int32_t = ::std::os::raw::c_int; +pub type __uint32_t = ::std::os::raw::c_uint; +pub type __int64_t = ::std::os::raw::c_long; +pub type __uint64_t = ::std::os::raw::c_ulong; +pub type __quad_t = ::std::os::raw::c_long; +pub type __u_quad_t = ::std::os::raw::c_ulong; +pub type __intmax_t = ::std::os::raw::c_long; +pub type __uintmax_t = ::std::os::raw::c_ulong; +pub type __dev_t = ::std::os::raw::c_ulong; +pub type __uid_t = ::std::os::raw::c_uint; +pub type __gid_t = ::std::os::raw::c_uint; +pub type __ino_t = ::std::os::raw::c_ulong; +pub type __ino64_t = ::std::os::raw::c_ulong; +pub type __mode_t = ::std::os::raw::c_uint; +pub type __nlink_t = ::std::os::raw::c_ulong; +pub type __off_t = ::std::os::raw::c_long; +pub type __off64_t = ::std::os::raw::c_long; +pub type __pid_t = ::std::os::raw::c_int; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)] +pub struct __fsid_t { + pub __val: [::std::os::raw::c_int; 2usize], +} +#[test] +fn bindgen_test_layout___fsid_t() { + assert_eq!( + ::std::mem::size_of::<__fsid_t>(), + 8usize, + concat!("Size of: ", stringify!(__fsid_t)) + ); + assert_eq!( + ::std::mem::align_of::<__fsid_t>(), + 4usize, + concat!("Alignment of ", stringify!(__fsid_t)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<__fsid_t>())).__val as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__fsid_t), + "::", + stringify!(__val) + ) + ); +} +pub type __clock_t = ::std::os::raw::c_long; +pub type __rlim_t = ::std::os::raw::c_ulong; +pub type __rlim64_t = ::std::os::raw::c_ulong; +pub type __id_t = ::std::os::raw::c_uint; +pub type __time_t = ::std::os::raw::c_long; +pub type __useconds_t = ::std::os::raw::c_uint; +pub type __suseconds_t = ::std::os::raw::c_long; +pub type __daddr_t = ::std::os::raw::c_int; +pub type __key_t = ::std::os::raw::c_int; +pub type __clockid_t = ::std::os::raw::c_int; +pub type __timer_t = *mut ::std::os::raw::c_void; +pub type __blksize_t = ::std::os::raw::c_long; +pub type __blkcnt_t = ::std::os::raw::c_long; +pub type __blkcnt64_t = ::std::os::raw::c_long; +pub type __fsblkcnt_t = ::std::os::raw::c_ulong; +pub type __fsblkcnt64_t = ::std::os::raw::c_ulong; +pub type __fsfilcnt_t = ::std::os::raw::c_ulong; +pub type __fsfilcnt64_t = ::std::os::raw::c_ulong; +pub type __fsword_t = ::std::os::raw::c_long; +pub type __ssize_t = ::std::os::raw::c_long; +pub type __syscall_slong_t = ::std::os::raw::c_long; +pub type __syscall_ulong_t = ::std::os::raw::c_ulong; +pub type __loff_t = __off64_t; +pub type __caddr_t = *mut ::std::os::raw::c_char; +pub type __intptr_t = ::std::os::raw::c_long; +pub type __socklen_t = ::std::os::raw::c_uint; +pub type __sig_atomic_t = ::std::os::raw::c_int; +pub type int_least8_t = ::std::os::raw::c_schar; +pub type int_least16_t = ::std::os::raw::c_short; +pub type int_least32_t = ::std::os::raw::c_int; +pub type int_least64_t = ::std::os::raw::c_long; +pub type uint_least8_t = ::std::os::raw::c_uchar; +pub type uint_least16_t = ::std::os::raw::c_ushort; +pub type uint_least32_t = ::std::os::raw::c_uint; +pub type uint_least64_t = ::std::os::raw::c_ulong; +pub type int_fast8_t = ::std::os::raw::c_schar; +pub type int_fast16_t = ::std::os::raw::c_long; +pub type int_fast32_t = ::std::os::raw::c_long; +pub type int_fast64_t = ::std::os::raw::c_long; +pub type uint_fast8_t = ::std::os::raw::c_uchar; +pub type uint_fast16_t = ::std::os::raw::c_ulong; +pub type uint_fast32_t = ::std::os::raw::c_ulong; +pub type uint_fast64_t = ::std::os::raw::c_ulong; +pub type intmax_t = __intmax_t; +pub type uintmax_t = __uintmax_t; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)] +pub struct _attributes_t { + pub flags: u64, + pub xfrm: u64, +} +#[test] +fn bindgen_test_layout__attributes_t() { + assert_eq!( + ::std::mem::size_of::<_attributes_t>(), + 16usize, + concat!("Size of: ", stringify!(_attributes_t)) + ); + assert_eq!( + ::std::mem::align_of::<_attributes_t>(), + 8usize, + concat!("Alignment of ", stringify!(_attributes_t)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_attributes_t>())).flags as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_attributes_t), + "::", + stringify!(flags) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_attributes_t>())).xfrm as *const _ as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(_attributes_t), + "::", + stringify!(xfrm) + ) + ); +} +pub type sgx_attributes_t = _attributes_t; +pub type sgx_misc_select_t = u32; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)] +pub struct _sgx_misc_attribute_t { + pub secs_attr: sgx_attributes_t, + pub misc_select: sgx_misc_select_t, +} +#[test] +fn bindgen_test_layout__sgx_misc_attribute_t() { + assert_eq!( + ::std::mem::size_of::<_sgx_misc_attribute_t>(), + 24usize, + concat!("Size of: ", stringify!(_sgx_misc_attribute_t)) + ); + assert_eq!( + ::std::mem::align_of::<_sgx_misc_attribute_t>(), + 8usize, + concat!("Alignment of ", stringify!(_sgx_misc_attribute_t)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_sgx_misc_attribute_t>())).secs_attr as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_sgx_misc_attribute_t), + "::", + stringify!(secs_attr) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<_sgx_misc_attribute_t>())).misc_select as *const _ as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(_sgx_misc_attribute_t), + "::", + stringify!(misc_select) + ) + ); +} +pub type sgx_misc_attribute_t = _sgx_misc_attribute_t; +pub type sgx_key_128bit_t = [u8; 16usize]; +pub type sgx_isv_svn_t = u16; +pub type sgx_config_svn_t = u16; +pub type sgx_config_id_t = [u8; 64usize]; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)] +pub struct _sgx_cpu_svn_t { + pub svn: [u8; 16usize], +} +#[test] +fn bindgen_test_layout__sgx_cpu_svn_t() { + assert_eq!( + ::std::mem::size_of::<_sgx_cpu_svn_t>(), + 16usize, + concat!("Size of: ", stringify!(_sgx_cpu_svn_t)) + ); + assert_eq!( + ::std::mem::align_of::<_sgx_cpu_svn_t>(), + 1usize, + concat!("Alignment of ", stringify!(_sgx_cpu_svn_t)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_sgx_cpu_svn_t>())).svn as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_sgx_cpu_svn_t), + "::", + stringify!(svn) + ) + ); +} +pub type sgx_cpu_svn_t = _sgx_cpu_svn_t; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)] +pub struct _sgx_key_id_t { + pub id: [u8; 32usize], +} +#[test] +fn bindgen_test_layout__sgx_key_id_t() { + assert_eq!( + ::std::mem::size_of::<_sgx_key_id_t>(), + 32usize, + concat!("Size of: ", stringify!(_sgx_key_id_t)) + ); + assert_eq!( + ::std::mem::align_of::<_sgx_key_id_t>(), + 1usize, + concat!("Alignment of ", stringify!(_sgx_key_id_t)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_sgx_key_id_t>())).id as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_sgx_key_id_t), + "::", + stringify!(id) + ) + ); +} +pub type sgx_key_id_t = _sgx_key_id_t; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct _key_request_t { + pub key_name: u16, + pub key_policy: u16, + pub isv_svn: sgx_isv_svn_t, + pub reserved1: u16, + pub cpu_svn: sgx_cpu_svn_t, + pub attribute_mask: sgx_attributes_t, + pub key_id: sgx_key_id_t, + pub misc_mask: sgx_misc_select_t, + pub config_svn: sgx_config_svn_t, + pub reserved2: [u8; 434usize], +} +#[test] +fn bindgen_test_layout__key_request_t() { + assert_eq!( + ::std::mem::size_of::<_key_request_t>(), + 512usize, + concat!("Size of: ", stringify!(_key_request_t)) + ); + assert_eq!( + ::std::mem::align_of::<_key_request_t>(), + 8usize, + concat!("Alignment of ", stringify!(_key_request_t)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_key_request_t>())).key_name as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_key_request_t), + "::", + stringify!(key_name) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_key_request_t>())).key_policy as *const _ as usize }, + 2usize, + concat!( + "Offset of field: ", + stringify!(_key_request_t), + "::", + stringify!(key_policy) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_key_request_t>())).isv_svn as *const _ as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(_key_request_t), + "::", + stringify!(isv_svn) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_key_request_t>())).reserved1 as *const _ as usize }, + 6usize, + concat!( + "Offset of field: ", + stringify!(_key_request_t), + "::", + stringify!(reserved1) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_key_request_t>())).cpu_svn as *const _ as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(_key_request_t), + "::", + stringify!(cpu_svn) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_key_request_t>())).attribute_mask as *const _ as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(_key_request_t), + "::", + stringify!(attribute_mask) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_key_request_t>())).key_id as *const _ as usize }, + 40usize, + concat!( + "Offset of field: ", + stringify!(_key_request_t), + "::", + stringify!(key_id) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_key_request_t>())).misc_mask as *const _ as usize }, + 72usize, + concat!( + "Offset of field: ", + stringify!(_key_request_t), + "::", + stringify!(misc_mask) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_key_request_t>())).config_svn as *const _ as usize }, + 76usize, + concat!( + "Offset of field: ", + stringify!(_key_request_t), + "::", + stringify!(config_svn) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_key_request_t>())).reserved2 as *const _ as usize }, + 78usize, + concat!( + "Offset of field: ", + stringify!(_key_request_t), + "::", + stringify!(reserved2) + ) + ); +} +impl Default for _key_request_t { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +pub type sgx_key_request_t = _key_request_t; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)] +pub struct _sgx_measurement_t { + pub m: [u8; 32usize], +} +#[test] +fn bindgen_test_layout__sgx_measurement_t() { + assert_eq!( + ::std::mem::size_of::<_sgx_measurement_t>(), + 32usize, + concat!("Size of: ", stringify!(_sgx_measurement_t)) + ); + assert_eq!( + ::std::mem::align_of::<_sgx_measurement_t>(), + 1usize, + concat!("Alignment of ", stringify!(_sgx_measurement_t)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_sgx_measurement_t>())).m as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_sgx_measurement_t), + "::", + stringify!(m) + ) + ); +} +pub type sgx_measurement_t = _sgx_measurement_t; +pub type sgx_mac_t = [u8; 16usize]; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct _sgx_report_data_t { + pub d: [u8; 64usize], +} +#[test] +fn bindgen_test_layout__sgx_report_data_t() { + assert_eq!( + ::std::mem::size_of::<_sgx_report_data_t>(), + 64usize, + concat!("Size of: ", stringify!(_sgx_report_data_t)) + ); + assert_eq!( + ::std::mem::align_of::<_sgx_report_data_t>(), + 1usize, + concat!("Alignment of ", stringify!(_sgx_report_data_t)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_sgx_report_data_t>())).d as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_sgx_report_data_t), + "::", + stringify!(d) + ) + ); +} +impl Default for _sgx_report_data_t { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +pub type sgx_report_data_t = _sgx_report_data_t; +pub type sgx_prod_id_t = u16; +pub type sgx_isvext_prod_id_t = [u8; 16usize]; +pub type sgx_isvfamily_id_t = [u8; 16usize]; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct _target_info_t { + pub mr_enclave: sgx_measurement_t, + pub attributes: sgx_attributes_t, + pub reserved1: [u8; 2usize], + pub config_svn: sgx_config_svn_t, + pub misc_select: sgx_misc_select_t, + pub reserved2: [u8; 8usize], + pub config_id: sgx_config_id_t, + pub reserved3: [u8; 384usize], +} +#[test] +fn bindgen_test_layout__target_info_t() { + assert_eq!( + ::std::mem::size_of::<_target_info_t>(), + 512usize, + concat!("Size of: ", stringify!(_target_info_t)) + ); + assert_eq!( + ::std::mem::align_of::<_target_info_t>(), + 8usize, + concat!("Alignment of ", stringify!(_target_info_t)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_target_info_t>())).mr_enclave as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_target_info_t), + "::", + stringify!(mr_enclave) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_target_info_t>())).attributes as *const _ as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(_target_info_t), + "::", + stringify!(attributes) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_target_info_t>())).reserved1 as *const _ as usize }, + 48usize, + concat!( + "Offset of field: ", + stringify!(_target_info_t), + "::", + stringify!(reserved1) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_target_info_t>())).config_svn as *const _ as usize }, + 50usize, + concat!( + "Offset of field: ", + stringify!(_target_info_t), + "::", + stringify!(config_svn) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_target_info_t>())).misc_select as *const _ as usize }, + 52usize, + concat!( + "Offset of field: ", + stringify!(_target_info_t), + "::", + stringify!(misc_select) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_target_info_t>())).reserved2 as *const _ as usize }, + 56usize, + concat!( + "Offset of field: ", + stringify!(_target_info_t), + "::", + stringify!(reserved2) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_target_info_t>())).config_id as *const _ as usize }, + 64usize, + concat!( + "Offset of field: ", + stringify!(_target_info_t), + "::", + stringify!(config_id) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_target_info_t>())).reserved3 as *const _ as usize }, + 128usize, + concat!( + "Offset of field: ", + stringify!(_target_info_t), + "::", + stringify!(reserved3) + ) + ); +} +impl Default for _target_info_t { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +pub type sgx_target_info_t = _target_info_t; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct _report_body_t { + pub cpu_svn: sgx_cpu_svn_t, + pub misc_select: sgx_misc_select_t, + pub reserved1: [u8; 12usize], + pub isv_ext_prod_id: sgx_isvext_prod_id_t, + pub attributes: sgx_attributes_t, + pub mr_enclave: sgx_measurement_t, + pub reserved2: [u8; 32usize], + pub mr_signer: sgx_measurement_t, + pub reserved3: [u8; 32usize], + pub config_id: sgx_config_id_t, + pub isv_prod_id: sgx_prod_id_t, + pub isv_svn: sgx_isv_svn_t, + pub config_svn: sgx_config_svn_t, + pub reserved4: [u8; 42usize], + pub isv_family_id: sgx_isvfamily_id_t, + pub report_data: sgx_report_data_t, +} +#[test] +fn bindgen_test_layout__report_body_t() { + assert_eq!( + ::std::mem::size_of::<_report_body_t>(), + 384usize, + concat!("Size of: ", stringify!(_report_body_t)) + ); + assert_eq!( + ::std::mem::align_of::<_report_body_t>(), + 8usize, + concat!("Alignment of ", stringify!(_report_body_t)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_report_body_t>())).cpu_svn as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_report_body_t), + "::", + stringify!(cpu_svn) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_report_body_t>())).misc_select as *const _ as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(_report_body_t), + "::", + stringify!(misc_select) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_report_body_t>())).reserved1 as *const _ as usize }, + 20usize, + concat!( + "Offset of field: ", + stringify!(_report_body_t), + "::", + stringify!(reserved1) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_report_body_t>())).isv_ext_prod_id as *const _ as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(_report_body_t), + "::", + stringify!(isv_ext_prod_id) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_report_body_t>())).attributes as *const _ as usize }, + 48usize, + concat!( + "Offset of field: ", + stringify!(_report_body_t), + "::", + stringify!(attributes) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_report_body_t>())).mr_enclave as *const _ as usize }, + 64usize, + concat!( + "Offset of field: ", + stringify!(_report_body_t), + "::", + stringify!(mr_enclave) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_report_body_t>())).reserved2 as *const _ as usize }, + 96usize, + concat!( + "Offset of field: ", + stringify!(_report_body_t), + "::", + stringify!(reserved2) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_report_body_t>())).mr_signer as *const _ as usize }, + 128usize, + concat!( + "Offset of field: ", + stringify!(_report_body_t), + "::", + stringify!(mr_signer) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_report_body_t>())).reserved3 as *const _ as usize }, + 160usize, + concat!( + "Offset of field: ", + stringify!(_report_body_t), + "::", + stringify!(reserved3) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_report_body_t>())).config_id as *const _ as usize }, + 192usize, + concat!( + "Offset of field: ", + stringify!(_report_body_t), + "::", + stringify!(config_id) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_report_body_t>())).isv_prod_id as *const _ as usize }, + 256usize, + concat!( + "Offset of field: ", + stringify!(_report_body_t), + "::", + stringify!(isv_prod_id) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_report_body_t>())).isv_svn as *const _ as usize }, + 258usize, + concat!( + "Offset of field: ", + stringify!(_report_body_t), + "::", + stringify!(isv_svn) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_report_body_t>())).config_svn as *const _ as usize }, + 260usize, + concat!( + "Offset of field: ", + stringify!(_report_body_t), + "::", + stringify!(config_svn) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_report_body_t>())).reserved4 as *const _ as usize }, + 262usize, + concat!( + "Offset of field: ", + stringify!(_report_body_t), + "::", + stringify!(reserved4) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_report_body_t>())).isv_family_id as *const _ as usize }, + 304usize, + concat!( + "Offset of field: ", + stringify!(_report_body_t), + "::", + stringify!(isv_family_id) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_report_body_t>())).report_data as *const _ as usize }, + 320usize, + concat!( + "Offset of field: ", + stringify!(_report_body_t), + "::", + stringify!(report_data) + ) + ); +} +impl Default for _report_body_t { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +pub type sgx_report_body_t = _report_body_t; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct _report_t { + pub body: sgx_report_body_t, + pub key_id: sgx_key_id_t, + pub mac: sgx_mac_t, +} +#[test] +fn bindgen_test_layout__report_t() { + assert_eq!( + ::std::mem::size_of::<_report_t>(), + 432usize, + concat!("Size of: ", stringify!(_report_t)) + ); + assert_eq!( + ::std::mem::align_of::<_report_t>(), + 8usize, + concat!("Alignment of ", stringify!(_report_t)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_report_t>())).body as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_report_t), + "::", + stringify!(body) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_report_t>())).key_id as *const _ as usize }, + 384usize, + concat!( + "Offset of field: ", + stringify!(_report_t), + "::", + stringify!(key_id) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_report_t>())).mac as *const _ as usize }, + 416usize, + concat!( + "Offset of field: ", + stringify!(_report_t), + "::", + stringify!(mac) + ) + ); +} +impl Default for _report_t { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +pub type sgx_report_t = _report_t; +pub type sgx_epid_group_id_t = [u8; 4usize]; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)] +pub struct _spid_t { + pub id: [u8; 16usize], +} +#[test] +fn bindgen_test_layout__spid_t() { + assert_eq!( + ::std::mem::size_of::<_spid_t>(), + 16usize, + concat!("Size of: ", stringify!(_spid_t)) + ); + assert_eq!( + ::std::mem::align_of::<_spid_t>(), + 1usize, + concat!("Alignment of ", stringify!(_spid_t)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_spid_t>())).id as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_spid_t), + "::", + stringify!(id) + ) + ); +} +pub type sgx_spid_t = _spid_t; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)] +pub struct _basename_t { + pub name: [u8; 32usize], +} +#[test] +fn bindgen_test_layout__basename_t() { + assert_eq!( + ::std::mem::size_of::<_basename_t>(), + 32usize, + concat!("Size of: ", stringify!(_basename_t)) + ); + assert_eq!( + ::std::mem::align_of::<_basename_t>(), + 1usize, + concat!("Alignment of ", stringify!(_basename_t)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_basename_t>())).name as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_basename_t), + "::", + stringify!(name) + ) + ); +} +pub type sgx_basename_t = _basename_t; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)] +pub struct _quote_nonce { + pub rand: [u8; 16usize], +} +#[test] +fn bindgen_test_layout__quote_nonce() { + assert_eq!( + ::std::mem::size_of::<_quote_nonce>(), + 16usize, + concat!("Size of: ", stringify!(_quote_nonce)) + ); + assert_eq!( + ::std::mem::align_of::<_quote_nonce>(), + 1usize, + concat!("Alignment of ", stringify!(_quote_nonce)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_quote_nonce>())).rand as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_quote_nonce), + "::", + stringify!(rand) + ) + ); +} +pub type sgx_quote_nonce_t = _quote_nonce; +pub const SGX_UNLINKABLE_SIGNATURE: sgx_quote_sign_type_t = 0; +pub const SGX_LINKABLE_SIGNATURE: sgx_quote_sign_type_t = 1; +pub type sgx_quote_sign_type_t = u32; +#[repr(C, packed)] +pub struct _quote_t { + pub version: u16, + pub sign_type: u16, + pub epid_group_id: sgx_epid_group_id_t, + pub qe_svn: sgx_isv_svn_t, + pub pce_svn: sgx_isv_svn_t, + pub xeid: u32, + pub basename: sgx_basename_t, + pub report_body: sgx_report_body_t, + pub signature_len: u32, + pub signature: __IncompleteArrayField, +} +#[test] +fn bindgen_test_layout__quote_t() { + assert_eq!( + ::std::mem::size_of::<_quote_t>(), + 436usize, + concat!("Size of: ", stringify!(_quote_t)) + ); + assert_eq!( + ::std::mem::align_of::<_quote_t>(), + 1usize, + concat!("Alignment of ", stringify!(_quote_t)) + ); +} +impl Default for _quote_t { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +pub type sgx_quote_t = _quote_t; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct _platform_info { + pub platform_info: [u8; 101usize], +} +#[test] +fn bindgen_test_layout__platform_info() { + assert_eq!( + ::std::mem::size_of::<_platform_info>(), + 101usize, + concat!("Size of: ", stringify!(_platform_info)) + ); + assert_eq!( + ::std::mem::align_of::<_platform_info>(), + 1usize, + concat!("Alignment of ", stringify!(_platform_info)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_platform_info>())).platform_info as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_platform_info), + "::", + stringify!(platform_info) + ) + ); +} +impl Default for _platform_info { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +pub type sgx_platform_info_t = _platform_info; +#[repr(C, packed)] +#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)] +pub struct _update_info_bit { + pub ucodeUpdate: ::std::os::raw::c_int, + pub csmeFwUpdate: ::std::os::raw::c_int, + pub pswUpdate: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout__update_info_bit() { + assert_eq!( + ::std::mem::size_of::<_update_info_bit>(), + 12usize, + concat!("Size of: ", stringify!(_update_info_bit)) + ); + assert_eq!( + ::std::mem::align_of::<_update_info_bit>(), + 1usize, + concat!("Alignment of ", stringify!(_update_info_bit)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_update_info_bit>())).ucodeUpdate as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_update_info_bit), + "::", + stringify!(ucodeUpdate) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_update_info_bit>())).csmeFwUpdate as *const _ as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(_update_info_bit), + "::", + stringify!(csmeFwUpdate) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_update_info_bit>())).pswUpdate as *const _ as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(_update_info_bit), + "::", + stringify!(pswUpdate) + ) + ); +} +pub type sgx_update_info_bit_t = _update_info_bit; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct _att_key_id_t { + pub att_key_id: [u8; 158usize], +} +#[test] +fn bindgen_test_layout__att_key_id_t() { + assert_eq!( + ::std::mem::size_of::<_att_key_id_t>(), + 158usize, + concat!("Size of: ", stringify!(_att_key_id_t)) + ); + assert_eq!( + ::std::mem::align_of::<_att_key_id_t>(), + 1usize, + concat!("Alignment of ", stringify!(_att_key_id_t)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_att_key_id_t>())).att_key_id as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_att_key_id_t), + "::", + stringify!(att_key_id) + ) + ); +} +impl Default for _att_key_id_t { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +pub type sgx_att_key_id_t = _att_key_id_t; +#[repr(C, packed)] +#[derive(Copy, Clone)] +pub struct _qe_report_info_t { + pub nonce: sgx_quote_nonce_t, + pub app_enclave_target_info: sgx_target_info_t, + pub qe_report: sgx_report_t, +} +#[test] +fn bindgen_test_layout__qe_report_info_t() { + assert_eq!( + ::std::mem::size_of::<_qe_report_info_t>(), + 960usize, + concat!("Size of: ", stringify!(_qe_report_info_t)) + ); + assert_eq!( + ::std::mem::align_of::<_qe_report_info_t>(), + 1usize, + concat!("Alignment of ", stringify!(_qe_report_info_t)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_qe_report_info_t>())).nonce as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_qe_report_info_t), + "::", + stringify!(nonce) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<_qe_report_info_t>())).app_enclave_target_info as *const _ + as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(_qe_report_info_t), + "::", + stringify!(app_enclave_target_info) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_qe_report_info_t>())).qe_report as *const _ as usize }, + 528usize, + concat!( + "Offset of field: ", + stringify!(_qe_report_info_t), + "::", + stringify!(qe_report) + ) + ); +} +impl Default for _qe_report_info_t { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +pub type sgx_qe_report_info_t = _qe_report_info_t; +pub const SGX_SUCCESS: _status_t = 0; +pub const SGX_ERROR_UNEXPECTED: _status_t = 1; +pub const SGX_ERROR_INVALID_PARAMETER: _status_t = 2; +pub const SGX_ERROR_OUT_OF_MEMORY: _status_t = 3; +pub const SGX_ERROR_ENCLAVE_LOST: _status_t = 4; +pub const SGX_ERROR_INVALID_STATE: _status_t = 5; +pub const SGX_ERROR_FEATURE_NOT_SUPPORTED: _status_t = 8; +pub const SGX_ERROR_INVALID_FUNCTION: _status_t = 4097; +pub const SGX_ERROR_OUT_OF_TCS: _status_t = 4099; +pub const SGX_ERROR_ENCLAVE_CRASHED: _status_t = 4102; +pub const SGX_ERROR_ECALL_NOT_ALLOWED: _status_t = 4103; +pub const SGX_ERROR_OCALL_NOT_ALLOWED: _status_t = 4104; +pub const SGX_ERROR_STACK_OVERRUN: _status_t = 4105; +pub const SGX_ERROR_UNDEFINED_SYMBOL: _status_t = 8192; +pub const SGX_ERROR_INVALID_ENCLAVE: _status_t = 8193; +pub const SGX_ERROR_INVALID_ENCLAVE_ID: _status_t = 8194; +pub const SGX_ERROR_INVALID_SIGNATURE: _status_t = 8195; +pub const SGX_ERROR_NDEBUG_ENCLAVE: _status_t = 8196; +pub const SGX_ERROR_OUT_OF_EPC: _status_t = 8197; +pub const SGX_ERROR_NO_DEVICE: _status_t = 8198; +pub const SGX_ERROR_MEMORY_MAP_CONFLICT: _status_t = 8199; +pub const SGX_ERROR_INVALID_METADATA: _status_t = 8201; +pub const SGX_ERROR_DEVICE_BUSY: _status_t = 8204; +pub const SGX_ERROR_INVALID_VERSION: _status_t = 8205; +pub const SGX_ERROR_MODE_INCOMPATIBLE: _status_t = 8206; +pub const SGX_ERROR_ENCLAVE_FILE_ACCESS: _status_t = 8207; +pub const SGX_ERROR_INVALID_MISC: _status_t = 8208; +pub const SGX_ERROR_INVALID_LAUNCH_TOKEN: _status_t = 8209; +pub const SGX_ERROR_MAC_MISMATCH: _status_t = 12289; +pub const SGX_ERROR_INVALID_ATTRIBUTE: _status_t = 12290; +pub const SGX_ERROR_INVALID_CPUSVN: _status_t = 12291; +pub const SGX_ERROR_INVALID_ISVSVN: _status_t = 12292; +pub const SGX_ERROR_INVALID_KEYNAME: _status_t = 12293; +pub const SGX_ERROR_SERVICE_UNAVAILABLE: _status_t = 16385; +pub const SGX_ERROR_SERVICE_TIMEOUT: _status_t = 16386; +pub const SGX_ERROR_AE_INVALID_EPIDBLOB: _status_t = 16387; +pub const SGX_ERROR_SERVICE_INVALID_PRIVILEGE: _status_t = 16388; +pub const SGX_ERROR_EPID_MEMBER_REVOKED: _status_t = 16389; +pub const SGX_ERROR_UPDATE_NEEDED: _status_t = 16390; +pub const SGX_ERROR_NETWORK_FAILURE: _status_t = 16391; +pub const SGX_ERROR_AE_SESSION_INVALID: _status_t = 16392; +pub const SGX_ERROR_BUSY: _status_t = 16394; +pub const SGX_ERROR_MC_NOT_FOUND: _status_t = 16396; +pub const SGX_ERROR_MC_NO_ACCESS_RIGHT: _status_t = 16397; +pub const SGX_ERROR_MC_USED_UP: _status_t = 16398; +pub const SGX_ERROR_MC_OVER_QUOTA: _status_t = 16399; +pub const SGX_ERROR_KDF_MISMATCH: _status_t = 16401; +pub const SGX_ERROR_UNRECOGNIZED_PLATFORM: _status_t = 16402; +pub const SGX_ERROR_NO_PRIVILEGE: _status_t = 20482; +pub const SGX_ERROR_PCL_ENCRYPTED: _status_t = 24577; +pub const SGX_ERROR_PCL_NOT_ENCRYPTED: _status_t = 24578; +pub const SGX_ERROR_PCL_MAC_MISMATCH: _status_t = 24579; +pub const SGX_ERROR_PCL_SHA_MISMATCH: _status_t = 24580; +pub const SGX_ERROR_PCL_GUID_MISMATCH: _status_t = 24581; +pub const SGX_ERROR_FILE_BAD_STATUS: _status_t = 28673; +pub const SGX_ERROR_FILE_NO_KEY_ID: _status_t = 28674; +pub const SGX_ERROR_FILE_NAME_MISMATCH: _status_t = 28675; +pub const SGX_ERROR_FILE_NOT_SGX_FILE: _status_t = 28676; +pub const SGX_ERROR_FILE_CANT_OPEN_RECOVERY_FILE: _status_t = 28677; +pub const SGX_ERROR_FILE_CANT_WRITE_RECOVERY_FILE: _status_t = 28678; +pub const SGX_ERROR_FILE_RECOVERY_NEEDED: _status_t = 28679; +pub const SGX_ERROR_FILE_FLUSH_FAILED: _status_t = 28680; +pub const SGX_ERROR_FILE_CLOSE_FAILED: _status_t = 28681; +pub const SGX_ERROR_UNSUPPORTED_ATT_KEY_ID: _status_t = 32769; +pub const SGX_ERROR_ATT_KEY_CERTIFICATION_FAILURE: _status_t = 32770; +pub const SGX_ERROR_ATT_KEY_UNINITIALIZED: _status_t = 32771; +pub const SGX_ERROR_INVALID_ATT_KEY_CERT_DATA: _status_t = 32772; +pub const SGX_INTERNAL_ERROR_ENCLAVE_CREATE_INTERRUPTED: _status_t = 61441; +pub type _status_t = u32; +pub use self::_status_t as sgx_status_t; +pub type sgx_enclave_id_t = u64; +pub type wchar_t = ::std::os::raw::c_int; +#[repr(C)] +#[repr(align(16))] +#[derive(Debug, Default, Copy, Clone, PartialEq)] +pub struct max_align_t { + pub __clang_max_align_nonce1: ::std::os::raw::c_longlong, + pub __bindgen_padding_0: u64, + pub __clang_max_align_nonce2: u128, +} +#[test] +fn bindgen_test_layout_max_align_t() { + assert_eq!( + ::std::mem::size_of::(), + 32usize, + concat!("Size of: ", stringify!(max_align_t)) + ); + assert_eq!( + ::std::mem::align_of::(), + 16usize, + concat!("Alignment of ", stringify!(max_align_t)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).__clang_max_align_nonce1 as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(max_align_t), + "::", + stringify!(__clang_max_align_nonce1) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).__clang_max_align_nonce2 as *const _ as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(max_align_t), + "::", + stringify!(__clang_max_align_nonce2) + ) + ); +} +#[repr(C, packed)] +#[derive(Copy, Clone)] +pub struct _sgx_kss_config_t { + pub config_id: sgx_config_id_t, + pub config_svn: sgx_config_svn_t, +} +#[test] +fn bindgen_test_layout__sgx_kss_config_t() { + assert_eq!( + ::std::mem::size_of::<_sgx_kss_config_t>(), + 66usize, + concat!("Size of: ", stringify!(_sgx_kss_config_t)) + ); + assert_eq!( + ::std::mem::align_of::<_sgx_kss_config_t>(), + 1usize, + concat!("Alignment of ", stringify!(_sgx_kss_config_t)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_sgx_kss_config_t>())).config_id as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_sgx_kss_config_t), + "::", + stringify!(config_id) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_sgx_kss_config_t>())).config_svn as *const _ as usize }, + 64usize, + concat!( + "Offset of field: ", + stringify!(_sgx_kss_config_t), + "::", + stringify!(config_svn) + ) + ); +} +impl Default for _sgx_kss_config_t { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +pub type sgx_kss_config_t = _sgx_kss_config_t; +pub type sgx_launch_token_t = [u8; 1024usize]; +extern "C" { + pub fn sgx_create_enclave( + file_name: *const ::std::os::raw::c_char, + debug: ::std::os::raw::c_int, + launch_token: *mut sgx_launch_token_t, + launch_token_updated: *mut ::std::os::raw::c_int, + enclave_id: *mut sgx_enclave_id_t, + misc_attr: *mut sgx_misc_attribute_t, + ) -> sgx_status_t; +} +extern "C" { + pub fn sgx_create_enclave_ex( + file_name: *const ::std::os::raw::c_char, + debug: ::std::os::raw::c_int, + launch_token: *mut sgx_launch_token_t, + launch_token_updated: *mut ::std::os::raw::c_int, + enclave_id: *mut sgx_enclave_id_t, + misc_attr: *mut sgx_misc_attribute_t, + ex_features: u32, + ex_features_p: *mut *const ::std::os::raw::c_void, + ) -> sgx_status_t; +} +extern "C" { + pub fn sgx_create_enclave_from_buffer_ex( + buffer: *mut u8, + buffer_size: usize, + debug: ::std::os::raw::c_int, + enclave_id: *mut sgx_enclave_id_t, + misc_attr: *mut sgx_misc_attribute_t, + ex_features: u32, + ex_features_p: *mut *const ::std::os::raw::c_void, + ) -> sgx_status_t; +} +extern "C" { + pub fn sgx_create_encrypted_enclave( + file_name: *const ::std::os::raw::c_char, + debug: ::std::os::raw::c_int, + launch_token: *mut sgx_launch_token_t, + launch_token_updated: *mut ::std::os::raw::c_int, + enclave_id: *mut sgx_enclave_id_t, + misc_attr: *mut sgx_misc_attribute_t, + sealed_key: *mut u8, + ) -> sgx_status_t; +} +extern "C" { + pub fn sgx_destroy_enclave(enclave_id: sgx_enclave_id_t) -> sgx_status_t; +} +extern "C" { + pub fn sgx_get_target_info( + enclave_id: sgx_enclave_id_t, + target_info: *mut sgx_target_info_t, + ) -> sgx_status_t; +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)] +pub struct _sgx_ps_cap_t { + pub ps_cap0: u32, + pub ps_cap1: u32, +} +#[test] +fn bindgen_test_layout__sgx_ps_cap_t() { + assert_eq!( + ::std::mem::size_of::<_sgx_ps_cap_t>(), + 8usize, + concat!("Size of: ", stringify!(_sgx_ps_cap_t)) + ); + assert_eq!( + ::std::mem::align_of::<_sgx_ps_cap_t>(), + 4usize, + concat!("Alignment of ", stringify!(_sgx_ps_cap_t)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_sgx_ps_cap_t>())).ps_cap0 as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_sgx_ps_cap_t), + "::", + stringify!(ps_cap0) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<_sgx_ps_cap_t>())).ps_cap1 as *const _ as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(_sgx_ps_cap_t), + "::", + stringify!(ps_cap1) + ) + ); +} +pub type sgx_ps_cap_t = _sgx_ps_cap_t; +extern "C" { + pub fn sgx_init_quote( + p_target_info: *mut sgx_target_info_t, + p_gid: *mut sgx_epid_group_id_t, + ) -> sgx_status_t; +} +extern "C" { + pub fn sgx_calc_quote_size( + p_sig_rl: *const u8, + sig_rl_size: u32, + p_quote_size: *mut u32, + ) -> sgx_status_t; +} +extern "C" { + pub fn sgx_get_quote_size(p_sig_rl: *const u8, p_quote_size: *mut u32) -> sgx_status_t; +} +extern "C" { + pub fn sgx_get_quote( + p_report: *const sgx_report_t, + quote_type: sgx_quote_sign_type_t, + p_spid: *const sgx_spid_t, + p_nonce: *const sgx_quote_nonce_t, + p_sig_rl: *const u8, + sig_rl_size: u32, + p_qe_report: *mut sgx_report_t, + p_quote: *mut sgx_quote_t, + quote_size: u32, + ) -> sgx_status_t; +} +extern "C" { + pub fn sgx_get_ps_cap(p_sgx_ps_cap: *mut sgx_ps_cap_t) -> sgx_status_t; +} +extern "C" { + pub fn sgx_get_whitelist_size(p_whitelist_size: *mut u32) -> sgx_status_t; +} +extern "C" { + pub fn sgx_get_whitelist(p_whitelist: *mut u8, whitelist_size: u32) -> sgx_status_t; +} +extern "C" { + pub fn sgx_get_extended_epid_group_id(p_extended_epid_group_id: *mut u32) -> sgx_status_t; +} +extern "C" { + pub fn sgx_report_attestation_status( + p_platform_info: *const sgx_platform_info_t, + attestation_status: ::std::os::raw::c_int, + p_update_info: *mut sgx_update_info_bit_t, + ) -> sgx_status_t; +} +extern "C" { + pub fn sgx_register_wl_cert_chain( + p_wl_cert_chain: *mut u8, + wl_cert_chain_size: u32, + ) -> sgx_status_t; +} +extern "C" { + pub fn sgx_select_att_key_id( + p_att_key_id_list: *const u8, + att_key_id_list_size: u32, + pp_selected_key_id: *mut *mut sgx_att_key_id_t, + ) -> sgx_status_t; +} +extern "C" { + pub fn sgx_init_quote_ex( + p_att_key_id: *const sgx_att_key_id_t, + p_qe_target_info: *mut sgx_target_info_t, + refresh_att_key: bool, + p_pub_key_id_size: *mut usize, + p_pub_key_id: *mut u8, + ) -> sgx_status_t; +} +extern "C" { + pub fn sgx_get_quote_size_ex( + p_att_key_id: *const sgx_att_key_id_t, + p_quote_size: *mut u32, + ) -> sgx_status_t; +} +extern "C" { + pub fn sgx_get_quote_ex( + p_app_report: *const sgx_report_t, + p_att_key_id: *const sgx_att_key_id_t, + p_qe_report_info: *mut sgx_qe_report_info_t, + p_quote: *mut u8, + quote_size: u32, + ) -> sgx_status_t; +} diff --git a/sgx_sdk_ffi/src/lib.rs b/sgx_sdk_ffi/src/lib.rs new file mode 100644 index 0000000..313f41e --- /dev/null +++ b/sgx_sdk_ffi/src/lib.rs @@ -0,0 +1,353 @@ +/* + * Copyright (C) 2019 Open Whisper Systems + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#[allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals, improper_ctypes)] +mod bindgen_wrapper; + +use std::fmt; +use std::mem; +use std::os::raw; +use std::ptr; + +use num_traits::FromPrimitive; + +use bindgen_wrapper::{ + sgx_calc_quote_size, sgx_create_enclave, sgx_create_enclave_from_buffer_ex, sgx_destroy_enclave, sgx_get_quote, sgx_init_quote, + sgx_quote_t, sgx_spid_t, sgx_status_t, SGX_SUCCESS, SGX_UNLINKABLE_SIGNATURE, +}; + +pub use bindgen_wrapper::{ + sgx_enclave_id_t as SgxEnclaveId, sgx_quote_t as SgxQuote, sgx_report_t as SgxReport, sgx_target_info_t as SgxTargetInfo, +}; + +pub type SgxResult = Result; + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum SgxStatus { + Success, + Error(SgxError), + Unknown(u32), +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq, num_derive::FromPrimitive)] +pub enum SgxError { + Unexpected = 1, + InvalidParameter = 2, + OutOfMemory = 3, + EnclaveLost = 4, + InvalidState = 5, + FeatureNotSupported = 8, + InvalidFunction = 4097, + OutOfTcs = 4099, + EnclaveCrashed = 4102, + EcallNotAllowed = 4103, + OcallNotAllowed = 4104, + StackOverrun = 4105, + UndefinedSymbol = 8192, + InvalidEnclave = 8193, + InvalidEnclaveId = 8194, + InvalidSignature = 8195, + NdebugEnclave = 8196, + OutOfEpc = 8197, + NoDevice = 8198, + MemoryMapConflict = 8199, + InvalidMetadata = 8201, + DeviceBusy = 8204, + InvalidVersion = 8205, + ModeIncompatible = 8206, + EnclaveFileAccess = 8207, + InvalidMisc = 8208, + InvalidLaunchToken = 8209, + MacMismatch = 12289, + InvalidAttribute = 12290, + InvalidCpusvn = 12291, + InvalidIsvsvn = 12292, + InvalidKeyname = 12293, + ServiceUnavailable = 16385, + ServiceTimeout = 16386, + AeInvalidEpidblob = 16387, + ServiceInvalidPrivilege = 16388, + EpidMemberRevoked = 16389, + UpdateNeeded = 16390, + NetworkFailure = 16391, + AeSessionInvalid = 16392, + Busy = 16394, + McNotFound = 16396, + McNoAccessRight = 16397, + McUsedUp = 16398, + McOverQuota = 16399, + KdfMismatch = 16401, + UnrecognizedPlatform = 16402, + NoPrivilege = 20482, + PclEncrypted = 24577, + PclNotEncrypted = 24578, + PclMacMismatch = 24579, + PclShaMismatch = 24580, + PclGuidMismatch = 24581, + FileBadStatus = 28673, + FileNoKeyId = 28674, + FileNameMismatch = 28675, + FileNotSgxFile = 28676, + FileCantOpenRecoveryFile = 28677, + FileCantWriteRecoveryFile = 28678, + FileRecoveryNeeded = 28679, + FileFlushFailed = 28680, + FileCloseFailed = 28681, + UnsupportedAttKeyId = 32769, + AttKeyCertificationFailure = 32770, + AttKeyUninitialized = 32771, + InvalidAttKeyCertData = 32772, + EnclaveCreateInterrupted = 61441, + SgxsdPendingRequestNotFound = 65537, +} + +pub struct SgxEnclave { + id: SgxEnclaveId, + buffer: Option<(*mut u8, usize, usize)>, +} + +// +// SgxEnclave impls +// + +impl SgxEnclave { + pub fn new(mut buffer: Vec, debug: bool) -> SgxResult { + let buffer_ptr = buffer.as_mut_ptr(); + let buffer_len = buffer.len(); + let buffer_cap = buffer.capacity(); + mem::forget(buffer); + + let mut enclave_id: SgxEnclaveId = Default::default(); + SgxStatus::from(unsafe { + sgx_create_enclave_from_buffer_ex( + buffer_ptr, + buffer_len, + debug as raw::c_int, + &mut enclave_id, + ptr::null_mut(), + 0u32, + ptr::null_mut(), + ) + }) + .ok()?; + Ok(SgxEnclave { + id: enclave_id, + buffer: Some((buffer_ptr, buffer_len, buffer_cap)), + }) + } + + pub fn id(&self) -> SgxEnclaveId { + self.id + } +} + +impl Drop for SgxEnclave { + fn drop(&mut self) { + unsafe { + if let Ok(()) = SgxStatus::from(sgx_destroy_enclave(self.id)).ok() { + if let Some((buffer_ptr, buffer_len, buffer_cap)) = self.buffer { + drop(Vec::from_raw_parts(buffer_ptr, buffer_len, buffer_cap)); + } + } + } + } +} + +// +// free functions +// + +pub fn create_enclave(enclave_filename: &str, debug: bool) -> SgxResult { + let enclave_filename_cstr = std::ffi::CString::new(enclave_filename).unwrap(); + let mut launch_token: [u8; 1024] = [0; 1024]; + let mut launch_token_updated: i32 = Default::default(); + let mut enclave_id: SgxEnclaveId = Default::default(); + SgxStatus::from(unsafe { + sgx_create_enclave( + enclave_filename_cstr.as_ptr(), + debug as std::os::raw::c_int, + &mut launch_token, + &mut launch_token_updated, + &mut enclave_id, + std::ptr::null_mut(), + ) + }) + .ok()?; + Ok(enclave_id) +} + +pub fn init_quote() -> SgxResult<(u32, SgxTargetInfo)> { + // NB: sgx_init_quote expects qe_target_info to be zeroed (undocumented!) + let mut qe_target_info: SgxTargetInfo = Default::default(); + let mut gid: [u8; 4] = Default::default(); + SgxStatus::from(unsafe { sgx_init_quote(&mut qe_target_info, &mut gid) }).ok()?; + Ok((u32::from_ne_bytes(gid), qe_target_info)) +} + +pub fn get_gid() -> SgxResult { + Ok(init_quote()?.0) +} + +pub fn get_qe_target_info() -> SgxResult { + Ok(init_quote()?.1) +} + +pub fn get_quote(report: SgxReport, spid: &[u8; 16], sig_rl: &[u8]) -> SgxResult> { + let (p_sig_rl, sig_rl_len) = get_sig_rl_ptr(sig_rl); + let mut quote_size: u32 = Default::default(); + SgxStatus::from(unsafe { sgx_calc_quote_size(p_sig_rl, sig_rl_len, &mut quote_size) }).ok()?; + + if (quote_size as usize) < mem::size_of::() { + return Err(SgxError::Unexpected.into()); + } + + let mut quote: Vec = vec![0; quote_size as usize]; + let quote_size = quote.len() as u32; + let spid_struct = sgx_spid_t { id: *spid }; + SgxStatus::from(unsafe { + sgx_get_quote( + &report, + SGX_UNLINKABLE_SIGNATURE, + &spid_struct, + std::ptr::null(), + p_sig_rl, + sig_rl_len, + std::ptr::null_mut(), + quote.as_mut_ptr() as *mut sgx_quote_t, + quote_size, + ) + }) + .ok()?; + + Ok(quote) +} + +fn get_sig_rl_ptr(sig_rl: &[u8]) -> (*const u8, u32) { + match sig_rl.len() { + 0 => (std::ptr::null(), 0), + len if len < (u32::max_value() as usize) => (sig_rl.as_ptr(), len as u32), + _ => (std::ptr::null(), 0), + } +} + +// +// SgxReport impls +// + +impl SgxReport { + pub const SIZE: usize = mem::size_of::(); + + pub fn new(data: &[u8]) -> Result { + if data.len() == Self::SIZE { + Ok(unsafe { std::ptr::read_unaligned(data.as_ptr() as *const Self) }) + } else { + Err(()) + } + } +} + +impl From<&[u8; Self::SIZE]> for SgxReport { + fn from(from: &[u8; Self::SIZE]) -> Self { + unsafe { std::ptr::read_unaligned(from.as_ptr() as *const Self) } + } +} + +// +// SgxStatus impls +// + +impl SgxStatus { + pub fn ok(self) -> SgxResult<()> { + match self { + SgxStatus::Success => Ok(()), + status => Err(status), + } + } + + pub fn err(&self) -> Option<&SgxError> { + match self { + SgxStatus::Error(error) => Some(error), + _ => None, + } + } +} + +impl std::error::Error for SgxStatus {} + +impl fmt::Display for SgxStatus { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self, fmt) + } +} + +impl From for SgxStatus { + fn from(status: sgx_status_t) -> Self { + if status == 0 { + SgxStatus::Success + } else if let Some(sgx_error_code) = SgxError::from_u32(status) { + SgxStatus::Error(sgx_error_code) + } else { + SgxStatus::Unknown(status) + } + } +} + +impl From for SgxStatus { + fn from(sgx_error: SgxError) -> Self { + SgxStatus::Error(sgx_error) + } +} + +impl From for sgx_status_t { + fn from(sgx_status: SgxStatus) -> Self { + match sgx_status { + SgxStatus::Success => SGX_SUCCESS, + SgxStatus::Error(sgx_error) => sgx_error.into(), + SgxStatus::Unknown(sgx_status) => sgx_status, + } + } +} + +// +// SgxError impls +// + +impl std::error::Error for SgxError {} + +impl fmt::Display for SgxError { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self, fmt) + } +} + +impl From for sgx_status_t { + fn from(sgx_error: SgxError) -> Self { + sgx_error as sgx_status_t + } +} + +#[cfg(test)] +mod test { + use std::mem; + + use super::*; + + #[test] + fn test_sgx_quote_align() { + assert_eq!(mem::align_of::(), 1); + } +}