First of all: I know that AES is a block cipher, not a hash function. However, I was stuck with a microcontroller with very little RAM and flash memory, and AES-128 is already implemented on it and is used for its intended purpose - encryption.
Unfortunately, I will also have to implement a hash function to check the integrity of files on the same microcontroller. Given the limited resources, I was wondering if it is possible to use the existing AES algorithm instead of MD5 for hashing. One possibility to do this:
- Encrypt the first block of the file with a dummy key (for example, all zeros)
- Encrypt the next block using the previous encrypted block as a key
- Continue this until all data in the file has been processed.
- Use last encrypted block as a hash
In theory, I think this should work. If there is corrupted data in the file, this will lead to differences in all subsequent blocks.
Now the big question is: how well will this method work in terms of collisions? Or to put it another way: how well will the last "hash" spread?
encryption aes hash md5
Makai
source share