0

我注意到有些人能够用 C 代码编写 SGX 代码。我试图这样做,假设我有以下代码。我仍然不知道如何编写一个可以编译这些文件的 Makefile 因为我没有在网上找到太多关于如何编译它的信息。

主程序

#define ENCLAVE_FILE "enclave.signed.dll"
#define MAX_BUF_LEN 100
#include "sgx_urts.h"
#include "enclave_u.h"
#include "stdio.h"
#include <string>

int main()
{

    //Encalve starts
    sgx_enclave_id_t eid;
    sgx_status_t    ret = SGX_SUCCESS;
    sgx_launch_token_t token = { 0 };
    int updated = 0;
    char buffer[MAX_BUF_LEN] = "Hello world!";

    ret = sgx_create_enclave(ENCLAVE_FILE, SGX_DEBUG_FLAG, &token, &updated, &eid, NULL);

    if (ret != SGX_SUCCESS) {
        printf("\nApp: error %#x, failed to create enclave. \n", ret);
    }

    //Encalve starts


    // (ECALL will happen here).

    printf("\nApp: Buffertesrs:\n");

    printf("App: Buffer before ECALL: %s\n", buffer);

    encalveChangebuffer(eid, buffer, MAX_BUF_LEN);

    printf("App: Buffer before ECALL: %s\n", buffer);



}

encalve.c

#include "enclave_t.h"
#include "sgx_trts.h"
#include <stdio.h>
#include <string.h>

void encalveChangebuffer(char * buf, size_t len) {

    const char * secret = "Hello from Enclave 2";
    if (len > strlen(secret))
        memcpy(buf, secret, strlen(secret) + 1);
    else
        memcpy(buf, "false", strlen("false") + 1);

}

encalve.edl

enclave {
    trusted {
        /* define ECALLs here. */
        public void encalveChangebuffer([in,out,size=len] char * buf, size_t len);
    };

    untrusted {
        /* define OCALLs here. */
    };
};

我正在寻找可以编译 sgx c 代码的 Makefile。

4

1 回答 1

0

查看此参考: SGX 开发人员参考

它有一个关于 Edger8r 工具的部分,解释了如何运行该工具以将 enclave.edl 编译成一堆 C 文件。它还有一个关于生成签名 DLL 所需的 sgx_sign.exe 的部分。有一个“Enclave 项目文件”部分列出了所有必需的文件和构建工具设置。

我没有所有的答案,但这应该是构建你的 make 文件的一个很好的起点。

于 2019-04-09T19:49:07.630 回答