Search code examples
copenssldigital-signatureevp-cipher

How to verify the digital signature given hash and public key?


There are plenty of examples written in C on how to verify a digital signature on a message but my use case requires me to provide only the message hash.

So is there an alternative to EVP_DigestVerifyUpdate(mdctx, msg, strlen(msg)); where I could directly provide a hash?


Solution

  • Is this what you are looking for?

    EVP_PKEY *public_key = ...;
    EVP_PKEY_CTX *public_key_ctx = EVP_PKEY_CTX_new(public_key, NULL);
    
    EVP_PKEY_verify_init(public_key_ctx);
    if (1 != EVP_PKEY_verify(public_key_ctx, sig, siglen, hash, hashlen))
        // invalid signature