簡體   English   中英

英特爾 SGX 將整數從應用程序傳遞到 Enclave

[英]Intel SGX pass ints from Application to Enclave

我正在嘗試將兩個整數傳遞給 SGX 飛地,將它們組合起來,然后將結果返回給應用程序。 但是,除了創建飛地之外,編譯代碼時似乎什么都沒有發生。 沒有給出錯誤,它似乎永遠不會到達 ECALL function。

如果有人知道這樣做的教程,我可以用作參考,那將不勝感激。

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;                                                                                                                                                                                                                                                                             }

請參閱下面的更正。 受信任的 function in_enclave接收ab ,計算總和並返回結果。 在(不受信任的)應用程序代碼中,function 結果放在point中。

調用 function 時檢查返回值。 從主應用程序代碼的角度來看,返回值是sgx_status_t類型,其中 OK 是SGX_SUCCESS SGX 開發者參考中有錯誤代碼列表或在源代碼中查找sgx_error.h 在此示例中,我們可以使用status的值來查找 ecall 失敗的原因。

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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM