比特币(BSV)知识库:比特币协议-RIPEMD-160

特别提示:

比特币(BSV)知识库-Bitcoin wiki-目前为全英文内容,暂无中文译文,并且仍在持续编写和补充中。欢迎中国的开发者在文章底部评论,进行阐述和探讨。

比特币(BSV)知识库:比特币协议-RIPEMD-160_第1张图片

RIPEMD-160

RIPEMD-160 is a cryptographic hash function based upon the Merkle–Damgård construction. It is used in the Bitcoin standard. It is a a strengthened version of the RIPEMD algorithm which produces a 128 bit hash digest while the RIPEMD-160 algorithm produces a 160-bit output. The compression function is made up of 80 stages made up of 5 blocks that run 16 times each. This pattern runs twice with the results being combined at the bottom using modulo 32 addition.

Padding

The compression function works upon 16 32-bit unsigned words. This requires the message to be padded to a multiple of 512 bits and the byte stream input to be padded into 32-bit words. The padding scheme is identical to MD4 using Merkle–Damgård strengthening to prevent length extension attacks. This consists of a one being added to the end of the message and the length of the message (in bits) being added to the end of the block. The bytes are pushed into the word low end first. Here are 4 examples of messages being padded into a word to show the possible patterns for different message lengths:

比特币(BSV)知识库:比特币协议-RIPEMD-160_第2张图片

The length of the message should then be added to the second to last element (the length is saved a 64-bit value across the last 2 words, but it is unlikely the message will be this long; 32-bits will certainly suffice for Bitcoin software.)

Compression Function

The compression function is made up of a variable sub block that the message block is passed though 16 times. There are 5 different variations for a total of 80 runs. This process occurs twice with the data meeting at the bottom to be moved on to the next block (if there is one) or added to the hash register is there isn't. The sub block can be varied by the design of a nonlinear function, the order in which the message block is read in per round, the amount of a left rotate and a k constant. The design of the sub block and the overall layout of the compression function is shown to the right.

比特币(BSV)知识库:比特币协议-RIPEMD-160_第3张图片

Sub block of the compression function.

比特币(BSV)知识库:比特币协议-RIPEMD-160_第4张图片

The full compression function.

 

Pseudocode for the process:

比特币(BSV)知识库:比特币协议-RIPEMD-160_第5张图片

The nonlinear functions are applied in the opposite directions up and down the left and right lines. The design of the functions from top to bottom on the left and bottom to top on the right are (Java syntax for operations):

  1. x ^ y ^ z
  2. (x & y) | (~x & z)
  3. (x | ~y) ^ z
  4. (x & z) | (y & ~z)
  5. z ^ (y | ~z)

The k values for left from top to bottom are:

  1. 0x00000000
  2. 0x5A827999
  3. 0x6ED9EBA1
  4. 0X8F1BBCDC
  5. 0XA953FD4E

The k values for right from top to bottom are:

  1. 0x50A28BE6
  2. 0x5C4DD124
  3. 0x6D703EF3
  4. 0x7A6D76E9
  5. 0x00000000

The order in which the words should be selected from the block array X for the left hand side are (each sub array within the 2D array represents a round. The array at the top represents the round at the top and the array at the bottom represents the round at the bottom):

比特币(BSV)知识库:比特币协议-RIPEMD-160_第6张图片

The order in which the words should be selected from the array X for the right hand side are (following the same pattern as above):

比特币(BSV)知识库:比特币协议-RIPEMD-160_第7张图片

The order of the left rotates on the left hand side are:

比特币(BSV)知识库:比特币协议-RIPEMD-160_第8张图片

The order of the left rotates on the right hand side are:

比特币(BSV)知识库:比特币协议-RIPEMD-160_第9张图片

Attribution

This content is based on content sourced from https://en.bitcoin.it/wiki/RIPEMD-160 under Creative Commons Attribution 3.0. Although it may have been extensively revised and updated we acknowledge the original authors.

 声明:

比特币(BSV)知识库项目由比特币协会(Bitcoin Association)发起并支持,更多信息请参见知识库官网:https://wiki.bitcoinsv.io/

你可能感兴趣的:(Bitcoin,wiki)