CN114996735A - Data encryption method and device, storage medium and terminal - Google Patents

Data encryption method and device, storage medium and terminal Download PDF

Info

Publication number
CN114996735A
CN114996735A CN202210641375.0A CN202210641375A CN114996735A CN 114996735 A CN114996735 A CN 114996735A CN 202210641375 A CN202210641375 A CN 202210641375A CN 114996735 A CN114996735 A CN 114996735A
Authority
CN
China
Prior art keywords
random number
content
updated
written
read
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210641375.0A
Other languages
Chinese (zh)
Inventor
许静雯
赵雪
吴戈
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Ziguang Zhanrui Communication Technology Co Ltd
Original Assignee
Beijing Ziguang Zhanrui Communication Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Ziguang Zhanrui Communication Technology Co Ltd filed Critical Beijing Ziguang Zhanrui Communication Technology Co Ltd
Priority to CN202210641375.0A priority Critical patent/CN114996735A/en
Publication of CN114996735A publication Critical patent/CN114996735A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/60Protecting data
    • G06F21/602Providing cryptographic facilities or services
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/60Protecting data
    • G06F21/62Protecting access to data via a platform, e.g. using keys or access control rules
    • G06F21/6218Protecting access to data via a platform, e.g. using keys or access control rules to a system of files or objects, e.g. local or distributed file system or database
    • G06F21/6245Protecting personal data, e.g. for financial or medical purposes
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/70Protecting specific internal or peripheral components, in which the protection of a component leads to protection of the entire computer
    • G06F21/71Protecting specific internal or peripheral components, in which the protection of a component leads to protection of the entire computer to assure secure computing or processing of information
    • G06F21/72Protecting specific internal or peripheral components, in which the protection of a component leads to protection of the entire computer to assure secure computing or processing of information in cryptographic circuits
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/70Protecting specific internal or peripheral components, in which the protection of a component leads to protection of the entire computer
    • G06F21/78Protecting specific internal or peripheral components, in which the protection of a component leads to protection of the entire computer to assure secure storage of data
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F7/00Methods or arrangements for processing data by operating upon the order or content of the data handled
    • G06F7/58Random or pseudo-random number generators
    • G06F7/588Random number generators, i.e. based on natural stochastic processes

Abstract

A data encryption method and device, a storage medium and a terminal are provided, wherein the data encryption method comprises the following steps: reading a new random number whenever content is to be written; updating the current hash tree by adopting 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 by adopting the encryption key to obtain encrypted content; and executing write operation on the encrypted content. According to the scheme, the encryption keys adopted when the content to be written is encrypted each time are different, even if the same content to be written is different, the encryption keys adopted when the content to be written is written twice are different, the written content is prevented from being tampered or replayed, and the safety of data security service is improved.

Description

