Homework on Hash Functions - Questions
1. Describe hash functions with your own words
Hash functions are a subtype of functions that:
- Generate an unique output for each input. The input may be of any size, but the output will have a fixed size.
- Does not have an inverse function (making impossible to calculate the input of the hash function using its output)
Based on this properties, hash functions are used to encrypt data. For instance, secure HTTP sites uses hash functions to ensure that only the web site and the user are able to see the information that both parties are sharing (in order to avoid third parties to retrieve sensitive data, such as credit card numbers and user passwords)
2. How are hash functions used in cryptocurrencies like bitcoin? (Try to research this on your own, we will cover this later in the course but challenge yourself and see if you can find information on this already now).
Hash functions are used to encrypt transactionsâ data together with additional metadata required by the blockchain (the hash of the previous block, the hash of the current block, the current timestamp, the difficulty -target of bits in 0-, the version and the nonce). Then, miners try to be the first one to deliver a hash with as many leading zeroes as the difficulty states, having as their actionable variable the nonce.
As the first miner to get a hash code that satisfies the difficulty will get the reward in bitcoins, it is important that there is no algorithm that allows anyone to calculate the proper nonce based in the rest of parameters, making the process transparent, and avoiding data manipulation. Also, considering that transactions are sensitive data, it is useful to manage those transactions in a encrypted way.
3. What does it mean when we say that hash functions need to be collision resistant? (We didnât use the term âcollision resistantâ in the lecture, but you will easily find this on Google, we add this question intentionally to make you research information on your own, thatâs how you learn best).
Hash functions are injective (each input has an output), but, considering that the amount of inputs is infinite, and the amount of outputs is restricted (and equal to 2^256), it is possible that two different inputs may deliver the same result.
Considering that, a hash function, that creates an output of N bits, is considered collision resistant if an attacker needs 2^(n/2) inputs to match two similar outputs (based on brute force). For instance, SHA-256 is still collision resistant, however, there are algorithms for MD5 that perform better than brute force to find collisions, which made MD5 unsafe for being used.