Bitcoin Forum
August 02, 2021, 07:19:23 AM *
News: Latest Bitcoin Core release: 0.21.1 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: hash function for dummies  (Read 246 times)
Husires
Hero Member
*****
Offline Offline

Activity: 616
Merit: 502



View Profile
July 31, 2020, 03:58:02 PM
Last edit: August 01, 2020, 07:02:27 AM by Husires
Merited by LoyceV (8), suchmoon (7), mk4 (3), Heisenberg_Hunter (3), o_e_l_e_o (2), DdmrDdmr (2), pooya87 (1)
 #1


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
      2. Bitcoin Hashing
      3. How does a hash function work?
      4. SHA-1, SHA-2 and SHA-256 Hash Algorithms
      5. Why do we need it?
      6. Hash function properties
      7. Hash function & Mining




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
Output: 198d93f2c0bff9767d4cdc047f2191b0921d81e410c10c0744311fadfdb516f9
Input: husires
Output: 3121cef89f206bef49882eb1aeb63a9e1d3e35075c27df817f5096dc84c2511a
What did you conclude from the examples above?



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.



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.



Hash function properties

To be considered effectively safe, it must have these characteristics:

  • Collision resistance: It is essential that different inputs do not have the same hash output.
  • Preimage resistance: finding another message that can give the same hash result

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:

  • Privacy: It is necessary to hide the input information. It should not be easy, or even possible, to know information about the inputs just by looking at the output
  • Randomness: Randomization enables some features that we will explain in detail below, such as: Proof Of Work


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
https://www.youtube.com/watch?v=mMxkxwPSfvo
https://en.wikipedia.org/wiki/Cryptographic_hash_function
https://www.thesslstore.com/blog/difference-sha-1-sha-2-sha-256-hash-algorithms/
https://xorbin.com/tools/sha256-hash-calculator
https://bitcoinexchangeguide.com/bitcoin-hash-functions/
https://academy.binance.com/security/what-is-hashing


BUY CRYPTO AT REASONABLE RATES
▄▄███████▄▄
▄█████▀ ▀█████▄
██████ ▄█▄ ██████
██████ █████ ██████
█████ ▄ ███ ▄ █████
████▌▐██ █ ██▌▐████
███▄ ▀▀▌ ▐▀▀ ▄███
▀████▄▄ ▄▄████▀
▀▀███████▀▀
▄▄███████▄▄
▄█████▀█▀█████▄
████        ▀████
███████  ███  █████
███████      ▀█████
███████  ███  █████
████        ▄████
▀█████▄█▄█████▀
▀▀███████▀▀
▄▄███████▄▄
▄█████▀▀▀█████▄
██████   ▐███████
██████▌   ▀▀███████
█████▀    ▄████████
████▄    ▀▀▀▀▀▀████
███▌         ▄███
▀█████████████▀
▀▀███████▀▀
&OTHER
COINS
1627888763
Hero Member
*
Offline Offline

Posts: 1627888763

View Profile Personal Message (Offline)

Ignore
1627888763
Reply with quote  #2

1627888763
Report to moderator
1627888763
Hero Member
*
Offline Offline

Posts: 1627888763

View Profile Personal Message (Offline)

Ignore
1627888763
Reply with quote  #2

1627888763
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1627888763
Hero Member
*
Offline Offline

Posts: 1627888763

View Profile Personal Message (Offline)

Ignore
1627888763
Reply with quote  #2

1627888763
Report to moderator
1627888763
Hero Member
*
Offline Offline

Posts: 1627888763

View Profile Personal Message (Offline)

Ignore
1627888763
Reply with quote  #2

1627888763
Report to moderator
odolvlobo
Legendary
*
Online Online

Activity: 3304
Merit: 1965



View Profile
July 31, 2020, 10:30:32 PM
 #2

...
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.

Buy stuff on Amazon with BTC or convert Amazon points to BTC here: Purse.io
Join an anti-signature campaign: Click ignore on the members of signature campaigns.
PGP Fingerprint: 6B6BC26599EC24EF7E29A405EAF050539D0B2925 Signing address: 13GAVJo8YaAuenj6keiEykwxWUZ7jMoSLt
pooya87
Legendary
*
Offline Offline

Activity: 2436
Merit: 4129


Beware of Greeks bearing gifts!


View Profile
August 01, 2020, 04:15:19 AM
Merited by DdmrDdmr (1)
 #3

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 Wink

Quote
Preimage resistance: find the input from a given output
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.
this is wrong.
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.

Yogee
Sr. Member
****
Offline Offline

Activity: 532
Merit: 277



View Profile
August 01, 2020, 04:37:28 AM
 #4

Husires, how about a compilation of your "for dummies" topics?

▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄
█                         █
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄        █
           ▄▄███████▄▄   █
    ▄▄▄▄▄▄█████████████  █
         ████▀     ▀████
         ████       ████
         ████▄     ▄████
    ▀▀▀▀▀▀█████████████  █
           ▀▀███████▀▀   █
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀        █
█                         █
▀▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▀
|●/
●/
●/
SLOTS
GAME SHOW
LIVE CASINO
●/
●/
ROULETTE
BLACKJACK
▄▄▄▄▄▄▄▄▄▄ ▄▄ ▄
|      ███▄
          █         ▄▄▄▄
  ▄█▀▀▀▀▀▀     ▄▄▄████████▄▄
▄█▀       ▄▄▄████████████████▄
▀██▄  ▄▄███████████████████████▄
  ▀██████████████████████████████▄
    ███████████████████████████████▀
    ▐█████████████████████████████ ███▄
    ▐███████████▀▀█████████████████▄ ▀▀█
  ▐█████▀██████     ███▀ ███  ▐████▀
   ███▀   ████     ▄██   ▐██  ▐██▀
    ██     ▀▀██▄   ██     ██   ▀
   ████       ███ ███     ███


    ▄██▄▄    ▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄▄
▄▄████████████████████▄▄▀██████████▄▄
▀█████████████████████████████████████▄
    ▀▀▀▀▀███████████████████████████████
          ▀███████████████████████████▀█
             ▀▀█████████████▀▄███████▀
              █▄▀▀██████████▐██████▀▄
              ▐███▄▀█████▄  ▐████▀▄███
              ████▀  ▀████  ▐███▀ ████▌
            ▄███▀      ██▀   ██▀   ███
          ▄███▀     ▄███▀  ▄███  ▄███
|
▄▄███████▄▄
▄█████████████▄
███████▌ ▐███████
████████  █████████
█████▀▀   ▄▄███████
███████  ██████████
█████▌      ▄████
▀█████████████▀
▀▀███████▀▀
▄▄███████▄▄
▄█████████████▄
█████▌      ▄████
███████  ██████████
LITECOIN DEPOSITS
AVAILABLE NOW
.
TWITTER     |     DISCORD
█▀▀▀▀▀











█▄▄▄▄▄
.
PLAY NOW
▀▀▀▀▀█











▄▄▄▄▄█
Husires
Hero Member
*****
Offline Offline

Activity: 616
Merit: 502



View Profile
August 01, 2020, 07:07:11 AM
 #5

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 Smiley

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
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.

BUY CRYPTO AT REASONABLE RATES
▄▄███████▄▄
▄█████▀ ▀█████▄
██████ ▄█▄ ██████
██████ █████ ██████
█████ ▄ ███ ▄ █████
████▌▐██ █ ██▌▐████
███▄ ▀▀▌ ▐▀▀ ▄███
▀████▄▄ ▄▄████▀
▀▀███████▀▀
▄▄███████▄▄
▄█████▀█▀█████▄
████        ▀████
███████  ███  █████
███████      ▀█████
███████  ███  █████
████        ▄████
▀█████▄█▄█████▀
▀▀███████▀▀
▄▄███████▄▄
▄█████▀▀▀█████▄
██████   ▐███████
██████▌   ▀▀███████
█████▀    ▄████████
████▄    ▀▀▀▀▀▀████
███▌         ▄███
▀█████████████▀
▀▀███████▀▀
&OTHER
COINS
Yogee
Sr. Member
****
Offline Offline

Activity: 532
Merit: 277



View Profile
August 02, 2020, 01:57:36 AM
 #6


Husires, how about a compilation of your "for dummies" topics?
I apologize if the topic is difficult, I will try to make it simple.
I don't think you get what I mean. You made a number of guides for dummies and I was asking if you could make a list of your topics similar to what Loycev does https://bitcointalk.org/index.php?topic=5145594.0

▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄
█                         █
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄        █
           ▄▄███████▄▄   █
    ▄▄▄▄▄▄█████████████  █
         ████▀     ▀████
         ████       ████
         ████▄     ▄████
    ▀▀▀▀▀▀█████████████  █
           ▀▀███████▀▀   █
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀        █
█                         █
▀▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▀
|●/
●/
●/
SLOTS
GAME SHOW
LIVE CASINO
●/
●/
ROULETTE
BLACKJACK
▄▄▄▄▄▄▄▄▄▄ ▄▄ ▄
|      ███▄
          █         ▄▄▄▄
  ▄█▀▀▀▀▀▀     ▄▄▄████████▄▄
▄█▀       ▄▄▄████████████████▄
▀██▄  ▄▄███████████████████████▄
  ▀██████████████████████████████▄
    ███████████████████████████████▀
    ▐█████████████████████████████ ███▄
    ▐███████████▀▀█████████████████▄ ▀▀█
  ▐█████▀██████     ███▀ ███  ▐████▀
   ███▀   ████     ▄██   ▐██  ▐██▀
    ██     ▀▀██▄   ██     ██   ▀
   ████       ███ ███     ███


    ▄██▄▄    ▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄▄
▄▄████████████████████▄▄▀██████████▄▄
▀█████████████████████████████████████▄
    ▀▀▀▀▀███████████████████████████████
          ▀███████████████████████████▀█
             ▀▀█████████████▀▄███████▀
              █▄▀▀██████████▐██████▀▄
              ▐███▄▀█████▄  ▐████▀▄███
              ████▀  ▀████  ▐███▀ ████▌
            ▄███▀      ██▀   ██▀   ███
          ▄███▀     ▄███▀  ▄███  ▄███
|
▄▄███████▄▄
▄█████████████▄
███████▌ ▐███████
████████  █████████
█████▀▀   ▄▄███████
███████  ██████████
█████▌      ▄████
▀█████████████▀
▀▀███████▀▀
▄▄███████▄▄
▄█████████████▄
█████▌      ▄████
███████  ██████████
LITECOIN DEPOSITS
AVAILABLE NOW
.
TWITTER     |     DISCORD
█▀▀▀▀▀











█▄▄▄▄▄
.
PLAY NOW
▀▀▀▀▀█











▄▄▄▄▄█
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!