首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用SGX的C语言Hello world

使用SGX的C语言Hello world
EN

Stack Overflow用户
提问于 2019-04-10 02:11:00
回答 1查看 423关注 0票数 0

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

main.c

代码语言:javascript
复制
#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

代码语言:javascript
复制
#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

代码语言:javascript
复制
enclave {
    trusted {
        /* define ECALLs here. */
        public void encalveChangebuffer([in,out,size=len] char * buf, size_t len);
    };

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

我正在寻找一个Makefile,可以编译sgx c代码。

EN

回答 1

Stack Overflow用户

发布于 2019-04-10 03:49:08

请查看此参考:SGX Developer Reference

其中有一节介绍了Edger8r工具,解释了如何运行该工具将enclave.edl编译为一组C文件。它还有一个关于sgx_sign.exe的部分,需要用来生成一个带签名的DLL。有一个"Enclave Project Files“部分列出了所有必需的文件和构建工具设置。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55598824

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档