Look at the DigestFile() function in test.cpp. It shows how to do exactly
what you want.
On Tue, 8 Mar 2005, Matt "Cyber Dog" LaPlante wrote:
I'm currently working on an application which uses Crypto++ as a large part
of the backend, primarily for its hash and checksum routines. Most of my
calls to Crypto involve only one or two lines as follows:
FileSource(filename, true, new HashFilter(hashtype, new HexEncoder(new
StringSink(output))));
This works fine for linear processing, but I've been trying to come up with
ways to make the process more efficient when creating multiple hashes from a
single file. Of course with purely linear calls you have to read the file
as many times as you wish to hash it, which is very inefficient. I know
Crypto is thread safe, and I've already threaded the application for test
purposes without a problem. The difficulty I have is that using code
similar to the above, threading the function calls themselves only has a
marginal effect since so much time is still spent reading the file n times.
Clearly the ideal situation would be to be able to perform multiple hash
calculations with a single read. For example, read the first X bytes, feed
these same bytes into MD5, SHA256, and Whirlpool at once, then read the next
X bytes and repeat. This would effectively reduce the processing time since
only a single disk read would be required. Can this type of parallel
processing be accomplished with Crypto++? If so, what functions would be
necessary? Sample code would be excellent...
Thanks,
Matt