Data encryption method and device, storage medium and terminal

By updating the hash tree to generate a new encryption key when writing content, the low security of existing data security services is solved, achieving higher data security and read/write performance.

CN114996735BActive Publication Date: 2026-02-17BEIJING SPREADTRUM HI TECH COMM TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210641375.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-08
Publication Date
2026-02-17
Estimated Expiration
2042-06-08

AI Technical Summary

Technical Problem

Existing data security services have low security and are easily tampered with or replayed.

Method used

Whenever there is content to be written, a new random number is read, the hash tree is updated, an encryption key is generated, the content is encrypted, and the updated hash tree is stored in the translation backup buffer to ensure that the encryption key is different each time.

Benefits of technology

It improves the security of data security services, prevents written content from being tampered with or replayed, and enhances read and write performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114996735B_ABST
    Figure CN114996735B_ABST
Patent Text Reader

Abstract

A data encryption method and device, a storage medium and a terminal, the data encryption method comprising: reading a new random number whenever there is content to be written; updating a current hash tree using the new random number to obtain an updated hash tree; obtaining an encryption key according to the updated hash tree; encrypting the content to be written using the encryption key to obtain encrypted content; and performing a write operation on the encrypted content. The above scheme can ensure that the encryption key used to encrypt the content to be written each time is different, and even if the same content to be written, the encryption key used in the two write operations is also different, preventing the content from being tampered with or replayed, and improving the security of the data security service.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] Embodiments of the present application relate to the field of data encryption, and in particular to a data encryption method and device, a storage medium and a terminal. BACKGROUND

[0002] A chip usually has independent storage units in or out of the chip, which can store keys, feature data or programs and the like. In order to ensure that the stored keys, data or programs are not tampered with, the chip needs to provide security services such as encryption, so that even if the data is stolen, the stolen data cannot be decrypted, thereby protecting commercial privacy and data security.

[0003] The existing data security services usually use a fixed secret key to encrypt the stored keys, data or programs to achieve data security services. However, the security of the existing data security services is low. SUMMARY

[0004] The technical problem solved by embodiments of the present application is that the security of the existing data security services is low.

[0005] To solve the above technical problem, embodiments of the present application provide a data encryption method, comprising: reading a new random number whenever there is content to be written; updating a current hash tree using the new random number to obtain an updated hash tree; obtaining an encryption secret key according to the updated hash tree; encrypting the content to be written using the encryption secret key to obtain encrypted content; and performing a write operation on the encrypted content.

[0006] Optionally, the updating of the current hash tree using the new random number to obtain the updated hash tree comprises: obtaining an update condition, determining a level of a random number to be updated in the current hash tree, the update condition being used to indicate the level of the random number to be updated; updating the random number to be updated using the new random number to obtain an updated random number; and obtaining the updated hash tree according to the updated random number.

[0007] Optionally, the hash tree comprises N levels of random numbers, an i-level random number being obtained based on an i-1-level random number, 1≤i≤N, N≥2, i and N being integers.

[0008] Optionally, the updating the to-be-updated random number by using the new random number comprises: obtaining decryption data according to the address of the to-be-written content, a pre-stored secret key, and an i-1 level random number, the i-1 level random number being an upper level random number of the i level to-be-updated random number; decrypting the read new random number by using the decryption data and based on a symmetric decryption algorithm to obtain plaintext corresponding to the new random number and store the plaintext; performing hash calculation on the plaintext corresponding to the new random number, the address of the to-be-written content, and the i-1 level random number to obtain a first hash value; comparing the obtained first hash value with a hash value corresponding to the new random number, and if the obtained first hash value is the same as the hash value corresponding to the new random number, obtaining the updated random number based on the plaintext corresponding to the new random number.

[0009] Optionally, the obtaining the updated random number based on the plaintext corresponding to the new random number comprises: if the level of the to-be-updated random number comprises an N-j level random number, updating an N-j+1 level random number based on an updated random number corresponding to the N-j level random number until updating the N level random number is completed, 1≤j

[0010] Optionally, the data encryption method further comprises: storing at least the N level random number in the updated hash tree in a translation lookaside buffer.

[0011] Optionally, the obtaining the encryption secret key according to the updated hash tree comprises: obtaining the encryption secret key according to the N level random number.

[0012] Optionally, the obtaining the encryption secret key according to the N level random number comprises: obtaining the encryption secret key according to the address of the to-be-written content and the N level random number.

[0013] Optionally, the obtaining the encryption secret key according to the address of the to-be-written content and the N level random number comprises: searching for a corresponding N level random number from the updated hash tree according to the address of the to-be-written content; and obtaining the encryption secret key according to the address of the to-be-written content, a pre-stored secret key, and the searched N level random number.

[0014] Optionally, the obtaining the encryption secret key according to the address of the to-be-written content, the pre-stored secret key, and the searched N level random number comprises: performing exclusive or operation on the address of the to-be-written content, the pre-stored secret key, and the searched N level random number, and taking a result of the exclusive or operation as the encryption secret key.

