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.
251Round(e, f, g, h, a, b, c, d, 0x391c0cb3ul + (w4 += sigma1(w2) + w13 + sigma0(w5)));252Round(d, e, f, g, h, a, b, c, 0x4ed8aa4aul + (w5 += sigma1(w3) + w14 + sigma0(w6)));253Round(c, d, e, f, g, h, a, b, 0x5b9cca4ful + (w6 += sigma1(w4) + w15 + sigma0(w7)));254Round(b, c, d, e, f, g, h, a, 0x682e6ff3ul + (w7 += sigma1(w5) + w0 + sigma0(w8)));255Round(a, b, c, d, e, f, g, h, 0x748f82eeul + (w8 += sigma1(w6) + w1 + sigma0(w9)));256Round(h, a, b, c, d, e, f, g, 0x78a5636ful + (w9 += sigma1(w7) + w2 + sigma0(w10)));257Round(g, h, a, b, c, d, e, f, 0x84c87814ul + (w10 += sigma1(w8) + w3 + sigma0(w11)));258Round(f, g, h, a, b, c, d, e, 0x8cc70208ul + (w11 += sigma1(w9) + w4 + sigma0(w12)));259Round(e, f, g, h, a, b, c, d, 0x90befffaul + (w12 += sigma1(w10) + w5 + sigma0(w13)));260Round(d, e, f, g, h, a, b, c, 0xa4506cebul + (w13 += sigma1(w11) + w6 + sigma0(w14)));261Round(c, d, e, f, g, h, a, b, 0xbef9a3f7ul + (w14 + sigma1(w12) + w7 + sigma0(w15)));262Round(b, c, d, e, f, g, h, a, 0xc67178f2ul + (w15 + sigma1(w13) + w8 + sigma0(w0)));264a += 0x6a09e667ul;265b += 0xbb67ae85ul;266c += 0x3c6ef372ul;267d += 0xa54ff53aul;268e += 0x510e527ful;269f += 0x9b05688cul;270g += 0x1f83d9abul;271h += 0x5be0cd19ul;273uint32_t t0 = a, t1 = b, t2 = c, t3 = d, t4 = e, t5 = f, t6 = g, t7 = h;275// Transform 2276Round(a, b, c, d, e, f, g, h, 0xc28a2f98ul);277Round(h, a, b, c, d, e, f, g, 0x71374491ul);278Round(g, h, a, b, c, d, e, f, 0xb5c0fbcful);279Round(f, g, h, a, b, c, d, e, 0xe9b5dba5ul);280Round(e, f, g, h, a, b, c, d, 0x3956c25bul);281Round(d, e, f, g, h, a, b, c, 0x59f111f1ul);282Round(c, d, e, f, g, h, a, b, 0x923f82a4ul);283Round(b, c, d, e, f, g, h, a, 0xab1c5ed5ul);284Round(a, b, c, d, e, f, g, h, 0xd807aa98ul);285Round(h, a, b, c, d, e, f, g, 0x12835b01ul);286Round(g, h, a, b, c, d, e, f, 0x243185beul);287Round(f, g, h, a, b, c, d, e, 0x550c7dc3ul);288Round(e, f, g, h, a, b, c, d, 0x72be5d74ul);289Round(d, e, f, g, h, a, b, c, 0x80deb1feul);290Round(c, d, e, f, g, h, a, b, 0x9bdc06a7ul);291Round(b, c, d, e, f, g, h, a, 0xc19bf374ul);292Round(a, b, c, d, e, f, g, h, 0x649b69c1ul);293Round(h, a, b, c, d, e, f, g, 0xf0fe4786ul);294Round(g, h, a, b, c, d, e, f, 0x0fe1edc6ul);295Round(f, g, h, a, b, c, d, e, 0x240cf254ul);296Round(e, f, g, h, a, b, c, d, 0x4fe9346ful);297Round(d, e, f, g, h, a, b, c, 0x6cc984beul);298Round(c, d, e, f, g, h, a, b, 0x61b9411eul);299Round(b, c, d, e, f, g, h, a, 0x16f988faul);300Round(a, b, c, d, e, f, g, h, 0xf2c65152ul);301Round(h, a, b, c, d, e, f, g, 0xa88e5a6dul);302Round(g, h, a, b, c, d, e, f, 0xb019fc65ul);303Round(f, g, h, a, b, c, d, e, 0xb9d99ec7ul);304Round(e, f, g, h, a, b, c, d, 0x9a1231c3ul);305Round(d, e, f, g, h, a, b, c, 0xe70eeaa0ul);306Round(c, d, e, f, g, h, a, b, 0xfdb1232bul);307Round(b, c, d, e, f, g, h, a, 0xc7353eb0ul);308Round(a, b, c, d, e, f, g, h, 0x3069bad5ul);309Round(h, a, b, c, d, e, f, g, 0xcb976d5ful);310Round(g, h, a, b, c, d, e, f, 0x5a0f118ful);311Round(f, g, h, a, b, c, d, e, 0xdc1eeefdul);312Round(e, f, g, h, a, b, c, d, 0x0a35b689ul);313Round(d, e, f, g, h, a, b, c, 0xde0b7a04ul);314Round(c, d, e, f, g, h, a, b, 0x58f4ca9dul);315Round(b, c, d, e, f, g, h, a, 0xe15d5b16ul);316Round(a, b, c, d, e, f, g, h, 0x007f3e86ul);317Round(h, a, b, c, d, e, f, g, 0x37088980ul);318Round(g, h, a, b, c, d, e, f, 0xa507ea32ul);319Round(f, g, h, a, b, c, d, e, 0x6fab9537ul);320Round(e, f, g, h, a, b, c, d, 0x17406110ul);321Round(d, e, f, g, h, a, b, c, 0x0d8cd6f1ul);322Round(c, d, e, f, g, h, a, b, 0xcdaa3b6dul);323Round(b, c, d, e, f, g, h, a, 0xc0bbbe37ul);324Round(a, b, c, d, e, f, g, h, 0x83613bdaul);325Round(h, a, b, c, d, e, f, g, 0xdb48a363ul);326Round(g, h, a, b, c, d, e, f, 0x0b02e931ul);327Round(f, g, h, a, b, c, d, e, 0x6fd15ca7ul);328Round(e, f, g, h, a, b, c, d, 0x521afacaul);329Round(d, e, f, g, h, a, b, c, 0x31338431ul);330Round(c, d, e, f, g, h, a, b, 0x6ed41a95ul);331Round(b, c, d, e, f, g, h, a, 0x6d437890ul);332Round(a, b, c, d, e, f, g, h, 0xc39c91f2ul);333Round(h, a, b, c, d, e, f, g, 0x9eccabbdul);334Round(g, h, a, b, c, d, e, f, 0xb5c9a0e6ul);335Round(f, g, h, a, b, c, d, e, 0x532fb63cul);336Round(e, f, g, h, a, b, c, d, 0xd2c741c6ul);337Round(d, e, f, g, h, a, b, c, 0x07237ea3ul);338Round(c, d, e, f, g, h, a, b, 0xa4954b68ul);339Round(b, c, d, e, f, g, h, a, 0x4c191d76ul);341w0 = t0 + a;342w1 = t1 + b;343w2 = t2 + c;344w3 = t3 + d;345w4 = t4 + e;346w5 = t5 + f;347w6 = t6 + g;348w7 = t7 + h;350// Transform 3351a = 0x6a09e667ul;352b = 0xbb67ae85ul;353c = 0x3c6ef372ul;354d = 0xa54ff53aul;355e = 0x510e527ful;356f = 0x9b05688cul;357g = 0x1f83d9abul;358h = 0x5be0cd19ul;360Round(a, b, c, d, e, f, g, h, 0x428a2f98ul + w0);361Round(h, a, b, c, d, e, f, g, 0x71374491ul + w1);362Round(g, h, a, b, c, d, e, f, 0xb5c0fbcful + w2);363Round(f, g, h, a, b, c, d, e, 0xe9b5dba5ul + w3);364Round(e, f, g, h, a, b, c, d, 0x3956c25bul + w4);365Round(d, e, f, g, h, a, b, c, 0x59f111f1ul + w5);366Round(c, d, e, f, g, h, a, b, 0x923f82a4ul + w6);367Round(b, c, d, e, f, g, h, a, 0xab1c5ed5ul + w7);368Round(a, b, c, d, e, f, g, h, 0x5807aa98ul);369Round(h, a, b, c, d, e, f, g, 0x12835b01ul);370Round(g, h, a, b, c, d, e, f, 0x243185beul);371Round(f, g, h, a, b, c, d, e, 0x550c7dc3ul);372Round(e, f, g, h, a, b, c, d, 0x72be5d74ul);373Round(d, e, f, g, h, a, b, c, 0x80deb1feul);374Round(c, d, e, f, g, h, a, b, 0x9bdc06a7ul);375Round(b, c, d, e, f, g, h, a, 0xc19bf274ul);376Round(a, b, c, d, e, f, g, h, 0xe49b69c1ul + (w0 += sigma0(w1)));377Round(h, a, b, c, d, e, f, g, 0xefbe4786ul + (w1 += 0xa00000ul + sigma0(w2)));378Round(g, h, a, b, c, d, e, f, 0x0fc19dc6ul + (w2 += sigma1(w0) + sigma0(w3)));379Round(f, g, h, a, b, c, d, e, 0x240ca1ccul + (w3 += sigma1(w1) + sigma0(w4)));380Round(e, f, g, h, a, b, c, d, 0x2de92c6ful + (w4 += sigma1(w2) + sigma0(w5)));381Round(d, e, f, g, h, a, b, c, 0x4a7484aaul + (w5 += sigma1(w3) + sigma0(w6)));382Round(c, d, e, f, g, h, a, b, 0x5cb0a9dcul + (w6 += sigma1(w4) + 0x100ul + sigma0(w7)));383Round(b, c, d, e, f, g, h, a, 0x76f988daul + (w7 += sigma1(w5) + w0 + 0x11002000ul));384Round(a, b, c, d, e, f, g, h, 0x983e5152ul + (w8 = 0x80000000ul + sigma1(w6) + w1));385Round(h, a, b, c, d, e, f, g, 0xa831c66dul + (w9 = sigma1(w7) + w2));386Round(g, h, a, b, c, d, e, f, 0xb00327c8ul + (w10 = sigma1(w8) + w3));387Round(f, g, h, a, b, c, d, e, 0xbf597fc7ul + (w11 = sigma1(w9) + w4));388Round(e, f, g, h, a, b, c, d, 0xc6e00bf3ul + (w12 = sigma1(w10) + w5));389Round(d, e, f, g, h, a, b, c, 0xd5a79147ul + (w13 = sigma1(w11) + w6));390Round(c, d, e, f, g, h, a, b, 0x06ca6351ul + (w14 = sigma1(w12) + w7 + 0x400022ul));391Round(b, c, d, e, f, g, h, a, 0x14292967ul + (w15 = 0x100ul + sigma1(w13) + w8 + sigma0(w0)));392Round(a, b, c, d, e, f, g, h, 0x27b70a85ul + (w0 += sigma1(w14) + w9 + sigma0(w1)));393Round(h, a, b, c, d, e, f, g, 0x2e1b2138ul + (w1 += sigma1(w15) + w10 + sigma0(w2)));394Round(g, h, a, b, c, d, e, f, 0x4d2c6dfcul + (w2 += sigma1(w0) + w11 + sigma0(w3)));395Round(f, g, h, a, b, c, d, e, 0x53380d13ul + (w3 += sigma1(w1) + w12 + sigma0(w4)));396Round(e, f, g, h, a, b, c, d, 0x650a7354ul + (w4 += sigma1(w2) + w13 + sigma0(w5)));397Round(d, e, f, g, h, a, b, c, 0x766a0abbul + (w5 += sigma1(w3) + w14 + sigma0(w6)));398Round(c, d, e, f, g, h, a, b, 0x81c2c92eul + (w6 += sigma1(w4) + w15 + sigma0(w7)));399Round(b, c, d, e, f, g, h, a, 0x92722c85ul + (w7 += sigma1(w5) + w0 + sigma0(w8)));400Round(a, b, c, d, e, f, g, h, 0xa2bfe8a1ul + (w8 += sigma1(w6) + w1 + sigma0(w9)));401Round(h, a, b, c, d, e, f, g, 0xa81a664bul + (w9 += sigma1(w7) + w2 + sigma0(w10)));402Round(g, h, a, b, c, d, e, f, 0xc24b8b70ul + (w10 += sigma1(w8) + w3 + sigma0(w11)));403Round(f, g, h, a, b, c, d, e, 0xc76c51a3ul + (w11 += sigma1(w9) + w4 + sigma0(w12)));404Round(e, f, g, h, a, b, c, d, 0xd192e819ul + (w12 += sigma1(w10) + w5 + sigma0(w13)));405Round(d, e, f, g, h, a, b, c, 0xd6990624ul + (w13 += sigma1(w11) + w6 + sigma0(w14)));406Round(c, d, e, f, g, h, a, b, 0xf40e3585ul + (w14 += sigma1(w12) + w7 + sigma0(w15)));407Round(b, c, d, e, f, g, h, a, 0x106aa070ul + (w15 += sigma1(w13) + w8 + sigma0(w0)));408Round(a, b, c, d, e, f, g, h, 0x19a4c116ul + (w0 += sigma1(w14) + w9 + sigma0(w1)));409Round(h, a, b, c, d, e, f, g, 0x1e376c08ul + (w1 += sigma1(w15) + w10 + sigma0(w2)));410Round(g, h, a, b, c, d, e, f, 0x2748774cul + (w2 += sigma1(w0) + w11 + sigma0(w3)));411Round(f, g, h, a, b, c, d, e, 0x34b0bcb5ul + (w3 += sigma1(w1) + w12 + sigma0(w4)));412Round(e, f, g, h, a, b, c, d, 0x391c0cb3ul + (w4 += sigma1(w2) + w13 + sigma0(w5)));413Round(d, e, f, g, h, a, b, c, 0x4ed8aa4aul + (w5 += sigma1(w3) + w14 + sigma0(w6)));414Round(c, d, e, f, g, h, a, b, 0x5b9cca4ful + (w6 += sigma1(w4) + w15 + sigma0(w7)));415Round(b, c, d, e, f, g, h, a, 0x682e6ff3ul + (w7 += sigma1(w5) + w0 + sigma0(w8)));416Round(a, b, c, d, e, f, g, h, 0x748f82eeul + (w8 += sigma1(w6) + w1 + sigma0(w9)));417Round(h, a, b, c, d, e, f, g, 0x78a5636ful + (w9 += sigma1(w7) + w2 + sigma0(w10)));418Round(g, h, a, b, c, d, e, f, 0x84c87814ul + (w10 += sigma1(w8) + w3 + sigma0(w11)));419Round(f, g, h, a, b, c, d, e, 0x8cc70208ul + (w11 += sigma1(w9) + w4 + sigma0(w12)));420Round(e, f, g, h, a, b, c, d, 0x90befffaul + (w12 += sigma1(w10) + w5 + sigma0(w13)));421Round(d, e, f, g, h, a, b, c, 0xa4506cebul + (w13 += sigma1(w11) + w6 + sigma0(w14)));422Round(c, d, e, f, g, h, a, b, 0xbef9a3f7ul + (w14 + sigma1(w12) + w7 + sigma0(w15)));423Round(b, c, d, e, f, g, h, a, 0xc67178f2ul + (w15 + sigma1(w13) + w8 + sigma0(w0)));425// Output426WriteBE32(out + 0, a + 0x6a09e667ul);427WriteBE32(out + 4, b + 0xbb67ae85ul);428WriteBE32(out + 8, c + 0x3c6ef372ul);429WriteBE32(out + 12, d + 0xa54ff53aul);430WriteBE32(out + 16, e + 0x510e527ful);431WriteBE32(out + 20, f + 0x9b05688cul);432WriteBE32(out + 24, g + 0x1f83d9abul);433WriteBE32(out + 28, h + 0x5be0cd19ul);434}436} // namespace sha256438typedef void (*TransformType)(uint32_t*, const unsigned char*, size_t);439typedef void (*TransformD64Type)(unsigned char*, const unsigned char*);441template<TransformType tr>442void TransformD64Wrapper(unsigned char* out, const unsigned char* in)443{444uint32_t s[8];445static const unsigned char padding1[64] = {4460x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,4470, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,4480, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,4490, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0450};451unsigned char buffer2[64] = {4520, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,4530, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,4540x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,4550, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0456};457sha256::Initialize(s);458tr(s, in, 1);459tr(s, padding1, 1);460WriteBE32(buffer2 + 0, s[0]);461WriteBE32(buffer2 + 4, s[1]);462WriteBE32(buffer2 + 8, s[2]);463WriteBE32(buffer2 + 12, s[3]);464WriteBE32(buffer2 + 16, s[4]);465WriteBE32(buffer2 + 20, s[5]);466WriteBE32(buffer2 + 24, s[6]);467WriteBE32(buffer2 + 28, s[7]);468sha256::Initialize(s);469tr(s, buffer2, 1);470WriteBE32(out + 0, s[0]);471WriteBE32(out + 4, s[1]);472WriteBE32(out + 8, s[2]);473WriteBE32(out + 12, s[3]);474WriteBE32(out + 16, s[4]);475WriteBE32(out + 20, s[5]);476WriteBE32(out + 24, s[6]);477WriteBE32(out + 28, s[7]);478}480TransformType Transform = sha256::Transform;481TransformD64Type TransformD64 = sha256::TransformD64;482TransformD64Type TransformD64_2way = nullptr;483TransformD64Type TransformD64_4way = nullptr;484TransformD64Type TransformD64_8way = nullptr;486bool SelfTest() {487// Input state (equal to the initial SHA256 state)488static const uint32_t init[8] = {4890x6a09e667ul, 0xbb67ae85ul, 0x3c6ef372ul, 0xa54ff53aul, 0x510e527ful, 0x9b05688cul, 0x1f83d9abul, 0x5be0cd19ul490};491// Some random input data to test with492static const unsigned char data[641] = "-" // Intentionally not aligned493"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do "494"eiusmod tempor incididunt ut labore et dolore magna aliqua. Et m"495"olestie ac feugiat sed lectus vestibulum mattis ullamcorper. Mor"496"bi blandit cursus risus at ultrices mi tempus imperdiet nulla. N"497"unc congue nisi vita suscipit tellus mauris. Imperdiet proin fer"498"mentum leo vel orci. Massa tempor nec feugiat nisl pretium fusce"499" id velit. Telus in metus vulputate eu scelerisque felis. Mi tem"500"pus imperdiet nulla malesuada pellentesque. Tristique magna sit.";