Paper Implementation : SHA-256 NSA Patent Whitepaper
Implementing the patented National Security Agency official SHA 256 paper
Apologies for the Paywall
LeetArxiv and the Finite Field Assembly (FF-asm) programming language are entirely funded by our Substack readers. Thank you for your understanding and support!
Introduction
It’s 2025, and the President of the United States has just launched a Solana meme coin called $TRUMP. Bitcoin is making a comeback, and so it’s time to dive into the SHA-256 hash function, the backbone of Bitcoin’s value.
SHA-256, or Secure Hash Algorithm 256-bit, was developed in 2001 by the National Security Agency (NSA). The official patent for SHA-256 is held by Glenn Lilly, who served as the director of the NSA’s mathematical research group.
Part 1 : Important Definitions
From the paper, SHA-256 utilizes these boolean and arithmetic operations:
AND denoted by ∧.
XOR denoted by ⊕.
OR denoted by∨.
Bitwise complement denoted by ¯.
Integer addition denoted by A + B.
Circular Right Shift of A by n bits. RotR(A, n)
Regular Right Shift of A by n bits. ShR(A, n)
Concatenation of Integers denoted by A || B
SHA-256 makes use of thse contants:
The first 32 bits of the fractional parts of the cube roots of the first 64 prime numbers.
NOTE
All integer operations are perfomed within the range 0 and 2^32. Upo overflow, the operations wrap around like a finite field
Section goals
Implement Regular Right Shift.
Implement Circular Right Shift.
Create an array of constants.
Implement LittleToBig endian conversion function
Function 1 : RegularRightShift Coding Guide + Solution
Write a function called RegularRightShift.
The function takes two inputs.
An unsigned integer called A.
An unsigned integer called n.
The function should return an unsigned integer.
The function shifts an integer A to the right, by n bits .
Depending on your language choice, this could be a simple >> or integer division by 2 for n times.
Keep reading with a 7-day free trial
Subscribe to LeetArxiv to keep reading this post and get 7 days of free access to the full post archives.