Title: hash function for dummies Post by: Husires on July 31, 2020, 03:58:02 PM Disclaimer: The information's contained in this explanation is the result of my understanding of hashing and may contain some errors. Search and confirm about it. Table of contents 1. Introduction (#post_point1) 2. Bitcoin Hashing (#post_point2) 3. How does a hash function work? (#post_point3) 4. SHA-1, SHA-2 and SHA-256 Hash Algorithms (#post_point4) 5. Why do we need it? (#post_point5) 6. Hash function properties (#post_point6) 7. Hash function & Mining (#post_point6) https://www.thesslstore.com/blog/wp-content/uploads/2018/08/Hashing.png Source: https://www.thesslstore.com/blog/difference-sha-1-sha-2-sha-256-hash-algorithms/ (https://www.thesslstore.com/blog/difference-sha-1-sha-2-sha-256-hash-algorithms/) Introduction If you spent some Bitcoins or did some research to find out how it works you will notice the word "cryptographic hash algorithms," "Bitcoin hash" or some technical vocabulary like "SHA-1, SHA 256, MD5, BLAKE, and RIPEMD." There is no doubt that you are familiar with the hash functions, even if you do not realize it, you use it daily and every time you create a user account on a website, your password acts as an entry point for the hash function. Bitcoin Hashing The hash function is a calculation that aims to generate a fixed-size output from a variable-sized input after it performs an operation (known as hash functions (implemented as hashing algorithms)) on it. We will always get the same hash from the same data, but modifying the data even a single bit will completely change the hash. usually written as hexadecimal. Mostly designed as one-way functions, it is very easy to create the output from the input, but relatively difficult to go in the opposite direction. How does a hash function work? Let's go back to the web account example, when you create an account, the password is run through a hash function, and the hash hash digest is stored in the server. When you want to log-in back, he same hash function is run on, and the server checks to see if the result matches the stored value. The same applies to Bitcoin. The possible output sizes for each hash algorithm are always constant. For example, SHA-256 produces 256-bit output, while SHA-1 always produces 160-bits digest. Let's try it with some examples: Code: Input: Husires SHA-1, SHA-2 and SHA-256 Hash Algorithms SHA stands for Secure Hashing Algorithm, numbers explain the differences between them in (how the resulting hash is created from the original data) and in the bit-length of the signature. SHA-1 is a 160-bit hash. SHA-2 comes in various lengths, but the most famous is 256 for "SHA-2," "SHA-256" or "SHA-256 bit." Note that large bit length does not automatically mean that the hash algorithm produces safer hashes. A bit has two possible values: 0 or 1. the number of possible values raised to the number of bits gives us unique hashes which will be 2256 possible combinations for SHA-256. Of course it can be solved but it needs a large amount of processing power which means that new bitcoins are mined over a long period of time, not all at once and thus the network still takes approximately 10 minutes to solve a block. https://www.researchgate.net/profile/Somitra_Sanadhya/publication/220335111/figure/fig1/AS:394006216364054@1470949810821/Round-function-of-SHA-256-hash-function.png Source: https://www.researchgate.net/figure/Round-function-of-SHA-256-hash-function_fig1_220335111 (https://www.researchgate.net/figure/Round-function-of-SHA-256-hash-function_fig1_220335111) Why do we need it? It can be used in many areas such as large file analysis, data management, and information security applications, but we will limit the explanation to bitcoin and some of the roles it plays in the mining process and the creation of new addresses and keys. Many cryptocurrencies depend on it in link and condense groups of transactions into blocks, and cryptographic links between each block. Likewise, to break a fragmentation function, it requires countless brute force attempts. In order for a person to "return" to the coding hash function, they would need to guess what the input was by trial and error in order for the corresponding output to be produced. https://waytomine.com/wp-content/uploads/2018/12/Sha-2561-810x356.jpg Source: https://waytomine.com/sha-256-algorithm-function-bitcoin-network/ (https://waytomine.com/sha-256-algorithm-function-bitcoin-network/) Hash function properties To be considered effectively safe, it must have these characteristics:
Collision resistance: The reason for their occurrence comes from the idea that the potential inputs are infinite, while the potential outputs are limited. SHA-1 was the primary algorithm (no longer safe because collisions have been found) but SHA-2 is the new standard. Note that: SHA1 was never commonly used in Bitcoin. A new generation of SHA-3 algorithms may be used at some point on the road Preimage resistance: it is similar to finding the result to x+y=10 you have absolutely no way of guessing the correct x and y even when you know the result is 10. what you can do is to find other values that can give the same result like 1 and 9 or 4 and 6,... Source:https://bitcointalk.org/index.php?topic=5265882.msg54911150#msg54911150 Other Properties:
Hash function & Mining We have many uses such as checking balances, segmenting transactions within a block to form Merkle Tree and others. Output hash begins with a certain number of zeros. The number of zeros determines the difficulty of mining, and varies according to the network hash rate (Bitcoin protocol easy to maintain average mining block time close to 10 minutes by adjusting mining difficulty.) Thus there is no need to find collisions. Sources Code: https://www.youtube.com/watch?v=0WiTaBI82Mc Title: Re: hash function for dummies Post by: odolvlobo on July 31, 2020, 10:30:32 PM ... Hash function & Mining We have many uses such as checking balances, segmenting transactions within a block to form Merkle Tree and others. Output hash begins with a certain number of zeros. The number of zeros determines the difficulty of mining, and varies according to the network hash rate (Bitcoin protocol easy to maintain average mining block time close to 10 minutes by adjusting mining difficulty.) Thus there is no need to find collisions. This paragraph is vague. Also, Bitcoin has never used the number of zeros to determine difficulty. It was mentioned in the white paper, but that is not how difficulty was actually implemented. Title: Re: hash function for dummies Post by: pooya87 on August 01, 2020, 04:15:19 AM Quote Mostly designed as one-way functions, it is very easy to create the output from the input, but relatively difficult to go in the opposite direction. if some function is not one-way then it can not be categorized as a hash algorithm. so they are all (not mostly) one-way or irreversible. and the "opposite direction" is impossible not difficult. it is about the chaotic nature of the algorithm, it is not math to maybe some day find a way to solve it with a lot of effort.Quote SHA-2 comes in various lengths, but the most famous is 256 for "SHA-2," "SHA-256" or "SHA-256 bit." SHA2 is simply the second version of the Secure Hash Algorithm standard by NIST the same way SHA1 is version one and SHA3 is version 3.BTW we have 2 256-bit SHA-2 variations, the popular SHA256 also used in bitcoin and the less popular alternative that fixes length extension attack called SHA512/256 Quote will be 2256 possible combinations for SHA-256. you forgot to fix this for forum and BBCode ;)Quote Preimage resistance: find the input from a given output this is wrong.Preimage resistance: The difference from the previous feature is that the attacker will try to guess was the input is by looking at specific outputs. preimage attack is basically finding another message that can give the same hash result. it is similar to finding the result to x+y=10 you have absolutely no way of guessing the correct x and y even when you know the result is 10. what you can do is to find other values that can give the same result like 1 and 9 or 4 and 6,... Quote We have many uses such as checking balances, segmenting transactions within a block to form Merkle Tree and others. Output hash begins with a certain number of zeros. The number of zeros determines the difficulty of mining, and varies according to the network hash rate (Bitcoin protocol easy to maintain average mining block time close to 10 minutes by adjusting mining difficulty.) that is if you want to poorly simplify the process of mining and how difficulty works. the correct way is that the hash is interpreted as an integer and then compared with another integer called target and is only accepted if it is smaller than or equal to that number.p.s. you focused too much on mining and are missing another important usage of hash in bitcoin which is during signing. ECDSA requires a fixed 256-bit integer to sign and a transaction is a bigger raw data which needs to be hashed and reduced to a fixed sized value then converted to that int for signing. Title: Re: hash function for dummies Post by: Yogee on August 01, 2020, 04:37:28 AM Husires, how about a compilation of your "for dummies" topics?
Title: Re: hash function for dummies Post by: Husires on August 01, 2020, 07:07:11 AM Also, Bitcoin has never used the number of zeros to determine difficulty. It was mentioned in the white paper, but that is not how difficulty was actually implemented. It has to do with how hashing can work in Bitcoin minning, but not how mining works, so perhaps I will add more details when we talk about POW.lets definition it as maximum accepted number if some function is not one-way then it can not be categorized as a hash algorithm. so they are all (not mostly) one-way or irreversible. and the "opposite direction" is impossible not difficult. it is about the chaotic nature of the algorithm, it is not math to maybe some day find a way to solve it with a lot of effort. Mining hash based on difficulty not impossible.this is wrong. Updated :)p.s. you focused too much on mining and are missing another important usage of hash in bitcoin which is during signing. ECDSA requires a fixed 256-bit integer to sign and a transaction is a bigger raw data which needs to be hashed and reduced to a fixed sized value then converted to that int for signing. Because I'm going to talk about that on this topic Bitcoin Scripts for dummies (https://bitcointalk.org/index.php?topic=5262177.msg54794708#msg54794708)I started talking about Bitcoin scripts .... P2SH, but I stopped when I realized I hadn't explained hash. Husires, how about a compilation of your "for dummies" topics? I apologize if the topic is difficult, I will try to make it simple.Title: Re: hash function for dummies Post by: Yogee on August 02, 2020, 01:57:36 AM Husires, how about a compilation of your "for dummies" topics? I apologize if the topic is difficult, I will try to make it simple. |