How to use MD4,MD5, SHA1 in Linux using C++

Hello,
I have this project where I have to give the user the option to apply MD4, MD5,or SHA1 in C++. Once the user selects one of the three specified hash functions, the program will apply the selected hash function to an arbitrary length local file named "input.txt". We were told that the functions are already implmented in Linux,at this time I would like to know how do you call such function in C++.Any help/advice would be greatly appreciated.

Thanks in Advance
MD4, MD5 http://linux.die.net/man/3/md2
SHA-1 http://linux.die.net/man/3/sha

Just #include the right files and you are good to go.

Hope this helps.
Duoas,
Thanks, that was helpful. However, I have another question. How would you apply the functon to a file. For example, say the user selects MD5, How would I apply MD5 to input.txt .
All the examples are in C, but you can use C++ I/O just as easily.

These two pages give good examples:
http://linux.die.net/man/3/evp_digestinit
http://linuxgazette.net/issue87/vinayak.html

For your project you'll have an easier time using the EVP Digest functions.

The trick is to use a read/write loop:
1) read input data
2) use EVP_DigestUpdate() to pass that data to the encryption routine
3) use EVP_DigestFinal_ex() to get the encrypted data out
4) write the output data to file
5) repeat as necessary

Pay attention to setup and clean up of your buffers on each iteration.

Good luck!
Topic archived. No new replies allowed.