#include #include #include "cryptlib.h" #include "filters.h" #include "files.h" #include "sha.h" #include "hex.h" int main(int argc, char* argv[]) { using namespace CryptoPP; // Create a file of all 0's with: // dd if=/dev/zero of=./zero.dat bs=4096 count=1 std::string digest; SHA256 sha256; // Create the digest on the file FileSource("zero.dat", true, new HashFilter(sha256, new StringSink(digest))); // Print the digest std::cout << "Digest: "; StringSource(digest, true, new HexEncoder(new FileSink(std::cout))); std::cout << std::endl; // Create a verifier byte result = 0; HashVerificationFilter verifier(sha256, new ArraySink(&result, sizeof(result))); // Wrap the data in sources StringSource ss(digest, true); FileSource fs("zero.dat", true); // Add the data to the filter ss.TransferTo(verifier); fs.TransferTo(verifier); // Signal end of data. The verifier will finish calculating // the digest, and compare the expected and calculated digests. verifier.MessageEnd(); if (result) std::cout << "Verified hash on file" << std::endl; else std::cout << "Failed to verify hash on file" << std::endl; return 0; }