2 #include "ypc/common/byte.h"
7 template <
typename Hash,
typename EC>
struct sign_impl {
10 typedef ::ypc::utc::bytes<uint8_t, ::ypc::utc::byte_encode::raw_bytes>
bytes;
13 static uint32_t get_signature_size() {
return ecc_t::get_signature_size(); }
15 static uint32_t sign_message(
const uint8_t *skey, uint32_t skey_size,
16 const uint8_t *data, uint32_t data_size,
17 uint8_t *sig, uint32_t sig_size) {
18 bytes hash(hash_t::get_msg_hash_size());
19 uint32_t ret = hash_t::msg_hash(data, data_size, hash.data(), hash.size());
23 ret = ecc_t::sign_message(skey, skey_size, hash.data(), hash.size(), sig,
28 static uint32_t verify_signature(
const uint8_t *data, uint32_t data_size,
29 const uint8_t *sig, uint32_t sig_size,
30 const uint8_t *public_key,
32 uint32_t hash_size = hash_t::get_msg_hash_size();
33 bytes hash(hash_size);
34 uint32_t ret = hash_t::msg_hash(data, data_size, hash.data(), hash_size);
39 ret = ecc_t::verify_signature(hash.data(), hash_size, sig, sig_size,
40 public_key, pkey_size);
44 template <
typename BytesType>
45 static uint32_t sign_message(
const BytesType &skey,
const BytesType &data,
47 sig = BytesType(ecc_t::get_signature_size());
48 return sign_message(skey.data(), skey.size(), data.data(), data.size(),
49 sig.data(), sig.size());
52 template <
typename BytesType>
53 static uint32_t verify_signature(
const BytesType &data,
const BytesType &sig,
54 const BytesType &public_key) {
58 return verify_signature(data.data(), data.size(), sig.data(), sig.size(),
59 public_key.data(), public_key.size());