[0015] Optionally, the data encryption method further comprises: performing hash calculation on the to-be-written content, an address of the to-be-written content and the encryption key to obtain a second hash value; and performing a read operation when a read operation is detected, obtaining to-be-read content and a hash value corresponding to the to-be-read content, obtaining a decryption key, and decrypting the to-be-read content based on the decryption key to obtain plaintext corresponding to the to-be-read content and cache the plaintext, performing hash calculation on the plaintext corresponding to the to-be-read content, an address of the to-be-read content and a random number corresponding to the to-be-read content obtained from the updated hash tree to obtain a hash value, and reading the to-be-read content cached through a specified read port if the hash value corresponding to the to-be-read content is the same as the calculated hash value.

[0016] Optionally, the data encryption method further comprises: performing hash calculation on the to-be-written content, an address of the to-be-written content and the encryption key to obtain a second hash value; and performing a read operation when a read operation is detected, obtaining to-be-read content and a hash value corresponding to the to-be-read content, obtaining a decryption key, and decrypting the to-be-read content based on the decryption key to obtain plaintext corresponding to the to-be-read content and cache the plaintext, performing hash calculation on the plaintext corresponding to the to-be-read content, an address of the to-be-read content and a random number corresponding to the to-be-read content obtained from the updated hash tree to obtain a hash value, and reading the to-be-read content cached through a specified read port if the hash value corresponding to the to-be-read content is the same as the calculated hash value.

[0017] Optionally, the data encryption method further comprises: performing hash calculation on the to-be-written content, an address of the to-be-written content and the encryption key to obtain a second hash value; and performing a read operation when a read operation is detected, obtaining to-be-read content and a hash value corresponding to the to-be-read content, obtaining a decryption key, and decrypting the to-be-read content based on the decryption key to obtain plaintext corresponding to the to-be-read content and cache the plaintext, performing hash calculation on the plaintext corresponding to the to-be-read content, an address of the to-be-read content and a random number corresponding to the to-be-read content obtained from the updated hash tree to obtain a hash value, and reading the to-be-read content cached through a specified read port if the hash value corresponding to the to-be-read content is the same as the calculated hash value.

[0018] Optionally, the pre-stored key is stored in a one-time programmable memory.

[0019] The embodiment of the present application further provides a data encryption device, comprising: a random number reading unit, configured to read a new random number whenever there is to-be-written content; a hash tree updating unit, configured to update a current hash tree by using the new random number to obtain an updated hash tree; a key determining unit, configured to obtain an encryption key according to the updated hash tree; an encryption unit, configured to encrypt the to-be-written content by using the encryption key to obtain encrypted content; and a write execution unit, configured to perform a write operation on the encrypted content.

[0020] The embodiment of the present application further provides a data computer readable storage medium, which has a computer program stored thereon, and the computer program performs the steps of any of the above data encryption methods when run by a processor.

[0021] The embodiment of the present application further provides a terminal, comprising a memory and a processor, wherein the memory has a computer program stored thereon, the computer program can be run on the processor, and the processor performs the steps of any of the above data encryption methods when running the computer program.

[0022] Compared with the prior art, the technical scheme of the embodiment of the present application has the following beneficial effects:

[0023] In the embodiment of the present application, a new random number is read whenever content to be written. The current hash tree is updated using the new random number to obtain an updated hash tree. An encryption key is obtained according to the address of the content to be written and the updated hash tree. The content to be written is encrypted using the obtained encryption key to obtain encrypted content and write the encrypted content. Since the current hash tree is updated using the read new random number whenever content to be written, and the encryption key used for encryption is obtained based on the updated hash tree, the encryption key used each time content to be written is different, so that the encryption key used each time content to be written is different, even if the same content to be written, the encryption key used at two times of writing is different, preventing the written content from being tampered or replayed, and improving the security of the data security service.

[0024] Further, the address of the content to be written or the address of the content to be read participates in deriving the key, that is, participates in obtaining the encryption key or the decryption key, which can prevent the stored data from being attacked due to position transposition, further improving the data security.

[0025] Further, at least the N-level random number in the updated hash tree is stored in the translation lookaside buffer, so that after the data is written, the N-level random number can be obtained from the translation lookaside buffer for subsequent reading of data, and the corresponding N-level random number is obtained based on the address of the read content to obtain the decryption key, without the need to recalculate the N-level random number, which can improve the read-write performance. BRIEF DESCRIPTION OF DRAWINGS

[0026] Figure 1 is a flowchart of a data encryption method in the embodiment of the present application;

[0027] Figure 2 is Figure 1 is a flowchart of a specific implementation of step S12 in

[0028] Figure 3 is Figure 2 is a flowchart of a specific implementation of step S122 in

[0029] Figure 4 is a flowchart of another data encryption method in the embodiment of the present application;

[0030] Figure 5 is a flowchart of a random number generation method in a hash tree in the embodiment of the present application;

[0031] Figure 6 is a principle diagram of data writing in the embodiment of the present application;

