Inside Bitcoin
Opening the selected file…
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) 2014-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 <crypto/hmac_sha256.h>7#include <crypto/sha256.h>8#include <support/cleanse.h>10#include <cstring>12CHMAC_SHA256::CHMAC_SHA256(const unsigned char* key, size_t keylen)13{14unsigned char rkey[64];15if (keylen <= 64) {16memcpy(rkey, key, keylen);17memset(rkey + keylen, 0, 64 - keylen);18} else {19CSHA256().Write(key, keylen).Finalize(rkey);20memset(rkey + 32, 0, 32);21}23for (int n = 0; n < 64; n++)24rkey[n] ^= 0x5c;25outer.Write(rkey, 64);27for (int n = 0; n < 64; n++)28rkey[n] ^= 0x5c ^ 0x36;29inner.Write(rkey, 64);31memory_cleanse(rkey, sizeof(rkey));32}34void CHMAC_SHA256::Finalize(unsigned char hash[OUTPUT_SIZE])35{36unsigned char temp[32];37inner.Finalize(temp);38outer.Write(temp, 32).Finalize(hash);39memory_cleanse(temp, sizeof(temp));40}