3 #include "ypc/corecommon/crypto/crypto_pack.h"
4 #include "ypc/corecommon/crypto/stdeth.h"
5 #include "ypc/corecommon/crypto/gmssl.h"
12 virtual bytes gen_ecc_private_key() = 0;
14 gen_ecc_public_key_from_private_key(
const bytes &private_key) = 0;
17 virtual bytes sign_message(
const bytes &msg,
const bytes &private_key) = 0;
19 virtual bool verify_message_signature(
const bytes &sig,
const bytes &message,
20 const bytes &pubkey) = 0;
24 virtual bytes ecc_decrypt(
const bytes &cipher,
const bytes &private_key,
32 virtual bytes gen_ecc_private_key() {
34 auto status = crypto_t::gen_private_key(ret);
36 std::cerr <<
"gen_ecc_private_key return " << std::hex << status
38 throw std::runtime_error(
"terminus lib gen_ecc_private_key fail");
42 virtual bytes gen_ecc_public_key_from_private_key(
const bytes &private_key) {
44 auto status = crypto_t::generate_pkey_from_skey(private_key, ret);
46 std::cerr <<
"gen_ecc_public_key_from_private_key return " << std::hex
47 << status << std::endl;
48 throw std::runtime_error(
49 "terminus lib gen_ecc_public_key_from_private_key fail");
55 auto status = crypto_t::hash_256(msg, sig);
57 std::cerr <<
"hash_256 return " << std::hex << status << std::endl;
58 throw std::runtime_error(
"terminus lib hash_256 fail");
63 virtual bytes sign_message(
const bytes &msg,
const bytes &private_key) {
65 auto status = crypto_t::sign_message(private_key, msg, ret);
67 std::cerr <<
"sign_message return " << std::hex << status << std::endl;
68 throw std::runtime_error(
"terminus lib sig_message fail");
73 virtual bool verify_message_signature(
const bytes &sig,
const bytes &message,
74 const bytes &pubkey) {
75 return stbox::stx_status::success ==
76 crypto_t::verify_signature(message, sig, pubkey);
83 crypto_t::encrypt_message_with_prefix(public_key, msg, prefix, ret);
85 std::cerr <<
"ecc_encrypt return " << std::hex << status << std::endl;
86 throw std::runtime_error(
"terminus lib ecc_encrypt fail");
91 virtual bytes ecc_decrypt(
const bytes &cipher,
const bytes &private_key,
95 crypto_t::decrypt_message_with_prefix(private_key, cipher, ret, prefix);
97 std::cerr <<
"ecc_decrypt return " << std::hex << status << std::endl;
98 throw std::runtime_error(
"terminus lib ecc_decrypt fail");
104 std::unique_ptr<crypto_pack> intel_sgx_and_eth_compatible();
105 std::unique_ptr<crypto_pack> sm_compatible();