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