Data encryption method and device, storage medium and terminal
Technical Field
The embodiment of the invention relates to the field of data encryption, in particular to a data encryption method and device, a storage medium and a terminal.
Background
On-chip or off-chip usually has a separate storage unit, which can store keys, feature data or programs. To ensure that the stored key, data or program is 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 business privacy and data security.
In the prior art, a fixed key is generally used to encrypt a stored key, data or program to implement a data security service, however, the security of the existing data security service is low.
Disclosure of Invention
The embodiment of the invention solves the technical problem that the existing data security service has lower security.
To solve the foregoing technical problem, an embodiment of the present invention provides a data encryption method, including: reading a new random number whenever content is to be written; updating the current hash tree by adopting 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 by adopting the encryption key to obtain encrypted content; and executing write operation on the encrypted content.
Optionally, the updating the current hash tree by using the new random number to obtain an updated hash tree includes: acquiring an updating condition, and determining the level of the random number to be updated in the current hash tree, wherein the updating condition is used for indicating the level of the random number to be updated; updating the random number to be updated by adopting the new random number to obtain an updated random number; and obtaining the updated hash tree according to the updated random number.
Optionally, the hash tree includes N levels of random numbers, i levels of random numbers are obtained based on i-1 levels of random numbers, i is greater than or equal to 1 and less than or equal to N, N is greater than or equal to 2, and i and N are integers.
Optionally, the updating the random number to be updated by using the new random number includes: obtaining decrypted data according to the address of the content to be written, a pre-stored secret key and an i-1-level random number, wherein the i-1-level random number is a previous-level random number of the i-level random number to be updated; decrypting the read new random number by adopting the decryption data and based on a symmetric decryption algorithm to obtain a plaintext corresponding to the new random number and storing the plaintext; carrying out hash calculation on a 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; and comparing the first hash value obtained by calculation with the hash value corresponding to the new random number, and if the first hash value obtained by calculation 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.
Optionally, the obtaining the updated random number based on the plaintext corresponding to the new random number includes: and if the level of the random number to be updated comprises N-j levels of random numbers, updating the N-j +1 levels of random numbers based on the updated random numbers corresponding to the N-j levels of random numbers until the updating of the N levels of random numbers is completed, wherein j is more than or equal to 1 and less than N, and j is an integer.
Optionally, the data encryption method further includes: storing at least the N-level random numbers in the updated hash tree in a translation lookaside buffer.
Optionally, the obtaining an encryption key according to the updated hash tree includes: and obtaining the encryption key according to the N-level random number.
Optionally, the obtaining the encryption key according to the N-level random number includes: and obtaining an encryption key according to the address of the content to be written and the N-level random number.
Optionally, the obtaining an encryption key according to the address of the content to be written and the N-level random number includes: searching a corresponding N-level random number from the updated hash tree according to the address of the content to be written; and obtaining the encryption key according to the address of the content to be written, a prestored key and the searched N-level random number.
Optionally, the obtaining the encryption key according to the address of the content to be written, a pre-stored key, and a searched N-level random number includes: and performing exclusive-or operation on the address of the content to be written, a pre-stored secret key and the searched N-level random number, and taking the exclusive-or operation result as the encryption secret key.
Optionally, the data encryption method further includes: performing hash calculation 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.
Optionally, the data encryption method further includes: when a reading operation is detected, acquiring a content to be read and a hash value corresponding to the content to be read; acquiring a decryption key, decrypting the content to be read based on the decryption key, obtaining a plaintext corresponding to the content to be read, and caching the plaintext; performing hash calculation 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, which is acquired from the updated hash tree, to obtain a hash value; and if the hash value corresponding to the content to be read is the same as the calculated hash value, reading the cached content to be read through an appointed read port.
Optionally, the obtaining a decryption key includes: and obtaining the decryption key according to the address of the content to be read, a prestored key and a random number corresponding to the content to be read, which is obtained from the updated hash tree.
Optionally, the pre-stored key is stored in a one-time programmable memory.
An embodiment of the present invention further provides a data encryption apparatus, including: a random number reading unit for reading a new random number whenever content is to be written; the hash tree updating unit is used for updating the current hash tree by adopting 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; the encryption unit is used for encrypting the content to be written by adopting the encryption secret key to obtain the encrypted content; and the writing execution unit is used for executing writing operation on the encrypted content.
Embodiments of the present invention further provide a data computer-readable storage medium, on which a computer program is stored, where the computer program is executed by a processor to perform the steps of any one of the data encryption methods.
The embodiment of the present invention further provides a terminal, which includes a memory and a processor, where the memory stores a computer program capable of running on the processor, and the processor executes any of the above steps of the data encryption method when running the computer program.
Compared with the prior art, the technical scheme of the embodiment of the invention has the following beneficial effects:
in an embodiment of the present invention, a new random number is read each time content is to be written. And updating the current hash tree by adopting a new random number to obtain an updated hash tree. And obtaining an encryption key according to the address of the content to be written and the updated hash tree. And encrypting the content to be written by using the obtained encryption key to obtain the encrypted content and writing the encrypted content. The current hash tree is updated by the read new random number each time the content is to be written, and the encryption keys used for encryption are obtained based on the updated hash tree, so that the encryption keys adopted each time the content is to be written are different, even if the same content is to be written, the encryption keys adopted in the two writing processes are different, the written content is prevented from being tampered or replayed, and the safety of data security service is improved.
Furthermore, the address of the content to be written or the address of the content to be read participates in deriving the key, namely participates in obtaining the encryption key or the decryption key, so that the stored data can be prevented from being attacked due to position exchange, and the data security is further improved.
Further, at least N-level random numbers in the updated hash tree are stored in the translation look-aside buffer, so that after data writing is completed, subsequent read data can obtain the N-level random numbers from the translation look-aside buffer, and obtain the corresponding N-level random numbers based on the address of the read content to obtain the decryption key, the N-level random numbers do not need to be recalculated, and the read-write performance can be improved.
Drawings
FIG. 1 is a flow chart of a method of data encryption in an embodiment of the invention;
FIG. 2 is a flowchart of one embodiment of step S12 of FIG. 1;
FIG. 3 is a flowchart of one embodiment of step S122 of FIG. 2;
FIG. 4 is a flow chart of another method of data encryption in an embodiment of the present invention;
FIG. 5 is a flow chart of a method for generating random numbers in a hash tree according to an embodiment of the present invention;
FIG. 6 is a schematic diagram of a data write in an embodiment of the present invention;
FIG. 7 is a schematic diagram of a data read in an embodiment of the invention;
fig. 8 is a schematic structural diagram of a data encryption device in an embodiment of the present invention.
Detailed Description
As described above, in order to ensure that a stored key, data, or program is not tampered with, a chip needs to provide security services such as encryption, so that even if data is stolen, the stolen data cannot be decrypted, thereby protecting business privacy and data security. In the prior art, a fixed key is generally used to encrypt a stored key, data or program to implement a data security service, however, the security of the existing data security service is low.
To solve the above problem, in the embodiment of the present invention, a new random number is read every time content is to be written. And updating the current hash tree by adopting a new random number to obtain an updated hash tree. And obtaining an encryption key according to the address of the content to be written and the updated hash tree. And encrypting the content to be written by using the obtained encryption key to obtain the encrypted content and writing the encrypted content. The current hash tree is updated by the read new random number each time the content is to be written, and the encryption keys used for encryption are obtained based on the updated hash tree, so that the encryption keys adopted each time the content is to be written are different, even if the same content is to be written, the encryption keys adopted in the two writing processes are different, the written content is prevented from being tampered or replayed, and the safety of data security service is improved.
In order to make the aforementioned objects, features and advantages of the embodiments of the present invention more comprehensible, specific embodiments accompanied with figures are described in detail below.
The embodiment of the invention provides a data encryption method, and the execution main body of the data encryption method can be a terminal, and also can be chips such as a control chip, a processing chip and a baseband chip which can be used for the terminal, or other various appropriate components. The terminal may also be referred to as User Equipment (UE), and the terminal may be various appropriate intelligent terminals, such as a mobile phone, a computer, and the like, but is not limited thereto.
Referring to fig. 1, a flowchart of a data encryption method in the embodiment of the present invention is shown, which may specifically include the following steps S11 to S15:
step S11, reading a new random number whenever content is to be written;
step S12, updating the current hash tree by adopting the new random number to obtain an updated hash tree;
step S13, obtaining an encryption key according to the updated hash tree;
step S14, encrypting the content to be written by using the encryption key to obtain the encrypted content;
in step S15, a write operation is performed on the encrypted content.
In a specific implementation, in step S11, whenever content is to be written, a new Random number may be generated by a Random Number Generator (RNG). After the new random number is generated, the new random number can be written into the corresponding write cache through the set write port, and the new random number is obtained from the write cache.
For example, the write port may 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.
The content to be written may be data to be written, a program to be written, or other content that needs to be encrypted.
Referring to fig. 2, which shows a flowchart of an embodiment of step S12 in fig. 1, step S12 may be specifically implemented by steps S121 to S123 as follows:
step S121, obtaining an update condition, and determining a level of the random number to be updated in the current hash tree.
In particular implementations, the update condition may be used to indicate a level of the random number to be updated. The update condition may indicate that the random numbers of the partial level are updated or may indicate that the random numbers of all levels are updated.
In some embodiments, the update condition may be determined based on a security level of the content to be written. The updating conditions corresponding to the contents to be written with different security levels are different. The higher the security level, the more levels of updated random numbers indicated by the corresponding update conditions, i.e., the more number of updated random numbers indicated.
In some embodiments, the hash tree includes N levels of random numbers, i levels of random numbers are obtained based on i-1 levels of random numbers, i is greater than or equal to 1 and less than or equal to N, N is greater than or equal to 2, and i and N are integers. Wherein the primary random number is obtained from the root hash. The root hash may be a pre-stored Count (CTR). The CTR may be stored in advance in the one-time programmable memory EFUSE. The CTR may change when a certain condition is satisfied, such as when the terminal is powered on or powered off, or may be controlled by software. The CTR may be configured to increase toward one direction and may also be configured to decrease toward one direction, so that rollback may be prevented and CTR repetition may be avoided.
For example, the hash tree includes three levels of random numbers, a primary random number is obtained according to the root hash, a secondary random number is obtained according to the primary random number, and a three-level random number is obtained according to the secondary random number. The update condition may indicate that all levels of random numbers, i.e., the primary random number, the secondary random number, and the tertiary random number, are updated. The update condition may also indicate that only the tertiary random numbers are updated. The update condition may also indicate that the secondary random number and the tertiary random number are updated.
And step S122, updating the random number to be updated by adopting the new random number to obtain an updated random number.
And S123, obtaining the updated hash tree according to the updated random number.
In specific implementation, referring to fig. 3, a flowchart of an embodiment of step S122 in fig. 2 is given, and specifically, the following steps S1221 to S1224 may be included.
Step S1221, obtaining decrypted data according to the address of the content to be written, the pre-stored key, and the i-1 level random number.
The i-1 level random number is a previous level random number of the i level random number to be updated. Wherein i is more than or equal to 1 and less than or equal to N, and i is a positive integer.
For example, if the data to be updated is a tertiary random number, the decrypted data is obtained according to the address of the content to be written, the pre-stored key, and the secondary random number.
If the data to be updated is the secondary random number, the decrypted data is obtained according to the address of the content to be written, the pre-stored key and the primary random number.
The pre-stored key is associated with the terminal, e.g. with a chip in the terminal, and the keys of different chips may be different.
In some embodiments, the address of the content to be written, the pre-stored key, and the i-1 level random number may be subjected to an exclusive or operation, and the decryption data may be obtained according to the exclusive or operation.
In other embodiments, the decryption key is obtained by using a shift cipher according to the address of the content to be written, a pre-stored key and the i-1 level random number.
And step S1222, decrypting the read new random number by using the decrypted data and based on a symmetric decryption algorithm to obtain a plaintext corresponding to the new random number and storing the plaintext.
In a specific implementation, the new random number obtained is encrypted data. The symmetric decryption algorithm may include Advanced Encryption Standard (AES), SM4 algorithm, and the like.
And caching the plaintext corresponding to the obtained new random number.
Step S1223, performing 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.
In specific implementation, hash algorithms such as an SHA-1 algorithm, an SHA-2 algorithm, or an SM3 algorithm may be used to perform 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. The hash operation may also be referred to as a hash operation, and the first hash value may also be referred to as a first hash value.
Step S1224 of comparing the computed first hash value with the hash value corresponding to the new random number, and if the computed 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.
In a specific implementation, when a new random number is read, a hash value corresponding to the new random number is read at the same time.
For example, if the random number to be updated is a tertiary random number, the updated tertiary random number is obtained based on the plaintext corresponding to the new random number. And taking the plaintext corresponding to the new random number as the updated random number.
In some embodiments, if the computed first hash value is not the same as the hash value corresponding to the new random number, an interrupt is output.
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 N-j levels of random numbers, the N-j +1 levels of random numbers are updated based on the updated random number corresponding to the N-j levels of random numbers until the update of the N levels of random numbers is completed, where j is greater than or equal to 1 and less than N, and j is an integer.
Specifically, the N-j level random number is updated according to the new random number to obtain an updated random number corresponding to the N-j level random number, namely, the updated N-j level random number. And updating the N-j + 1-level random number according to the updated N-j-level random number, and so on until the updating of the N-level random number is completed.
For example, the hash tree includes three levels of random numbers, a primary random number, a secondary random number, and a tertiary random number. If the random number to be updated comprises a secondary random number and a tertiary random number, updating the secondary random number based on the new random number to obtain an updated secondary random number. And updating the tertiary random number according to the updated secondary random number to obtain the updated tertiary random number.
With continued reference to fig. 1, in one embodiment of step S13, the encryption key may be obtained from a class N random number.
Further, an encryption key may be obtained according to the address of the content to be written and the N-level random number.
Further, according to the address of the content to be written, searching the corresponding N-level random number from the updated hash tree; and obtaining the encryption key according to the address of the content to be written, a prestored key and the searched N-level random number.
In some non-limiting embodiments, an exclusive or operation is performed on the address of the content to be written, the pre-stored key, and the searched N-level random number, and a result of the exclusive or operation is used as the encryption key.
In other embodiments, a shift encryption algorithm is adopted to perform a shift operation on the address of the content to be written, the pre-stored key, and the searched N-level random number to obtain an encryption key.
In step S14, an encryption algorithm such as AES algorithm or SM4 algorithm may be adopted to encrypt the content to be written, so as to obtain the encrypted content. The AES algorithm may include, among others, the AES-256 algorithm.
In step S15, when performing a write operation on the encrypted content, the encrypted content may be written into a corresponding object, such as a Double Data Rate (DDR) memory or a Flash memory (Flash) memory, according to an address of the content to be written.
In some embodiments, the encrypted content may be stored in the corresponding write cache, and then written through the corresponding write port. The write port may be an Advanced eXtensible Interface (AXI) write port, or may be another type of write port, specifically related to a write object.
Further, performing hash calculation 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. The data to be written is encrypted, and at the same time, the data to be written is subjected to hash operation and stored to obtain a second hash value, so that the safety of the data is further improved, and the probability of stealing or tampering the data is further reduced.
As can be seen from the above, whenever content is to be written, a new random number is read. And updating the current hash tree by adopting a new random number to obtain an updated hash tree. And obtaining an encryption key according to the address of the content to be written and the updated hash tree. And encrypting the content to be written by using the obtained encryption key to obtain the encrypted content and writing the encrypted content. The current hash tree is updated by the read new random number each time the content is to be written, and the encryption keys used for encryption are obtained based on the updated hash tree, so that the encryption keys adopted each time the content is to be written are different, even if the same content is to be written, the encryption keys adopted in the two writing processes are different, the written content is prevented from being tampered or replayed, and the safety of data security service is improved.
In a specific implementation, after obtaining the updated hash tree, at least the N-level random number in the updated hash tree is stored in a Translation Lookaside Buffer (TLB) to update the originally stored three-level random number. The updated random number is stored in the TLB, and the random number can be acquired from the TLB in the subsequent use without recalculation, so that the read-write performance is improved.
Referring to fig. 4, a flow chart of another data encryption method in the embodiment of the present invention is shown, and compared with the method illustrated in fig. 1, on the basis of steps S11 to S15, the following steps S41 to S44 may be further included.
Step S41, when a read operation is detected, acquiring a content to be read and a hash value corresponding to the content to be read.
Step S42, obtain a decryption key, and decrypt the content to be read based on the decryption key, to obtain a plaintext corresponding to the content to be read and cache the plaintext.
In some embodiments, the decryption key may be obtained according to the address of the content to be read, a pre-stored key, and a random number corresponding to the content to be read, which is obtained from the updated hash tree.
The AES algorithm or SM4 algorithm may be adopted to decrypt the content to be read, so as to obtain the plaintext corresponding to the content to be read.
The pre-stored key may be stored in a one-time programmable memory (Efuse).
Step S43, performing hash calculation 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.
Hash calculation can be 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, which is obtained from the updated hash tree, by using hash algorithms such as SHA-1, SHA-2, SM3, and the like.
Step S44, if the hash value corresponding to the content to be read is the same as the computed hash value, reading the cached content to be read through the designated read port.
The position of the plaintext cache corresponding to the content to be read is related to the designated read port. For example, when the read port is designated as the AHB read port, the location of the cache is the AHB read cache.
In order to facilitate better understanding of the embodiments of the present invention, the following describes a process for generating random numbers at each level in a hash tree with reference to a flowchart of a method for generating random numbers in a hash tree shown in fig. 5. Fig. 5 illustrates an example of generating a primary random number according to root hash, generating a secondary random number according to the primary random number, and generating a tertiary random number according to the secondary random number with reference to fig. 5.
Specifically, the generated new random number may be stored in the cache AXI Read buf through the Read port AXI Read ctrl, and the new random number and a Hash value (Read RNG Hash) of the new random number are Read from the cache AXI Read buf. The new random number is encrypted data. And carrying out exclusive OR (XOR) operation on the Address (Address) of the new random number, a pre-stored key (Efuse key) stored in the Efuse and the Efuse Count (CTR), and obtaining a decryption key according to the XOR operation. The method comprises the steps of reading a new random number by using an AES-256 algorithm or an SM4 algorithm, decrypting the read new random number by using a decryption key, obtaining a Plaintext (Plantex RNG) after decryption of the new random number, and storing the obtained Plaintext (Plantex RNG) in a random number cache (RNG buf).
The Hash function (Hash message) is used to perform Hash operation on the Plaintext (plain RNG) decrypted by the new random number, the Address (Address) of the new random number, and the Efuse CTR, for example, the SHA-256 algorithm or SM3 algorithm is used to perform Hash operation, so as to obtain a Hash value. Comparing (complete) the obtained Hash value of the new random number (Read RNG Hash) with the Hash value obtained by operation, if the obtained Hash value of the new random number (Read RNG Hash) is the same as the Hash value obtained by operation, obtaining a Plaintext (Plaintext RNG) after decryption of the new random number from RNG buf, storing the Plaintext (Plaintext RNG) in RNG TLB, and outputting a primary random number (LEVEL1 RNG) through an output port (RNG TLB ctrl). The primary random number (LEVEL1 RNG) is a Plaintext (Plaintext RNG) decrypted by acquiring a new random number.
The number of the primary random numbers can be multiple, and in the process of obtaining each primary random number according to the root hash, new random numbers corresponding to each primary random number are generated.
When the secondary random number is generated from the primary random number and the decryption key is obtained, an exclusive or (XOR) operation is performed on the Address (Address) of the new random number, the key (Efuse key) pre-stored in the Efuse, and the primary random number (LEVEL1 RNG), and the decryption key is obtained according to the exclusive or operation. And carrying out Hash operation on the Plaintext (Plaintext RNG) after the new random number is decrypted, the Address (Address) of the new random number and the primary random number (LEVEL1 RNG) by adopting a Hash function (Hash message) to obtain a Hash value. That is, the root hash (Efuse CTR) in FIG. 5 is replaced with the primary random number (LEVEL1 RNG) to obtain the secondary random number (LEVEL2 RNG) from the primary random number (LEVEL1 RNG).
The number of the secondary random numbers (LEVEL2 RNG) is multiple, and a corresponding new random number is generated in the generation process of each secondary random number (LEVEL2 RNG). Each secondary random number (LEVEL2 RNG) may be derived based on the same primary random number (LEVEL1 RNG) or may be derived based on a different primary random number (LEVEL1 RNG).
By analogy, until the N-level random number is obtained based on the N-1 level random number, the specific process may refer to the description in obtaining the first-level random number based on the root hash, which is not described herein again.
A schematic diagram of data writing in an embodiment of the present invention is given with reference to fig. 6, and a data writing process is described below with reference to fig. 6 by taking an example in which a hash tree includes three levels of random numbers.
And storing the generated new random number in the cache AHB write buf through the write port AHB write ctrl, and obtaining the content to be written from the cache AHB write buf. And when the content is to be written, acquiring a new random number, and updating the hash tree based on the new random number to obtain an updated random number.
And acquiring a three-level random number corresponding to the content to be written from the updated hash tree according to the address of the content to be written. And performing exclusive OR (XOR) on the Address (Address) of the content to be written, a pre-stored key (Efuse key) stored in the Efuse and the tertiary random number (LEVEL3 RNG), and obtaining the encryption key according to the XOR. The method comprises the steps of encrypting the content to be written by adopting an AES-256 algorithm or an SM4 algorithm and an encryption key to obtain encrypted data, which can also be called ciphertext (ciphterext), storing the obtained ciphertext (ciperenext) in an AXI write-in port cache (write buf), and writing the ciphertext (ciperenext) into a corresponding memory through an AXI write-in port (write ctrl).
The Hash function (Hash message) is used to perform Hash operation on the content to be written, the Address (Address) of the content to be written, and the tertiary random number (LEVEL3 RNG), for example, the SHA-256 algorithm is used to perform Hash operation, so as to obtain a Hash value. The Hash value obtained by the operation is stored in an AXI write port cache (write buf), and is written into a corresponding memory through an AXI write port (write ctrl).
A schematic diagram of data reading in the embodiment of the present invention is given with reference to fig. 7, and a data reading process is described below with reference to fig. 7 by taking an example in which a hash tree includes three levels of random numbers.
The Read data is stored in the cache AXI Read buf through the Read port AXI Read ctrl, and the data and a Hash value (Read Hash) of the Read data are Read from the cache AXI Read buf. And the read data is encrypted data.
And acquiring the corresponding three-level random number from the hash tree according to the Address (Address) of the read data. And performing exclusive OR (XOR) operation on the Address (Address) of the read data, a pre-stored key (Efuse key) stored in the Efuse and the tertiary random number (LEVEL3 RNG), and obtaining a decryption key according to the XOR operation. And decrypting the read data by adopting an AES-256 algorithm or an SM4 algorithm and a decryption key to obtain a decrypted Plaintext (Plaintext RNG). The length of the Plaintext (Plaintext RNG) is related to the decryption algorithm used, e.g. AES-256 algorithm, resulting in 32bytes (bytes) of Plaintext. The obtained plain text (Plaintext RNG) is stored in the corresponding buffer, and when read through the Ahb bus, it is stored in the AHB read buffer (read buf).
And performing Hash operation on the decrypted plain text (plain text) of the read data, the Address (Address) of the read data and the three-LEVEL random number (LEVEL3 RNG) by using a Hash function (Hash message), for example, performing Hash operation by using a SHA-256 algorithm to obtain a Hash value with the length of 32 bytes. And comparing (complete) the Hash value (Read Hash) of the obtained Read data with the Hash value (Hash value) obtained by operation, if the Hash value (Read Hash) of the Read data is the same as the Hash value (Hash value) obtained by operation, determining that the Read data is correct, and reading the decrypted plain text (plain) through AHB Read ctrl.
The embodiment of the invention also provides a data encryption device. Referring to fig. 8, a schematic structural diagram of a data encryption device in an embodiment of the present invention is provided, and the data encryption device 80 may include
A random number reading unit 81 for reading a new random number whenever content is to be written;
a hash tree updating unit 82, configured to update the current hash tree by using the new random number to obtain an updated hash tree;
a key determining unit 83, configured to obtain an encryption key according to the updated hash tree;
an encrypting unit 84, configured to encrypt the content to be written by using the encryption key to obtain an encrypted content;
a write execution unit 85, configured to perform a write operation on the encrypted content.
In a specific implementation, the specific working principle and the working flow of the data encryption device 80 may refer to the description of the data encryption method provided in any of the above embodiments, and are not described herein again.
Embodiments of the present invention further provide a computer-readable storage medium, on which a computer program is stored, where the computer program is executed by a processor, and the steps of the data encryption method provided in any of the above embodiments are provided.
The computer-readable storage medium may include a non-volatile memory (non-volatile) or a non-transitory memory, and may further include an optical disc, a mechanical hard disk, a solid state hard disk, and the like.
Specifically, in the embodiment of the present invention, the processor may be a Central Processing Unit (CPU), and the processor may also be other general-purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field Programmable Gate Arrays (FPGAs) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, and the like. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
It will also be appreciated that the memory in the embodiments of the subject application can be either volatile memory or nonvolatile memory, or can include both volatile and nonvolatile memory. The nonvolatile memory may be a read-only memory (ROM), a Programmable ROM (PROM), an Erasable PROM (EPROM), an Electrically Erasable PROM (EEPROM), or a flash memory. Volatile memory may be Random Access Memory (RAM) which acts as external cache memory. By way of example and not limitation, many forms of Random Access Memory (RAM) are available, such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (enhanced SDRAM), SDRAM (SLDRAM), synchlink DRAM (SLDRAM), and direct bus RAM (DR RAM).
The embodiment of the invention also provides a terminal, which comprises a memory and a processor, wherein the memory is coupled with the processor, and the memory can be positioned in the terminal or positioned outside the terminal. The memory and the processor may be connected by a communication bus. The memory is stored with a computer program that can be run on the processor, and the processor executes the steps of the data encryption method provided by the above embodiment when running the computer program. The terminal can include but is not limited to a mobile phone, a computer, a tablet computer and other terminal devices, and can also be a server, a cloud platform and the like.
The above embodiments may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented in software, the above-described embodiments may be implemented in whole or in part in the form of a computer program product. The computer program product comprises one or more computer instructions or computer programs. The procedures or functions according to the embodiments of the present application are wholly or partially generated when the computer instructions or the computer program are loaded or executed on a computer. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer program may 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 may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center by wire or wirelessly.
In the several embodiments provided in the present application, it should be understood that the disclosed method, apparatus and system may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative; for example, the division of the unit is only a logic function division, and there may be another division manner in actual implementation; for example, various elements or components may be combined or may be integrated in another system or some features may be omitted, or not implemented. The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may be physically included alone, or two or more units may be integrated into one unit. The integrated unit can be realized in a form of hardware, or in a form of hardware plus a software functional unit. For example, for each device or product applied to or integrated into a chip, each module/unit included in the device or product may be implemented by hardware such as a circuit, or at least a part of the module/unit may be implemented by a software program running on a processor integrated within the chip, and the rest (if any) part of the module/unit may be implemented by hardware such as a circuit; for each device or product applied to or integrated with the chip module, each module/unit included in the device or product may be implemented by using hardware such as a circuit, and different modules/units may be located in the same component (e.g., a chip, a circuit module, etc.) or different components of the chip module, or at least some of the modules/units may be implemented by using a software program running on a processor integrated within the chip module, and the rest (if any) of the modules/units may be implemented by using hardware such as a circuit; for each device and product applied to or integrated in the terminal, each module/unit included in the device and product may be implemented by hardware such as a circuit, different modules/units may be located in the same component (e.g., a chip, a circuit module, etc.) or different components in the terminal, or at least part of the modules/units may be implemented by a software program running on a processor integrated in the terminal, and the rest (if any) part of the modules/units may be implemented by hardware such as a circuit.
It should be understood that the term "and/or" herein is only one kind of association relationship describing the association object, and means that there may be three kinds of relationships, for example, a and/or B, and may mean: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the character "/" in this document indicates that the former and latter related objects are in an "or" relationship.
The "plurality" appearing in the embodiments of the present application means two or more.
The descriptions of the first, second, etc. appearing in the embodiments of the present application are only for illustrating and differentiating the objects, and do not represent the order or the particular limitation of the number of the devices in the embodiments of the present application, and do not constitute any limitation to the embodiments of the present application.
It should be noted that the sequence numbers of the steps in this embodiment do not represent a limitation on the execution sequence of the steps.
Although the present invention is disclosed above, the present invention is not limited thereto. Various changes and modifications may be effected therein by one skilled in the art without departing from the spirit and scope of the invention as defined in the appended claims.

