title: How to calculate SHA512/224 and SHA512/256 hashes using OpenSSL?
body: <p>Here's how I calculate a SHA512 hash in C.</p>
  
  <pre><code>#include &lt;openssl/sha.h&gt;
  #include &lt;stdio.h&gt;
  
  char *calc_sha512(char *data) {
      SHA512_CTX ctx;
      char *md = malloc(sizeof(char)*(SHA512_DIGEST_LENGTH+1));
  
      SHA512_Init(&amp;ctx);
      SHA512_Update(&amp;ctx, data, strlen(data));
      SHA512_Final(md, &amp;ctx);
      md[SHA512_DIGEST_LENGTH] = '\0';
  
      return md;
  }
  
  int main() {
      printf("%s\n", calc_sha512("foo"));
  
      return 1;
  }
  </code></pre>
  
  <p>Now when I try to transform it to 512/<em>t</em> (either 512/224 or 512/256), it doesn't work. I initially thought that for calculating a 512/t hash, you'd simply have to truncate the output to <em>t</em> bits, but upon further reading, it doesn't only truncate the output, it also have different initial constant values. So I'm trying to figure out any function in OpenSSL that supports that? So far I have looked into docs and header files, I can't find such method under either SHA or EVP. Does OpenSSL even support SHA512/<em>t</em> hashing algorithms? Does it provide the functionality out of the box? Any pointers to that would be helpful.</p>