|
@@ -17,6 +17,7 @@
|
|
|
#ifndef SGX_API_H
|
|
|
#define SGX_API_H
|
|
|
|
|
|
+#include "sgx_arch.h"
|
|
|
#include "pal_error.h"
|
|
|
|
|
|
int sgx_ocall (unsigned long code, void * ms);
|
|
@@ -31,10 +32,6 @@ void sgx_reset_ustack(void);
|
|
|
bool sgx_copy_ptr_to_enclave(void** ptr, void* uptr, uint64_t size);
|
|
|
uint64_t sgx_copy_to_enclave(const void* ptr, uint64_t maxsize, const void* uptr, uint64_t usize);
|
|
|
|
|
|
-int sgx_report (sgx_arch_targetinfo_t * targetinfo,
|
|
|
- void * reportdata, sgx_arch_report_t * report);
|
|
|
-
|
|
|
-int sgx_getkey (sgx_arch_keyrequest_t * keyrequest, sgx_arch_key128_t * key);
|
|
|
|
|
|
int sgx_get_report (sgx_arch_hash_t * mrenclave,
|
|
|
sgx_arch_attributes_t * attributes,
|
|
@@ -43,9 +40,74 @@ int sgx_get_report (sgx_arch_hash_t * mrenclave,
|
|
|
|
|
|
int sgx_verify_report (sgx_arch_report_t * report);
|
|
|
|
|
|
-uint32_t rdrand (void);
|
|
|
-uint64_t rdfsbase (void);
|
|
|
-void wrfsbase (uint64_t addr);
|
|
|
+/*
|
|
|
+ * sgx_report:
|
|
|
+ * Generate SGX hardware signed report.
|
|
|
+ */
|
|
|
+static inline int sgx_report (sgx_arch_targetinfo_t * targetinfo,
|
|
|
+ void * reportdata, sgx_arch_report_t * report)
|
|
|
+{
|
|
|
+ __asm__ volatile(
|
|
|
+ ENCLU "\n"
|
|
|
+ :: "a"(EREPORT), "b"(targetinfo), "c"(reportdata), "d"(report)
|
|
|
+ : "memory");
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+ * sgx_getkey:
|
|
|
+ * Retrieve SGX hardware enclave cryptography key.
|
|
|
+ */
|
|
|
+static inline int64_t sgx_getkey (sgx_arch_keyrequest_t * keyrequest,
|
|
|
+ sgx_arch_key128_t * key)
|
|
|
+{
|
|
|
+ int64_t rax = EGETKEY;
|
|
|
+ __asm__ volatile(
|
|
|
+ ENCLU "\n"
|
|
|
+ : "+a"(rax)
|
|
|
+ : "b"(keyrequest), "c"(key)
|
|
|
+ : "memory");
|
|
|
+ return rax;
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+ * rdrand:
|
|
|
+ * Get hardware generated random value.
|
|
|
+ */
|
|
|
+static inline uint32_t rdrand (void)
|
|
|
+{
|
|
|
+ uint32_t ret;
|
|
|
+ __asm__ volatile(
|
|
|
+ "1: .byte 0x0f, 0xc7, 0xf0\n" /* RDRAND %EAX */
|
|
|
+ "jnc 1b\n"
|
|
|
+ :"=a"(ret)
|
|
|
+ :: "cc");
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+ * rdfsbase:
|
|
|
+ * read FS register (allowed in enclaves).
|
|
|
+ */
|
|
|
+static inline uint64_t rdfsbase (void)
|
|
|
+{
|
|
|
+ uint64_t fsbase;
|
|
|
+ __asm__ volatile(
|
|
|
+ ".byte 0xf3, 0x48, 0x0f, 0xae, 0xc0\n" /* RDFSBASE %RAX */
|
|
|
+ : "=a"(fsbase));
|
|
|
+ return fsbase;
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+ * wrfsbase:
|
|
|
+ * modify FS register (allowed in enclaves).
|
|
|
+ */
|
|
|
+static inline void wrfsbase (uint64_t addr)
|
|
|
+{
|
|
|
+ __asm__ volatile(
|
|
|
+ ".byte 0xf3, 0x48, 0x0f, 0xae, 0xd7\n" /* WRFSBASE %RDI */
|
|
|
+ :: "D"(addr));
|
|
|
+}
|
|
|
|
|
|
void restore_sgx_context(sgx_context_t *ctx);
|
|
|
void _restore_sgx_context(sgx_context_t *ctx);
|