LoginSignup
1
1

More than 5 years have passed since last update.

忙しい人のためのIntel SGXでHello World

Last updated at Posted at 2019-02-24

前回の記事でIntel SGXの導入について述べたので,ここではどうやってHelloWorldするかを述べます.

下準備

Sample Enclaveアプリケーションは次の2種類にわけることができます.基本的にはAppがEnclaveの関数を叩く形になります.
- App: メインのアプリケーション
- Enclave: Enclave用のプログラム

edlはヘッダーだと思ってもらえると都合がいいと思います.

Let's helloworld

ここでは,自作の特に何もしないhelloworld()という関数を定義してみましょう.

まずTrusted Library/配下にMycode.cppとMycode.edlを生成します.ファイルを生成したら,Visual Studioにドラッグ&ドロップします.

そしたらEnclave.edlに次の1行を記述してください.これによって,メインのアプリケーションであるApp.cppから今回追記するプログラムが呼べるようになります.

enclave {
  /* add */
  from "TrustedLibrary/Mycode.edl" import *;
}

続いて, Mycode.edlを編集します.

enclave {
  trusted {
    public void helloworld(void);
  }
}

続いて, Mycode.cppを編集します.

#include "Enclave.h"
#include "Enclave_t.h"
void helloworld() {
}

最後にApp.cppから呼び出します

ecall_thread_functions();
helloworld(global_eid); // <- insert here
sgx_destroy_enclave(global_eid);

まとめ

新しい関数の生成方法は次の通りです.
1. Mycode.cppMycode.edlをTrusted Library/に作成する.
2. Enclave.edlfrom "Mycode.edl" import *宣言を書く.
3. Mycode.edlpublic void helloworld(void);のプロトタイプ宣言を行う.
4. Mycode.cppに本体の宣言を行う.
5. App.cppからhelloworld()をコールする.

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1