Data storage method, server, medium and device
Through the padding expansion and hash calculation method of the SHA-1 algorithm, a buffer identifier related to the input information and constants is generated, which solves the problem of SHA-1 being broken, improves the security of the ciphertext, and enhances the block The security of the input information characteristic value of the chain.
Patent Information
- Application Number
- CN202111404029.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-24
- Publication Date
- 2024-08-23
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
With the development of computer computing power, the existing SHA-1 algorithm has been broken. How to enhance SHA-1 to improve its security.
By padding the length of the input information to 512 bits, dividing it into multiple data blocks, and using preset constants and formulas to perform hash calculations, buffer identifiers H0, H1, H2, and H2 related to the input information and constants are generated. The H3 and H4 values form a 160-bit hash value to be stored in the blockchain.
The security of the ciphertext is improved, making brute force cracking more difficult and reducing the attacker's likelihood of success.
Smart Images

Figure CN114091117B
Abstract
Description
Technical Field
[0001] The present application relates to the field of blockchain technology, and more specifically, to data storage methods, servers, media and devices. Background Art
[0002] SHA-1 (Secure Hash Algorithm) is a function that generates 160-bit ciphertext and is widely used in the prior art. However, with the continuous development of computer computing power, security personnel have successfully cracked the SHA-1 algorithm.
[0003] Therefore, how to enhance and strengthen the existing SHA-1 is an inevitable requirement for technological development. Summary of the invention
[0004] In view of this, the present application provides a data storage method, server, medium and device.
[0005] To achieve the above objectives, this application provides the following technical solutions:
[0006] According to a first aspect of an embodiment of the present disclosure, there is provided a data storage method, including:
[0007] Get the input information to be stored in the blockchain;
[0008] The length of the input information is padded and expanded to 512 bits*Q to obtain a first message, where Q is any integer greater than or equal to 1;
[0009] Dividing the first message into Q data blocks, the number of bits of the data blocks is 512 bits;
[0010] Set the initial value of G to 1;
[0011] For the Gth data block, perform the following operations:
[0012] Dividing the data block into 16 target sub-data blocks, the number of bits of the target sub-data blocks is 32 bits;
[0013] Performing operations on the 16 target sub-data blocks to obtain 64 operation sub-data blocks to obtain 80 sub-data blocks, wherein the number of bits of the operation sub-data blocks is 32 bits, and the 80 sub-data blocks include the 16 target sub-data blocks and the 64 operation sub-data blocks;
[0014] Get 80 preset constants, the values of which are as follows:
[0015] K t = first preset value (0<=t<=19)
[0016] Kt = second preset value (20<=t<=39)
[0017] K t = third preset value (40<=t<=59)
[0018] K t = fourth preset value (60<=t<=79);
[0019] Set the initial value of i to 1;
[0020] For the i-th preset value, convert the i-th preset value into a decimal number to obtain a first character string consisting of the decimal number;
[0021] Using the formula Get the second string; where b m is the character at position m in the second string, b1 is the character at position 1 in the second string, and b1=a1; a v is the character at position v in the first string, P(a v ) refers to a v The probability of appearing in the first string, n refers to the total number of characters contained in the first string, a v _number refers to a v the number of times it appears in the first string;
[0022] Using the formula To get the third string, where c m+1 is the character at position m+1 in the third string;
[0023] Convert the obtained third character string into hexadecimal to obtain the i-th candidate value;
[0024] Let the i-th preset value = the i-th candidate value mod 0xFFFFFFFF;
[0025] Set i=i+1, return to step 1, and for the i-th preset value, convert the i-th preset value into a decimal number to obtain a first character string consisting of the decimal numbers, until i is equal to 5;
[0026] Get the initial value of the buffer identifier H0, the initial value of H1, the initial value of H2, the initial value of H3, and the initial value of H4;
[0027] Assign the initial value of H0, the initial value of H1, the initial value of H2, the initial value of H3, and the initial value of H4 to the first parameter, the second parameter, the third parameter, the fourth parameter, and the fifth parameter, respectively;
[0028] Set the initial value of P to 0;
[0029] For t = P, the following calculation is performed:
[0030] TEMP=S5(H0)+f t (H1,H2,H3)+H4+W t +K t ; H4=H3; H3=H2; H2=S 30 (H1); H1 = H0; H0 = TEMP; where W t is the t+1th sub-data block among the 80 sub-data blocks, f t (H1, H2, H3) is a pre-set function; S5(H0) means shifting H0 left by 5 bits; S 30 (H1) means shifting H1 left by 30 bits;
[0031] Set P=P+1, return to step t=P, and perform the following calculations until P is equal to 80 to obtain the values of the buffer identifiers H0, H1, H2, H3, and H4;
[0032] Let the final value of H0 = the value of H0 + the first parameter, the final value of H1 = the value of H1 + the second parameter, the final value of H2 = the value of H2 + the third parameter, the final value of H3 = the value of H3 + the fourth parameter, and the final value of H4 = the value of H4 + the fifth parameter;
[0033] The final value of H0, the final value of H1, the final value of H2, the final value of H3, and the final value of H4 are used as the initial value of H0, the initial value of H1, the initial value of H2, the initial value of H3, and the initial value of H4 of the buffer corresponding to the G+1th data block, respectively;
[0034] Set G=G+1, return to step 1 and perform the following operations on the Gth data block until G is greater than Q;
[0035] In the order of H0, H1, H2, H3, H4, the final value of H0, the final value of H1, the final value of H2, the final value of H3, and the final value of H4 form a 160-bit hash value;
[0036] Based on the 160-bit hash value, a ciphertext is obtained;
[0037] The ciphertext is stored in the blockchain.
[0038] According to a second aspect of an embodiment of the present disclosure, there is provided a data storage device, including:
[0039] A first acquisition module, used to acquire input information to be stored in the blockchain;
[0040] A padding and expansion module, used for padding and expanding the length of the input information to 512 bits*Q to obtain a first message, where Q is any integer greater than or equal to 1;
[0041] A first division module, used for dividing the first message into Q data blocks, the number of bits of the data blocks is 512 bits;
[0042] A first setting module, used to set the initial value of G to 1;
[0043] For the Gth data block, perform the following operations:
[0044] A second division module is used to divide the data block into 16 target sub-data blocks, and the number of bits of the target sub-data blocks is 32 bits;
[0045] A calculation module, used for performing calculation on the 16 target sub-data blocks to obtain 64 calculation sub-data blocks, so as to obtain 80 sub-data blocks, wherein the number of bits of the calculation sub-data blocks is 32 bits, and the 80 sub-data blocks include the 16 target sub-data blocks and the 64 calculation sub-data blocks;
[0046] The second acquisition module is used to obtain 80 preset constants, and the values of the 80 constants are as follows:
[0047] K t = first preset value (0<=t<=19)
[0048] K t = second preset value (20<=t<=39)
[0049] K t = third preset value (40<=t<=59)
[0050] K t = fourth preset value (60<=t<=79);
[0051] A first setting module, used to set the initial value of i to 1;
[0052] A first conversion module, configured to convert an i-th preset value into a decimal number to obtain a first character string consisting of the decimal number;
[0053] The third acquisition module is used to use the formula Get the second string; where b m is the character at position m in the second string, b1 is the character at position 1 in the second string, and b1=a1; a v is the character at position v in the first string, P(av ) refers to a v The probability of appearing in the first string, n refers to the total number of characters contained in the first string, a v _number refers to a v the number of times it appears in the first string;
[0054] The fourth acquisition module is used to use the formula To get the third string, where c m+1 is the character at position m+1 in the third string;
[0055] A second conversion module, used for converting the obtained third character string into hexadecimal to obtain an i-th candidate value;
[0056] The second setting module is used to set the i-th preset value = the i-th candidate value mod 0xFFFFFFFF;
[0057] A first trigger module, configured to set i=i+1 and return to the first conversion module until i is equal to 5;
[0058] A fifth acquisition module, used to acquire an initial value of the identifier H0 of the buffer, an initial value of H1, an initial value of H2, an initial value of H3, and an initial value of H4;
[0059] A second assignment module, used for assigning the initial value of H0, the initial value of H1, the initial value of H2, the initial value of H3, and the initial value of H4 to the first parameter, the second parameter, the third parameter, the fourth parameter, and the fifth parameter, respectively;
[0060] The third assignment module is used to set the initial value of P to 0;
[0061] The calculation module is used to perform the following calculation for t=P:
[0062] TEMP=S5(H0)+f t (H1,H2,H3)+H4+W t +K t ; H4=H3; H3=H2; H2=S 30 (H1); H1 = H0; H0 = TEMP; where W t is the t+1th sub-data block among the 80 sub-data blocks, f t (H1, H2, H3) is a pre-set function; S5(H0) means shifting H0 left by 5 bits; S 30 (H1) means shifting H1 left by 30 bits;
[0063] The second trigger module is used to set P=P+1 and return to the calculation module until P is equal to 80 to obtain the values of the identifiers H0, H1, H2, H3 and H4 of the buffer;
[0064] The fourth assignment module is used to make the final value of H0 = the value of H0 + the first parameter, the final value of H1 = the value of H1 + the second parameter, the final value of H2 = the value of H2 + the third parameter, the final value of H3 = the value of H3 + the fourth parameter, and the final value of H4 = the value of H4 + the fifth parameter;
[0065] a fifth assignment module, used to use the final value of H0, the final value of H1, the final value of H2, the final value of H3, and the final value of H4 as the initial value of H0, the initial value of H1, the initial value of H2, the initial value of H3, and the initial value of H4 of the buffer corresponding to the G+1th data block, respectively;
[0066] A third trigger module is used to set G=G+1 and return to the second division module until G is greater than Q;
[0067] a sixth acquisition module, configured to determine, in the order of H0, H1, H2, H3, and H4, a 160-bit digest consisting of a final value of H0, a final value of H1, a final value of H2, a final value of H3, and a final value of H4 as a ciphertext;
[0068] A storage module is used to store the ciphertext in a blockchain.
[0069] According to a third aspect of an embodiment of the present disclosure, a server is provided, including:
[0070] processor;
[0071] a memory for storing instructions executable by the processor;
[0072] Wherein, the processor is configured to execute the instructions to implement the data storage method as described in the first aspect.
[0073] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided. When instructions in the storage medium are executed by a processor of a server, the server is enabled to execute the data storage method as described in the first aspect.
[0074] According to the fifth aspect of the embodiment of the present disclosure, a computer program product is provided, which can be directly loaded into the internal memory of a computer, wherein the memory is the memory included in the server shown in the third aspect and contains software code, and the computer program can implement the data storage method described in the first aspect after being loaded and executed by the computer.
[0075] It can be seen from the above technical solution that the data storage method provided by the present application, after obtaining the preset 80 constants, performs the following processing on each constant: converting the constant from hexadecimal to decimal to obtain a first character string consisting of the decimal number; using the formula Get the second string; where b m is the character at position m in the second string, b1 is the character at position 1 in the second string, and b1=a1; a v is the character at position v in the first string, P(a v ) refers to a v The probability of appearing in the first string, n refers to the total number of characters contained in the first string, a v _number refers to a v The number of times it appears in the first string; using the formula To get the third string, where c m+1 is the character at the m+1th position in the third character string; convert the obtained third character string into hexadecimal to obtain a candidate value; let the constant = candidate value mod 0xFFFFFFFF, thereby reassigning the constant to obtain the reassigned constant 80. The values of H0, H1, H2, H3, and H4 obtained based on the 80 re-assigned constants are different from the values of H0, H1, H2, H3, and H4 obtained based on the 80 pre-set constants. In this application, if the input information is divided into multiple data blocks, then in the process of calculating the next data block, the initial value of the identifier H0, the initial value of H1, the initial value of H2, the initial value of H3, and the initial value of H4 of the buffer corresponding to the next data block are the final value of H0, the final value of H1, the final value of H2, the final value of H3, and the final value of H4 obtained from the previous data block, that is, the specific content of the obtained ciphertext, which is not only related to the number of data blocks into which the input information is divided, but also to the 80 re-assigned constants. If brute force cracking is required, it is necessary to try to crack the number of data blocks into which the input information is divided, as well as the 80 re-assigned constants. Compared with the prior art, brute force cracking is more difficult, thereby improving the security of the ciphertext. BRIEF DESCRIPTION OF THE DRAWINGS
[0076] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0077] Figure 1 A structural diagram of a blockchain device provided in an embodiment of the present application;
[0078] Figure 2 A structural diagram of the blockchain provided in the embodiment of the present application;
[0079] Figure 3 A flowchart of a data storage method provided in an embodiment of the present application;
[0080] Figures 4a to 4c , which is a schematic diagram of input information filling and expansion provided in an embodiment of the present application;
[0081] Figure 5 The schematic diagram of sorting a data block into 16 target sub-data blocks is shown;
[0082] Figure 6 A structural diagram of a data storage device provided in an embodiment of the present application;
[0083] Figure 7 The invention is a block diagram showing a device for a server according to an exemplary embodiment. DETAILED DESCRIPTION
[0084] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0085] The embodiments of the present application provide a data storage method, device, server, medium and product. Before introducing the technical solution provided by the embodiments of the present application, the application environment involved in the embodiments of the present application is first described.
[0086] like Figure 1 , which is a structural diagram of a blockchain device provided in an embodiment of the present application.
[0087] The blockchain device includes multiple nodes 11, which can be electronic devices or servers.
[0088] Exemplarily, the electronic device can be any electronic product that can interact with a user through one or more methods such as a keyboard, touchpad, touch screen, remote control, voice interaction or handwriting device, for example, a mobile phone, a laptop computer, a tablet computer, a PDA, a personal computer, a wearable device, a smart TV, a PAD, etc.
[0089] Exemplarily, the server may be a single server, a server cluster consisting of multiple servers, or a cloud computing server center. The server may include a processor, a memory, a network interface, and the like.
[0090] The blockchain device includes multiple nodes that respectively store an identical blockchain.
[0091] For any node among the multiple nodes, the node stores the node identifiers of other nodes in the blockchain device, so that the generated block can be broadcast to other nodes in the blockchain device according to the identifiers of other nodes.
[0092] In order to enable those skilled in the art to better understand the embodiments of the present application, the structure of the blockchain is introduced in detail below.
[0093] like Figure 2 As shown in Figure 1, the blockchain consists of multiple blocks. The genesis block includes a block header and a block body. The block header stores input information feature values, version numbers, timestamps, and difficulty values, and the block body stores input information. The next block of the genesis block uses the genesis block as its parent block. The next block also includes a block header and a block body. The block header stores the input information feature values of the current block, the block header feature values, version numbers, timestamps, and difficulty values of the parent block, and so on. This ensures that the block data stored in each block in the blockchain is associated with the block data stored in the parent block, ensuring the security of the input information in the block.
[0094] When generating each block in the blockchain, the node where the blockchain is located needs to perform SHA-1 algorithm calculation on the input information when receiving the input information, and store the obtained 160-bit ciphertext as the characteristic value of the input information in the block header. After obtaining the block body and block header, the current block is obtained. Subsequently, the node where the blockchain is located sends the newly generated block to other nodes according to the node identification of other nodes, and other nodes verify the newly generated block and add the newly generated block to the blockchain stored in it after completing the verification.
[0095] With the continuous development of computer computing power and the accumulation of collision cipher libraries in the application of the SHA-1 algorithm, the ciphertext generated by the SHA-1 algorithm may be cracked by brute force. If the SHA-1 algorithm is replaced with other algorithms, such as the SHA-2 algorithm, to prevent the ciphertext generated by it from being cracked by brute force, but the SHA-2 algorithm generates 256-bit ciphertext, which is different from the 160-bit ciphertext generated by the SHA-1 algorithm. This improvement will affect the interface and message format, increase the cost of transformation, and is more difficult.
[0096] The embodiment of the present application provides a method for improving SHA-1, so that the length of the ciphertext obtained by the improved SHA-1 algorithm remains 160 bits, thereby eliminating the need to improve the interface and message format, thereby reducing the transformation cost.
[0097] The data storage method provided in the embodiment of the present application can be applied to any application scenario using SHA-1, for example, the calculation scenario of the characteristic value of bank transaction data. The input information is different in different application scenarios. For example, in the calculation scenario of the characteristic value of bank transaction data, the input information is transaction data.
[0098] The data storage method provided in the embodiment of the present application is described below.
[0099] like Figure 3 As shown, it is a flowchart of the data storage method provided in an embodiment of the present application, and the method includes the following steps S301 to S326.
[0100] Step S301: Obtain input information to be stored in the blockchain.
[0101] Exemplarily, the input information may be transaction data, such as transfer transaction data.
[0102] Step S302: padding the length of the input information to 512 bits*Q to obtain a first message, where Q is any integer greater than or equal to 1.
[0103] There are multiple ways of filling and expanding provided in the embodiments of the present application. The embodiments of the present application provide but are not limited to the following three.
[0104] The first implementation of step S302 includes steps A11 to A14.
[0105] Step A11: Add a 1 at the end of the input information.
[0106] Exemplarily, the input information is binary data.
[0107] For example, if the length of the input information is an integer multiple of 512, then there is no need to perform a padding and expansion operation; if the length of the input information is not an integer multiple of 512, then a padding and expansion operation is required.
[0108] Step A12: Add 0 after the 1 in the input information until the length of the second message after the addition is 448 modulo 512.
[0109] For example, if the remainder after taking the length of the input information modulo 512 is 448, then steps A11 to A12 may not be performed. If the remainder after taking the length of the input information modulo 512 is not 448, then steps A11 to A12 may be performed.
[0110] Step A13: Add a 1 at the end of the second message.
[0111] Step A14: add 63 zeros after the 1 in the second message to obtain the first message.
[0112] In order for those skilled in the art to better understand the implementation of the first step S302, an example is given below.
[0113] like Figure 4a As shown, it is a schematic diagram of the input information filling and expansion provided in an embodiment of the present application.
[0114] Assuming that the length of the input information is 600 bits, the modulo remainder of the input information to 512 is 88, and a 1 and 359 0s are added to the input information to obtain the second message. A 1 and 63 0s are added to the second message to obtain the first message.
[0115] The second implementation of step S302 includes steps A21 to A23.
[0116] Step A21: Add a 1 at the end of the input information.
[0117] Exemplarily, the input information is binary data.
[0118] For example, if the length of the input information is an integer multiple of 512, then there is no need to perform a padding and expansion operation; if the length of the input information is not an integer multiple of 512, then a padding and expansion operation is required.
[0119] Step A22: Add 0 after the 1 in the input information until the length of the second message after the addition is 448 modulo 512.
[0120] For example, if the remainder after the length of the input information is modulo 512 is 448, then steps A21 to A22 may not be performed. If the remainder after the length of the input information is modulo 512 is not 448, then steps A21 to A22 may be performed.
[0121] Step A23: Add 64 ones to the end of the second message to obtain the first message.
[0122] In order for those skilled in the art to better understand the implementation of the second step S302, an example is given below.
[0123] like Figure 4b As shown, it is a schematic diagram of the input information filling and expansion provided in an embodiment of the present application.
[0124] Assuming that the length of the input information is 600 bits, the modulo remainder of the input information to 512 is 88, a 1 and 359 0s are added to the input information to obtain the second message. After 64 1s are added to the second message, the first message is obtained.
[0125] The third implementation of step S302 includes step A31 to step A32.
[0126] Step A31: Add a 1 at the end of the input information.
[0127] Exemplarily, the input information is binary data.
[0128] For example, if the length of the input information is an integer multiple of 512, then there is no need to perform a padding and expansion operation; if the length of the input information is not an integer multiple of 512, then a padding and expansion operation is required.
[0129] Step A32: Add 0 after the 1 in the padded position of the input information until the remainder of the length of the first message after the padded position is 0 after taking the modulus of 512, so as to obtain the first message.
[0130] In order for those skilled in the art to better understand the implementation of the third step S302, an example is given below.
[0131] like Figure 4c As shown, it is a schematic diagram of input information filling and expansion provided in an embodiment of the present application.
[0132] Assume that the length of the input information is 600 bits, and the remainder of the input information modulo 512 is 88. Then, 1 1 and 423 0s are added after the input information to obtain the first message.
[0133] Step S303: Divide the first message into Q data blocks, where the number of bits of the data blocks is 512 bits.
[0134] by Figures 4a to 4c For example, Q=2.
[0135] Exemplarily, in the embodiment of the present application, the first message is divided into Q data blocks, and one data block is obtained for every 512 bits of data obtained starting from the header of the first message.
[0136] Step S304: Set the initial value of G to 1.
[0137] Step S305: Perform the following operations for the Gth data block:
[0138] Step S306: Divide the data block into 16 target sub-data blocks, and the number of bits of the target sub-data blocks is 32 bits.
[0139] Step S307: perform operations on the 16 target sub-data blocks to obtain 64 operation sub-data blocks to obtain 80 sub-data blocks, the bit number of the operation sub-data blocks is 32 bits, and the 80 sub-data blocks include 16 target sub-data blocks and 64 operation sub-data blocks.
[0140] Step S308: Obtain 80 preset constants, the values of which are as follows:
[0141] K t = first preset value (0<=t<=19)
[0142] K t = second preset value (20<=t<=39)
[0143] K t = third preset value (40<=t<=59)
[0144] K t = fourth preset value (60<=t<=79).
[0145] In an optional implementation, the 80 constants corresponding to different data blocks may be different, for example, the corresponding relationship between the 16 target sub-data blocks obtained in step S306 and the 80 constants may be preset, that is, the 80 constants may be different for different data blocks.
[0146] In an optional implementation, the 80 constants corresponding to different input information may be different, for example, the corresponding relationship between the input information and the 80 constants may be preset, that is, the 80 constants may be different depending on the input information.
[0147] In an optional implementation, the 80 constants corresponding to different data blocks may be the same.
[0148] In an optional implementation, the first preset value is 0x5A827999, the second preset value is 0x6ED9EBA1, the third preset value is 0x8F1BBCDC, and the fourth preset value is 0xCA62C1D6.
[0149] Exemplarily, the 80 sub-data blocks include, in sequence: 16 target sub-data blocks and 64 operation sub-data blocks.
[0150] The order of the 16 target sub-data blocks is: sorted according to the order in which the target sub-data blocks are obtained by dividing the data blocks.
[0151] like Figure 5 As shown, it is a schematic diagram of sorting that a data block is divided into 16 target sub-data blocks.
[0152] Starting from the head of the data block, each time 32 bits of data are extracted to obtain a target sub-data block, the target sub-data block 1, the target sub-data block 2, the target sub-data block 3, the target sub-data block 4, ..., the target sub-data block 16 can be obtained in sequence. The order of the above 16 target sub-data blocks is: target sub-data block 1, target sub-data block 2, target sub-data block 3, target sub-data block 4, ..., target sub-data block 16.
[0153] In an optional implementation, there are multiple implementations of step S307. The embodiment of the present application provides but is not limited to the following implementation. The method includes steps B11 to B14.
[0154] Step B11: Set the initial value of R to 0.
[0155] Step B12: Let t = R, and perform the following operations:
[0156] Step B13: W t =M t (0≤t<16), where M t is the t+1th target sub-data block; W t =S1(W t-3 XOR W t-14 XOR W t-16 )(16≤t≤79); where S1 refers to shifting left by 1 bit.
[0157] Step B14: Set R=R+1, and return to step B12 until R equals 80.
[0158] The above 80 sub-data blocks are: W0, W1, W2, W3, ..., W 79 .
[0159] In an optional implementation, at least one of the 16 target sub-data blocks may be subjected to a logic operation to obtain 64 operation sub-data blocks. The above-mentioned XOR operation is not limited.
[0160] Step S309: Set the initial value of i to 1.
[0161] Step S310: For the i-th preset value, convert the i-th preset value into a decimal number to obtain a first character string consisting of the decimal numbers.
[0162] It can be understood that, since the first character string is a decimal number, the characters contained in the first character string are characters from 0 to 9.
[0163] Step S311: Using formula Get the second string; where b mis the character at position m in the second string, b1 is the character at position 1 in the second string, and b1=a1; a v is the character at position v in the first string, P(a v ) refers to a v The probability of appearing in the first string, n refers to the total number of characters contained in the first string, a v _number refers to a v The number of times it occurs in the first string.
[0164] In an embodiment of the present application, the specific value of the character at the m+1th position in the second character string is set to be related to the character at the mth position. The second character obtained in this way has strong randomness and perturbation, which increases the strength and complexity of the algorithm, thereby achieving reinforced optimization of the SHA-1 algorithm.
[0165] If the input information is different, the first character string will also be different. If the characters in the first character string change by one or more bits, the method for obtaining the second character string provided by the present application will cause at least 1 / 2 of the characters in the obtained second character string to change significantly, i.e., the avalanche effect of the algorithm, thereby significantly enhancing the complexity of the password, making it almost impossible to achieve brute force cracking with the existing computing power, and the cost of brute force cracking increases dramatically.
[0166] The following example illustrates the process of obtaining the second character string.
[0167] For example, if the first string consists of 10 characters, they are: a1, a2, a3, a4, a5, a6, a7, a8, a9, a 10 .
[0168] Assume that a1=1, a2=2, a3=3, a4=4, a5=5, a6=6, a7=7, a8=8, a9=9, a 10 =0, then P(a1)=P(a2)=P(a3)=P(a4)=P(a5)=P(a6)=P(a7)=P(a8)=P(a9)=P(a 10 )=0.1.
[0169] b1=a1=1;
[0170]
[0171]
[0172]
[0173]
[0174]
[0175]
[0176]
[0177]
[0178]
[0179] Then the second string is {1,0.1,0.01,0.001,0.0001,0.00001,0.000001,0.0000001,0.00000001,0.000000001}
[0180] Step S312: Using the formula:
[0181] To get the third string, where c m+1 It is the character at position m+1 in the third string.
[0182] Mod refers to the remainder function.
[0183] Still taking the above example, Then the characters in the third string are:
[0184] c1=(100000000 0 *b1) mod 10 = 1;
[0185] c2=(100000000 1 * b2) mod 10 = 0;
[0186] c3=(100000000 2 * b2) mod 10 = 0;
[0187] c4=(100000000 3 * b2) mod 10 = 0;
[0188] c5=(100000000 4 * b2) mod 10 = 0;
[0189] c6=(100000000 5 * b2) mod 10 = 0;
[0190] c7=(100000000 6 * b2) mod 10 = 0;
[0191] c8=(100000000 7 * b2) mod 10 = 0;
[0192] c9=(100000000 8 * b2) mod 10 = 0;
[0193] c 10 =(100000000 9 * b2) mod 10 = 0;
[0194] That is, the third character string obtained is {1000000000}.
[0195] It can be understood that step S312 is to ensure that the characters in the obtained third character string are characters from 0 to 9.
[0196] Step S313: Convert the obtained third character string into hexadecimal to obtain the i-th candidate value.
[0197] Still taking the third character string {1000000000} as an example, after converting to hexadecimal, we get 5f5e100.
[0198] Step S314: Let the i-th preset value = the i-th candidate value mod 0xFFFFFFFF.
[0199] Step S315: Set i=i+1 and return to step S310 until i equals 5.
[0200] It can be understood that the above steps S309 to S315 are a process for reassigning the first preset value, the second preset value, the third preset value, and the fourth preset value.
[0201] In an optional implementation, for different input information, the values of the 80 constants obtained in step S308 are different, that is, the initial values of the first preset value to the fourth preset value corresponding to different input information are different, so in the present application, the first preset value to the fourth preset value after reassignment are different in the case of different plain text inputs. This increases randomness and the algorithm's ability to resist brute force cracking.
[0202] In an optional implementation, for different data blocks, the values of the 80 constants obtained in step S308 are different, that is, the initial values of the first preset value to the fourth preset value corresponding to different data blocks are different, so in the present application, the first preset value to the fourth preset value after reassignment are different in the case of different data blocks. This increases randomness and the algorithm's ability to resist brute force cracking.
[0203] Step S316: Obtain the initial value of the buffer identifier H0, the initial value of H1, the initial value of H2, the initial value of H3, and the initial value of H4.
[0204] In an optional implementation, for the first data block, that is, when step S316 is executed for the first time, the initial values of the buffer zone identifiers H0, H1, H2, H3, and H4 corresponding to the 16 target sub-data blocks can be found from the correspondence between the pre-set 16 sub-data blocks and the initial values of the buffer zone identifiers H0, H1, H2, H3, and H4.
[0205] That is, H corresponding to different target sub-blocks i The initial value of is different. Since the target sub-data block is related to the input information, the randomness and the algorithm's anti-brute force cracking ability are increased, and the algorithm performance consumption is small. It can be ported and implemented on different platforms and hardware devices to meet the requirements of various usage scenarios of blockchain in financial business systems.
[0206] In an optional implementation, the buffer {Hi} is initialized to the following value:
[0207] H0=0x67452301
[0208] H1=0xEFCDAB89
[0209] H2 = 0x98BADCFE
[0210] H3=0x10325476
[0211] H4=0xC3D2E1F0
[0212] Step S317: assign the initial value of H0, the initial value of H1, the initial value of H2, the initial value of H3, and the initial value of H4 to the first parameter, the second parameter, the third parameter, the fourth parameter, and the fifth parameter, respectively.
[0213] Step S318: Set the initial value of P to 0.
[0214] Step S319: For t=P, perform the following calculation:
[0215] TEMP=S5(H0)+f t (H1,H2,H3)+H4+W t +K t ; H4=H3; H3=H2; H2=S 30 (H1); H1 = H0; H0 = TEMP; where W t is the t+1th sub-data block among the 80 sub-data blocks, ft (H1, H2, H3) is a pre-set function; S5(H0) means shifting H0 left by 5 bits; S 30 (H1) means shifting H1 left by 30 bits.
[0216] For example, f t (H1, H2, H3) is a pre-set function with H1, H2, H3 as independent variables. For example, the pre-set function f t (H1, H2, H3) are as follows:
[0217] f t (H1,H2,H3)=(H1 AND H2)or((NOT H1)AND H3)(0<=t<=19)
[0218] f t (H1,H2,H3)=H1 XOR H2 XOR H3(20<=t<=39)
[0219] f t (H1,H2,H3)=(H1 AND H2)or(H1 AND H3)or(H2 AND H3)(40<=t<=59)
[0220] f t (H1, H2, H3)=H1 XOR H2 XOR H3 (60<=t<=79).
[0221] In an optional implementation, f t (H1, H2, H3) can be piecewise functions or not. The above is only an example and does not apply to f. t (H1, H2, H3) causes limitation.
[0222] Step S320: Set P=P+1, and return to step S319 until P is equal to 80 to obtain the values of the buffer zone identifiers H0, H1, H2, H3, and H4.
[0223] Step S321: Let the final value of H0 = the value of H0 + the first parameter, the final value of H1 = the value of H1 + the second parameter, the final value of H2 = the value of H2 + the third parameter, the final value of H3 = the value of H3 + the fourth parameter, and the final value of H4 = the value of H4 + the fifth parameter.
[0224] Step S322: Use the final value of H0, the final value of H1, the final value of H2, the final value of H3, and the final value of H4 as the initial value of H0, the initial value of H1, the initial value of H2, the initial value of H3, and the initial value of H4 of the buffer corresponding to the G+1th data block.
[0225] That is, when step S316 is executed for the second time, the buffer identifier H is obtained. i The initial value of = the H obtained when step S321 is executed for the first time i The final value of .
[0226] When step S316 is executed for the third time, the buffer identifier H is obtained. i The initial value of = H obtained when step S321 is executed for the second time i The final value of . And so on and so forth.
[0227] If the first message is divided into multiple data blocks, multiple iterations may be required. The final value of H0, H1, H2, H3, and H4 obtained in the previous data block are the initial value of H0, H1, H2, H3, and H4 of the next data block. Therefore, the final ciphertext is related to the number of iterations, making the ciphertext more difficult to crack.
[0228] Step S323: Set G=G+1 and return to step S305 until G is greater than Q.
[0229] Step S324: In the order of H0, H1, H2, H3, and H4, a 160-bit hash value is composed of the final value of H0, the final value of H1, the final value of H2, the final value of H3, and the final value of H4.
[0230] Understandably, H i The length of the value is 32 bits, so 5 H i A 160-bit hash value.
[0231] Step S325: Obtain ciphertext based on the 160-bit hash value.
[0232] In an optional implementation, the 160-bit hash value is determined as the ciphertext.
[0233] In an optional implementation, a third string corresponding to a first preset value, a third string corresponding to a second preset value, a third string corresponding to a third preset value, and a third string corresponding to a fourth preset value are obtained; a fourth string is obtained, the fourth string consisting of the third string corresponding to the first preset value, the third string corresponding to the second preset value, the third string corresponding to the third preset value, and the third string corresponding to the fourth preset value; and a ciphertext is determined to be a result of a logical operation of the 160-bit hash value and the fourth string.
[0234] For example, ciphertext = 160-bit hash value XOR fourth character string.
[0235] Step S326: Store the ciphertext in the blockchain.
[0236] Exemplarily, the ciphertext can be stored as a characteristic value of the input information in a corresponding block in the blockchain.
[0237] The data storage method provided by the present application performs the following processing on each constant after obtaining 80 preset constants: converting the constant from hexadecimal to decimal to obtain a first character string consisting of the decimal number; using the formula Get the second string; where b m is the character at position m in the second string, b1 is the character at position 1 in the second string, and b1=a1; a v is the character at position v in the first string, P(a v ) refers to a v The probability of appearing in the first string, n refers to the total number of characters contained in the first string, a v _number refers to a v The number of times it appears in the first string; using the formula To get the third string, where c m+1 is the character at the m+1th position in the third character string; convert the obtained third character string into hexadecimal to obtain a candidate value; let the constant = candidate value mod 0xFFFFFFFF, thereby reassigning the constant to obtain the reassigned constant 80. The values of H0, H1, H2, H3, and H4 obtained based on the 80 re-assigned constants are different from the values of H0, H1, H2, H3, and H4 obtained based on the 80 pre-set constants. In this application, if the input information is divided into multiple data blocks, then in the process of calculating the next data block, the initial value of the identifier H0, the initial value of H1, the initial value of H2, the initial value of H3, and the initial value of H4 of the buffer corresponding to the next data block are the final value of H0, the final value of H1, the final value of H2, the final value of H3, and the final value of H4 obtained from the previous data block, that is, the specific content of the obtained ciphertext, which is not only related to the number of data blocks into which the input information is divided, but also to the 80 re-assigned constants. If brute force cracking is required, it is necessary to try to crack the number of data blocks into which the input information is divided, as well as the 80 re-assigned constants. Compared with the prior art, brute force cracking is more difficult, thereby improving the security of the ciphertext.
[0238] The data storage method provided in the embodiment of the present application improves the security of the characteristic values of the input information of the blockchain. Attackers cannot use the current SHA-1 dictionary library to reversely decrypt the characteristic values, thus avoiding the possibility of brute force cracking.
[0239] The method is described in detail in the embodiments disclosed in the above-mentioned application. The method of the application can be implemented by various forms of devices. Therefore, the application also discloses a device, and a specific embodiment is given below for detailed description.
[0240] like Figure 6 As shown, it is a structural diagram of a data storage device provided by an embodiment of the present application, and the device includes: a first acquisition module 601, a padding expansion module 602, a first division module 603, a first setting module 604, a second division module 605, a calculation module 606, a second acquisition module 607, a first setting module 608, a first conversion module 609, a third acquisition module 610, a fourth acquisition module 611, a second conversion module 612, a second setting module 613, a first trigger module 614, a fifth acquisition module 615, a second assignment module 616, a third assignment module 617, a calculation module 618, a second trigger module 619, a fourth assignment module 620, a fifth assignment module 621, a third trigger module 622, a sixth acquisition module 623, a seventh acquisition module 624, and a storage module 625, wherein:
[0241] A first acquisition module 601 is used to acquire input information to be stored in the blockchain;
[0242] A padding and expansion module 602 is used to pad and expand the length of the input information to 512 bits*Q to obtain a first message, where Q is any integer greater than or equal to 1;
[0243] A first division module 603 is used to divide the first message into Q data blocks, where the number of bits of the data blocks is 512 bits;
[0244] A first setting module 604, used to set the initial value of G to 1;
[0245] For the Gth data block, perform the following operations:
[0246] A second division module 605 is used to divide the data block into 16 target sub-data blocks, where the number of bits of the target sub-data blocks is 32 bits;
[0247] A calculation module 606 is used to perform calculations on the 16 target sub-data blocks to obtain 64 calculation sub-data blocks to obtain 80 sub-data blocks, wherein the number of bits of the calculation sub-data blocks is 32 bits, and the 80 sub-data blocks include the 16 target sub-data blocks and the 64 calculation sub-data blocks;
[0248] The second acquisition module 607 is used to obtain 80 preset constants, and the values of the 80 constants are as follows:
[0249] K t = first preset value (0<=t<=19)
[0250] K t = second preset value (20<=t<=39)
[0251] K t = third preset value (40<=t<=59)
[0252] K t = fourth preset value (60<=t<=79);
[0253] A first setting module 608, used to set the initial value of i to 1;
[0254] A first conversion module 609 is configured to convert an i-th preset value into a decimal number to obtain a first character string consisting of the decimal number;
[0255] The third acquisition module 610 is used to use the formula Get the second string; where b m is the character at position m in the second string, b1 is the character at position 1 in the second string, and b1=a1; a v is the character at position v in the first string, P(a v ) refers to a v The probability of appearing in the first string, n refers to the total number of characters contained in the first string, a v _number refers to a v the number of times it appears in the first string;
[0256] The fourth acquisition module 611 is used to use the formula To get the third string, where c m+1 is the character at position m+1 in the third string;
[0257] A second conversion module 612, configured to convert the obtained third character string into hexadecimal to obtain an i-th candidate value;
[0258] The second setting module 613 is used to set the i-th preset value = the i-th candidate value mod 0xFFFFFFFF;
[0259] A first trigger module 614, configured to set i=i+1 and return to the first conversion module until i is equal to 5;
[0260] A fifth acquisition module 615 is used to acquire the initial value of the identifier H0 of the buffer, the initial value of H1, the initial value of H2, the initial value of H3, and the initial value of H4;
[0261] A second assignment module 616, configured to assign the initial value of H0, the initial value of H1, the initial value of H2, the initial value of H3, and the initial value of H4 to the first parameter, the second parameter, the third parameter, the fourth parameter, and the fifth parameter, respectively;
[0262] The third assignment module 617 is used to set the initial value of P to 0;
[0263] The calculation module 618 is used to perform the following calculation for t=P:
[0264] TEMP=S5(H0)+f t (H1,H2,H3)+H4+W t +K t ; H4=H3; H3=H2; H2=S 30 (H1); H1 = H0; H0 = TEMP; where W t is the t+1th sub-data block among the 80 sub-data blocks, f t (H1, H2, H3) is a pre-set function; S5(H0) means shifting H0 left by 5 bits; S 30 (H1) means shifting H1 left by 30 bits;
[0265] The second trigger module 619 is used to set P=P+1 and return to the calculation module until P is equal to 80 to obtain the values of the identifiers H0, H1, H2, H3 and H4 of the buffer;
[0266] The fourth assignment module 620 is used to set the final value of H0 = the value of H0 + the first parameter, the final value of H1 = the value of H1 + the second parameter, the final value of H2 = the value of H2 + the third parameter, the final value of H3 = the value of H3 + the fourth parameter, and the final value of H4 = the value of H4 + the fifth parameter;
[0267] A fifth assignment module 621, configured to use the final value of H0, the final value of H1, the final value of H2, the final value of H3, and the final value of H4 as the initial value of H0, the initial value of H1, the initial value of H2, the initial value of H3, and the initial value of H4 of the buffer corresponding to the G+1th data block, respectively;
[0268] The third trigger module 622 is used to set G=G+1 and return to the second division module until G is greater than Q;
[0269] A sixth acquisition module 623, configured to obtain a 160-bit hash value consisting of the final value of H0, the final value of H1, the final value of H2, the final value of H3, and the final value of H4 in the order of H0, H1, H2, H3, and H4;
[0270] A seventh acquisition module 624, configured to obtain a ciphertext based on the 160-bit hash value;
[0271] The storage module 625 is used to store the ciphertext in the blockchain.
[0272] In an optional implementation, the supplementary expansion module includes:
[0273] A first padding unit, used to pad a 1 at the end of the input information;
[0274] A second padding unit is used to add 0 after the 1 of the input information padding until the length of the second message after the padding is a remainder of 448 after taking the modulus of 512;
[0275] A third padding unit, used for padding a 1 at the end of the second message;
[0276] The fourth padding unit is used to add 63 zeros after the padding 1 of the second message to obtain the first message.
[0277] In an optional implementation, the first preset value is 0x5A827999, the second preset value is 0x6ED9EBA1, the third preset value is 0x8F1BBCDC, and the fourth preset value is 0xCA62C1D6.
[0278] In an optional implementation, the preset function f t (H1, H2, H3) are as follows:
[0279] f t (H1,H2,H3)=(H1 AND H2)or((NOT H1)AND H3)(0<=t<=19)
[0280] f t (H1,H2,H3)=H1 XOR H2 XOR H3(20<=t<=39)
[0281] f t (H1,H2,H3)=(H1 AND H2)or(H1 AND H3)or(H2 AND H3)(40<=t<=59)
[0282] f t(H1, H2, H3)=H1 XOR H2 XOR H3 (60<=t<=79).
[0283] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0284] Figure 7 The invention is a block diagram showing a device for a server according to an exemplary embodiment.
[0285] The server includes, but is not limited to, a processor 71 , a memory 72 , a network interface 73 , an I / O controller 74 , and a communication bus 75 .
[0286] It should be noted that those skilled in the art can understand that Figure 7 The server structure shown in the figure does not constitute a limitation on the server, and the server may include Figure 7 More or fewer components may be shown, or certain components may be combined, or the components may be arranged differently.
[0287] Combine the following Figure 7 A detailed introduction to each component of the server:
[0288] The processor 71 is the control center of the server. It uses various interfaces and lines to connect various parts of the entire server. It executes various functions of the server and processes data by running or executing software programs and / or modules stored in the memory 72, and calling data stored in the memory 72, so as to monitor the server as a whole. The processor 71 may include one or more processing units; illustratively, the processor 71 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 71.
[0289] The processor 71 may be a central processing unit (CPU), or an application specific integrated circuit ASIC (ASIC), or one or more integrated circuits configured to implement the embodiments of the present invention;
[0290] The memory 72 may include a memory, such as a high-speed random access memory (RAM) 721 and a read-only memory (ROM) 722, and may also include a large-capacity storage device 723, such as at least one disk storage, etc. Of course, the server may also include hardware required for other services.
[0291] The memory 72 is used to store executable instructions of the processor 71. The processor 71 has the function of a data storage method.
[0292] A wired or wireless network interface 73 is configured to connect the server to a network.
[0293] The processor 71, the memory 72, the network interface 73 and the I / O controller 74 may be interconnected via a communication bus 75, which may be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc.
[0294] In an exemplary embodiment, the server may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the above-mentioned data storage method.
[0295] In an exemplary embodiment, the present disclosure provides a storage medium including instructions, such as a memory 72 including instructions, and the instructions can be executed by a processor 71 of a server to complete the above method. Optionally, the storage medium can be a non-transitory computer-readable storage medium, for example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0296] In an exemplary embodiment, a computer-readable storage medium is also provided, which can be directly loaded into the internal memory of a computer, such as the above-mentioned memory 72, and contains software code. After being loaded and executed by a computer, the computer program can implement the steps shown in any embodiment of the above-mentioned data storage method.
[0297] In an exemplary embodiment, a computer program product is also provided, which can be directly loaded into the internal memory of a computer, such as the memory included in the server, and contains software code. After being loaded and executed by a computer, the computer program can implement the steps shown in any embodiment of the data storage method described above.
[0298] It should be noted that the data storage method, server, medium and device provided by the present invention can be used in the blockchain field or the financial field. The above is only an example and does not limit the application field of the data storage method, server, medium and device provided by the present invention.
[0299] It should be noted that the features described in the various embodiments in this specification can be replaced or combined with each other. For the device or system embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.
[0300] It should also be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0301] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0302] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A data storage method, characterized in that: include: Get the input information to be stored in the blockchain; The length of the input information is padded and expanded to 512 bits*Q to obtain a first message, where Q is any integer greater than or equal to 1; Dividing the first message into Q data blocks, the number of bits of the data blocks is 512 bits; Set the initial value of G to 1; For the Gth data block, perform the following operations: Dividing the data block into 16 target sub-data blocks, the number of bits of the target sub-data blocks is 32 bits; Performing operations on the 16 target sub-data blocks to obtain 64 operation sub-data blocks to obtain 80 sub-data blocks, wherein the number of bits of the operation sub-data blocks is 32 bits, and the 80 sub-data blocks include the 16 target sub-data blocks and the 64 operation sub-data blocks; Get 80 preset constants, the values of which are as follows: K t = first preset value, 0<=t<=19; K t = second preset value, 20<=t<=39; K t = third preset value, 40<=t<=59; K t = fourth preset value, 60<=t<=79; For the 80 constants K t The re-assignment process includes: Set the initial value of i to 1; For the i-th preset value, convert the i-th preset value into a decimal number to obtain a first character string consisting of the decimal number; Using the formula Get the second string; where b m is the character at position m in the second string, b1 is the character at position 1 in the second string, and b1=a1; a1 is the character at position 1 in the first string; a v is the character at position v in the first string, P(a v ) refers to a v The probability of appearing in the first string, n refers to the total number of characters contained in the first string, a v _number refers to a v the number of times it appears in the first string; Using the formula To get the third string, where c m+1 is the character at position m+1 in the third string; Convert the obtained third character string into hexadecimal to obtain the i-th candidate value; Let the i-th preset value = the i-th candidate value mod 0xFFFFFFFF; Set i=i+1, return to step 1, and for the i-th preset value, convert the i-th preset value into a decimal number to obtain a first string consisting of the decimal numbers, until i is equal to 5; thereby obtaining the 80 constants K after reassignment. t ; Get the initial value of the buffer identifier H0, the initial value of H1, the initial value of H2, the initial value of H3, and the initial value of H4; Assign the initial value of H0, the initial value of H1, the initial value of H2, the initial value of H3, and the initial value of H4 to the first parameter, the second parameter, the third parameter, the fourth parameter, and the fifth parameter, respectively; Set the initial value of P to 0; For t = P, the following calculation is performed: TEMP=S5(H0)+f t (H1,H2,H3)+H4+W t +K t ;H4=H3;H3=H2;H2=S 30 (H1);H1= H0; H0 = TEMP; where W t is the t+1th sub-data block among the 80 sub-data blocks, f t (H1, H2, H3) is a pre-set function; S5(H0) means shifting H0 left by 5 bits; S 30 (H1) means shifting H1 left by 30 bits; Preset function f t (H1, H2, H3) are as follows: f t (H1,H2,H3)=(H1 AND H2)or((NOT H1)AND H3),0<=t<=19; f t (H1,H2,H3)=H1 XOR H2 XOR H3,20<=t<=39; f t (H1,H2,H3)=(H1 AND H2)or(H1 AND H3)or(H2 AND H3),40<=t<=59; f t (H1,H2,H3)=H1 XOR H2 XOR H3,60<=t<=79; Set P=P+1, return to step t=P, and perform the following calculations until P is equal to 80 to obtain the values of the buffer identifiers H0, H1, H2, H3, and H4; Let the final value of H0 = the value of H0 + the first parameter, the final value of H1 = the value of H1 + the second parameter, the final value of H2 = the value of H2 + the third parameter, the final value of H3 = the value of H3 + the fourth parameter, and the final value of H4 = the value of H4 + the fifth parameter; The final value of H0, the final value of H1, the final value of H2, the final value of H3, and the final value of H4 are used as the initial value of H0, the initial value of H1, the initial value of H2, the initial value of H3, and the initial value of H4 of the buffer corresponding to the G+1th data block, respectively; Set G=G+1, return to step 1 and perform the following operations on the Gth data block until G is greater than Q; According to the order of H0, H1, H2, H3, H4, a 160-bit hash value consisting of the final value of H0, the final value of H1, the final value of H2, the final value of H3, and the final value of H4 is obtained; wherein the length of H0, H1, H2, H3, and H4 is 32 bits; Based on the 160-bit hash value, a ciphertext is obtained; The ciphertext is stored in the blockchain.
2. The data storage method according to claim 1, characterized in that: The step of padding and expanding the length of the input information to 512 bits*Q to obtain the first message includes: Add a 1 at the end of the input information; Add 0 after the 1 in the input information until the length of the second message after the addition is 448 modulo 512; Add a 1 at the end of the second message; 63 zeros are added after the padded 1 in the second message to obtain the first message.
3. The data storage method according to claim 1 or 2, characterized in that: The step of performing operations on the 16 target sub-data blocks to obtain 64 operation sub-data blocks includes: Set the initial value of R to 0; Let t = R and do the following: W t =M t , 0≤t<16, where M t is the t+1th target sub-data block; W t =S1(W t-3 XORW t-14 XOR W t-16 ), 16≤t≤79; where S1 means shifting left by 1 bit; Let R=R+1, return to step t=R, and perform the following operations until R equals 80.
4. The data storage method according to claim 1, characterized in that: The first preset value is 0x5A827999, the second preset value is 0x6ED9EBA1, the third preset value is 0x8F1BBCDC, and the fourth preset value is 0xCA62C1D6.
5. A data storage device, characterized in that: include: A first acquisition module, used to acquire input information to be stored in the blockchain; A padding and expansion module, used for padding and expanding the length of the input information to 512 bits*Q to obtain a first message, where Q is any integer greater than or equal to 1; A first division module, used for dividing the first message into Q data blocks, the number of bits of the data blocks is 512 bits; A first setting module, used to set the initial value of G to 1; For the Gth data block, perform the following operations: A second division module is used to divide the data block into 16 target sub-data blocks, and the number of bits of the target sub-data blocks is 32 bits; A calculation module, used for performing calculation on the 16 target sub-data blocks to obtain 64 calculation sub-data blocks, so as to obtain 80 sub-data blocks, wherein the number of bits of the calculation sub-data blocks is 32 bits, and the 80 sub-data blocks include the 16 target sub-data blocks and the 64 calculation sub-data blocks; The second acquisition module is used to obtain 80 preset constants, and the values of the 80 constants are as follows: K t = first preset value, 0<=t<=19; K t = second preset value, 20<=t<=39; K t = third preset value, 40<=t<=59; K t = fourth preset value, 60<=t<=79; For the 80 constants K t The re-assignment process includes: A first setting module, used to set the initial value of i to 1; A first conversion module, configured to convert an i-th preset value into a decimal number to obtain a first character string consisting of the decimal number; The third acquisition module is used to use the formula Get the second string; where b m is the character at position m in the second string, b1 is the character at position 1 in the second string, and b1=a1; a1 is the character at position 1 in the first string; a v is the character at position v in the first string, P(a v ) refers to a v The probability of appearing in the first string, n refers to the total number of characters contained in the first string, a v _number refers to a v the number of times it appears in the first string; The fourth acquisition module is used to use the formula To get the third string, where c m+1 is the character at position m+1 in the third string; A second conversion module, used for converting the obtained third character string into hexadecimal to obtain an i-th candidate value; The second setting module is used to set the i-th preset value = the i-th candidate value mod 0xFFFFFFFF; The first trigger module is used to set i=i+1 and return to the first conversion module until i is equal to 5; thereby obtaining the 80 constants K after reassignment. t ; A fifth acquisition module, used to acquire an initial value of the identifier H0 of the buffer, an initial value of H1, an initial value of H2, an initial value of H3, and an initial value of H4; A second assignment module, used for assigning the initial value of H0, the initial value of H1, the initial value of H2, the initial value of H3, and the initial value of H4 to the first parameter, the second parameter, the third parameter, the fourth parameter, and the fifth parameter, respectively; The third assignment module is used to set the initial value of P to 0; The calculation module is used to perform the following calculation for t=P: TEMP=S5(H0)+f t (H1,H2,H3)+H4+W t +K t ;H4=H3;H3=H2;H2=S 30 (H1);H1= H0; H0 = TEMP; where W t is the t+1th sub-data block among the 80 sub-data blocks, f t (H1, H2, H3) is a pre-set function; S5(H0) means shifting H0 left by 5 bits; S 30 (H1) means shifting H1 left by 30 bits; Preset function f t (H1,H2,H3) are as follows: f t (H1,H2,H3)=(H1 AND H2)or((NOT H1)AND H3),0<=t<=19; f t (H1,H2,H3)=H1 XOR H2 XOR H3,20<=t<=39; f t (H1,H2,H3)=(H1 AND H2)or(H1 AND H3)or(H2 AND H3),40<=t<=59; f t (H1,H2,H3)=H1 XOR H2 XOR H3,60<=t<=79; The second trigger module is used to set P=P+1 and return to the calculation module until P is equal to 80 to obtain the values of the identifiers H0, H1, H2, H3 and H4 of the buffer; The fourth assignment module is used to make the final value of H0 = the value of H0 + the first parameter, the final value of H1 = the value of H1 + the second parameter, the final value of H2 = the value of H2 + the third parameter, the final value of H3 = the value of H3 + the fourth parameter, and the final value of H4 = the value of H4 + the fifth parameter; a fifth assignment module, used to use the final value of H0, the final value of H1, the final value of H2, the final value of H3, and the final value of H4 as the initial value of H0, the initial value of H1, the initial value of H2, the initial value of H3, and the initial value of H4 of the buffer corresponding to the G+1th data block, respectively; A third trigger module is used to set G=G+1 and return to the second division module until G is greater than Q; A sixth acquisition module is used to obtain a 160-bit hash value consisting of the final value of H0, the final value of H1, the final value of H2, the final value of H3, and the final value of H4 in the order of H0, H1, H2, H3, and H4; wherein the lengths of H0, H1, H2, H3, and H4 are all 32 bits; A seventh acquisition module, configured to obtain a ciphertext based on the 160-bit hash value; A storage module is used to store the ciphertext in a blockchain.
6. The data storage device according to claim 5, characterized in that: The supplementary expansion module comprises: A first padding unit, used for padding a 1 at the end of the input information; A second padding unit is used to add 0 after the 1 of the input information padding until the length of the second message after the padding is a remainder of 448 after taking the modulus of 512; A third padding unit, used for padding a 1 at the end of the second message; The fourth padding unit is used to add 63 zeros after the padding 1 of the second message to obtain the first message.
7. A server, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the data storage method according to any one of claims 1 to 4.
8. A computer-readable storage medium, when instructions in the storage medium are executed by a processor of a server, enables the server to execute the data storage method according to any one of claims 1 to 4.
9. A computer program product that can be directly loaded into the internal memory of a computer, wherein the memory is the memory included in the server described in claim 7 and contains software code, and the computer program can implement the data storage method described in any one of claims 1 to 4 after being loaded and executed by the computer.
Citation Information
Patent Citations
Method for generating message authentication code
CN101227286A
Method for generating message summary
CN101247233A
Method of carrying out proof of work on block in block chain system and device thereof
CN106571925A
Hash value generation device, hash value generation program, and hash value generation method
JP2013076854A
Processor with secure hash algorithm and digital signal processing method with secure hash algorithm
US20180375643A1
