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) 2017-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.4//5// This is a translation to GCC extended asm syntax from YASM code by Intel6// (available at the bottom of this file).8#if defined(__x86_64__) || defined(__amd64__)10#include <cstddef>11#include <cstdint>13namespace sha256_sse414{15/*16Both Clang and GCC fail with ASan on this inline assembly:17- Clang: compile failure with -O0 or -O2 + -fcf-protection under ASan.18See https://github.com/llvm/llvm-project/issues/9218219and https://github.com/bitcoin/bitcoin/issues/31913.20- GCC: runtime SEGV during SHA256AutoDetect()'s self-test under ASan,21regardless of optimization level.22See https://github.com/bitcoin/bitcoin/issues/34881.23*/24#if defined(__SANITIZE_ADDRESS__)25__attribute__((no_sanitize("address")))26#elif defined(__clang__)27#if __has_feature(address_sanitizer) // fallback can be removed once support for Clang 21 is dropped28__attribute__((no_sanitize("address")))29#endif30#endif31void Transform(uint32_t* s, const unsigned char* chunk, size_t blocks)32{33static const uint32_t K256 alignas(16) [] = {340x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,350x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,360xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,370x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,380xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,390x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,400x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,410xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,420x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,430x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,440xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,450xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,460x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,470x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,480x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,490x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,50};51static const uint32_t FLIP_MASK alignas(16) [] = {0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f};52static const uint32_t SHUF_00BA alignas(16) [] = {0x03020100, 0x0b0a0908, 0xffffffff, 0xffffffff};53static const uint32_t SHUF_DC00 alignas(16) [] = {0xffffffff, 0xffffffff, 0x03020100, 0x0b0a0908};54uint32_t a, b, c, d, f, g, h, y0, y1, y2;55uint64_t tbl;56uint64_t inp_end, inp;57uint32_t xfer alignas(16) [4];59__asm__ __volatile__(60"shl $0x6,%2;"61"je Ldone_hash_%=;"62"add %1,%2;"63"mov %2,%14;"64"mov (%0),%3;"65"mov 0x4(%0),%4;"66"mov 0x8(%0),%5;"67"mov 0xc(%0),%6;"68"mov 0x10(%0),%k2;"69"mov 0x14(%0),%7;"70"mov 0x18(%0),%8;"71"mov 0x1c(%0),%9;"72"movdqa %18,%%xmm12;"73"movdqa %19,%%xmm10;"74"movdqa %20,%%xmm11;"76"Lloop0_%=:"77"lea %17,%13;"78"movdqu (%1),%%xmm4;"79"pshufb %%xmm12,%%xmm4;"80"movdqu 0x10(%1),%%xmm5;"81"pshufb %%xmm12,%%xmm5;"82"movdqu 0x20(%1),%%xmm6;"83"pshufb %%xmm12,%%xmm6;"84"movdqu 0x30(%1),%%xmm7;"85"pshufb %%xmm12,%%xmm7;"86"mov %1,%15;"87"mov $3,%1;"89"Lloop1_%=:"90"movdqa 0x0(%13),%%xmm9;"91"paddd %%xmm4,%%xmm9;"92"movdqa %%xmm9,%16;"93"movdqa %%xmm7,%%xmm0;"94"mov %k2,%10;"95"ror $0xe,%10;"96"mov %3,%11;"97"palignr $0x4,%%xmm6,%%xmm0;"98"ror $0x9,%11;"99"xor %k2,%10;"100"mov %7,%12;"101"ror $0x5,%10;"102"movdqa %%xmm5,%%xmm1;"103"xor %3,%11;"104"xor %8,%12;"105"paddd %%xmm4,%%xmm0;"106"xor %k2,%10;"107"and %k2,%12;"108"ror $0xb,%11;"109"palignr $0x4,%%xmm4,%%xmm1;"110"xor %3,%11;"111"ror $0x6,%10;"112"xor %8,%12;"113"movdqa %%xmm1,%%xmm2;"114"ror $0x2,%11;"115"add %10,%12;"116"add %16,%12;"117"movdqa %%xmm1,%%xmm3;"118"mov %3,%10;"119"add %12,%9;"120"mov %3,%12;"121"pslld $0x19,%%xmm1;"122"or %5,%10;"123"add %9,%6;"124"and %5,%12;"125"psrld $0x7,%%xmm2;"126"and %4,%10;"127"add %11,%9;"128"por %%xmm2,%%xmm1;"129"or %12,%10;"130"add %10,%9;"131"movdqa %%xmm3,%%xmm2;"132"mov %6,%10;"133"mov %9,%11;"134"movdqa %%xmm3,%%xmm8;"135"ror $0xe,%10;"136"xor %6,%10;"137"mov %k2,%12;"138"ror $0x9,%11;"139"pslld $0xe,%%xmm3;"140"xor %9,%11;"141"ror $0x5,%10;"142"xor %7,%12;"143"psrld $0x12,%%xmm2;"144"ror $0xb,%11;"145"xor %6,%10;"146"and %6,%12;"147"ror $0x6,%10;"148"pxor %%xmm3,%%xmm1;"149"xor %9,%11;"150"xor %7,%12;"151"psrld $0x3,%%xmm8;"152"add %10,%12;"153"add 4+%16,%12;"154"ror $0x2,%11;"155"pxor %%xmm2,%%xmm1;"156"mov %9,%10;"157"add %12,%8;"158"mov %9,%12;"159"pxor %%xmm8,%%xmm1;"160"or %4,%10;"161"add %8,%5;"162"and %4,%12;"163"pshufd $0xfa,%%xmm7,%%xmm2;"164"and %3,%10;"165"add %11,%8;"166"paddd %%xmm1,%%xmm0;"167"or %12,%10;"168"add %10,%8;"169"movdqa %%xmm2,%%xmm3;"170"mov %5,%10;"171"mov %8,%11;"172"ror $0xe,%10;"173"movdqa %%xmm2,%%xmm8;"174"xor %5,%10;"175"ror $0x9,%11;"176"mov %6,%12;"177"xor %8,%11;"178"ror $0x5,%10;"179"psrlq $0x11,%%xmm2;"180"xor %k2,%12;"181"psrlq $0x13,%%xmm3;"182"xor %5,%10;"183"and %5,%12;"184"psrld $0xa,%%xmm8;"185"ror $0xb,%11;"186"xor %8,%11;"187"xor %k2,%12;"188"ror $0x6,%10;"189"pxor %%xmm3,%%xmm2;"190"add %10,%12;"191"ror $0x2,%11;"192"add 8+%16,%12;"193"pxor %%xmm2,%%xmm8;"194"mov %8,%10;"195"add %12,%7;"196"mov %8,%12;"197"pshufb %%xmm10,%%xmm8;"198"or %3,%10;"199"add %7,%4;"200"and %3,%12;"201"paddd %%xmm8,%%xmm0;"202"and %9,%10;"203"add %11,%7;"204"pshufd $0x50,%%xmm0,%%xmm2;"205"or %12,%10;"206"add %10,%7;"207"movdqa %%xmm2,%%xmm3;"208"mov %4,%10;"209"ror $0xe,%10;"210"mov %7,%11;"211"movdqa %%xmm2,%%xmm4;"212"ror $0x9,%11;"213"xor %4,%10;"214"mov %5,%12;"215"ror $0x5,%10;"216"psrlq $0x11,%%xmm2;"217"xor %7,%11;"218"xor %6,%12;"219"psrlq $0x13,%%xmm3;"220"xor %4,%10;"221"and %4,%12;"222"ror $0xb,%11;"223"psrld $0xa,%%xmm4;"224"xor %7,%11;"225"ror $0x6,%10;"226"xor %6,%12;"227"pxor %%xmm3,%%xmm2;"228"ror $0x2,%11;"229"add %10,%12;"230"add 12+%16,%12;"231"pxor %%xmm2,%%xmm4;"232"mov %7,%10;"233"add %12,%k2;"234"mov %7,%12;"235"pshufb %%xmm11,%%xmm4;"236"or %9,%10;"237"add %k2,%3;"238"and %9,%12;"239"paddd %%xmm0,%%xmm4;"240"and %8,%10;"241"add %11,%k2;"242"or %12,%10;"243"add %10,%k2;"244"movdqa 0x10(%13),%%xmm9;"245"paddd %%xmm5,%%xmm9;"246"movdqa %%xmm9,%16;"247"movdqa %%xmm4,%%xmm0;"248"mov %3,%10;"249"ror $0xe,%10;"250"mov %k2,%11;"
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.