title: Python SHA256 hash computation
body: <p>I'm writing a SHA256 implementation in Python, padding, parsing and message schedule seem to work fine, my problem lies in the hash computation. Currently I'm just trying to calculate the working variable 'a'.
  This is the value I get (In hex)</p>
  
  <blockquote>
    <p>5d6aebe0</p>
  </blockquote>
  
  <p>Expected Output, according to <a href="https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA256.pdf" rel="nofollow noreferrer">this</a>:</p>
  
  <blockquote>
    <p>5D6AEBCD</p>
  </blockquote>
  
  <p>Here is my code:</p>
  
  <p>Set the working variables to the constants specified in <a href="https://csrc.nist.gov/csrc/media/publications/fips/180/4/final/documents/fips180-4-draft-aug2014.pdf" rel="nofollow noreferrer">FIPS-180</a></p>
  
  <pre class="lang-py prettyprint-override"><code>a = int('6a09e667', 16)
  b = int('bb67ae85', 16)
  c = int('3c6ef372', 16)
  d = int('a54ff53a', 16)
  e = int('510e527f', 16)
  f = int('9b05688c', 16)
  g = int('1f83d9ab', 16)
  h = int('5be0cd19', 16)
  </code></pre>
  
  <p>Set the two important variables that depend on value t:</p>
  
  <pre class="lang-py prettyprint-override"><code>W = int('61626380', 16)
  K = int('428a2f98', 16)
  </code></pre>
  
  <p>From the pseudo code on <a href="https://en.wikipedia.org/wiki/SHA-2#Pseudocode" rel="nofollow noreferrer">wikipedia</a>:</p>
  
  <pre><code>S1 = hash.ROTR(e, 6) ^ hash.ROTR(e, 11) ^ hash.ROTR(e, 25)
  ch = (e &amp; f) ^ ((~e) &amp; g)#((e1) &amp; g)
  temp1 = (h + S1 + ch + K + W) % math.pow(2, 32)
  S0 = hash.ROTR(a, 2) ^ hash.ROTR(a, 13) ^ hash.ROTR(a, 22)
  maj = (a &amp; b) ^ (a &amp; c) ^ (b &amp; c)
  temp2 = (S0 + maj) % math.pow(2, 32)
  a = int((temp1 + temp2) % math.pow(2, 32))
  </code></pre>
  
  <p>ROTR function:</p>
  
  <pre class="lang-py prettyprint-override"><code>@staticmethod
  def ROTR(x, n, w=32):
      return (x &gt;&gt; n) | (x &lt;&lt; w - n)
  </code></pre>
  
  <p>Or, split into functions, like specified in <a href="https://csrc.nist.gov/csrc/media/publications/fips/180/4/final/documents/fips180-4-draft-aug2014.pdf" rel="nofollow noreferrer">FIPS-180</a> (Prodcuces the same output)</p>
  
  <pre class="lang-py prettyprint-override"><code>T1 = int((h + hash.SIGMA1(e) + hash.Ch(e, f, g) + hash.K[t] + W) % math.pow(2, 32))
  T2 = int((hash.SIGMA0(a) + hash.Maj(a, b, c)) % math.pow(2, 32))
  a = int((T1 + T2) % math.pow(2, 32))
  </code></pre>
  
  <p>Hash class:</p>
  
  <pre class="lang-py prettyprint-override"><code>@staticmethod
  def ROTR(x, n, w=32):
      return (x &gt;&gt; n) | (x &lt;&lt; w - n)
  def SIGMA0(x):
      return hash.ROTR(x, 2) ^ hash.ROTR(x, 13) ^ hash.ROTR(x, 22)
  def SIGMA1(x):
      return hash.ROTR(x, 6) ^ hash.ROTR(x, 11) ^ hash.ROTR(x, 25)
  def Ch(x, y, z):
      return (x &amp; y) ^ (~x &amp; z)
  def Maj(x, y, z):
      return (x &amp; y) ^ (x &amp; z) ^ (y &amp; z)
  </code></pre>
  
  <p>I'm using Python 3 btw. Thanks in advance.</p>