本文整理汇总了C++中hash_digest::data方法的典型用法代码示例。如果您正苦于以下问题:C++ hash_digest::data方法的具体用法?C++ hash_digest::data怎么用?C++ hash_digest::data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hash_digest
的用法示例。
在下文中一共展示了hash_digest::data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: slice_block_hash
leveldb::Slice slice_block_hash(const hash_digest& block_hash)
{
// Cut first 16 bytes of block hash
BITCOIN_ASSERT(block_hash.size() == 32);
return leveldb::Slice(
reinterpret_cast<const char*>(block_hash.data() + 16), 16);
}
示例2: verify_signature
bool verify_signature(const ec_point& public_key, hash_digest hash,
const endorsement& signature)
{
init.init();
return 1 == secp256k1_ecdsa_verify(hash.data(), hash.size(),
signature.data(), signature.size(), public_key.data(),
public_key.size()
);
}
示例3: verify_signature
bool verify_signature(const ec_point& public_key, hash_digest hash,
const data_chunk& signature)
{
std::reverse(hash.begin(), hash.end());
init.init();
return 1 == secp256k1_ecdsa_verify(
hash.data(), hash.size(),
signature.data(), signature.size(),
public_key.data(), public_key.size()
);
}
示例4: verify
bool elliptic_curve_key::verify(hash_digest hash, const data_chunk& signature)
{
BITCOIN_ASSERT(key_ != nullptr);
// SSL likes a reversed hash
std::reverse(hash.begin(), hash.end());
// -1 = error, 0 = bad sig, 1 = good
if (ECDSA_verify(0, hash.data(), hash.size(),
signature.data(), signature.size(), key_) == 1)
return true;
return false;
}
示例5: get_block_hash
int get_block_hash(Db*, const Dbt*, const Dbt* data, Dbt* second_key)
{
std::stringstream ss(std::string(
reinterpret_cast<const char*>(data->get_data()), data->get_size()));
protobuf::Block proto_block;
proto_block.ParseFromIstream(&ss);
message::block serial_block = protobuf_to_block_header(proto_block);
second_hash = hash_block_header(serial_block);
second_key->set_data(second_hash.data());
second_key->set_size(second_hash.size());
return 0;
}
示例6: recover_public
bool recover_public(const secp256k1_context* context, byte_array<Size>& out,
const recoverable_signature& recoverable, const hash_digest& hash)
{
secp256k1_pubkey pubkey;
secp256k1_ecdsa_recoverable_signature sign;
const auto recovery_id = static_cast<int>(recoverable.recovery_id);
return
secp256k1_ecdsa_recoverable_signature_parse_compact(context,
&sign, recoverable.signature.data(), recovery_id) == 1 &&
secp256k1_ecdsa_recover(context, &pubkey, &sign, hash.data()) == 1 &&
serialize(context, out, pubkey);
}
示例7: sign
bool sign(ec_signature& out, const ec_secret& secret, const hash_digest& hash)
{
secp256k1_ecdsa_signature signature;
const auto context = signing.context();
if (secp256k1_ecdsa_sign(context, &signature, hash.data(), secret.data(),
secp256k1_nonce_function_rfc6979, nullptr) != 1)
return false;
std::copy_n(std::begin(signature.data), out.size(), out.begin());
return true;
}
示例8: sign
data_chunk elliptic_curve_key::sign(hash_digest hash) const
{
BITCOIN_ASSERT(key_ != nullptr);
// SSL likes a reversed hash
std::reverse(hash.begin(), hash.end());
data_chunk signature(ECDSA_size(key_));
unsigned int signature_length = signature.size();
if (!ECDSA_sign(0, hash.data(), hash.size(),
signature.data(), &signature_length, key_))
return data_chunk();
signature.resize(signature_length);
return signature;
}
示例9: verify_signature
bool verify_signature(const secp256k1_context* context,
const secp256k1_pubkey point, const hash_digest& hash,
const ec_signature& signature)
{
// Copy to avoid exposing external types.
secp256k1_ecdsa_signature parsed;
std::copy(signature.begin(), signature.end(), std::begin(parsed.data));
// secp256k1_ecdsa_verify rejects non-normalized (low-s) signatures, but
// bitcoin does not have such a limitation, so we always normalize.
secp256k1_ecdsa_signature normal;
secp256k1_ecdsa_signature_normalize(context, &normal, &parsed);
return secp256k1_ecdsa_verify(context, &normal, hash.data(), &point) == 1;
}
示例10: sign_compact
compact_signature sign_compact(ec_secret secret, hash_digest hash)
{
init.init();
compact_signature out;
ec_secret nonce;
unsigned index = 0;
do {
nonce = create_nonce(secret, hash, index++);
} while (secp256k1_ecdsa_sign_compact(hash.data(), hash.size(),
out.signature.data(), secret.data(), nonce.data(), &out.recid) <= 0);
return out;
}
示例11: sign
endorsement sign(ec_secret secret, hash_digest hash, ec_secret nonce)
{
init.init();
int out_size = max_endorsement_size;
endorsement signature(out_size);
if (0 < secp256k1_ecdsa_sign(hash.data(), hash.size(), signature.data(),
&out_size, secret.data(), nonce.data()))
{
signature.resize(out_size);
return signature;
}
// Error case:
return endorsement();
}
示例12: sign_recoverable
bool sign_recoverable(recoverable_signature& out, const ec_secret& secret,
const hash_digest& hash)
{
int recovery_id;
const auto context = signing.context();
secp256k1_ecdsa_recoverable_signature signature;
const auto result =
secp256k1_ecdsa_sign_recoverable(context, &signature, hash.data(),
secret.data(), secp256k1_nonce_function_rfc6979, nullptr) == 1 &&
secp256k1_ecdsa_recoverable_signature_serialize_compact(context,
out.signature.data(), &recovery_id, &signature) == 1;
BITCOIN_ASSERT(recovery_id >= 0 && recovery_id <= 3);
out.recovery_id = static_cast<uint8_t>(recovery_id);
return result;
}
示例13: sign
data_chunk sign(ec_secret secret, hash_digest hash, ec_secret nonce)
{
std::reverse(hash.begin(), hash.end());
init.init();
int out_size = 72;
data_chunk signature(out_size);
if (!verify_private_key(nonce)) // Needed because of upstream bug
return data_chunk();
bool valid = secp256k1_ecdsa_sign(hash.data(), hash.size(),
signature.data(), &out_size, secret.data(), nonce.data()) == 1;
if (!valid)
return data_chunk();
signature.resize(out_size);
return signature;
}
示例14: store
void hashtable_database_writer::store(const hash_digest& key_hash,
size_t value_size, write_value_function write)
{
// Calculate the end of the last record.
const uint64_t header_size = 24 + buckets_ * 8;
const uint64_t records_end_offset = header_size + total_records_size_;
// [ tx hash ] 32
// [ varuint value size ]
// [ ... value data ... ]
// [ next tx in bucket ] 8
const size_t record_size =
32 + variable_uint_size(value_size) + value_size + 8;
// If a record crosses a page boundary then we align it with
// the beginning of the next page.
const size_t record_begin =
align_if_crossing_page(page_size_, records_end_offset, record_size);
BITCOIN_ASSERT(file_.size() >= record_begin + record_size);
// We will insert new transactions at the beginning of the bucket's list.
// I assume that more recent transactions in the blockchain are used
// more often than older ones.
// We lookup the existing value in the bucket first.
const uint64_t bucket_index = remainder(key_hash.data(), buckets_);
BITCOIN_ASSERT(bucket_index < buckets_);
const uint64_t previous_bucket_value = read_bucket_value(bucket_index);
// Now begin writing the record itself.
uint8_t* entry = file_.data() + record_begin;
auto serial = make_serializer(entry);
serial.write_hash(key_hash);
serial.write_variable_uint(value_size);
// Call the supplied callback to serialize the data.
write(serial.iterator());
serial.set_iterator(serial.iterator() + value_size);
serial.write_8_bytes(previous_bucket_value);
BITCOIN_ASSERT(serial.iterator() == entry + record_size);
// Change file size value at file start.
// This must be done first so any subsequent writes don't
// overwrite this record in case of a crash or interruption.
BITCOIN_ASSERT(record_begin >= header_size);
const uint64_t alignment_padding =
record_begin - header_size - total_records_size_;
BITCOIN_ASSERT(alignment_padding <= page_size_);
total_records_size_ += record_size + alignment_padding;
// Now add record to bucket.
const uint64_t record_begin_offset = record_begin - header_size;
link_record(bucket_index, record_begin_offset);
}
示例15: recover_compact
ec_point recover_compact(compact_signature signature,
hash_digest hash, bool compressed)
{
init.init();
size_t public_key_size = ec_uncompressed_size;
if (compressed)
public_key_size = ec_compressed_size;
ec_point out(public_key_size);
int out_size;
if (0 < secp256k1_ecdsa_recover_compact(hash.data(), hash.size(),
signature.signature.data(), out.data(), &out_size, compressed,
signature.recid))
{
BITCOIN_ASSERT(public_key_size == static_cast<size_t>(out_size));
return out;
}
// Error case:
return ec_point();
}