Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using AES for file integrity checks, replacing MD5

First off: I know that AES is a block cipher and not a hashing function. However, I'm stuck with a micro controller with very little RAM and flash memory, and AES-128 is already implemented on it and used for its intended purpose - encryption.

Unfortunately, I'll also have to implement a hashing function for file integrity checks on the same micro controller. Given the limited resources, I was wondering if it would be possible to use the existing AES algorithm instead of MD5 for hashing. One possibility to do that would be:

  1. Encrypt the first block of the file using a dummy key (like all zeroes for example)
  2. Encrypt the next block using the previous encrypted block as the key
  3. Continue this way until all data in the file has been processed
  4. Use the last encrypted block as the hash

In theory, I think this should work. If there is corrupted data anywhere in the file, it would lead to differences in all subsequent blocks.

Now, the big question is: How well would this method perform in terms of collisions? Or to put it differently: How well would the final "hash" be distributed?

like image 252
Makai Avatar asked Jan 08 '11 12:01

Makai


People also ask

Is AES better than MD5?

A hash, like MD5 or SHA is used to verify passwords because it's hard to invert, that is, to obtain the password from the hash-string. An AES encryption, on the other hand, is invertible, the original message can be obtained if you know the key.

Does AES use MD5?

To improve the quality of data security systems on smartphones, in this research the integration of AES 256 bit algorithm by using MD5 hashing is proposed. The use of MD5 aims to increase the key strength of the encryption and decryption process of document files.

How is a hash algorithm used in checking the integrity of a file?

Cryptographic Hash Function algorithm works by comparing the file's original and current hash values. And if a byte or even a piece of the file's data has been changed, the original and current hash values will be different, and therefore you will know whether it's the same file or not.


2 Answers

It sounds like you want to use AES-CMAC, an authentication algorithm based in AES.

like image 102
President James K. Polk Avatar answered Oct 30 '22 02:10

President James K. Polk


Most emphatically yes you can make a hash function out of AES. In fact, a number of the submissions for the NIST SHA3 contest, which will decide the next US-government-approved hash function, do exactly that.

A traditional hash function is just a cascaded compression function, and it's easy to construct compression functions from block cyphers. (Some people have also gone the other way, and pulled the block cypher out of SHA-2 to use independantly.)

You can, of course, build a proper hash function out of it, but if all you need is file integrity, and therefore don't need it to have preimage resistance, collision resistance, or all those other properties that cryptographic hashes have against malicious adversaries, then you can probably even just put your AES chip in whatever chaining mode it has, feed in the file as the message, and use the last block as the hash. (Just pick fixed values to use for the key and IV. Nothing up my sleeve numbers that look random but aren't are probably good choices, like the first 128 bits after the decimal point in e and pi.)

like image 32
me22 Avatar answered Oct 30 '22 04:10

me22