我注意到有些人能够用C代码编写SGX代码。我试着这样做,假设我有以下代码。我仍然不知道如何编写一个Makefile来编译这些文件,因为我在网上没有找到太多关于如何编译它的信息。
main.c
#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. */
};
};我正在寻找一个Makefile,可以编译sgx c代码。
发布于 2019-04-10 03:49:08
请查看此参考:SGX Developer Reference。
其中有一节介绍了Edger8r工具,解释了如何运行该工具将enclave.edl编译为一组C文件。它还有一个关于sgx_sign.exe的部分,需要用来生成一个带签名的DLL。有一个"Enclave Project Files“部分列出了所有必需的文件和构建工具设置。
我没有所有的答案,但这应该是构建make文件的一个很好的起点。
https://stackoverflow.com/questions/55598824
复制相似问题