H ASHING : SHA256 T AYLER A NGEVINE B ACHELOR OF A RTS D R. K EN B LAHA 3/13/2014
I NTRODUCTION Review the hash function SHA-256 Goal: understand how SHA-256 computes it’s hash. Why have I decided to focus on Sha-256 algorithms? Battle tested Considered to be some of the “safest” algorithms Bitcoin is based around SHA-256. The way the algorithm is implemented using MessageDigest left a lot of unknowns. Was under the impression that I would need to code the algorithm.
M ORE INTRO Named after it’s digest length. Will not focus on SHA-1 because it has been “broken” Would rather focus on today’s standard rather than the past. SHA-384 and SHA-512 because they are essentially the same. Why go over the code? I believe it is necessary to understand the code of an algorithm in order to recognize it’s weaknesses or it’s strengths.
W HAT IS A HASH ? Hash function takes a string of any length, and generates fixed-length output data. It is not reversible. Because you are taking a string and basically dividing it. Therefore, you are losing information. If you have lost information about the original input, then it is nearly impossible to reverse the hash.
W HAT MAKES A GOOD HASH ? Same input will always lead to the same output. Avoids collision attacks
A LITTLE INFORMATION … Sha 256 is more safe from collision attacks than other algorithms. MD5 = 128 byte output, 64 bits of security SHA-1 = 160 byte output, 80 bits of security. SHA 256 = 256 byte output, 128 bits of security What are collision attacks? Find two input strings that produce the same hash. “abc” “aiieagnea;[sagjeiao;iaeohgao;ejagea” Hash functions can have infinite input length, but a fixed output.
H OW DOES IT WORK ? Padding aka Preprocessing Block decomposition Hash Algorithm
P REPROCESSING Message (M) is l bits long. Append message with a 1 Followed by n zero bits. N is smallest, non-negative solution to the equation. L n = 448 mod 512 This leaves enough room to append what we have so far with a 64-bit block that equals our message represented in binary. Message = “abc” N = 448. N = 423 zero bits
N OTATION Algorithm uses AND, XOR, OR, Circular Right Shift, and Logical Right Shifts in order to compute the hash.
AND pqp AND q Produces 1 if both p and q are 1’s.
OR pqp OR q Produces 1 if p or q are 1
XOR pqp XOR q Produces 1 if p or q is 1, but not both.
C IRCULAR S HIFT R IGHT S H R( VARIABLE, NUMBER ) variable: a,b,c,d,e,f,g,h Number: amount of shift.
L OGICAL R IGHT S HIFT R OT R( VARIABLE, NUMBER ) Variable: a,b,c,d,e,f,g,h. Number: amount of shifts
E QUATIONS
W HERE IT STARTS TO GET COMPLICATED. Generally H 1 – H 8 are set to the first 32 bits of the fractional parts of the square roots of the first eight primes.
E XAMPLE Square root of 2 = Fractional part = Hexadecimal = 6A09E667.
W HERE DOES OUR PASSWORD COME INTO PLAY ? Or original password was padded to 512 bytes. Which is 16 words. A 64 word array is created we will refer to as W W 0 – W 15 are initialized to our padded password. The rest (W 16 – W 63 ) are set to a value determined by this function J is just the counter in a for loop.
A LGORITHM C OMPUTATION ( EXECUTED 64 TIMES )
A – H are initialized with H 1 – H 8
L AST S TEP Take your original and H 1 – H 8 add a – h to them.
I SSUES Putting together a puzzle Some things are difficult to find answers to.
S OURCES Algorithm pdf pdf 07/SHA256english.pdf 07/SHA256english.pdf Actual Implementation source/libjava/classpath/gnu/java/security/hash/Sha256. java source/libjava/classpath/gnu/java/security/hash/Sha256. java Various Information wikipedia.org/ technology-explained/
M ORE S OURCES Various Information -does-message-schedule-mean-in-sha does-message-schedule-mean-in-sha MessageDigest.html MessageDigest.html Converting bytes to a string array-to-string-in-java/ array-to-string-in-java/ Hash Calculator
QUESTIONS?