title: SHA256 implementation in c
body: <p>I am trying to program SHA256 implementation from this website: <a href="http://bradconte.com/sha256_c" rel="nofollow">http://bradconte.com/sha256_c</a>
  in a MSP430 MCU board. I am using the open-source Energia IDE for programming. </p>
  
  <p>This is the testcode: </p>
  
  <pre><code> unsigned char  hash[32];
   SHA256_CTX ctx;
   sha256_init(&amp;ctx);
   sha256_update(&amp;ctx,(unsigned char*)"abc",3);
   sha256_final(&amp;ctx,hash);
   PrintHex(hash);
  </code></pre>
  
  <p>This converts to hex </p>
  
  <pre><code> void PrintHex(unsigned char * data) 
   {
      char tmp[16];
      for (int i=0; i&lt;32; i++) { 
      sprintf(tmp, "%02x",data[i]); 
      Serial.print(tmp); 
      }
   }
  </code></pre>
  
  <p>The problem is that the output is always a wrong hash code.</p>
  
  <p>This is the output:</p>
  
  <pre><code>    2bb53935edbba17dc04a04854518754d8a66484491b585b0d0700cd2512f5420
  </code></pre>
  
  <p>Is it the testcode or something else that I am doing wrong here?</p>