为广大币圈朋友提供币圈基础入门专业知识!
当前位置首页 > 比特币基础> 正文

区块链里的哈希加密算法是什么,区块链里的哈希加密算法有哪些

发布时间:2023-12-07-20:52:00 来源:网络 比特币基础 区块   加密算法

区块链里的哈希加密算法是什么,区块链里的哈希加密算法有哪些

近年来,随着区块链技术的发展,哈希加密算法也受到了越来越多的关注。哈希加密算法是指将任意长度的消息压缩到固定长度的消息摘要的一种散列函数,它可以防止信息被篡改。它在区块链技术中扮演着重要的角色,可以保证数据的安全性、可靠性和不可篡改性。本文将为您介绍区块链里的哈希加密算法的基本概念、拓展关键词及其相关应用。

1.SHA256算法:SHA256算法是一种安全散列算法,它是一种不可逆的算法,即从一个消息摘要不能推断出原始消息,它是区块链中最常用的哈希函数之一。SHA256算法可以将任意长度的消息压缩到256位的消息摘要,它可以有效地防止信息被篡改,确保数据的安全性和可靠性。

2.RIPEMD-160算法:RIPEMD-160算法是一种安全哈希算法,它可以将任意长度的消息压缩到160位的消息摘要,它也是一种不可逆的算法,可以有效地防止信息被篡改,确保数据的安全性和可靠性。RIPEMD-160算法在比特币的区块链中被广泛应用,它可以更好地保证交易的安全性。

3.HMAC算法:HMAC算法是一种基于哈希函数的消息认证码算法,它可以验证消息的完整性和安全性,同时可以防止消息被篡改。HMAC算法在区块链技术中被广泛应用,可以保证数据的安全性和可靠性,同时可以防止数据被篡改。

总之,哈希加密算法在区块链技术中扮演着重要的角色,它可以保证数据的安全性、可靠性和不可篡改性,其中最常用的哈希函数有SHA256算法、RIPEMD-160算法和HMAC算法。


请查看相关英文文档

1. The cryptographic technology of blockchain includes

Cryptographic technology is the core of blockchain technology. The cryptographic technology of blockchain includes digital signature algorithm and hash algorithm.
Digital Signature Algorithm
Digital signature algorithm is a subset of the digital signature standard, representing a specific public key algorithm used only for digital signatures. The key is run on the message hash generated by SHA-1: to verify a signature, the hash of the message is recalculated, the signature is decrypted using the public key and the results are compared. The abbreviation is DSA.

Digital signature is a special form of electronic signature. So far, at least more than 20 countries have passed laws recognizing electronic signatures, including the European Union and the United States. my country's electronic signature law was adopted at the 11th meeting of the Standing Committee of the 10th National People's Congress on August 28, 2004. . A digital signature is defined in the ISO 7498-2 standard as: “Some data appended to a data unit, or a cryptographic transformation made to the data unit, which allows the recipient of the data unit to confirm the source and origin of the data unit. The integrity of the data unit and protects the data from forgery by a person (e.g. the recipient)”. The digital signature mechanism provides an identification method to solve problems such as forgery, denial, impersonation and tampering. It uses data encryption technology and data transformation technology to enable both parties to send and receive data to meet two conditions: the receiver can identify what the sender claims. Identity; the sender cannot later deny that it sent the data.
Digital signature is an important branch of cryptography theory. It is proposed to sign electronic documents to replace handwritten signatures on traditional paper documents, so it must have 5 characteristics.
(1) The signature is credible.
(2) The signature cannot be forged.
(3) Signatures are not reusable.
(4) Signed documents are immutable.
(5) The signature is non-repudiation.
Hash algorithm
Hash is to convert an input of any length (also called pre-mapping, pre-image) into a fixed-length output through a hash algorithm, and the output is a hash value. This transformation is a compressed mapping in which the space of hash values ​​is usually much smaller than the space of inputs. Different inputs may hash to the same output, but the input values ​​cannot be deduced in reverse. Simply put, it is a function that compresses a message of any length into a message digest of a fixed length.
Hash algorithm is a one-way cryptographic system, that is, it is an irreversible mapping from plaintext to ciphertext, with only encryption process and no decryption process. At the same time, the hash function can change an input of any length to obtain a fixed-length output. The one-way characteristics of the hash function and the fixed length of the output data allow it to generate messages or data.
Represented by the Bitcoin blockchain, secondary hashing is used many times in the workload proof and key encoding process, such as SHA (SHA256(k)) or RIPEMD160 (SHA256(K)). This method The benefit is that it increases the workload or increases the difficulty of cracking if the protocol is not clear.
Represented by the Bitcoin blockchain, the two main hash functions used are:
1. SHA-256, mainly used to complete PoW (proof of work) calculations;
2.RIPEMD160, mainly used to generate Bitcoin addresses. As shown in Figure 1 below, the process of generating an address from a public key for Bitcoin.

