0

I noticed some people able to write an SGX code in C code. I tried to do that, Assume I have the following code. Still I don't know how to write a Makefile that can compile these file As I didn't find much information online on how to compile it.

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. */
    };
};

I am looking for a Makefile that can compile sgx c code.

user1584540
  • 21
  • 1
  • 1
  • 5

1 Answers1

0

Check out this reference: SGX Developer Reference.

It has a section about Edger8r Tool that explains how to run that tool to compile enclave.edl to a bunch of C files. It also has a section about sgx_sign.exe that is needed to produce a signed DLL. There's a section "Enclave Project Files" that lists all required files and build tool settings.

I don't have all the answers, but that should be a good starting point for building your make file.

battlmonstr
  • 5,841
  • 1
  • 23
  • 33