Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2020-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <key.h>6#include <secp256k1.h>7#include <test/fuzz/FuzzedDataProvider.h>8#include <test/fuzz/fuzz.h>9#include <test/fuzz/util.h>11#include <cstdint>12#include <vector>14int ec_seckey_import_der(const secp256k1_context* ctx, unsigned char* out32, const unsigned char* seckey, size_t seckeylen);15int ec_seckey_export_der(const secp256k1_context* ctx, unsigned char* seckey, size_t* seckeylen, const unsigned char* key32, bool compressed);17FUZZ_TARGET(secp256k1_ec_seckey_import_export_der)18{19FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};20{21std::vector<uint8_t> out32(32);22(void)ec_seckey_import_der(secp256k1_context_static, out32.data(), ConsumeFixedLengthByteVector(fuzzed_data_provider, CKey::SIZE).data(), CKey::SIZE);23}24{25std::vector<uint8_t> seckey(CKey::SIZE);26const std::vector<uint8_t> key32 = ConsumeFixedLengthByteVector(fuzzed_data_provider, 32);27size_t seckeylen = CKey::SIZE;28const bool compressed = fuzzed_data_provider.ConsumeBool();29secp256k1_context* secp256k1_context_sign = secp256k1_context_create(SECP256K1_CONTEXT_NONE);30const bool exported = ec_seckey_export_der(secp256k1_context_sign, seckey.data(), &seckeylen, key32.data(), compressed);31secp256k1_context_destroy(secp256k1_context_sign);32if (exported) {33std::vector<uint8_t> out32(32);34const bool imported = ec_seckey_import_der(secp256k1_context_static, out32.data(), seckey.data(), seckey.size()) == 1;35assert(imported && key32 == out32);36}37}38}
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.