当前位置: 首页>>代码示例>>C++>>正文


C++ data_slice类代码示例

本文整理汇总了C++中data_slice的典型用法代码示例。如果您正苦于以下问题:C++ data_slice类的具体用法?C++ data_slice怎么用?C++ data_slice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了data_slice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: create_token

static bool create_token(encrypted_token& out_token,
    const std::string& passphrase, data_slice owner_salt,
    const ek_entropy& owner_entropy,
    const byte_array<parse_encrypted_token::prefix_size>& prefix)
{
    BITCOIN_ASSERT(owner_salt.size() == ek_salt_size ||
        owner_salt.size() == ek_entropy_size);

    const auto lot_sequence = owner_salt.size() == ek_salt_size;
    auto factor = scrypt_token(normal(passphrase), owner_salt);

    if (lot_sequence)
        factor = bitcoin_hash(splice(factor, owner_entropy));

    ec_compressed point;
    if (!secret_to_public(point, factor))
        return false;

    return build_checked_array(out_token,
    {
        prefix,
        owner_entropy,
        point
    });
}
开发者ID:GeopaymeEE,项目名称:libbitcoin,代码行数:25,代码来源:encrypted_keys.cpp

示例2: hmac_sha256_hash

hash_digest hmac_sha256_hash(data_slice data, data_slice key)
{
    hash_digest hash;
    HMACSHA256(data.data(), data.size(), key.data(),
        key.size(), hash.data());
    return hash;
}
开发者ID:alt-project,项目名称:crypto,代码行数:7,代码来源:hash.cpp

示例3: hmac_sha512_hash

long_hash hmac_sha512_hash(data_slice data, data_slice key)
{
    long_hash hash;
    HMACSHA512(data.data(), data.size(), key.data(),
        key.size(), hash.data());
    return hash;
}
开发者ID:alt-project,项目名称:crypto,代码行数:7,代码来源:hash.cpp

示例4: verify_checksum

bool verify_checksum(data_slice data)
{
    if (data.size() < checksum_size)
        return false;

    data_slice body(data.begin(), data.end() - checksum_size);
    auto checksum = from_little_endian_unsafe<uint32_t>(data.end() - checksum_size);
    return bitcoin_checksum(body) == checksum;
}
开发者ID:bankonca,项目名称:libbitcoin,代码行数:9,代码来源:checksum.cpp

示例5: scrypt

data_chunk scrypt(data_slice data, data_slice salt, uint64_t N, uint32_t p,
    uint32_t r, size_t length)
{
    data_chunk output(length);
    const auto result = crypto_scrypt(data.data(), data.size(), salt.data(),
        salt.size(), N, r, p, output.data(), output.size());
    handle_script_result(result);
    return output;
}
开发者ID:stealthylabs,项目名称:libbitcoin,代码行数:9,代码来源:hash.cpp

示例6: is_uncompressed_key

bool is_uncompressed_key(data_slice point)
{
    const auto size = point.size();
    if (size != ec_uncompressed_size)
        return false;

    const auto first = point.data()[0];
    return first == uncompressed;
}
开发者ID:GeopaymeEE,项目名称:libbitcoin,代码行数:9,代码来源:elliptic_curve.cpp

示例7: while

binary_type::binary_type(size_type size, data_slice blocks)
{
    // Copy blocks
    blocks_.resize(blocks.size());
    std::copy(blocks.begin(), blocks.end(), blocks_.begin());
    // Pad with 00 for safety.
    while (blocks_.size() * bits_per_block < size)
        blocks_.push_back(0x00);
    resize(size);
}
开发者ID:veox,项目名称:libbitcoin,代码行数:10,代码来源:binary.cpp

示例8: sha256_hash

hash_digest sha256_hash(data_slice first, data_slice second)
{
    hash_digest hash;
    SHA256CTX context;
    SHA256Init(&context);
    SHA256Update(&context, first.data(), first.size());
    SHA256Update(&context, second.data(), second.size());
    SHA256Final(&context, hash.data());
    return hash;
}
开发者ID:RojavaCrypto,项目名称:libbitcoin,代码行数:10,代码来源:hash.cpp

示例9: pkcs5_pbkdf2_hmac_sha512

long_hash pkcs5_pbkdf2_hmac_sha512(data_slice passphrase,
    data_slice salt, size_t iterations)
{
    long_hash hash;
    const auto result = pkcs5_pbkdf2(passphrase.data(), passphrase.size(),
        salt.data(), salt.size(), hash.data(), hash.size(), iterations);

    if (result != 0)
        throw std::bad_alloc();

    return hash;
}
开发者ID:stealthylabs,项目名称:libbitcoin,代码行数:12,代码来源:hash.cpp

示例10: encode_base85