Claims (17)

1. A method of data encryption, comprising:
reading a new random number whenever content is to be written;
updating the current hash tree by adopting 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 by adopting the encryption key to obtain encrypted content;
and executing write operation on the encrypted content.
2. The data encryption method of claim 1, wherein the updating the current hash tree using the new random number to obtain an updated hash tree comprises:
acquiring an updating condition, and determining the level of the random number to be updated in the current hash tree, wherein the updating condition is used for indicating the level of the random number to be updated;
updating the random number to be updated by adopting the new random number to obtain an updated random number;
and obtaining the updated hash tree according to the updated random number.
3. The data encryption method of claim 2, wherein the hash tree includes N levels of random numbers, i levels of random numbers are obtained based on i-1 levels of random numbers, i is greater than or equal to 1 and less than or equal to N, N is greater than or equal to 2, and i and N are integers.
4. The data encryption method of claim 3, wherein said updating the random number to be updated with the new random number comprises:
obtaining decrypted data according to the address of the content to be written, a pre-stored secret key and an i-1-level random number, wherein the i-1-level random number is a previous-level random number of the i-level random number to be updated;
decrypting the read new random number by adopting the decrypted data based on a symmetric decryption algorithm to obtain a plaintext corresponding to the new random number and storing the plaintext;
carrying out hash calculation on a 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;
and comparing the first hash value obtained by calculation with the hash value corresponding to the new random number, and if the first hash value obtained by calculation 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.
5. The data encryption method according to claim 4, wherein the obtaining the updated random number based on the plaintext corresponding to the new random number comprises:
and if the level of the random number to be updated comprises N-j levels of random numbers, updating the N-j +1 levels of random numbers based on the updated random numbers corresponding to the N-j levels of random numbers until the updating of the N levels of random numbers is completed, wherein j is more than or equal to 1 and less than N, and j is an integer.
6. The data encryption method of claim 3, further comprising: storing at least the N-level random numbers in the updated hash tree in a translation lookaside buffer.
7. The data encryption method of claim 3, wherein obtaining an encryption key from the updated hash tree comprises: and obtaining the encryption key according to the N-level random number.
8. The data encryption method of claim 7, wherein said deriving the encryption key from a random number of N levels comprises:
and obtaining an encryption key according to the address of the content to be written and the N-level random number.
9. The data encryption method according to claim 8, wherein the obtaining an encryption key according to the address of the content to be written and the N-level random number includes:
searching a corresponding N-level random number from the updated hash tree according to the address of the content to be written;
and obtaining the encryption key according to the address of the content to be written, a prestored key and the searched N-level random number.
10. The data encryption method according to claim 9, wherein the obtaining the encryption key according to the address of the content to be written, a pre-stored key, and a searched N-level random number includes:
and performing exclusive-or operation on the address of the content to be written, a pre-stored secret key and the searched N-level random number, and taking the exclusive-or operation result as the encryption secret key.
11. The data encryption method of claim 1, further comprising:
performing hash calculation 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.
12. The data encryption method of claim 11, further comprising:
when a reading operation is detected, acquiring a content to be read and a hash value corresponding to the content to be read;
acquiring a decryption key, decrypting the content to be read based on the decryption key, obtaining a plaintext corresponding to the content to be read, and caching the plaintext;
performing hash calculation 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, which is acquired from the updated hash tree, to obtain a hash value;
and if the hash value corresponding to the content to be read is the same as the calculated hash value, reading the cached content to be read through an appointed read port.
13. The data encryption method of claim 12, wherein said obtaining a decryption key comprises:
and obtaining the decryption key according to the address of the content to be read, a prestored key and a random number corresponding to the content to be read, which is obtained from the updated hash tree.
14. A data encryption method according to claim 10 or 13, wherein said pre-stored key is stored in a one-time programmable memory.
15. A data encryption apparatus, comprising:
a random number reading unit for reading a new random number whenever content is to be written;
the hash tree updating unit is used for updating the current hash tree by adopting 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;
the encryption unit is used for encrypting the content to be written by adopting the encryption secret key to obtain the encrypted content;
and the writing execution unit is used for executing writing operation on the encrypted content.
16. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of the data encryption method of any one of claims 1 to 14.
17. A terminal comprising a memory and a processor, the memory having stored thereon a computer program operable on the processor, wherein the processor, when executing the computer program, performs the steps of the data encryption method of any one of claims 1 to 14.
CN202210641375.0A 2022-06-08 2022-06-08 Data encryption method and device, storage medium and terminal Pending CN114996735A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210641375.0A CN114996735A (en) 2022-06-08 2022-06-08 Data encryption method and device, storage medium and terminal

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210641375.0A CN114996735A (en) 2022-06-08 2022-06-08 Data encryption method and device, storage medium and terminal

