2 #include "ypc/core_t/analyzer/internal/keymgr_session.h"
3 #include "ypc/core_t/analyzer/var/enclave_hash_var.h"
4 #include "ypc/core_t/analyzer/var/keymgr_var.h"
5 #include "ypc/core_t/analyzer/var/model_var.h"
6 #include "ypc/core_t/analyzer/var/request_key_var.h"
7 #include "ypc/corecommon/nt_cols.h"
8 #include "ypc/corecommon/package.h"
9 #include "ypc/stbox/ebyte.h"
10 #include "ypc/stbox/stx_status.h"
14 typedef nt<stbox::bytes>
ntt;
16 template <
typename Crypto,
typename ModelT,
17 bool has_model = !std::is_same<ModelT, void>::value>
20 template <
typename Crypto,
typename ModelT>
33 uint32_t init_model(
const uint8_t *model, uint32_t len) {
34 auto ret = internal::keymgr_session::init_keymgr_session();
36 LOG(ERROR) <<
"init_keymgr_session failed: " << stbox::status_string(ret);
43 stbox::bytes private_key, dian_pkey;
44 ret = keymgr_interface_t::request_private_key_for_public_key(
45 mod.get<ntt::pkey>(), private_key, dian_pkey);
47 LOG(ERROR) <<
"request_private_key failed: " << stbox::status_string(ret);
52 auto model_data = mod.get<ntt::model_data>();
53 stbox::bytes decrypted_model(
54 ecc::get_decrypt_message_size_with_prefix(model_data.size()));
56 ret = ecc::decrypt_message_with_prefix(
57 private_key.data(), private_key.size(), model_data.data(),
58 model_data.size(), decrypted_model.data(), decrypted_model.size(),
59 ypc::utc::crypto_prefix_arbitrary);
61 LOG(ERROR) <<
"decrypt_message_with_prefix failed: "
62 << stbox::status_string(ret);
66 model_var_t::m_model =
69 model_var_t::m_model_pkey = mod.get<ntt::pkey>();
70 ret = ecc::hash_256(decrypted_model, model_var_t::m_model_hash);
72 LOG(ERROR) <<
"hash_256 failed: " << stbox::status_string(ret);
76 return stbox::stx_status::success;