// Accepts only byte arrays bounded to 4 bytes.
bool encode_base85(std::string& out, data_slice in)
{
    const size_t size = in.size();
    if (size % 4 != 0)
        return false;

    const size_t encoded_size = size * 5 / 4;
    std::string encoded;
    encoded.reserve(encoded_size + 1);
    size_t byte_index = 0;
    uint32_t accumulator = 0;

    for (const uint8_t unencoded_byte: in)
    {
        accumulator = accumulator * 256 + unencoded_byte;
        if (++byte_index % 4 == 0)
        {
            for (uint32_t divise = 85 * 85 * 85 * 85; divise > 0; divise /= 85)
                encoded.push_back(encoder[accumulator / divise % 85]);

            accumulator = 0;
        }
    }

    out.assign(encoded.begin(), encoded.end());
    BITCOIN_ASSERT(out.size() == encoded_size);
    return true;
}
开发者ID:Mrkebubun,项目名称:libbitcoin,代码行数:29,代码来源:base85.cpp

示例11: to_null_data_pattern

operation::stack operation::to_null_data_pattern(data_slice data)
{
    if (data.size() > max_null_data_size)
        return operation::stack();

    return operation::stack
    {
        operation{ opcode::return_, data_chunk() },
        operation{ opcode::special, to_chunk(data) }
    };
}
开发者ID:zauguin,项目名称:libbitcoin,代码行数:11,代码来源:operation.cpp

示例12: verify_signature

bool verify_signature(data_slice 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;
    const auto context = verification.context();
    secp256k1_ecdsa_signature_normalize(context, &normal, &parsed);

    // This uses a data slice and calls secp256k1_ec_pubkey_parse() in place of
    // parse() so that we can support the der_verify data_chunk optimization.
    secp256k1_pubkey pubkey;
    const auto size = point.size();
    return
        secp256k1_ec_pubkey_parse(context, &pubkey, point.data(), size) == 1 &&
        secp256k1_ecdsa_verify(context, &normal, hash.data(), &pubkey) == 1;
}
开发者ID:GeopaymeEE,项目名称:libbitcoin,代码行数:21,代码来源:elliptic_curve.cpp

示例13: unwrap

// This verifies the checksum.
bool unwrap(wallet::wrapped_data& data, data_slice wrapped)
{
    if (!verify_checksum(wrapped))
        return false;

    data.version = wrapped.data()[0];
    const auto payload_begin = std::begin(wrapped) + 1;
    const auto checksum_begin = std::end(wrapped) - checksum_size;
    data.payload.resize(checksum_begin - payload_begin);
    std::copy(payload_begin, checksum_begin, data.payload.begin());
    data.checksum = from_little_endian_unsafe<uint32_t>(checksum_begin);
    return true;
}
开发者ID:Varmetric,项目名称:libbitcoin-explorer,代码行数:14,代码来源:utility.cpp

示例14: create_mnemonic

word_list create_mnemonic(data_slice entropy, const dictionary &lexicon)
{
    if ((entropy.size() % mnemonic_seed_multiple) != 0)
        return word_list();

    const size_t entropy_bits = (entropy.size() * byte_bits);
    const size_t check_bits = (entropy_bits / entropy_bit_divisor);
    const size_t total_bits = (entropy_bits + check_bits);
    const size_t word_count = (total_bits / bits_per_word);

    BITCOIN_ASSERT((total_bits % bits_per_word) == 0);
    BITCOIN_ASSERT((word_count % mnemonic_word_multiple) == 0);

    const auto data = build_chunk({entropy, sha256_hash(entropy)});

    size_t bit = 0;
    word_list words;

    for (size_t word = 0; word < word_count; word++)
    {
        size_t position = 0;
        for (size_t loop = 0; loop < bits_per_word; loop++)
        {
            bit = (word * bits_per_word + loop);
            position <<= 1;

            const auto byte = bit / byte_bits;

            if ((data[byte] & bip39_shift(bit)) > 0)
                position++;
        }

        BITCOIN_ASSERT(position < dictionary_size);
        words.push_back(lexicon[position]);
    }

    BITCOIN_ASSERT(words.size() == ((bit + 1) / bits_per_word));
    return words;
}
开发者ID:GeopaymeEE,项目名称:libbitcoin,代码行数:39,代码来源:mnemonic.cpp

示例15:

inline data_chunk operator +(data_slice a, data_slice b)
{
    data_chunk out;
    out.reserve(a.size() + b.size());
    out.insert(out.end(), a.begin(), a.end());
    out.insert(out.end(), b.begin(), b.end());
    return out;
}
开发者ID:Airbitz,项目名称:libbitcoin,代码行数:8,代码来源:ec_keys.cpp


注:本文中的data_slice类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。