2. What is the blockchain cryptographic algorithm?

As an emerging technology, blockchain has received more and more widespread attention. It is a new transformation of traditional technology in the Internet era. Applications, including distributed data storage technology, consensus mechanisms and cryptography, etc. With the creation of various blockchain research alliances, related research has received more and more funding and personnel support. Hash algorithm, zero-knowledge proof, ring signature and other cryptographic algorithms used in the blockchain:

Hash algorithm

Hash algorithm is the basic technology of the blockchain. The essence of the Hash function is to A set of data of arbitrary length (finite) is mapped into a set of data streams of defined length. If this function satisfies both:

(1) The calculation of the Hash value of any input set of data is very simple;

(2) Think It is computationally difficult to find 2 different data with the same hash value.

Hash functions that satisfy the above two properties are also called cryptographic Hash functions. Unless there is any contradiction, the Hash function usually refers to the cryptographic Hash function. For the Hash function, finding such a value is called a collision. Currently popular Hash functions include MD5, SHA1, SHA2, and SHA3.

Bitcoin uses SHA256, and most blockchain systems use the SHA256 algorithm. So here we will introduce SHA256 first.

1. SHA256 algorithm steps

STEP1: Add padding bits. The message is padded so that the message length is congruent with 448 mod 512 (length = 448 mod 512). The number of padding bits ranges from 1 to 512. The highest bit of the padding bit string is 1 and the remaining bits are 0.

STEP2: Additional length value. Append the bit length of the initial message (before padding) expressed in 64-bit to the result of step 1 (low-order byte first).

STEP3: Initialize the cache. Use a 256-bit cache to store the intermediate and final results of the hash function.

STEP4: Processes 512-bit (16 words) message packet sequence. The algorithm uses six basic logic functions and consists of 64 steps of iterative operations. Each step takes a 256-bit cache value as input and then updates the cache content. Each step uses a 32-bit constant value Kt and a 32-bit Wt. Where Wt is the message after grouping, t=1,2,...,16.

STEP5: After all 512-bit packets are processed, the output generated by the last packet of the SHA256 algorithm is a 256-bit message.

2. Ring signature

In 2001, three cryptographers, Rivest, Shamir and Tauman, proposed the ring signature for the first time. It is a simplified group signature, with only ring members and no managers, and does not require cooperation among ring members. In the ring signature scheme, the signer first selects a temporary set of signers, which includes the signer. The signer can then use his own private key and the public keys of others in the signature set to generate signatures independently without the help of others. Members of a set of signers may not be aware that they are included.

The ring signature scheme consists of the following parts:

(1) Key generation. Generate a key pair (public key PKi, private key SKi) for each member in the ring.

(2) Signature. The signer uses his own private key and the public keys of any n ring members (including himself) to generate signature a for message m.

(3) Signature verification. The verifier verifies whether the signature is signed by a member of the ring based on the ring signature and message m. If it is valid, it will be accepted, otherwise it will be discarded.

The properties that ring signatures satisfy:

(1) Unconditional anonymity: The attacker cannot determine which member of the ring generated the signature, even after obtaining the ring member’s private In the case of key, the probability does not exceed 1/n.

(2) Correctness: The signature must be verified by all others.

(3) Unforgeability: Other members in the ring cannot forge the signature of the real signer. Even if an external attacker obtains a valid ring signature, he cannot forge a signature for message m.

3. Comparison between ring signature and group signature