[0032] Figure 7 is a principle diagram of data reading in the embodiment of the present application;

[0033] Figure 8 Figure 1 is a structural schematic diagram of a data encryption device in an embodiment of the present application. DETAILED DESCRIPTION

[0034] As described above, in order to ensure that the stored key, data or program is not tampered, the chip needs to provide security services such as encryption, so that even if the data is stolen, the stolen data cannot be decrypted, thereby protecting the commercial privacy and data security. The existing data security service usually uses a fixed secret key to encrypt the stored key, data or program to achieve data security service. However, the security of the existing data security service is low.

[0035] To solve the above problem, in an embodiment of the present application, whenever there is content to be written, a new random number is read. The current hash tree is updated using the new random number to obtain an updated hash tree. According to the address of the content to be written and the updated hash tree, an encryption key is obtained. The obtained encryption key is used to encrypt the content to be written to obtain encrypted content and write it. Since each time there is content to be written, the current hash tree is updated using the read new random number, and the encryption key used for encryption is obtained based on the updated hash tree, so that the encryption key used each time there is content to be written is different, and the encryption key used each time the content to be written is encrypted is different, that is, even if the same content to be written, the encryption key used in the two times of writing is different, preventing the written content from being tampered or replayed, and improving the security of the data security service.

[0036] In order to make the above-mentioned purposes, features and advantages of the embodiments of the present application more obvious and easy to understand, the specific embodiments of the present application will be described in detail below with reference to the accompanying drawings.

[0037] The embodiment of the present application provides a data encryption method, and the execution subject of the data encryption method can be a terminal itself, or a chip such as a control chip, a processing chip, a baseband chip or other various appropriate components. The terminal can also be referred to as a user equipment (User Equipment, UE), and the terminal can be various appropriate intelligent terminals such as a mobile phone, a computer and the like, but is not limited thereto.

[0038] Reference Figure 1 Figure 1 is a flowchart of a data encryption method in an embodiment of the present application, which can specifically include the following steps S11 to S15:

[0039] Step S11, whenever there is content to be written, a new random number is read;

[0040] Step S12, the current hash tree is updated using the new random number to obtain an updated hash tree;

[0041] Step S13, obtaining an encryption key according to the updated hash tree;

[0042] Step S14, encrypting the to-be-written content by using the encryption key to obtain encrypted content;

[0043] Step S15, performing a write operation on the encrypted content.

[0044] In a specific implementation, in step S11, a new random number can be generated by a random numeral generator (RNG) whenever there is to-be-written content. After the new random number is generated, the new random number can be written into a corresponding write cache through a set write port, and the new random number can be obtained from the write cache.

[0045] For example, the write port can be an advanced high performance bus (AHB) write port, an advanced eXtensible interface (AXI) write port, a random access memory (RAM) write port, or another customized write port.

[0046] The to-be-written content can be to-be-written data, to-be-written programs, or other content that needs to be encrypted.

[0047] Referring to Figure 2 , a flowchart of a specific implementation of step S12 in Figure 1 is given, and step S12 can be implemented through steps S121 to S123 as follows:

[0048] Step S121, obtaining an update condition to determine the level of the random number to be updated in the current hash tree.

[0049] In a specific implementation, the update condition can be used to indicate the level of the random number to be updated. The update condition can indicate random numbers of an update partial level or all levels.

[0050] In some embodiments, the update condition can be determined based on the security level of the to-be-written content. The update conditions corresponding to to-be-written content of different security levels are different. The higher the security level, the more levels of random numbers indicated by the update condition, that is, the more random numbers indicated by the update condition.

[0051] In some embodiments, the hash tree comprises N levels of random numbers, an i-level random number is derived based on an (i-1)-level random number, 1≤i≤N, N≥2, i and N are integers. The first-level random number is derived based on a root hash. The root hash can be a pre-stored counter (CTR). The CTR can be pre-stored in an eFuse. The CTR can be changed when certain conditions are met, such as when the terminal is powered off, or the CTR can be changed by software control, etc. The CTR can be configured to increase in one direction, or can be configured to decrease in one direction, so that rollback can be prevented and CTR repetition can be avoided.

[0052] For example, the hash tree comprises three levels of random numbers, the first-level random number is derived based on a root hash, the second-level random number is derived based on the first-level random number, and the third-level random number is derived based on the second-level random number. The update condition can indicate that all levels of random numbers are updated, i.e., the first-level random number, the second-level random number, and the third-level random number are updated. The update condition can also indicate that only the third-level random number is updated. The update condition can also indicate that the second-level random number and the third-level random number are updated.

[0053] In step S122, the new random number is used to update the random number to be updated, to obtain an updated random number.

[0054] In step S123, the updated hash tree is obtained based on the updated random number.

[0055] In a specific implementation, referring to Figure 3 , a flowchart of a specific implementation of step S122 in Figure 2 is given, which can specifically include the following steps S1221 to S1224.

[0056] In step S1221, decryption data is obtained based on the address of the content to be written, a pre-stored key, and an (i-1)-level random number.

