Skip to content

Instantly share code, notes, and snippets.

@iaoedsz2008
Created May 6, 2019 03:00
Show Gist options
  • Save iaoedsz2008/9c60cb32659a406f58746b52422311cc to your computer and use it in GitHub Desktop.
Save iaoedsz2008/9c60cb32659a406f58746b52422311cc to your computer and use it in GitHub Desktop.
void hmac_sha512 (const unsigned char* input, int inputlength, unsigned char* output, unsigned int* outputlength)
{
const EVP_MD* engine = EVP_sha512 ();
#if OPENSSL_VERSION_NUMBER < 0x10100000L
HMAC_CTX ctx;
HMAC_CTX_init (&ctx);
HMAC_Init_ex (&ctx, API_SECRET, strlen (API_SECRET), engine, NULL);
HMAC_Update (&ctx, (const unsigned char*)input, inputlength);
HMAC_Final (&ctx, output, outputlength);
#else
HMAC_CTX* ctx = HMAC_CTX_new ();
HMAC_Init_ex (ctx, API_SECRET, strlen (API_SECRET), engine, NULL);
HMAC_Update (ctx, (const unsigned char*)input, inputlength);
HMAC_Final (ctx, output, outputlength);
HMAC_CTX_free (ctx);
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment