m
(Halfway through Walkthrough)
Line 14: Line 14:
 
H4 = 0x10325476 <br/>
 
H4 = 0x10325476 <br/>
 
H5 = 0xC3D2E1F0 <br/>
 
H5 = 0xC3D2E1F0 <br/>
 +
  
 
===== Step 2: =====
 
===== Step 2: =====
Line 41: Line 42:
 
'''010010000110010101101100011011000110111110………0101000'''
 
'''010010000110010101101100011011000110111110………0101000'''
  
====Step 3====
+
 
 +
====Step 3A====
 +
 
 +
Break message into 512-bit chunks
 +
 
 +
Taking the example from above, since it is 512 bits, we will only have one chunk
 +
 
 +
====Step 3B====
 +
 
 +
Break each chunk into 16, 32-bit words
 +
 
 +
Example:
 +
 
 +
The words would be
 +
 
 +
    W<sub>0</sub> = 01001000011001010110110001101100<br/>
 +
    W<sub>1</sub> = 01101111100000000000000000000000<br/>
 +
W<sub>2</sub>-W<sub>14</sub> = 00000000000000000000000000000000<br/>
 +
    W<sub>15</sub> = 00000000000000000000000000101000<br/>
 +
 
 +
====Step 4====
 +
 
 +
Extend the first chunk to 80 32-bit words using the function
 +
 
 +
 
 +
for i from 16 to 79
 +
 
 +
      w[i] = (w[i-3] '''xor''' w[i-8] '''xor''' w[i-14] '''xor''' w[i-16]) '''leftrotate''' 1
 +
 
 +
Example:
 +
 
 +
  Using the example we have been using, the first iteration would go like this:
 +
 
 +
    w[16] = (w[16-3] '''xor''' w[16-8] '''xor''' w[16-14] '''xor''' w[16-16]) '''leftrotate''' 1
 +
    w[16] = (w[13] '''xor''' w[8] '''xor''' w[2] '''xor''' w[0]) '''leftrotate''' 1
 +
 
 +
  The '''xor''' function will compare the bits of the two strings in in each index<br/> and give an output based on the input of the the strings
 +
 
 +
      '''A'''        '''B'''      '''A xor B'''
 +
      0        0    ->    0
 +
      0        1    ->    1
 +
      1        0    ->    1
 +
      1        1    ->    0
 +
 
 +
    w[13] = 00000000000000000000000000000000
 +
    '''xor'''
 +
    w[8]  = 00000000000000000000000000000000
 +
    '''xor'''
 +
    w[2]  = 00000000000000000000000000000000
 +
    '''xor'''
 +
    w[0]  = 01001000011001010110110001101100
 +
 +
          = 01001000011001010110110001101100
 +
         
 +
 
 +
The '''leftrotate x''' function shifts each bit x times to the left. Any bits <br/>that are shifted past the beginning of the string are cycled back to the end of the string.
 +
 
 +
Taking the string we got, we leftrotate the string one bit
 +
 
 +
<span style="color:red">0</span>1001000011001010110110001101100
 +
 
 +
= 1001000011001010110110001101100<span style="color:red">0</span>
 +
 
 +
 
 +
So, after the first iteration W<sub>16</sub> is added to the chunk as:
 +
 
 +
W<sub>16</sub> = 10010000110010101101100011011000
 +
 
 +
After all of the iterations, we should have a chunk of 2560 bits
 +
 
 +
====Step 5A====
 +
 
 +
  Initialize The "Hash Values" for the chunk
 +
 
 +
  A = H1
 +
  B = H2
 +
  C = H3
 +
  D = H4
 +
  E = H5
 +
 
 +
====Step 6====

Revision as of 11:14, 29 November 2022

Hey Today we are talking about code anoymization. Let's Define an equation: $ Y=x^2 $


SHA-1 Walkthrough

Step 1:

Initialize 5 Random strings

H1 = 0x67452301
H2 = 0xEFCDAB89
H3 = 0x98BADCFE
H4 = 0x10325476
H5 = 0xC3D2E1F0


Step 2:

Take the word you want to hash (in binary), and append a 1 to the end of it. Then append as many zeros as it takes to make it divisible by 512, with the length of the message in a 64 bit integer appended at the end of the string.

Example:

The word "Hello" in binary is:

                     01001000 01100101 01101100 01101100 01101111
                       (H)      (e)      (l)      (l)      (o)

Add 1 to the end:

= 01001000011001010110110001101100011011111

Since "Hello" is less than 448 we add 0’s until the string is 448 bits long:

= 01001000011001010110110001101100011011111000…0 (len = 448 bits)

Lastly take the length of the string before processing (40 bits in this case) append that as a 64 bit integer

= ...0000101000 (length of added bits = 64)

So total length is 512 in this example

010010000110010101101100011011000110111110………0101000


Step 3A

Break message into 512-bit chunks

Taking the example from above, since it is 512 bits, we will only have one chunk

Step 3B

Break each chunk into 16, 32-bit words

Example:

The words would be

    W0 = 01001000011001010110110001101100
W1 = 01101111100000000000000000000000
W2-W14 = 00000000000000000000000000000000
W15 = 00000000000000000000000000101000

Step 4

Extend the first chunk to 80 32-bit words using the function


for i from 16 to 79
     w[i] = (w[i-3] xor w[i-8] xor w[i-14] xor w[i-16]) leftrotate 1

Example:

 Using the example we have been using, the first iteration would go like this:
   w[16] = (w[16-3] xor w[16-8] xor w[16-14] xor w[16-16]) leftrotate 1
   w[16] = (w[13] xor w[8] xor w[2] xor w[0]) leftrotate 1
 The xor function will compare the bits of the two strings in in each index
and give an output based on the input of the the strings
      A        B       A xor B
      0        0    ->    0
      0        1    ->    1 
      1        0    ->    1
      1        1    ->    0
   w[13] = 00000000000000000000000000000000
    xor
   w[8]  = 00000000000000000000000000000000
    xor
   w[2]  = 00000000000000000000000000000000
    xor
   w[0]  = 01001000011001010110110001101100

         = 01001000011001010110110001101100
         
The leftrotate x function shifts each bit x times to the left. Any bits 
that are shifted past the beginning of the string are cycled back to the end of the string.
Taking the string we got, we leftrotate the string one bit
01001000011001010110110001101100
= 10010000110010101101100011011000


So, after the first iteration W16 is added to the chunk as:

W16 = 10010000110010101101100011011000
After all of the iterations, we should have a chunk of 2560 bits

Step 5A

 Initialize The "Hash Values" for the chunk
 A = H1
 B = H2
 C = H3
 D = H4
 E = H5

Step 6

Alumni Liaison

Basic linear algebra uncovers and clarifies very important geometry and algebra.

Dr. Paul Garrett