[0057] The (i-1)-level random number is the upper-level random number of the i-level random number to be updated. 1≤i≤N, i is a positive integer.

[0058] For example, the data to be updated is a third-level random number, and the decryption data is obtained based on the address of the content to be written, a pre-stored key, and a second-level random number.

[0059] For example, the data to be updated is a second-level random number, and the decryption data is obtained based on the address of the content to be written, a pre-stored key, and a first-level random number.

[0060] The pre-stored key is related to the terminal, such as related to the chip in the terminal, and the keys of different chips can be different.

[0061] In some embodiments, the address of the content to be written, the pre-stored secret key, and the i-1 level random number are subjected to an XOR operation, and the decrypted data is obtained according to the XOR operation.

[0062] In other embodiments, the decrypted secret key is obtained by using a shift cipher according to the address of the content to be written, the pre-stored secret key, and the i-1 level random number.

[0063] In step S1222, the read new random number is decrypted using the decrypted data and based on a symmetric decryption algorithm to obtain the plaintext corresponding to the new random number and store the plaintext.

[0064] In a specific implementation, the obtained new random number is encrypted data. The symmetric decryption algorithm can include an Advanced Encryption Standard (AES), an SM4 algorithm, etc.

[0065] The obtained plaintext corresponding to the new random number can be cached.

[0066] In step S1223, the plaintext corresponding to the new random number, the address of the content to be written, and the i-1 level random number are subjected to a hash calculation to obtain a first hash value.

[0067] In a specific implementation, a hash algorithm such as an SHA-1 algorithm, an SHA-2 algorithm, or an SM3 algorithm can be used to perform the hash calculation on the plaintext corresponding to the new random number, the address of the content to be written, and the i-1 level random number to obtain the first hash value. The hash operation can also be referred to as a hash operation, and the first hash value can also be referred to as a first hash value.

[0068] In step S1224, the calculated first hash value is compared with the hash value corresponding to the new random number. If the calculated first hash value is the same as the hash value corresponding to the new random number, the updated random number is obtained based on the plaintext corresponding to the new random number.

[0069] In a specific implementation, when the new random number is read, the hash value corresponding to the new random number is also read.

[0070] For example, if the random number to be updated is a third-level random number, the updated third-level random number is obtained based on the plaintext corresponding to the new random number. The plaintext corresponding to the new random number is used as the updated random number.

[0071] In some embodiments, if the calculated first hash value is not the same as the hash value corresponding to the new random number, an interruption is output.

[0072] In a specific implementation, when the updated random number is obtained based on the plaintext corresponding to the new random number in step S1224, if the level of the random number to be updated includes an N-j level random number, the N-j+1 level random number is updated based on the updated random number corresponding to the N-j level random number, until the update of the N level random number is completed, 1≤j

[0073] Specifically, the N-j level random number is updated according to the new random number, and the updated random number corresponding to the N-j level random number is obtained, that is, the updated N-j level random number is obtained. The N-j+1 level random number is updated according to the updated N-j level random number, and so on, until the update of the N level random number is completed.

[0074] For example, the hash tree includes three levels of random numbers, namely, a first level random number, a second level random number, and a third level random number. If the random numbers to be updated include the second level random number and the third level random number, the second level random number is updated based on the new random number, and the updated second level random number is obtained. The third level random number is updated according to the updated second level random number, and the updated third level random number is obtained.

[0075] Continuing to refer to Figure 1 In a specific implementation of step S13, the encryption key can be obtained according to the N level random number.

[0076] Further, the encryption key can be obtained according to the address of the content to be written and the N level random number.

[0077] Further, the corresponding N level random number can be found from the updated hash tree according to the address of the content to be written; and the encryption key can be obtained according to the address of the content to be written, the pre-stored key, and the found N level random number.

[0078] In some non-limiting embodiments, the address of the content to be written, the pre-stored key, and the found N level random number are subjected to an exclusive OR operation, and the result of the exclusive OR operation is taken as the encryption key.

[0079] In other embodiments, a shift encryption algorithm is used to perform a shift operation on the address of the content to be written, the pre-stored key, and the found N level random number, and the encryption key is obtained.

[0080] In step S14, an encryption algorithm such as an AES algorithm or an SM4 algorithm can be used to encrypt the content to be written, and the encrypted content is obtained. The AES algorithm can include an AES-256 algorithm, etc.

[0081] In step S15, when performing a write operation on the encrypted content, the encrypted content can be written into a corresponding object according to an address of the content to be written, such as a memory like a Double Data Rate (DDR) or a Flash.

[0082] In some embodiments, the encrypted content can be first stored in a corresponding write cache, and then written through a corresponding write port. The write port can be an Advanced eXtensible Interface (AXI) write port, or other types of write ports, which are related to the write object.

[0083] Further, a second hash value is obtained by performing a hash calculation on the content to be written, the address of the content to be written, and the encryption key; and a write operation is performed on the second hash value. By performing the encryption on the data to be written and performing the hash operation on the data to be written to obtain the second hash value, the security of the data is further improved, and the probability of data being stolen or tampered is further reduced.

