2 #include "ypc/common/limits.h"
3 #include "ypc/core_t/analyzer/analyzer_context.h"
4 #include "ypc/core_t/analyzer/var/enclave_hash_var.h"
5 #include "ypc/core_t/analyzer/var/keymgr_var.h"
6 #include "ypc/core_t/analyzer/var/request_key_var.h"
7 #include "ypc/core_t/ecommon/package.h"
8 #include "ypc/corecommon/package.h"
9 #include "ypc/stbox/ebyte.h"
10 #include "ypc/stbox/stx_status.h"
11 #include "ypc/stbox/tsgx/channel/dh_session_initiator.h"
12 #include "ypc/stbox/tsgx/ocall.h"
17 template <
typename Crypto>
25 uint32_t request_private_key_for_public_key(
const stbox::bytes &pubkey,
26 stbox::bytes &private_key,
27 stbox::bytes &dian_pkey) {
31 stbox::bytes recv_bytes;
32 auto status = keymgr_var::m_keymgr_session->send_request_recv_response(
33 (
char *)request_msg.data(), request_msg.size(),
34 utc::max_keymgr_response_buf_size, recv_bytes);
35 if (recv_bytes.size() !=
36 ecc::get_private_key_size() + ecc::get_public_key_size()) {
37 return stbox::stx_status::ecc_invalid_skey_size;
39 private_key = stbox::bytes(recv_bytes.data(), ecc::get_private_key_size());
40 dian_pkey = stbox::bytes(recv_bytes.data() + private_key.size(),
41 ecc::get_public_key_size());
43 if (status != stbox::stx_status::success) {
44 LOG(ERROR) <<
"error for m_keymgr_session->send_request_recv_response: "
45 << stbox::status_string(status);
48 stbox::bytes check_pkey;
49 status = (stbox::stx_status)ecc::generate_pkey_from_skey(private_key,
52 LOG(ERROR) <<
"error for generate_ecc_pkey_from_skey: " << status;
56 if (pubkey != check_pkey) {
57 LOG(ERROR) <<
"check failed, invalid private key";
58 return stbox::stx_status::kmgr_session_inconsistency_pkey_skey;