Publications (1)

Publication Number Publication Date
CN114996735A true CN114996735A (en) 2022-09-02

Family

ID=83033219

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210641375.0A Pending CN114996735A (en) 2022-06-08 2022-06-08 Data encryption method and device, storage medium and terminal

Country Status (1)

Country Link
CN (1) CN114996735A (en)

Similar Documents

Publication Publication Date Title
US10540297B2 (en) Memory organization for security and reliability
US20190229924A1 (en) Key rotating trees with split counters for efficient hardware replay protection
CN107038383B (en) Data processing method and device
CN107078904B (en) Hybrid cryptographic key derivation
CN109564553B (en) Multi-stage memory integrity method and apparatus
US20060107047A1 (en) Method, device, and system of securely storing data
US11308241B2 (en) Security data generation based upon software unreadable registers
US20190050347A1 (en) Memory data protection based on authenticated encryption
CN112469036B (en) Message encryption and decryption method and device, mobile terminal and storage medium
US20060294370A1 (en) Method, device, and system of maintaining a context of a secure execution environment
US10027640B2 (en) Secure data re-encryption
US20200175178A1 (en) Encrypted data exchange
US20230325516A1 (en) Method for file encryption, terminal, electronic device and computer-readable storage medium
CN115982761A (en) Sensitive information processing method and device, electronic equipment and storage medium
CN111966328A (en) Random number generator using multiple entropy sources and method for generating random numbers
US11354427B2 (en) Encrypting/decrypting method for multi-digit number and encrypting/decrypting server
US20200076591A1 (en) Systems and Methods for Automated Generation and Update of Cipher Parameters
WO2019178981A1 (en) Password management method and device employing customized rules, terminal apparatus, and storage medium
US9053325B2 (en) Decryption key management system
CN114996735A (en) Data encryption method and device, storage medium and terminal
CN111949996A (en) Generation method, encryption method, system, device and medium of security private key
KR101999209B1 (en) A system and method for encryption of pointers to virtual function tables
KR20170053056A (en) Security server using case based reasoning engine and storage medium for installing security function
CN111512308A (en) Storage controller, file processing method, device and system
EP3832945A1 (en) System and method for protecting memory encryption against template attacks

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination