I'm working on an assignment where I have to compare a brute-force attack on a collision-free MAC vs. a one-way property MAC using the OpenSSL EVP library in C. Just to clarify, I'm not looking for any help on the assignment, just the implementation of EVP.
I've created the following code which creates a hash of the given input string:
OpenSSL_add_all_digests();
// Set Hash Digest
md = EVP_get_digestbyname("MD5");
// Create Hash
EVP_MD_CTX_init(&c);
EVP_DigestInit_ex(&c, md, NULL);
EVP_DigestUpdate(&c, plaintext, strlen(plaintext));
EVP_DigestFinal_ex(&c, hash, &hash_len);
EVP_MD_CTX_cleanup(&c);
This works exactly as needed to create the hash. How do I set the property for one-way vs. collision-free? I was not able to find anything specific in the documentation and just need clarification around this point.
I think you are confusing properties of an algorithm with the properties of an object or - in C terms - contexts. MD5 has the one way property, just like the sun has the property to give a yellowish light. You cannot remove or configure that property. So you need to use different hash methods, not configure a specific one.
Note that MD5 is not a MAC in itself (HMAC-MD5 is), it's a secure hash algorithm.