How to calculate the message digest programmatically
We are going to implement the digest
program that will calculate SHA3-256 message digest of a file.
Our digest
program will receive only one command-line argument: the name of the input file to be hashed.
As with symmetric encryption in the previous chapter, let’s make a high-level plan for calculating the message digest:
- First, we must initialize the message digest calculation context.
- Then, we must feed data to the message digest calculation context chunk by chunk, reading chunks from the input file.
- Next, we must finalize the calculation and get the message digest.
- Finally, we must print the calculated message digest to stdout.
Similar to symmetric encryption, OpenSSL contains the new EVP API and the old, deprecated low-level API for message digest calculation. The functions of the EVP API start with the EVP_
prefix, while the functions of the low-level API start with hash function-specific...