Jan Moritz
Jan Moritz

Reputation: 2215

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?

Upvotes: 1

Views: 1163

Answers (1)

Marek Klein
Marek Klein

Reputation: 1490

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

Upvotes: 1

Related Questions