SGX Enclave:执行处理的实际函数去哪里以及如何编译

SGX Enclave: Where the actual function that does the procession goes and how it gets compiled

阅读大量文档后,我做了第一个简单的 enclave 函数:

enclave {
     //Include files 

     //Import other edl files

     //Data structure declarations to be used as parameters of the
     //function prototypes in edl

     trusted {
          public function myFirstMethod([in]  int *a, [in]  int *b,[out] int *sum);
     };

     untrusted {
     };
};

然后 bash 我 运行 edger8r:

sgx_edger8r enclave.edl

然后它生成了以下文件,如您在架构中所见:

所以我假设在 enclave_t.c 的某个地方,我找到的唯一参考是在这个函数中:

static sgx_status_t SGX_CDECL sgx_myFirstMethod(void* pms)
{
    CHECK_REF_POINTER(pms, sizeof(ms_myFirstMethod_t));
    ms_myFirstMethod_t* ms = SGX_CAST(ms_myFirstMethod_t*, pms);
    sgx_status_t status = SGX_SUCCESS;
    int* _tmp_a = ms->ms_a;
    size_t _len_a = sizeof(*_tmp_a);
    int* _in_a = NULL;
    int* _tmp_b = ms->ms_b;
    size_t _len_b = sizeof(*_tmp_b);
    int* _in_b = NULL;

    CHECK_UNIQUE_POINTER(_tmp_a, _len_a);
    CHECK_UNIQUE_POINTER(_tmp_b, _len_b);

    if (_tmp_a != NULL) {
        _in_a = (int*)malloc(_len_a);
        if (_in_a == NULL) {
            status = SGX_ERROR_OUT_OF_MEMORY;
            goto err;
        }

        memcpy(_in_a, _tmp_a, _len_a);
    }
    if (_tmp_b != NULL) {
        _in_b = (int*)malloc(_len_b);
        if (_in_b == NULL) {
            status = SGX_ERROR_OUT_OF_MEMORY;
            goto err;
        }

        memcpy(_in_b, _tmp_b, _len_b);
    }
    ms->ms_retval = myFirstMethod(_in_a, _in_b);
err:
    if (_in_a) free(_in_a);
    if (_in_b) free(_in_b);

    return status;
}

尤其是在

    ms->ms_retval = myFirstMethod(_in_a, _in_b);

但是 myFirstMethod 放在哪里?还有我如何将我的 enclave 编译为应用程序的一部分作为静态库。

据我搜索,教程在这些 links:

所有提到的 Visual Studio 本身并不 运行 超过 GNU/Linux 所以我有点难以理解。

编辑 1:

进一步查看我在 https://github.com/01org/linux-sgx 上看到我可以像 link 提到的那样在模拟模式下编译:

make SGX_MODE=SIM

而且我已经成功安装了 driver and the sdk。我想通过 SIMULATION 模式编译而不是真实模式。

Dimitris 首先检查您是否有此列表中的兼容硬件 https://github.com/ayeks/SGX-hardware

然后尝试克隆一个 运行 这个 repo https://github.com/digawp/hello-enclave

这将帮助您了解其工作原理

edger8r 的自动生成输出仅用于提供 enclave 与不受信任的外部世界之间的接口。它们不应包含您的实现。

您应该在另一个源文件中定义 myFirstMethod,比如 enclave.cenclave.cpp 和 link 它与您的项目的其余部分。函数的签名与您在 edl 中声明的完全相同,指针限定符除外,它供 edger8r 使用。

它将是这样的:

enclave.cpp:

void myFirstMethod(int *a, int *b, int *sum)
{
  *sum = *a + *b;
}