c++ - 英特尔 SGX 将整数从应用程序传递到 Enclave

标签 c++ intel sgx enclave

我正在尝试将两个整数传递给 SGX 飞地,将它们组合起来,然后将结果返回给应用程序。
但是,除了创建飞地之外,编译代码时似乎什么都没有发生。没有给出错误,它似乎永远不会到达 ECALL 函数。

如果有人知道这样做的教程,我可以用作引用,那将不胜感激。

EDL:

enclave {
    from "sgx_tae_service.edl" import *;

    /* enum definition */
    enum TEE_ERROR {
        TEE_ERROR_INVALID_SIGNATURE = 0,
        TEE_ERROR_INVALID_COUNTER = 1,
        TEE_ERROR_INVALID_SECRET = 2
    };


    trusted {
        /* define ECALLs here. */
        public int in_enclave([in] int* a, [in] int* b);
};

    untrusted {
        /* define OCALLs here. */
        void ocall_print_int([out] int* i);
    };
};

飞地.cpp
int in_enclave(int* a, int* b){
        ocall_print("In the Enclave.");
        int result =0;
        result = a + b;
        ocall_print_int(&result);

}

应用程序.cpp
int test(void) {
    if (initialize_enclave(&global_eid, "enclave.token", "enclave.signed.so") < 0) {
        std::cout << "Fail to initialize enclave." << std::endl;
        return 1;
    }else{

    std::cout<<"Enclave made. "<<"\n";
}
        int a =34, b =23,point = 0;
        in_enclave(global_eid,&point,&a,&b);

    return 0;                                                                                                                                                                                                                                                                             }

最佳答案

请参阅下面的更正。可信函数in_enclave接收 ab ,计算总和,并返回结果。在(不受信任的)应用程序代码中,函数结果放置在 point 中。 .

调用函数时检查返回值。从主应用程序代码的角度来看,返回值的类型为 sgx_status_t。其中 OK 是 SGX_SUCCESS . SGX 开发人员引用中有错误代码列表或查找 sgx_error.h 在源代码中。在本例中,我们可以使用 status 的值。找出调用失败的原因。

EDL

    trusted {
        public int in_enclave(int a, int b);
    };

飞地
    int in_enclave(int a, int b){
        return a + b;
    }

应用
    int a = 34, b = 23, point = 0;
    sgx_status_t status = in_enclave(global_eid, &point, a, b);
    if (SGX_SUCCESS != status) {
        // error occurred! 💩
    }
    printf("%d\n", point);

关于c++ - 英特尔 SGX 将整数从应用程序传递到 Enclave,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61648303/

相关文章:

c++ - 如何使用Boost::GIL垂直翻转图像

c++ - 在 OS X 10.6 下构建的 Cocoa 应用程序在 OS X 10.7 上崩溃

c++ - 使用 mmap 时出现段错误

x86 - INTEL VT-D 根表和上下文表关系

windows - 定期运行英特尔的 VTune

c++ - C++ 的抗侧信道数学函数

rust - 链接时如何始终包含 Rust 依赖项?

c++ - 保护新交所算法的安全

c++ - 使用互斥量调节两个进程之间的 IPC

security - 读取英特尔 DRBG 参数