[0084] As can be seen from the above, a new random number is read each time there is content to be written. The current hash tree is updated using the new random number to obtain an updated hash tree. An encryption key is obtained according to the address of the content to be written and the updated hash tree. The content to be written is encrypted using the obtained encryption key to obtain encrypted content and write the encrypted content. Since the current hash tree is updated using the read new random number each time there is content to be written, and the encryption key used for encryption is obtained based on the updated hash tree, the encryption key used each time there is content to be written is different, so that the encryption key used each time the content to be written is encrypted is different, even if the same content to be written, the encryption key used in two times of writing is different, preventing the written content from being tampered or replayed, and improving the security of the data security service.

[0085] In a specific implementation, after obtaining the updated hash tree, at least N-level random numbers in the updated hash tree are stored in a Translation Lookaside Buffer (TLB) to update the originally stored three-level random numbers. By storing the updated random numbers in the TLB, the updated random numbers can be obtained from the TLB in subsequent use, without the need for re-computation, thereby improving the read-write performance.

[0086] Referring to Figure 4 , a flowchart of another data encryption method in the embodiment of the present application is given, and Figure 1Compared with the method shown, the method can further include steps S41-S44 based on steps S11-S15.

[0087] In step S41, when a read operation is detected, the content to be read and a hash value corresponding to the content to be read are obtained.

[0088] In step S42, a decryption key is obtained, and the content to be read is decrypted based on the decryption key to obtain plaintext corresponding to the content to be read and cache the plaintext.

[0089] In some embodiments, the decryption key can be obtained according to an address of the content to be read, a pre-stored key, and a random number corresponding to the content to be read obtained from the updated hash tree.

[0090] The content to be read can be decrypted by using an AES algorithm or an SM4 algorithm to obtain plaintext corresponding to the content to be read.

[0091] The pre-stored key can be stored in an electrically programmable memory (EFuse).

[0092] In step S43, the plaintext corresponding to the content to be read, the address of the content to be read, and the random number corresponding to the content to be read obtained from the updated hash tree are subjected to hash calculation to obtain a hash value.

[0093] The plaintext corresponding to the content to be read, the address of the content to be read, and the random number corresponding to the content to be read obtained from the updated hash tree can be subjected to hash calculation by using a hash algorithm such as SHA-1, SHA-2, or SM3.

[0094] In step S44, if the hash value corresponding to the content to be read is the same as the calculated hash value, the content to be read cached is read through a specified read port.

[0095] The position of the plaintext cache corresponding to the content to be read is related to the specified read port. For example, when the specified read port is an AHB read port, the position of the cache is an AHB read cache.

[0096] To better enable those skilled in the art to better understand the embodiments of the present application, the following will be combined with specific examples of the present application. Figure 5 A flowchart of a method for generating a random number in a hash tree is given, and the generation process of the random number in each level of the hash tree is described. Among them, Figure 5 For example, a first-level random number is generated according to a root hash, a second-level random number is generated according to the first-level random number, and a third-level random number is generated according to the second-level random number. Refer to Figure 5 .

[0097] Specifically, the generated new random number can be stored in the cache AXI read buf through the read port AXI read ctrl, the new random number and the hash value (Read RNG Hash) of the new random number can be read from the cache AXI read buf. The new random number is encrypted data. The address (Address) of the new random number, the pre-stored key (Efuse key) stored in the Efuse and the Efuse counter (CTR) are subjected to an exclusive or operation (XOR), and a decryption key is obtained according to the exclusive or operation. The Efuse counter (CTR) is used as a root hash, and an AES-256 algorithm or an SM4 algorithm is used. The read new random number is decrypted by using the decryption key to obtain a plaintext (Plaintext RNG) of the decrypted new random number, and the obtained plaintext (Plaintext RNG) is stored in the random number cache (RNG buf).

[0098] The hash function (Hash message) is used to hash the plaintext (Plaintext RNG) of the decrypted new random number, the address (Address) of the new random number and the Efuse CTR, for example, a SHA-256 algorithm or an SM3 algorithm is used to hash to obtain a hash value Hash value. The obtained hash value (Read RNG Hash) of the new random number is compared with the obtained hash value Hash value, if the obtained hash value (Read RNG Hash) of the new random number is the same as the obtained hash value Hash value, the plaintext (Plaintext RNG) of the decrypted new random number is obtained from the RNG buf and stored in the RNG TLB, and the first-level random number (LEVEL1 RNG) is output through the output port (RNG TLB ctrl). The first-level random number (LEVEL1 RNG) is the obtained plaintext (Plaintext RNG) of the decrypted new random number.

[0099] The number of first-level random numbers can be multiple, and in the process of obtaining each first-level random number according to the root hash, the new random number corresponding to each first-level random number is generated.

[0100] It should be noted that when generating the second-level random number from the first-level random number to obtain the decryption key, an XOR operation is performed on the address of the new random number, the pre-stored key in Efuse, and the first-level random number (LEVEL1RNG). The decryption key is obtained from the XOR operation. A hash function is then used to hash the plaintext RNG after decryption of the new random number, the address of the new random number, and the first-level random number (LEVEL1RNG) to obtain the hash value. In other words, the plaintext RNG, the address of the new random number, and the first-level random number (LEVEL1RNG) are hashed together to obtain the hash value. Figure 5 The root hash (EfuseCTR) in the code is replaced with a first-level random number (LEVEL1 RNG) to obtain a second-level random number (LEVEL2 RNG) based on the first-level random number (LEVEL1 RNG).

[0101] There are multiple LEVEL2 RNGs, and each LEVEL2 RNG generates a new random number during its generation. Each LEVEL2 RNG can be based on the same LEVEL1 RNG or on different LEVEL1 RNGs.

[0102] This process continues until N-level random numbers are obtained based on N-1 level random numbers. For details, please refer to the description of obtaining first-level random numbers based on root hash, which will not be repeated here.

[0103] Combination Figure 6 The present invention provides a schematic diagram of a data writing principle in an embodiment of the invention. The following is a detailed explanation with reference to the diagram. Figure 6 Taking a hash tree with three levels of random numbers as an example, the data writing process will be explained.

[0104] The newly generated random number is stored in the cache AHB write buf by writing to port AHB write ctrl. The content to be written is then obtained from the cache AHB write buf. When there is content to be written, a new random number is obtained, and the hash tree is updated based on the new random number to obtain the updated random number.

[0105] According to the address of the to-be-written content, the corresponding three-level random number of the to-be-written content is obtained from the updated hash tree. The address (Address) of the to-be-written content, the pre-stored key (Efuse key) stored in the Efuse, and the three-level random number (LEVEL3 RNG) are subjected to an exclusive or operation (XOR), and an encryption key is obtained according to the exclusive or operation. The AES-256 algorithm or the SM4 algorithm is adopted, and the to-be-written content is encrypted by using the encryption key to obtain encrypted data, which can also be referred to as ciphertext. The obtained ciphertext is stored in the AXI write port buffer (write buf), and is written into the corresponding memory through the AXI write port (write ctrl).

[0106] The to-be-written content, the address (Address) of the to-be-written content, and the three-level random number (LEVEL3 RNG) are subjected to a hash operation by using a hash function (Hash message), for example, a hash operation is performed by using the SHA-256 algorithm to obtain a hash value (Hash value). The obtained hash value (Hash value) is stored in the AXI write port buffer (write buf), and is written into the corresponding memory through the AXI write port (write ctrl).

[0107] In combination with Figure 7 , a principle diagram of data reading in an embodiment of the present application is given, and the data reading process is described below in combination with FIG. Figure 7 , taking the hash tree including three levels of random numbers as an example.

[0108] The read data is stored in the buffer (AXI read buf) through the read port (AXI read ctrl), and the data and the hash value (Read Hash) of the read data are read from the buffer (AXI read buf). The read data is encrypted data.

[0109] According to the address (Address) of the read data, the corresponding three-level random number is obtained from the hash tree. The address (Address) of the read data, the pre-stored secret key (Efuse key) stored in the Efuse, and the three-level random number (LEVEL3 RNG) are subjected to XOR operation. The decryption key is obtained according to the XOR operation. The AES-256 algorithm or the SM4 algorithm is adopted, and the read data is decrypted by using the decryption key to obtain the decrypted plaintext (Plaintext RNG). The length of the plaintext (Plaintext RNG) is related to the decryption algorithm adopted. For example, if the AES-256 algorithm is used for decryption, 32 bytes of plaintext are obtained. The obtained plaintext (Plaintext RNG) is stored in the corresponding cache. When read through the AHB bus, it is stored in the AHB read buffer (read buf).

[0110] The decrypted plaintext of the read data (Plaintext), the address (Address) of the read data, and the three-level random number (LEVEL3 RNG) are subjected to hash operation by using the hash function (Hash message), for example, subjected to hash operation by using the SHA-256 algorithm, to obtain a hash value (Hash value) with a length of 32 bytes. The obtained hash value (ReadHash) of the read data is compared (complete) with the obtained hash value (Hash value). If the hash value (ReadHash) of the read data is the same as the obtained hash value (Hash value), it is determined that the read data is correct, and the decrypted plaintext (Plaintext) is read through the AHB read control (AHB read ctrl).

[0111] The embodiment of the present application also provides a data encryption device. Referring to Figure 8 , a structure diagram of a data encryption device in the embodiment of the present application is given. The data encryption device 80 can include

[0112] A random number reading unit 81 is configured to read a new random number whenever there is content to be written;

[0113] A hash tree updating unit 82 is configured to update the current hash tree by using the new random number to obtain an updated hash tree;

[0114] A secret key determining unit 83 is configured to obtain an encryption key according to the updated hash tree;

[0115] An encryption unit 84 is configured to encrypt the content to be written by using the encryption key to obtain encrypted content;

[0116] A write execution unit 85 is configured to execute a write operation on the encrypted content.

[0117] In specific implementations, the specific working principle and working process of the data encryption apparatus 80 can refer to the description of the data encryption method provided in any of the above embodiments, which will not be repeated here.

[0118] The embodiment of the present application further provides a computer readable storage medium, which stores a computer program, and the computer program is run by a processor to execute the steps of the data encryption method provided in any of the above embodiments.

[0119] The computer readable storage medium can include a non-volatile memory or a non-transitory memory, and can also include an optical disc, a mechanical hard disk, a solid state disk, etc.

[0120] Specifically, in the embodiment of the present application, the processor can be a central processing unit (CPU), and the processor can also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor, etc.

[0121] It should also be understood that the memory in the embodiments of the present application can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. Among them, the non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM) or flash memory. The volatile memory can be random access memory (RAM) used as an external cache. By way of example, but not by way of limitation, many forms of random access memory (RAM) are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM) and direct memory bus random access memory (DR RAM).

[0122] The embodiments of the present application also provide a terminal, including a memory and a processor, the memory and the processor are coupled, the memory can be located in the terminal, also can be located outside the terminal. The memory and the processor can be connected through a communication bus. The memory stores a computer program that can run on the processor, and the processor executes the steps of the data encryption method provided by the above-mentioned embodiments when running the computer program. The terminal can include but is not limited to terminal equipment such as mobile phone, computer, tablet computer, etc., and can also be a server, cloud platform, etc.

[0123] The above-described embodiments can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented by software, the above-described embodiments can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions or computer programs. When the computer instructions or computer programs are loaded or executed on a computer, the processes or functions described in the embodiments of the present application are wholly or partially generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer program can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer program can be transmitted from one website, computer, server or data center to another website, computer, server or data center through wired or wireless manner.

[0124] In several embodiments provided in the present application, it should be understood that the disclosed methods, devices and systems can be implemented in other ways. For example, the above-described device embodiments are only illustrative; for example, the division of the units is only a logical function division, and actual implementation can have another division manner; for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. The units described as separate components can be or can not be physically separated, and the components displayed as units can be or can not be physical units, that is, they can be located in one place, or can be distributed on a plurality of network units. According to actual needs, part or all of the units can be selected to achieve the purpose of the embodiment scheme.

[0125] In addition, each function unit in each embodiment of the present application can be integrated in one processing unit, or each unit can be physically included separately, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a hardware plus software function unit. For example, for each device or product applied to or integrated in a chip, each module / unit contained therein can be realized in the form of a circuit or hardware, or at least part of the modules / units can be realized in the form of a software program running on a processor integrated in the chip, and the remaining (if any) part of the modules / units can be realized in the form of a circuit or hardware; for each device or product applied to or integrated in a chip module, each module / unit contained therein can be realized in the form of a circuit or hardware, and different modules / units can be located in the same component (for example, a chip, a circuit module, etc.) or different components of the chip module, or at least part of the modules / units can be realized in the form of a software program running on a processor integrated in the chip module, and the remaining (if any) part of the modules / units can be realized in the form of a circuit or hardware; for each device or product applied to or integrated in a terminal, each module / unit contained therein can be realized in the form of a circuit or hardware, and different modules / units can be located in the same component (for example, a chip, a circuit module, etc.) or different components of the terminal, or at least part of the modules / units can be realized in the form of a software program running on a processor integrated in the terminal, and the remaining (if any) part of the modules / units can be realized in the form of a circuit or hardware.

[0126] It should be understood that the term "and / or" herein merely describes an association relationship of associated objects, and indicates that there can be three relationships, for example, A and / or B can represent three cases of A alone, A and B together, and B alone. In addition, the character " / " herein represents an "or" relationship between the associated objects before and after it.

[0127] "Multiple" appearing in the embodiments of the present application means two or more.

[0128] The first, second, and the like appearing in the embodiments of the present application are only for illustrative and distinguishing purposes, and do not have an order, nor represent a special limitation on the number of devices in the embodiments of the present application, and cannot constitute any limitation on the embodiments of the present application.

[0129] It should be noted that the serial numbers of the steps in the embodiments do not represent a limitation on the execution order of the steps.

[0130] Although the present application has been disclosed with reference to the above embodiments, the application is not limited to the above embodiments. It will be apparent to those skilled in the art that various modifications and changes can be made thereto without departing from the spirit and scope of the application. The scope of the application should be limited only by the appended claims.

Claims

1. A data encryption method characterized by, The method comprises the following steps: reading a new random number whenever there is content to be written; updating a current hash tree using the new random number to obtain an updated hash tree; obtaining an encryption key according to the updated hash tree; encrypting the content to be written using the encryption key to obtain encrypted content; performing a write operation on the encrypted content; wherein the step of updating the current hash tree using the new random number to obtain an updated hash tree comprises the following steps: obtaining an update condition to determine the level of the random number to be updated in the current hash tree, the update condition being used to indicate the level of the random number to be updated, the update condition being determined based on the security level of the content to be written, and the update condition corresponding to the content to be written being different for different security levels; updating the random number to be updated using the new random number to obtain an updated random number; obtaining the updated hash tree according to the updated random number; the hash tree comprises N levels of random numbers, the i-level random number being obtained based on the (i-1)-level random number, 1≤i≤N, and N≥2, i and N being integers; the step of obtaining the encryption key according to the N-level random number comprises the following step:

2. The data encryption method of claim 1, wherein, updating the random number to be updated using the new random number comprises the following steps: obtaining decryption data according to the address of the content to be written, a pre-stored key, and the (i-1)-level random number, the (i-1)-level random number being the upper-level random number of the i-level random number to be updated; decrypting the read new random number using the decryption data and based on a symmetric decryption algorithm to obtain the plaintext corresponding to the new random number and store the plaintext; performing a hash calculation on the plaintext corresponding to the new random number, the address of the content to be written, and the (i-1)-level random number to obtain a first hash value; comparing the calculated first hash value with the hash value corresponding to the new random number, and if the calculated first hash value is the same as the hash value corresponding to the new random number, obtaining the updated random number based on the plaintext corresponding to the new random number.

3. The data encryption method of claim 2, wherein, the step of obtaining the updated random number based on the plaintext corresponding to the new random number comprises the following step: if the level of the random number to be updated comprises N-j-level random numbers, updating the N-j+1-level random number based on the updated random number corresponding to the N-j-level random number until the update of the N-level random number is completed, 1≤j 4. The data encryption method of claim 1, wherein, The method further comprises the following steps: storing at least the N-level random number in the updated hash tree in a translation lookaside buffer.

5. The data encryption method of claim 1, wherein, the step of obtaining the encryption key according to the address of the content to be written and the N-level random number comprises the following step: obtaining the encryption key according to the address of the content to be written and the N-level random number.

6. The data encryption method of claim 5, wherein, the step of obtaining the encryption key according to the address of the content to be written and the N-level random number comprises the following steps: finding the corresponding N-level random number from the updated hash tree according to the address of the content to be written; obtaining the encryption key according to the address of the content to be written, a pre-stored key, and the found N-level random number.

7. The data encryption method of claim 6, wherein, The encryption key is obtained according to the address of the content to be written, a pre-stored secret key and the N-level random number searched. The address of the content to be written, the pre-stored secret key and the N-level random number searched are subjected to an XOR operation, and the XOR operation result is taken as the encryption key.

8. The data encryption method of claim 1, wherein, Further comprising: Hash calculation is performed on the content to be written, the address of the content to be written and the encryption key to obtain a second hash value; A write operation is performed on the second hash value.

9. The data encryption method of claim 8, wherein, Further comprising: When a read operation is detected, the content to be read and a hash value corresponding to the content to be read are obtained; A decryption key is obtained, and the content to be read is decrypted based on the decryption key to obtain plaintext corresponding to the content to be read and cache the plaintext; Hash calculation is performed on the plaintext corresponding to the content to be read, the address of the content to be read and the random number corresponding to the content to be read obtained from the updated hash tree to obtain a hash value; If the hash value corresponding to the content to be read is the same as the calculated hash value, the content to be read cached is read through a specified read port.

10. The data encryption method of claim 9, wherein, The decryption key is obtained according to the address of the content to be read, a pre-stored secret key and the random number corresponding to the content to be read obtained from the updated hash tree. The pre-stored secret key is stored in a one-time programmable memory.

11. The data encryption method of claim 7 or 10, wherein, Comprising:

12. A data encryption device, characterized by comprising: A random number reading unit, configured to read a new random number whenever there is content to be written; A hash tree updating unit, configured to update a current hash tree by using the new random number to obtain an updated hash tree; A secret key determining unit, configured to obtain an encryption key according to the updated hash tree; An encryption unit, configured to encrypt the content to be written by using the encryption key to obtain encrypted content; A write execution unit, configured to perform a write operation on the encrypted content; The hash tree updating unit is configured to obtain an update condition and determine the level of a random number to be updated in the current hash tree, the update condition being used to indicate the level of the random number to be updated, the update condition being determined based on the security level of the content to be written, and the update conditions corresponding to different security levels of the content to be written being different; The new random number is used to update the random number to be updated to obtain an updated random number, and the updated hash tree is obtained according to the updated random number; the hash tree comprises N levels of random numbers, an i-level random number being obtained based on an (i-1)-level random number, 1≤i≤N, N≥2, i and N being integers; The encryption key is obtained according to the N-level random number. The computer program is run by the processor to execute the steps of the data encryption method in any one of claims 1 to 11.

13. A computer readable storage medium having stored thereon a computer program, characterized in that, The processor runs the computer program to execute the steps of the data encryption method in any one of claims 1 to 11.

14. A terminal comprising a memory and a processor, said memory having stored thereon a computer program capable of running on said processor, characterized in that, ​

Citation Information

Patent Citations

  • Method and apparatus for protecting confidentiality and integrity of data storage

    CN1841255A