[openssl-users] Openssl api for signature verification using digest

Linta Maria lintamaria194 at gmail.com
Tue Aug 28 11:08:36 UTC 2018

Hi All,

I have started using open ssl recently for implementing some cryptographic

Now I want to implement signature verification by taking Signature and
hashed data as input, but I am not able to get the proper API.

I have used below code, but it’s not working. Please help me to get the
correct API.

#include <openssl/evp.h>

#include <openssl/rsa.h>


unsigned char *md, *sig;

size_t mdlen, siglen;

EVP_PKEY *verify_key;


  * NB: assumes verify_key, sig, siglen md and mdlen are already set up

  * and that verify_key is an RSA public key


ctx = EVP_PKEY_CTX_new(verify_key, NULL /* no engine */);

if (!ctx)

     /* Error occurred */

if (EVP_PKEY_verify_init(ctx) <= 0)

     /* Error */

if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0)

     /* Error */

if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0)

     /* Error */

/* Perform operation */

ret = EVP_PKEY_verify(ctx, sig, siglen, md, mdlen);


  * ret == 1 indicates success, 0 verify failure and < 0 for some

  * other error.


Best regards,

*George Linta Maria*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mta.openssl.org/pipermail/openssl-users/attachments/20180828/5e357c36/attachment-0001.html>

More information about the openssl-users mailing list