0

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.

Dexter
  • 1,128
  • 3
  • 25
  • 51

1 Answers1

1

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.

Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263
  • Thank you, that helps! Would SHA256 (HMAC-SHA256) work as "collision-free" (or at least more collision-resistant) since it has a larger hash output length? – Dexter Nov 30 '15 at 19:47
  • Yes, the output size matters. The more complex rounds matter even more. Note that MD5 is *supposed* to be collision resistant, so it may not be a good candidate for a non-collision resistant hash. Neither MD5 or SHA-256 is of course collision free in the strict sense (you would need a perfect hash function for that). – Maarten Bodewes Nov 30 '15 at 19:55