How to calculate a SHA-512 hash in C++ on Linux?

Nathan Osman picture Nathan Osman · Feb 26, 2011 · Viewed 14.8k times · Source

Is there a standard library or commonly used library that can be used for calculating SHA-512 hashes on Linux?

I'm looking for a C or C++ library.

Answer

Zimbabao picture Zimbabao · Feb 26, 2011

Have you checked OpenSSL. I myself have not used it but documentation says it supports it.

Here is list of few more implementations.

Example code

 md = EVP_get_digestbyname("sha512");
 EVP_MD_CTX_init(&mdctx);
 EVP_DigestInit_ex(&mdctx, md, NULL);
 EVP_DigestUpdate(&mdctx, mess1, strlen(mess1));
 EVP_DigestUpdate(&mdctx, mess2, strlen(mess2));
 EVP_DigestFinal_ex(&mdctx, md_value, &md_len);
 EVP_MD_CTX_cleanup(&mdctx);