(1) Anonymity. It is a system in which individuals sign on behalf of a group. The verifier can verify that the signature is signed by a member of the group, but cannot know which member, so as to achieve the anonymity of the signer.

(2) Traceability. In group signatures, the existence of the group administrator ensures the traceability of the signature. Group administrators can revoke signatures to reveal the true signer. The ring signature itself cannot reveal the signer unless the signer himself wants to reveal or add additional information to the signature. Proposed a verifiable ringSignature scheme, in which the real signer hopes that the verifier knows his identity. At this time, the real signer can confirm his identity by revealing the secret information he holds.

(3) Management system. Group signatures are managed by the group administrator, while ring signatures do not need to be managed. The signer only has to select a possible set of signers, obtain its public key, and then publish the set. All members are equal.

The Xueshuo Innovation Blockchain Technology Workstation under Lianqiao Education Online is the only approved "Smart Learning Factory 2020- Xueshuo Innovation Workstation" launched by the School Planning and Construction Development Center of the Ministry of Education of China. "Blockchain Technology Professional" pilot workstation. The professional position is based on providing students with diversified growth paths, promoting the reform of the training model integrating professional degree research, production, and research, and building an applied and compound talent training system.

3. What are the characteristics of the hash algorithm in the blockchain

The hash algorithm can be viewed as a small computer program, regardless of the size of the input data Regardless of the type, it can convert input data into fixed-length output. The hash algorithm can only accept the input of a single piece of data at any time and rely on the input data to create a hash value.
There are different hashing algorithms depending on the length of the final hash value.
The cryptographic hash algorithm used in the blockchain has the following characteristics:
1. Able to quickly create hash values ​​for any type of data
2. Deterministic
3. Pseudo-random
4. One-way function
5. Anti-collision

4. What is hash algorithm

Hash algorithm is also called " "Hashing" is one of the four core technologies of blockchain. It is an algorithm that can calculate a fixed-length string (also called message digest) corresponding to a digital message.

The hash algorithm is a one-way cryptographic mechanism in the blockchain that ensures that transaction information is not tampered with. Blockchain uses a hashing algorithm to encrypt transactions in a transaction block and compress the information into a hash string consisting of a series of numbers and letters.

The hash value of the blockchain can uniquely and accurately identify a block. When verifying the authenticity of a block, you only need to simply calculate the hash value of the block. If there is no change, it means that the information on the block has not been tampered with.

Related information:

The Xueshuo Innovation Blockchain Technology Workstation under Lianqiao Education Online is a "smart project" carried out by the School Planning, Construction and Development Center of the Ministry of Education of China. "Learning Workshop 2020-Executive Master Innovation Workstation" is the only approved "Blockchain Technology Professional" pilot workstation. The professional position is based on providing students with diversified growth paths, promoting the reform of the training model integrating professional degree research, production, and research, and building an applied and compound talent training system.

5. What is the hashing algorithm in the blockchain?

What is the hashing algorithm? How to protectProve the fairness of mining? The hash algorithm is a cryptographic algorithm that can only encrypt but cannot decrypt. It can convert information of any length into a fixed-length string. This string has two characteristics: 1. Even if the input value changes only a little, the output hash value will be completely different. 2. Only exactly the same input values ​​can get exactly the same output values. 3. There is no pattern between the input value and the output value, so the input value cannot be calculated from the output value. To find the specified output value, you can only use the enumeration method: constantly replace the input value and find the output value that meets the conditions. The hashing algorithm ensures that the results of Bitcoin mining cannot be reversed. Therefore, miners continue to perform calculations, essentially brute force the correct input value, and whoever finds it first will be rewarded with bitcoins.

6. Hash algorithm

1. The original data cannot be deduced reversely through the hash value (so the hash algorithm is also called one-way hash algorithm)
2 .It is very sensitive to the input data. If one bit is changed in time, the hash value is also very different
3. The probability of hash conflict should be small,
4. The execution efficiency should be high and the time will be long. Text, the hash value can be calculated as quickly as possible

The result of MD5 is 128 bits --> 32 hexadecimal strings

The hash algorithm most commonly used for encryption is MD5 (MD5 Message-Digest Algorithm, MD5 message digest algorithm) and SHA (Secure Hash Algorithm, secure hash algorithm)

By getting the encrypted ciphertext and then putting it in the dictionary table (rainbow table) By comparison, if the same ciphertext is found, the plaintext can be known.
You can add salt (add a string) to the user's password and then encrypt it and store it.

The blockchain is composed of blocks, and each block is divided into two parts: block header and block body.
The block header stores the hash value of its own block body and the previous block header.
Because of this chain relationship and the uniqueness of the hash value, as long as any block on the blockchain is modified, the hash values ​​saved in all subsequent blocks will be incorrect.
The blockchain uses the SHA256 hash algorithm. Calculating the hash value is very time-consuming. If you want to tamper with a block, you must recalculate the hash values ​​of all blocks following the block. In a short time Almost impossible to do.

Suppose we have k machines and the range of hash values ​​of data is [0, MAX]. We divide the entire range into m small intervals (m is much larger than k), and each machine is responsible for m/k small intervals. When a new machine is added, we will transfer the data between certain cells from the original machineMove to a new machine. In this way, there is no need to rehash and move all the data, and the balance of the amount of data on each machine is maintained.

7. What is the hash algorithm?

The hash algorithm is: a special function. No matter how long a string of characters is input, a fixed length can be obtained through this function. The output value is just like an ID number, which is always 18 digits and unique in the country.

The output value of the hash algorithm is called the hash value. The hashing algorithm, also known as "hash", is one of the four core technologies of the blockchain. It can calculate the fixed-length string corresponding to a digital message.

Principle:

The principle of the Hash algorithm is to map the value of the input space into the Hash space. Since the space of the Hash value is much smaller than the input space, And with the help of the drawer principle, it can be concluded that there must be situations where different inputs are mapped to the same output. If a Hash algorithm is good enough, then it will have a smaller probability of conflict. In other words, a good Hash algorithm will have a smaller probability of conflict. The Hash algorithm should have excellent anti-collision capabilities.

8. What is the hash algorithm?

The hash algorithm is a special function. No matter how long a string of characters is input, a fixed value can be obtained through this function. The output value of the length is just like an ID number, which is always 18 digits and unique in the country. The output value of the hash algorithm is called the hash value.

Principle:

The hash algorithm has three characteristics, which endow the blockchain with features such as non-tamperability and anonymity, and ensure that the entire blockchain System integrity.

The first characteristic is that it is one-way. For example, if you input a string of data, you can get a hash value through the hash algorithm, but there is no way to get the input string of data back through this hash value. This is one-way, and it is precisely based on this that the blockchain effectively protects the security of our information.

The second characteristic of the hash algorithm is its anti-tampering ability. For any input, even a small change will cause a very large change in the hash value.

This characteristic of it plays a key role in the connection between blocks. Each block of the blockchain is marked by the hash value of the previous block. Unless someone can crack all the hashes on the entire chain, it is impossible to tamper with the data once it is recorded on the chain.

The third characteristic of the hash algorithm is its anti-collision capability. The so-called collision is to input two different data and finally get the same input.

Just like when we go shopping, collision means that most inputs can get a unique output. In the world of blockchain, the address of any transaction or account is completely generated based on the hash algorithm. This also ensures that the transaction or account address is unique in the blockchain networksex.

No matter how much money is transferred or how many people are transferred to this transfer, it will only exist in the big ledger of the blockchain. It is like white blood cells in the human body. Not only is every part of the blockchain inseparable from it, but it also gives the blockchain various characteristics and protects the security of the entire blockchain system.

9. Blockchain: Tamper-proof Hash Encryption Algorithm

Students A and B toss a coin in the classroom and bet on who will clean the house. If heads come up, A will clean. If the tail is up, then B sweeps. There is nothing wrong with this strategy.

However, if the scenario is transferred to an online chat room, and A and B also play a coin-tossing game, B will probably not agree, because when A tosses a coin, B will not guess.

Heads or tails, A can say that B guessed wrong.

How to solve this problem? How about encrypting the result of the coin toss first, and then B guesses? You can try this method.

Assume that any odd number represents the front side of the coin, and any even number represents the tail side. A wants a number 375, then multiplies it by 258, tells B the result is 96750, and declares that the 375 A wants is the key, which he keeps for safekeeping.
When verifying the result next, A can lie and claim that 258 is the number he wants and 375 is the key, and A is still invincible. What if A tells B the key in advance? B can directly calculate the original number, losing the confidentiality function.

This method of knowing the encryption method and knowing the decryption method obviously does not work. Is there a way to know the encryption method and still not be able to recover the original text?

Obviously there is, it is OK to add irreversible operations to the encryption process. A designs a new encryption method:

Assume that the number A wants is 375 and encrypts it:

B gets the result 120943, but he can hardly calculate the key 375 based on 120943.
If B wants to verify whether A is lying:

Finally, he can flip a coin...

This encryption method that loses part of the information is called "one-way encryption". Also called hash algorithm.

There is a problem:

This is possible, but it can be solved by increasing the difficulty of the above algorithm so that A is difficult to find.

According to the above statement, a reliable hash algorithm should satisfy:

The hash function in cryptography has three important properties, namely collision resistance and irreversibility of the preimage. , problem friendliness.

Collision means that student A can find out an odd and an even number in advance to make the hash results consistent, which is computationally infeasible.

First of all, if the news about the large space sauna is compressed into a small space, there will definitely be a collision. Assuming that the length of the hash value is fixed to 256 bits, if the order is 1,2,...2 256 +1, these 2 256 +1 input values, calculate their hash values ​​one by one, you will definitely find two input values ​​whose hash values ​​are the same.

Student A, when you see this, please don’t be too happy too soon. Because you have to have time to figure it out before it's yours. Why do you say that?

According to the birthday paradox, if 2 130 +1 inputs are randomly selected, there is a 99.8% probability of finding at least one pair of collision inputs. Then for a hash function with a hash value length of 256 bits, an average of 2128 hash calculations need to be completed to find the collision pair. If a computer performed 10,000 hash calculations per second, it would take approximately 10 27 years to complete 2 128 hash calculations.

Student A, don’t think about cheating. You probably won’t live this long. Of course, it is possible if computer computing power is greatly improved.

So what other uses does integrity have?

Used to verify the integrity of the information, because if the information is not tampered with during transmission, the hash value obtained by running the hash calculation will be different from the original hash value.

Therefore, in the blockchain, the collision resistance of the hash function can be used to verify the integrity of blocks and transactions.

Because a hash value corresponds to countless plaintexts, theoretically you don't know which one it is. For example, the results of 4+5=9 and 2+7=9 are the same. I know that the result I entered is 9, but can I know what number I entered?

If, when performing hash calculation on message m, a random prefix r is introduced, and based on the hash value H(r||m), it is difficult to recover message m, which means that the hash function The value hides message m.

Therefore, student B, it is impossible to deduce the original data based on the results. It is like finding a needle in a haystack.

Problem friendliness means that there is no convenient way to generate a hash value that meets special requirements. What does it mean? In layman's terms, there is no shortcut, you need to figure it out step by step. If the required hash result starts with several 0s, then the number of hash calculations required to find a hash value with the first 3 digits all being 0 and a hash value with the first 6 digits all being 0 is a certain number. Quantitative relationship.

How can this be used? In the blockchain, it can be used as proof of work in the consensus algorithm.

Mainly describes three important properties of the hash function: collision resistance, preimage irreversibility, and problem friendliness.

Because of these important properties, functions such as integrity verification of blocks and transactions in the blockchain and workload proof of the consensus algorithm are implemented using hash functions.

[1]. Zou Jun, Zhang Haining. Blockchain Technology Guide [M]. Beijing: Mechanical Press, 2016.11
[2]. Chang Chai, Han Feng. Blockchain from digital currency to credit society [M]. Beijing: CITIC Press, 2016.7
[3]. Zhang Jian. Blockchain defines the new future financial and economic landscape [M]. Beijing: Machinery Industry Publishing House, 2016.6

博客主人唯心底涂
男,单身,无聊上班族,闲着没事喜欢研究股票,无时无刻分享股票入门基础知识,资深技术宅。
  • 37417 文章总数
  • 3637283访问次数
  • 3079建站天数