Data storage method and electronic device

By establishing a one-to-one correspondence between the unique security key in each TEE and the RPMB storage area, the security risks caused by security key calls in the multi-TEE framework are resolved, and the security and accuracy of RPMB data writing are improved.

CN117668933BActive Publication Date: 2025-09-12HONOR DEVICE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211057403.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-08-30
Publication Date
2025-09-12
Estimated Expiration
2042-08-30

AI Technical Summary

Technical Problem

In a multi-trusted execution environment (TEE) framework, a TEE that does not store security keys has security risks when calling the security keys of other TEEs, resulting in insufficient security when writing data to the replay-protected memory block (RPMB).

Method used

A unique security key is stored in each TEE and mapped one-to-one with the corresponding RPMB storage area. The local security key is used to authenticate and store the data to avoid cross-TEE key calls. The hypervisor module and the driver module in the REE are used to transmit data to simplify the process.

Benefits of technology

Improves the security and accuracy of data written to RPMB in a multi-TEE framework, reduces key interactions, simplifies the writing process, and enhances the pertinence and security of data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117668933B_ABST
    Figure CN117668933B_ABST
Patent Text Reader

Abstract

The embodiment of the present application is applicable to the field of data processing, and provides a data storage method and electronic device, which are applied to an electronic device including at least two TEEs and RPMB, wherein the RPMB includes at least two storage areas, and the security keys stored in each storage area of ​​the at least two storage areas are different, and the at least two TEEs include a first TEE, and the at least two storage areas include a first storage area, wherein the first TEE and the first storage area store the same first security key, and the first TA uses the first security key to perform authentication calculations on the data to be stored, obtains the first authentication data, and then sends the first data packet obtained according to the data to be stored and the first authentication data to the first storage area, and the first storage area stores the data to be stored based on the same first security key. This can improve the security of writing data to RPMB in a multi-TEE framework.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing, and more particularly, to a data storage method and an electronic device. Background Art

[0002] A replay protected memory block (RPMB) is a separate physical partition in memory, often used to store sensitive data such as encryption keys. This memory can include Universal Flash Storage (UFS) and embedded Multi Media Card (eMMC).

[0003] With the continuous advancement of terminal technology, the multi-trusted execution environment (TEE) architecture has become a common architecture. Usually, RPMB needs to use a secure key to authenticate the data to be stored sent by the TEE, and store the data to be stored if the authentication is successful. The Secure Key can only be stored in one TEE. When the terminal device adopts a multi-TEE framework, the TEE that does not store the Secure Key needs to call the Secure Key in the TEE that stores the Secure Key to authenticate the data and obtain the first authentication data, so that RPMB can determine whether to store the data to be stored based on the first authentication data. However, in the process of calling the Secure Key, the TEE that does not store the Secure Key may leak the security key, which poses a security risk.

[0004] Based on this, how to improve the security of each TEE in the multi-TEE framework writing data to RPMB has become an urgent problem to be solved. Summary of the Invention

[0005] The present application provides a data storage method that can improve the security of each TEE in a multi-TEE framework writing data to RPMB.

[0006] In a first aspect, a data storage method is provided. The method is applied to an electronic device, wherein the electronic device includes at least two trusted execution environments (TEEs) and a replay protected memory block (RPMB). The RPMB includes at least two storage areas, each of the at least two storage areas stores a different security key, one of the at least two TEEs corresponds to one of the at least two storage areas, the at least two TEEs include a first TEE, a first trusted application (TA) runs in the first TEE, the at least two storage areas include a first storage area, the first TEE corresponds to the first storage area, the first TEE and the first storage area store a first security key, the first security key is used for the first storage area and the first TA to perform authentication calculations on data to be stored, and the data to be stored is data written to the first storage area. The method includes:

[0007] The first TA sends a first data packet to the first storage area. The first data packet includes the data to be stored and first authentication data. The first authentication data is data obtained by the first TA using the first security key to perform authentication calculation on the data to be stored.

[0008] The first storage area stores data to be stored based on a first security key.

[0009] It should be understood that storage devices support the function of multiple RPMB regions. Different RPMB partitions can write different security keys. Correspondingly, different security keys can also be stored in different TEEs.

[0010] In an embodiment of the present application, the electronic device includes at least two trusted execution environments TEE and a replay protection memory block RPMB, the RPMB includes at least two storage areas, the security keys stored in each of the at least two storage areas are different, one of the at least two TEEs corresponds one-to-one to one of the at least two storage areas, the at least two TEEs include a first TEE, a first trusted application TA runs in the first TEE, the at least two storage areas include a first storage area, the first TEE corresponds to the first storage area, wherein the first TEE stores a first security key, the first storage area stores the same first security key as that in the first TEE, the first TA uses the first security key to perform authentication calculations on the data to be stored to obtain first authentication data, and then sends a first data packet obtained based on the data to be stored and the first authentication data to the first storage area, and the first storage area stores the data to be stored based on the same first security key. Thus making the first TEE when storing data to be stored to the first storage area corresponding thereto, the first security key used is the security key stored in the first TEE, there is no need to call security key from other TEEs, so as to avoid the situation of security key leakage that may occur when calling security key from other TEEs, improve the security of writing data to RPMB in multi-TEE framework. Meanwhile, using the data storage method provided in the embodiment of the present application, each TEE is in the process of writing data to RPMB, there is no need to call security key each other, reduces the data interaction caused by calling security key, simplifies the process of writing data to RPMB. Further, due to the different security keys stored in each storage area in at least two storage areas, even if the first TEE appears when writing data to RPMB subregions, mistakenly sending data to other RPMB subregions (i.e., not the RPMB subregions corresponding to the first TEE), due to the different security keys stored in other RPMB subregions and the security keys stored in the first TEE, therefore other RPMB subregions are verified by the security keys stored thereon to write data and can cause verification not to pass, so that other RPMB subregions cannot store the data sent by the first TEE, improve the pertinence of writing data to RPMB, and further improve the security of the data of RPMB.

[0011] In conjunction with the first aspect, in certain implementations of the first aspect, the electronic device further includes a kernel, the kernel includes a hypervisor module, and the first TA sends the first data packet to the first storage area, including:

[0012] The first TA sends a first data packet to the Hypervisor module;

[0013] The Hypervisor module sends a first data packet to the first storage area.

[0014] It should be understood that the Hypervisor module has the function of accessing all physical devices on the electronic device, including disks and memory. After the server is started, the Hypervisor module will load the operating systems of all virtual machine clients (including TEE-0, TEE-1 and storage devices) and allocate memory, disk and network for the virtual machines. This allows the Hypervisor module to directly allocate data interfaces for the first TEE and storage device, so that data can be transferred between TEE-0 and storage devices, and between TEE-1 and storage devices.

[0015] In conjunction with the first aspect, in certain implementations of the first aspect, the first data packet includes a first parameter, where the first parameter is used to indicate the first storage area; and the hypervisor module sends the first data packet to the first storage area, including:

[0016] The hypervisor module determines a first storage area based on the first parameter;

[0017] The Hypervisor module sends a first data packet to the first storage area.

[0018] The first parameter may refer to a SECURITY PROTOCOL SPECIFIC parameter, and the SECURITY PROTOCOLSPECIFIC parameter is used to indicate an identifier of the RPMB partition to which the first data packet is sent.

[0019] In an embodiment of the present application, an electronic device includes at least two trusted execution environments (TEEs) and a replay protection memory block (RPMB), one of the at least two TEEs corresponds to a storage area in the RPMB, and the at least two TEEs include a first TEE, a first trusted application (TA) is running in the first TEE, and the RPMB includes a first storage area, and the first TEE corresponds to the first storage area, wherein a first security key is stored in the first TEE, and the first storage area stores the same first security key as that in the first TEE. The first TA uses the first security key to perform authentication calculations on the data to be stored to obtain first authentication data, and then sends a first data packet obtained based on the data to be stored, the first parameter, and the first authentication data to the Hypervisor module. The Hypervisor module determines that the receiving object of the first data packet is the first storage area based on the first parameter, and then sends the first data packet to the first storage area. The first storage area stores the data to be stored based on the same first security key. This enables the Hypervisor module to accurately send the first data packet to the first storage object, and further improves the accuracy of writing data to the first storage area on the basis of authenticating the data written to the first storage area using an independent security key.

[0020] In conjunction with the first aspect, in certain implementations of the first aspect, the kernel further includes an ATF module, and the first TA sends a first data packet to the hypervisor module, including:

[0021] The first TA sends a first data packet to the ATF module;

[0022] The ATF module sends a first data packet to the Hypervisor module.

[0023] In an embodiment of the present application, an electronic device includes at least two trusted execution environments TEE and a replay protection memory block RPMB, one of the at least two TEEs corresponds one-to-one to a storage area in the RPMB, and the at least two TEEs include a first TEE, a first trusted application TA runs in the first TEE, and the RPMB includes a first storage area, and the first TEE corresponds to the first storage area, wherein a first security key is stored in the first TEE, and the first storage area stores the same first security key as that in the first TEE. The first TA uses the first security key to perform authentication calculations on the data to be stored to obtain first authentication data, and then sends the first data packet obtained based on the data to be stored and the first authentication data to the first storage area. In the process of sending the first data packet to the first storage area, it can be sent to the first storage area through the ATF module. Usually, sending data to RPMB through the ATF module is a pre-set process, so the user does not need to set how to send data to RPMB, which improves the convenience of writing data to the first storage area to the first TEE.

[0024] In combination with the first aspect, in certain implementations of the first aspect, the electronic device further includes a rich execution environment (REE), in which a first TEE RPMB driver module runs, and the hypervisor module sends a first data packet to the first storage area, including:

[0025] The Hypervisor module sends a first data packet to the first TEE RPMB driver module;

[0026] The first TEE RPMB driver module sends a first data packet to the first storage area.

[0027] It should be understood that modifying processes in the kernel requires obtaining the corresponding permissions. However, in one possible scenario, due to restrictions imposed by the chip manufacturer, it is impossible to obtain permissions to modify processes in the kernel. Therefore, by using the data storage method provided in the embodiment of the present application, it is possible to send the first data packet from the first TEE to the first storage area without modifying the processes in the kernel.

[0028] It should be understood that modifying processes in the kernel requires obtaining the corresponding permissions. However, in one possible scenario, due to restrictions imposed by the chip manufacturer, it is impossible to obtain permissions to modify processes in the kernel. Therefore, by using the data storage method provided in the embodiment of the present application, it is possible to send the first data packet from the first TEE to the first storage area without modifying the processes in the kernel.

[0029] The data storage method provided in the embodiment of the present application is applied to an electronic device, which includes at least two TEEs and RPMBs, wherein the RPMB includes at least two storage areas, wherein one TEE in at least two TEEs corresponds to a storage area in the RPMB, wherein at least two TEEs include a first TEE, wherein a first TA is running in the first TEE, and at least two storage areas include a first storage area, wherein the first TEE corresponds to the first storage area, wherein a first security key is stored in the first TEE, wherein the first storage area stores the same first security key as that in the first TEE, and the first TA uses the first security key to perform authentication calculation on the data to be stored, obtains the first authentication data, and then uses the first data packet obtained according to the data to be stored and the first authentication data to send the first data packet to the first storage area. The first TEE RPMB driver module running in the REE is used to send the first data packet. Since the first TEE RPMB driver module runs in the REE, rather than in the Kernel, in the process of sending the first data packet to the first storage area, the first TEE does not need to modify the process in the Kernel, that is, there is no need to obtain the permission to modify the process in the Kernel, thereby improving the convenience of the first TEE sending the first data packet to the first storage area.

[0030] In combination with the first aspect, in some implementations of the first aspect, the kernel further includes a storage device driver module, and the first TEE RPMB driver module sends the first data packet to the first storage area, including:

[0031] The first TEE RPMB driver module sends a first data packet to the storage device driver module;

[0032] The storage device driver module sends a first data packet to the first storage area.

[0033] Exemplarily, the storage device driver module is an eMMC driver module.

[0034] Exemplarily, the storage device driver module is a UFS driver module.

[0035] In combination with the first aspect, in certain implementations of the first aspect, the kernel includes a first TEE tz driver module, and the hypervisor module sends a first data packet to the first TEE RPMB driver module, including:

[0036] The Hypervisor module sends a first data packet to the first TEE tz driver module;

[0037] The first TEE tz driver module sends a first data packet to the first TEE RPMB driver module.

[0038] In conjunction with the first aspect, in certain implementations of the first aspect, the first storage area stores the data to be stored based on the first security key, including:

[0039] The first storage area uses the first security key to perform authentication calculation on the data to be stored in the first data packet to obtain second authentication data;

[0040] In the case where the first authentication data and the second authentication data match, the first storage area stores the data to be stored.

[0041] It should be understood that the first authentication data is obtained by performing an authentication calculation on the data to be stored using the first security key, and the second authentication data is also obtained by performing an authentication calculation on the data to be stored using the same first security key. In other words, if the first security key and the data to be stored are the same, and the authentication calculation method is the same, then the first authentication data and the second authentication data are obtained by performing the same calculation on the same data using the same security key, and the first authentication data and the second authentication data are also identical.

[0042] It should be understood that in the process of obtaining the first authentication data and the second authentication data, authentication calculations need to be performed on the data to be stored separately. To account for errors that may occur in the authentication calculations, the first authentication data and the second authentication data can be considered to match when the portion of the first authentication data and the second authentication data that is identical exceeds a preset threshold. If it is determined that the first authentication data and the second authentication data match, the first storage area can store the data to be stored.

[0043] In the data storage method provided in the embodiment of the present application, the electronic device includes at least two trusted execution environments TEE and a replay protection memory block RPMB, one TEE in at least two TEEs corresponds to a storage area in the RPMB, at least two TEEs include a first TEE, a first trusted application TA is running in the first TEE, RPMB includes a first storage area, the first TEE corresponds to the first storage area, wherein the first security key is stored in the first TEE, the first storage area stores the same first security key as the first TEE, the first TA uses the first security key to perform authentication calculation on the data to be stored, obtains the first authentication data, and then sends the first data packet obtained according to the data to be stored and the first authentication data to the first storage area, the first storage area uses the same first security key to perform the same authentication calculation on the data to be stored in the first data packet, obtains the second authentication data, and when the first authentication data and the second authentication data match, stores the data to be stored, and stores the data to be stored based on the same first security key. In this way, the data stored in the first storage area are all data that have been verified by the first storage area through an independent security key, which can effectively avoid data from unknown sources from attacking the data stored in the first storage area, thereby improving the security of the data stored in the first storage area.

[0044] In conjunction with the first aspect, in certain implementations of the first aspect, the electronic device further includes a rich execution environment (REE) and a first device, the first client application (CA) running in the REE, and the method further includes:

[0045] receiving a first operation, where the first operation is used to instruct acquisition of data to be stored;

[0046] In response to the first operation, the first CA sends a first request to the first TA, where the first request is used to instruct the first TA to obtain data to be stored;

[0047] In response to the first request, the first TA instructs the first device to collect first data;

[0048] The first TA obtains data to be stored based on the first data.

[0049] In combination with the first aspect, in some implementations of the first aspect, the first device includes a fingerprint sensor.

[0050] In combination with the first aspect, in some implementations of the first aspect, the first device includes a camera.

[0051] In combination with the first aspect, in certain implementations of the first aspect, the first TA includes a face TA and a first RPMB service module, the first RPMB service module stores a first security key, the data to be stored is face recognition data, and the first TA sends a first data packet to the hypervisor module, including:

[0052] Face TA instructs the camera to collect face recognition data;

[0053] The face TA sends the face recognition data to the first RPMB service module;

[0054] The first RPMB service module generates a first data packet based on the face recognition data;

[0055] The first RPMB service module sends a first data packet to the Hypervisor module.

[0056] In conjunction with the first aspect, in certain implementations of the first aspect, the electronic device further includes a rich execution environment (REE) and a camera, the face client application (CA) runs in the REE, and before the face client application (TA) instructs the camera to collect face recognition data, the method further includes:

[0057] Face CA detects a face recognition registration operation, which is used to instruct the acquisition of face recognition data;

[0058] In response to the face recognition registration operation, face CA sends a face recognition registration request to face TA, where the face recognition registration request is used to instruct face TA to obtain face recognition data;

[0059] Face TA instructs the camera to collect face recognition data, including:

[0060] In response to the face recognition registration request, the face TA instructs the camera to collect face recognition data.

[0061] In combination with the first aspect, in certain implementations of the first aspect, the first TA includes a fingerprint TA and a second RPMB service module, the second RPMB service module stores a first security key, the data to be stored is fingerprint data, and the first TA sends a first data packet to the hypervisor module, including:

[0062] Fingerprint TA instructs the fingerprint sensor to collect fingerprint data;

[0063] The fingerprint TA sends the fingerprint data to the second RPMB service module;

[0064] The second RPMB service module generates a first data packet based on the fingerprint data;

[0065] The second RPMB service module sends the first data packet to the Hypervisor module.

[0066] Exemplarily, the data to be stored may be data collected by a fingerprint sensor.

[0067] In conjunction with the first aspect, in certain implementations of the first aspect, the electronic device further includes a rich execution environment (REE) and a fingerprint sensor, the fingerprint client application (CA) runs in the REE, and before the fingerprint client application (TA) instructs the fingerprint sensor to collect fingerprint data, the method further includes:

[0068] The fingerprint CA detects a fingerprint registration operation, which is used to instruct the acquisition of fingerprint data;

[0069] In response to the fingerprint registration operation, the fingerprint CA sends a fingerprint registration request to the fingerprint TA, where the fingerprint registration request is used to instruct the fingerprint TA to obtain fingerprint data;

[0070] Fingerprint TA instructs the fingerprint sensor to collect fingerprint data, including:

[0071] In response to the fingerprint registration request, the fingerprint TA instructs the fingerprint sensor to collect fingerprint data.

[0072] In conjunction with the first aspect, in certain implementations of the first aspect, the kernel further includes an ATF module, and the second RPMB service module sends the first data packet to the hypervisor module, including:

[0073] The second RPMB service module sends the first data packet to the ATF module;

[0074] The ATF module sends a first data packet to the Hypervisor module.

[0075] In an embodiment of the present application, the electronic device includes at least two trusted execution environments TEE and a replay protection memory block RPMB, wherein the RPMB includes at least two storage areas, the security keys stored in each of the at least two storage areas are different, one TEE in the at least two TEEs corresponds to one storage area in the at least two storage areas, the at least two TEEs include a first TEE, a fingerprint TA and a second RPMB service module are running in the first TEE, the RPMB includes a first storage area, the first TEE corresponds to the first storage area, wherein the second RPMB service module in the first TEE stores a first security key, and the first storage area stores a fingerprint corresponding to the second RPMB. The same first security key is used in the MB service module, the fingerprint TA collects fingerprint data, and sends the fingerprint data to the second RPMB service module. The second RPMB service module uses the first security key to perform authentication calculation on the fingerprint data to obtain the first authentication data, and then sends the first data packet obtained according to the fingerprint data and the first authentication data to the first storage area. In the process of sending the first data packet to the first storage area, it can be sent to the first storage area through the ATF module. Usually, sending data to RPMB through the ATF module is a pre-set process, so the user does not need to set how to send data to RPMB, which improves the convenience of writing data to the first storage area of ​​the first TEE.

[0076] In combination with the first aspect, in some implementations of the first aspect, the authentication calculation includes a hash HMAC calculation.

[0077] In an embodiment of the present application, the second TA uses a security key to perform authentication calculations on the data to be stored through a hash operation to obtain first authentication data. Since the hash operation is an encryption algorithm that is currently widely used and has withstood various forms of attacks, the first authentication data obtained through the hash operation is more reliable encrypted data, thereby improving the security of the first authentication data.

[0078] In a second aspect, a data storage device is provided, comprising a unit for executing any of the methods of the first aspect. The device may be a server, a terminal device, or a chip within the terminal device. The device may include an acquisition unit and a processing unit.

[0079] When the device is a terminal device, the processing unit may be a processor, and the input unit may be a communication interface; the terminal device may also include a memory for storing computer program code, and when the processor executes the computer program code stored in the memory, the terminal device executes any one of the methods in the first aspect.

[0080] When the device is a chip in a terminal device, the processing unit may be a processing unit inside the chip, and the input unit may be an output interface, a pin or a circuit, etc.; the chip may also include a memory, which may be a memory inside the chip (for example, a register, a cache, etc.) or a memory located outside the chip (for example, a read-only memory, a random access memory, etc.); the memory is used to store computer program code, and when the processor executes the computer program code stored in the memory, the chip executes any one of the methods in the first aspect.

[0081] In one possible implementation, a memory is used to store computer program code; a processor executes the computer program code stored in the memory, and when the computer program code stored in the memory is executed, the processor is used to execute: a first TA sends a first data packet to a first storage area, the first data packet includes data to be stored and first authentication data, the first authentication data is data obtained after the first TA uses a first security key to perform authentication calculations on the data to be stored; the first storage area stores the data to be stored based on the first security key.

[0082] In a third aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program code, and when the computer program code is executed by a data storage device, the data storage device executes any one of the data storage methods in the first aspect.

[0083] In a fourth aspect, a computer program product is provided, comprising: a computer program code, which, when executed by a data storage device, causes the data storage device to execute any one of the device methods in the first aspect.

[0084] In an embodiment of the present application, an electronic device includes at least two trusted execution environments TEE and a replay protection memory block RPMB, the RPMB includes at least two storage areas, the security keys stored in each of the at least two storage areas are different, one of the at least two TEEs corresponds one-to-one to one of the at least two storage areas, the at least two TEEs include a first TEE, a first trusted application TA runs in the first TEE, the at least two storage areas include a first storage area, the first TEE corresponds to the first storage area, wherein the first TEE stores a first security key, the first storage area stores the same first security key as that in the first TEE, the first TA uses the first security key to perform authentication calculations on the data to be stored to obtain first authentication data, and then sends a first data packet obtained based on the data to be stored and the first authentication data to the first storage area, and the first storage area stores the data to be stored based on the same first security key. Thus making the first TEE when storing data to be stored to the first storage area corresponding thereto, the first security key used is the security key stored in the first TEE, there is no need to call security key from other TEEs, so as to avoid the situation of security key leakage that may occur when calling security key from other TEEs, improve the security of writing data to RPMB in multi-TEE framework. Meanwhile, using the data storage method provided in the embodiment of the present application, each TEE is in the process of writing data to RPMB, there is no need to call security key each other, reduces the data interaction caused by calling security key, simplifies the process of writing data to RPMB. Further, due to the different security keys stored in each storage area in at least two storage areas, even if the first TEE appears when writing data to RPMB subregions, mistakenly sending data to other RPMB subregions (i.e., not the RPMB subregions corresponding to the first TEE), due to the different security keys stored in other RPMB subregions and the security keys stored in the first TEE, therefore other RPMB subregions are verified by the security keys stored thereon to write data and can cause verification not to pass, so that other RPMB subregions cannot store the data sent by the first TEE, improve the pertinence of writing data to RPMB, and further improve the security of the data of RPMB. BRIEF DESCRIPTION OF THE DRAWINGS

[0085] Figure 1 It is a flow chart of RPMB writing data;

[0086] Figure 2 It is a schematic diagram of the logical addresses of multiple RPMB partitions;

[0087] Figure 3 is a schematic diagram of a hardware system of an electronic device applicable to the present application;

[0088] Figure 4 is a schematic diagram of a software system for an electronic device applicable to the present application;

[0089] Figure 5 This is a schematic diagram of an application scenario provided by an embodiment of the present application;

[0090] Figure 6 is a schematic diagram of an electronic device for data storage provided by an embodiment of the present application;

[0091] Figure 7 This is a flow chart of a data storage method provided by an embodiment of the present application;

[0092] Figure 8 is a schematic diagram of another electronic device for data storage provided in an embodiment of the present application;

[0093] Figure 9 This is a flow chart of another data storage method provided by an embodiment of the present application;

[0094] Figure 10 This is a schematic diagram of data flow of a data storage method provided in an embodiment of the present application;

[0095] Figure 11 is a schematic diagram of a data format of a write request provided in an embodiment of the present application;

[0096] Figure 12 is a schematic diagram of a data format of a first data packet provided in an embodiment of the present application;

[0097] Figure 13 This is a flow chart of another data storage method provided by an embodiment of the present application;

[0098] Figure 14 This is a schematic diagram of data flow of another data storage method provided by an embodiment of the present application;

[0099] Figure 15 is a schematic diagram of an electronic device provided by this application;

[0100] Figure 16 This is a schematic diagram of an electronic device for data storage provided by this application. DETAILED DESCRIPTION

[0101] The technical solutions in the embodiments of the present application will be described below in conjunction with the accompanying drawings in the embodiments of the present application. In the description of the embodiments of the present application, unless otherwise specified, " / " means or, for example, A / B can mean A or B; "and / or" in this article is merely a description of the association relationship of associated objects, indicating that three relationships can exist, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, "multiple" means two or more than two.

[0102] In the following, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the quantity of the technical features indicated. Therefore, a feature specified as "first," "second," or "third" may explicitly or implicitly include one or more of the features.

[0103] To facilitate understanding, some descriptions of concepts related to the embodiments of the present application are given as examples for reference.

[0104] 1. RPMB

[0105] RPMB refers to an independent physical partition in the memory, usually used to store data that needs to be protected from illegal tampering, such as public keys and serial numbers related to fingerprint payment on mobile phones. Generally, RPMB will authenticate write operations, but read operations do not require authentication.

[0106] It should be understood that in the process of producing electronic devices, a unique security key will be generated for each electronic device, and the security key will be burned into the OTP area in the memory of the electronic device. Among them, the OTP area refers to an area that can only be burned once. At the same time, the host of the electronic device will store the security key in a secure execution environment (for example, TEE). When the host writes data to RPMB, RPMB can use the security key for authentication.

[0107] For example, the host (trusted application TA in TEE) writes data to the device (for example, UFS) as an example for description.

[0108] like Figure 1As shown, the host sends a request to read the count value Write Cnt and a random number to the device to obtain the count value Write Cnt in the device. After receiving the request to read the count value Write Cnt, the device uses the security key to perform an HMAC calculation on the count value Write Cnt and the random number to generate a first MAC. The device then fills the Write Cnt, random number, and first MAC into the corresponding area of ​​the RPMB packet, generates an RPMB packet, and sends the RPMB packet to the host. Upon receiving the RPMB packet, the host uses the security key to perform an HMAC calculation on the Write Cnt and random number in the RPMB packet to obtain a second MAC. The host compares the values ​​of the first MAC and the second MAC to see if they are consistent. If the values ​​of the first MAC and the second MAC are consistent, the host compares the random number sent by the host to the device with the random number in the RPMB packet to see if they are consistent. If the random number sent by the host to the device is consistent with the random number in the RPMB packet, the host determines that the Write Cnt in the RPMB packet is authentic.

[0109] Furthermore, the Host uses the security key to perform an HMAC calculation on the destination address of the data to be stored, the data to be stored, and the Write Cnt to obtain a third MAC, and fills the third MAC into the MAC area of ​​the RPMB packet to obtain an updated RPMB packet, and then sends the updated RPMB packet to the Device. The Device receives the updated RPMB packet, uses the security key to perform an HMAC calculation on the destination address of the data to be stored, the data to be stored, and the Write Cnt to obtain a fourth MAC, compares the fourth MAC with the third MAC, and if the fourth MAC and the third MAC are consistent, compares the Write Cnt in the updated RPMB packet with the Write Cnt in the Device to see if they are consistent. If the Write Cnt in the updated RPMB packet and the Write Cnt in the Device are consistent, the data to be stored in the updated RPMB packet is stored in the destination address corresponding to the data to be stored, and increments the Write Cnt in the Device by 1 to obtain an updated Write Cnt.

[0110] In one possible scenario, RPMB refers to an area in UFS. Based on the description in the JESD220E document of the UFS 3.0 protocol and above, the storage device supports the function of multiple RPMB regions. When the storage device supports the multiple RPMB region function, each area in the RPMB has an independent authentication key, counter, and result memory, and the starting value of the logical address of each area in the RPMB is 0.

[0111] The starting address of the logical address of each area in the RPMB is 0. For example, Figure 2 As shown in the figure, the starting value of the physical address of RPMBregion0 is 0x00000000, the starting value of the logical address of RPMBregion0 is 0x00000000, and the area size of region0 is 12M bits. The starting value of the physical address of RPMBregion1 adjacent to RPMBregion0 is 0x00800000, but the starting value of the logical address of RPMBregion1 is still 0x00000000, and the area size of RPMBregion1 is 4M bits.

[0112] 2. Trusted execution environment (TEE)

[0113] A TEE is an independent, secure runtime environment within a terminal device, typically logically isolated from a rich execution environment (REE). TEEs are protected by strict protections designed to defend against software attacks that are common in REEs. Therefore, TEEs are typically used for tasks requiring high security.

[0114] 3. Rich execution environment (REE)

[0115] REE generally refers to the general operating environment on terminal devices, which does not have specific security features. For example, Android and iOS systems are both REE.

[0116] TEE and REE are isolated from each other. Usually, REE cannot directly access the hardware and software resources of TEE and can only interact through authorized application programming interfaces.

[0117] 4. Trusted Application (TA)

[0118] TA usually refers to an application running on TEE and can provide security services for applications running outside TEE.

[0119] 5. Client Application (CA)

[0120] CA usually refers to the application running on REE.

[0121] 6. Hypervisor

[0122] A hypervisor is a software layer running between the underlying physical server and the operating system. It provides access to all physical devices on electronic devices, including disks and memory. The hypervisor coordinates access to hardware resources and protects each virtual machine. After the server boots, the hypervisor loads the operating systems of all virtual machine clients and allocates memory, disks, and network resources to the virtual machines. Based on the hypervisor's mechanisms, electronic devices can support multiple TEEs running simultaneously.

[0123] 7. ATF

[0124] ATF( Trusted Firmware) refers to The underlying open-source firmware code provided by the chip divides the entire system into four operating levels: EL0, EL1, EL2, and EL3. Applications run at EL0, drivers run at EL1, hypervisor modules run at EL2, and ATF modules run at EL3.

[0125] At present, when the terminal device adopts a multi-TEE architecture, each TEE needs to write data to the RPMB. It should be understood that the RPMB needs to use a secure key to authenticate the data to be stored sent by the TEE, and store the data to be stored if the authentication is successful. Since the RPMB needs to authenticate the data to be stored through the same Secure Key, no matter which TEE the Secure Key is stored in, other TEEs need to use the Secure Key for authentication calculations, and all need to interact with the TEE that stores the Secure Key. In the process of data interaction, security key leakage may occur, posing a security risk.

[0126] The data storage method provided by the embodiment of the present application is applied to an electronic device, which includes at least two TEEs and RPMB, RPMB includes at least two storage areas, one TEE in at least two TEEs corresponds to a storage area in RPMB, at least two TEEs include a first TEE, a first TA is running in the first TEE, at least two storage areas include a first storage area, the first TEE corresponds to the first storage area, wherein a first security key is stored in the first TEE, the first storage area stores the same first security key as that in the first TEE, the first TA uses the first security key to perform authentication calculation on the data to be stored, obtains the first authentication data, and then sends the first data packet obtained according to the data to be stored and the first authentication data to the first storage area, the first storage area stores the data to be stored based on the same first security key. In this way, when the first TEE stores the data to be stored in the first storage area corresponding to it, the first security key used is the security key stored in the first TEE, and there is no need to call the security key from other TEEs, thereby avoiding the situation where the security key leakage that may occur when calling the security key from other TEEs is avoided, and the security of writing data to RPMB in the multi-TEE framework is improved.

[0127] The data storage method provided in the embodiment of the present application can be applied to electronic devices. Optionally, the electronic device includes a terminal device, which can also be referred to as a terminal, user equipment (UE), mobile station (MS), mobile terminal (MT), etc. The terminal device can be a mobile phone, a smart TV, a wearable device, a tablet computer (Pad), a computer with wireless transceiver function, a virtual reality (VR) terminal device, an augmented reality (AR) terminal device, a wireless terminal in industrial control, a wireless terminal in self-driving, a wireless terminal in remote medical surgery, a wireless terminal in smart grid, a wireless terminal in transportation safety, a wireless terminal in smart city, a wireless terminal in smart home, etc. The embodiments of the present application do not limit the specific technology and specific device form adopted by the terminal device.

[0128] For example, Figure 3: The figure shows a schematic diagram of the structure of the electronic device 100. The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display 194, and a subscriber identification module (SIM) card interface 195. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.

[0129] It should be understood that the structures illustrated in the embodiments of the present application do not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown, or may combine or separate certain components, or arrange the components differently. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0130] The processor 110 may include one or more processing units. For example, the processor 110 may include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU). The different processing units may be independent devices or integrated into one or more processors.

[0131] Exemplarily, in an embodiment of the present application, the processor 110 can be used to execute the data storage method provided in an embodiment of the present application; for example, a first trusted application TA sends a first data packet to a second trusted application, the first data packet includes data to be stored, the data to be stored refers to data written to the RPMB, the first TA refers to a trusted application running on the first TEE, and the second TA refers to a trusted application running in the second TEE; the second TA uses a security key to perform authentication calculations on the data to be stored in the first data packet to obtain first authentication data; the second TA generates a second data packet based on the first authentication data and the data to be stored; the second TA sends a second data packet to the RPMB; and the RPMB stores the data to be stored based on the second data packet.

[0132] The controller may be the nerve center and command center of the electronic device 100. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.

[0133] Processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in processor 110 is a cache memory. This memory can store instructions or data that have just been used or are being recycled by processor 110. If processor 110 needs to use the same instruction or data again, it can directly access the memory. This avoids duplicate accesses, reduces processor 110 latency, and thus improves system efficiency.

[0134] The fingerprint sensor 180H is used to collect fingerprints. The electronic device 100 can use the collected fingerprint characteristics to implement fingerprint unlocking, access application locks, fingerprint photography, fingerprint call answering, etc.

[0135] The camera 193 is used to capture still images or videos. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the light signal into an electrical signal, and then passes the electrical signal to the ISP for conversion into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard RGB, YUV or other format. In some embodiments, the electronic device 100 may include 1 or N cameras 193, where N is a positive integer greater than 1.

[0136] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 via the external memory interface 120 to implement data storage functions. For example, files such as music and videos can be stored on the external memory card.

[0137] The internal memory 121 can be used to store computer executable program codes, which include instructions. The processor 110 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area can store data created during the use of the electronic device 100 (such as audio data, a phone book, etc.), etc. In addition, the internal memory 121 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.

[0138] Optionally, the memory (also called storage device) in the electronic device includes eMMC and Universal File Store (UFS). Among them, the RPMB in the memory is usually used to store data with confidentiality requirements. When writing data to the RPMB, it is necessary to perform authentication calculations using a pre-stored security key to obtain authentication data. The RPMB verifies the written data with the security key stored thereon, and after the verification passes, the verified data is stored on the RPMB.

[0139] The electronic device 100 can implement audio functions such as music playback and recording through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone jack 170D, and the application processor.

[0140] The audio module 170 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals. The audio module 170 can also be used to encode and decode audio signals. In some embodiments, the audio module 170 can be provided in the processor 110, or some functional modules of the audio module 170 can be provided in the processor 110.

[0141] The speaker 170A, also called a "speaker", is used to convert audio electrical signals into sound signals. The electronic device 100 can listen to music or listen to hands-free calls through the speaker 170A.

[0142] The receiver 170B, also called a "handset", is used to convert audio electrical signals into sound signals. When the electronic device 100 receives a call or a voice message, the user can place the receiver 170B close to the ear to hear the voice.

[0143] Microphone 170C, also known as "microphone" or "microphone", is used to convert sound signals into electrical signals. When making a call or sending a voice message, the user can speak by putting their mouth close to the microphone 170C to input the sound signal into the microphone 170C. The electronic device 100 can be provided with at least one microphone 170C. In other embodiments, the electronic device 100 can be provided with two microphones 170C, which can not only collect sound signals but also realize noise reduction function. In other embodiments, the electronic device 100 can also be provided with three, four or more microphones 170C to collect sound signals, reduce noise, identify the source of sound, realize directional recording function, etc.

[0144] The headphone jack 170D is used to connect a wired headphone and can be the USB interface 130 or a 3.5mm open mobile terminal platform (OMTP) standard interface or a cellular telecommunications industry association of the USA (CTIA) standard interface.

[0145] It should be noted that any electronic device mentioned in the embodiments of the present application may include more or fewer modules in the electronic device 100.

[0146] The software system of the electronic device 100 can adopt a layered architecture, an event-driven architecture, a micro-kernel architecture, a micro-service architecture, or a cloud architecture. In the embodiment of the present application, the Android system with a layered architecture is used as an example to illustrate the software structure of the electronic device 100.

[0147] Figure 4 It is a software structure block diagram of the electronic device 100 according to an embodiment of the present application.

[0148] The layered architecture of electronic device 100 divides the software into several layers, each with a clear role and division of labor. Layers communicate with each other via software interfaces. In some embodiments, the Android system is divided into four layers: from top to bottom, the application layer, the application framework layer, the Android runtime and system libraries, and the kernel layer.

[0149] The application layer can include a series of application packages.

[0150] like Figure 4 As shown, the application package may include applications such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message, etc.

[0151] The application framework layer provides an application programming interface (API) and programming framework for the applications in the application layer. The application framework layer includes some predefined functions.

[0152] like Figure 4 As shown, the application framework layer may include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, and the like.

[0153] The window manager is used to manage window programs. The window manager can obtain the display size, determine whether there is a status bar, lock the screen, take screenshots, etc.

[0154] Content providers are used to store and retrieve data and make it accessible to applications. The data may include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.

[0155] The view system includes visual controls, such as those for displaying text and images. The view system is used to build applications. A display interface can consist of one or more views. For example, a display interface containing a text notification icon might include a view for displaying text and a view for displaying images.

[0156] The phone manager is used to provide communication functions of the electronic device 100, such as management of call status (including answering, hanging up, etc.).

[0157] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.

[0158] The Notification Manager allows applications to display notifications in the status bar. These messages can be displayed briefly and then disappear automatically without user interaction. For example, the Notification Manager is used to notify users of completed downloads and message reminders. The Notification Manager can also display notifications in the top status bar of the system as icons or scrolling text, such as notifications from background applications, or as dialog windows on the screen. Examples include text messages in the status bar, beeps, vibrations on electronic devices, and flashing indicator lights.

[0159] Android Runtime includes core libraries and a virtual machine. Android runtime is responsible for scheduling and management of the Android system.

[0160] The core library consists of two parts: one is the function that needs to be called by the Java language, and the other is the Android core library.

[0161] The application layer and application framework layer run in a virtual machine. The virtual machine executes Java files in the application layer and application framework layer as binary files. The virtual machine manages object lifecycles, stack management, thread management, security and exception management, and garbage collection.

[0162] The system library can include multiple functional modules, such as surface manager, media library, 3D graphics processing library (such as OpenGL ES), 2D graphics engine (such as SGL), etc.

[0163] The surface manager is used to manage the display subsystem and provide fusion of 2D and 3D layers for multiple applications.

[0164] The media library supports playback and recording of a variety of common audio and video formats, as well as static image files. The media library can support a variety of audio and video encoding formats, such as MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.

[0165] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.

[0166] A 2D graphics engine is a drawing engine for 2D drawings.

[0167] The kernel layer is the layer between hardware and software. The kernel layer includes at least display drivers, camera drivers, audio drivers, sensor drivers, Wi-Fi drivers, etc.

[0168] It should be noted that the electronic device mentioned in the embodiments of the present application may include more or fewer modules in the above-mentioned electronic device.

[0169] The application scenarios provided by the embodiments of the present application are described below with reference to the accompanying drawings.

[0170] With the continuous development of terminal technology, multi-TEE architecture has become a common architecture. For example, Figure 5As shown, the terminal device includes three TEEs and storage devices, namely TEE-0, TEE-1, TEE-2 and UFS. Among them, the RPMB in the UFS includes three RPMB partitions, namely RPMB region0, RPMB region1 and RPMB region2. The RPMB partition corresponding to TEE-0 is RPMB region0, the RPMB partition corresponding to TEE-1 is RPMB region1, and the RPMB partition corresponding to TEE-2 is RPMB region2. The data written by TEE-0 to RPMB is stored in RPMB region0, the data written by TEE-1 to RPMB is stored in RPMB region1, and the data written by TEE-2 to RPMB is stored in RPMB region2.

[0171] Among them, TEE-0 and RPMB region0 store the same secure key0 respectively, TEE-1 and RPMBregion1 store the same secure key1 respectively, and TEE-2 and RPMB region2 store the same secure key2 respectively.

[0172] The following uses TEE-0 (the first TEE) as an example to explain how to store data written to the RPMB partition. When TEE-0 writes data to RPMB region0 (the first storage area), TEE-0 uses secure key0 (the first security key) to authenticate the data to be stored and generates a data packet to be sent to RPMB region0. After RPMB region0 receives the data packet sent by TEE-0, it uses secure key0 to verify the data packet and, if the verification passes, stores the data to be stored in the data packet.

[0173] It should be understood that the process of writing data to TEE-1 and TEE-2 is similar to the process of writing data to TEE-0 mentioned above, and will not be repeated here.

[0174] Since each TEE can use the security key stored on it to write data to the corresponding RPMB partition, the situation of mutual call of security keys between TEEs is avoided, and the security key leakage that may occur in the process of mutual call of security keys is avoided.

[0175] It should be understood that the above is an example of an application scenario and does not limit the application scenario of this application.

[0176] The following combination Figures 6 to 12 The data storage method provided in the embodiment of the present application is described in detail.

[0177] The data storage method provided in the embodiment of the present application can be applied to an electronic device including at least two TEEs. For example, Figure 6 As shown, the electronic device includes TEE-0, TEE-1 and TEE-2, and the storage device in the electronic device includes three RPMB partitions, namely RPMB region0, RPMB region1 and RPMB region2, wherein the same secure key0 is stored in TEE-0 and RPMBregion0 respectively, the same securekey1 is stored in TEE-1 and RPMB region1 respectively, and the same secure key2 is stored in TEE-2 and RPMB region2 respectively. The first TA running in TEE-0 (equivalent to the first TEE) generates a first data packet based on the data to be stored, and sends the first data packet to RPMB region0 (equivalent to the first storage area). RPMB region0 verifies the first data packet and stores the data to be stored in the first data packet after the verification is passed.

[0178] It should be understood that the first TEE may also refer to TEE-1, and correspondingly, the first storage area may refer to RPMBregion1, and the first security key may refer to secure key1. The first TEE may also refer to TEE-2, and correspondingly, the first storage area may refer to RPMBregion2, and the first security key may refer to secure key2. This embodiment of the present application does not limit this.

[0179] Optionally, when the first TEE also refers to TEE-0, the corresponding first storage area refers to RPMB region0, and the first security key refers to secure key0, the second TEE can refer to TEE-1, the corresponding second storage area can refer to RPMB region0, and the second security key refers to secure key1. Usually, secure key0 is different from secure key1.

[0180] For ease of understanding, Figures 7 to 12 The illustrated embodiment is described by taking the example that the first TEE refers to TEE-0, the corresponding first storage area refers to RPMB region0, and the first security key refers to secure key0. Figure 13 and Figure 14 The illustrated embodiment is described by taking the first TEE as TEE-1, the corresponding first storage area as RPMB region1, and the first security key as secure key1 as an example.

[0181] The following combination Figure 7 For application Figure 6 The data storage method of the electronic device shown is described in detail.

[0182] Figure 7 This is a flow chart of a data storage method provided in one embodiment of the present application. Figure 7 As shown, this method is applied to Figure 6 In the electronic device shown. The method includes:

[0183] S101. A first TA sends a first data packet to a first storage region (ie, RPMB region0).

[0184] Among them, the first data packet includes the data to be stored and the first authentication data. The data to be stored refers to the data written to RPMBregion0, and the first authentication data refers to the data obtained by authenticating the data to be stored using secure key0 (equivalent to the first security key). The first TA refers to a trusted application running on TEE-0 (equivalent to the first TEE), and RPMB region0 (equivalent to the first storage area) refers to the RPMB partition corresponding to TEE-0 on the storage device.

[0185] It should be understood that based on the protocol above UFS 3.0, the storage device supports the function of multiple RPMB region. When the storage device supports the function of multiple RPMB region, the storage device can be divided into multiple RPMB partitions. Each RPMB partition has its own independent authentication key, counter and result memory. This allows each RPMB partition to use its independent authentication key to verify the data to be stored.

[0186] It should be understood that in the process of producing electronic equipment, a security key will be burned into the memory in the electronic equipment, and at the same time, the security key will be written into the TEE, so that when TEE writes data to RPMB, a security key can be used to authenticate the stored data and calculate, and authentication data can be obtained, so that RPMB can pass through the verification of authentication data when storing data, ensuring the security of the written data. Due to the electronic equipment in the embodiment of the present application including multiple RPMB partitions, correspondingly, each RPMB partition has different security keys. In other words, the process of burning a security key in the storage device in the electronic device is to burn the corresponding security key to each RPMB partition in the storage device, and the corresponding security key is burned into the corresponding TEE.

[0187] In one possible scenario, the process of burning security keys into the TEE and storage device can be to burn the security keys directly according to a pre-set path, without the need for an additional application to initiate the process of burning the security keys.

[0188] In one possible scenario, the process of burning the security key into the TEE and the storage device can be to burn the security key according to a preset path under the call of the control program on the production line.

[0189] It should be understood that the storage device supports the function of multiple RPMB regions, and different RPMB partitions can write different security keys.

[0190] For example, the RPMB partition corresponding to TEE-0 is RPMB region0, and the security key of RPMB region0 is secure key0. During the production of electronic devices, secure key0 is burned into RPMB region0, and secure key0 is written into TEE-0 at the same time.

[0191] For example, the RPMB partition corresponding to TEE-1 is RPMB region1, and the security key of RPMB region1 is secure key1. During the production of electronic devices, secure key1 is burned into RPMB region1, and secure key1 is written into TEE-1 at the same time.

[0192] For example, the RPMB partition corresponding to TEE-2 is RPMB region2, and the security key of RPMB region2 is secure key2. During the production of electronic devices, secure key2 is burned into RPMB region2, and secure key2 is written into TEE-2 at the same time.

[0193] Optionally, when the first TEE refers to TEE-0, the corresponding first storage area refers to RPMB region0, and the first security key refers to secure key0, the second TEE can refer to TEE-1, the corresponding second storage area can refer to RPMB region0, and the second security key refers to secure key1. Usually, secure key0 is different from secure key1.

[0194] This is equivalent to different security keys stored in different RPMBs for authenticating written data, so that different RPMB partitions can use different security keys to authenticate data written to RPMB.

[0195] The data to be stored may refer to data collected by the first TA on TEE-0.

[0196] For example, the first TA in TEE-0 is an application that requires fingerprint data for encryption and decryption. The data to be stored may refer to fingerprint data collected by the first TA through a fingerprint collector.

[0197] For example, the first TA in TEE-0 is an application that requires voice data for encryption and decryption. The data to be stored may refer to voice data collected by the first TA through a microphone.

[0198] For example, the first TA in TEE-0 is an application that requires a character password for encryption and decryption. The data to be stored may refer to character data obtained by the first TA by receiving a user's click operation on the display screen.

[0199] For example, the first TA in TEE-0 is an application that requires eyeprint data for encryption and decryption. The data to be stored may refer to the eyeprint data collected by the first TA through a camera.

[0200] For example, the first TA in TEE-0 is an application that requires facial recognition for encryption and decryption. The data to be stored may refer to facial data collected by the first TA through a camera.

[0201] Exemplarily, the first TA may also be an application that provides security services to the CA, and the data to be stored may refer to the cryptographic data sent by the CA to the first TA, including but not limited to the above-mentioned fingerprint data, voice data, character data, eye pattern data and face data.

[0202] After obtaining the data to be stored, the first TA can use secure key0 stored in TEE-0 to authenticate the data to obtain first authentication data. The first authentication data and the data to be stored are then combined to obtain a first data packet, which is then sent to the RPMB partition corresponding to TEE-0, namely RPMB region0.

[0203] Optionally, the authentication calculation may refer to a hash calculation. A hash calculation may be a method of calculating data using a hash-based message authentication code (HMAC), a method for message authentication based on a hash function and a key. HMAC is a method currently used by many security protocols to provide authentication services and is widely used. For example, HMAC is widely used in the Internet Protocol Security (IPSec) and other network protocols (such as SSL), and has withstood various forms of attacks. For this reason, HMAC can also be referred to as an existing Internet security standard.

[0204] Exemplarily, the first TA may use secure key0 to perform hash calculation on the data to be stored to obtain the first authentication data.

[0205] In an embodiment of the present application, the first TA uses secure key0 to perform authentication calculations on the data to be stored through hash calculations to obtain first authentication data. Since hash operations are currently widely used encryption algorithms that have withstood various forms of attacks, the first authentication data obtained through hash calculations is more reliable encrypted data, thereby improving the security of the first authentication data.

[0206] Exemplarily, the first TA may also use secure key0 to calculate the data to be stored through Cipher Block Chaining-Message Authentication Code (CMAC) to obtain the first authentication data.

[0207] It should be understood that the first TA can package the first authentication data and the data to be stored according to a preset data format to obtain a first data packet.

[0208] Exemplarily, the first TA may place the first authentication data before the data to be stored, and package the first authentication data and the data to be stored to obtain a first data packet.

[0209] Exemplarily, the first TA may place the first authentication data after the data to be stored, and package the data to be stored and the first authentication data to obtain a first data packet.

[0210] In one possible case, the first TA can package the first authentication data, the data to be stored and the write request to obtain a first data packet, and then send the first data packet to the RPMB region0 (that is, the first storage area) corresponding to the first TA in the storage device.

[0211] S102. The first storage region (ie, RPMB region0) stores data to be stored based on secure key0.

[0212] After receiving the first data packet, RPMB region0 may first unpack the first data packet to obtain the data to be stored and the first authentication data. RPMB region0 may verify the first authentication data based on secure key0 stored in RPMB region0, and if the verification passes, store the data to be stored in the first data packet.

[0213] In an embodiment of the present application, the electronic device includes at least two trusted execution environments TEE and a replay protection memory block RPMB, the RPMB includes at least two storage areas, the security keys stored in each of the at least two storage areas are different, one of the at least two TEEs corresponds one-to-one to one of the at least two storage areas, the at least two TEEs include a first TEE, a first trusted application TA runs in the first TEE, the at least two storage areas include a first storage area, the first TEE corresponds to the first storage area, wherein the first TEE stores a first security key, the first storage area stores the same first security key as that in the first TEE, the first TA uses the first security key to perform authentication calculations on the data to be stored to obtain first authentication data, and then sends a first data packet obtained based on the data to be stored and the first authentication data to the first storage area, and the first storage area stores the data to be stored based on the same first security key. Thus making the first TEE when storing data to be stored to the first storage area corresponding thereto, the first security key used is the security key stored in the first TEE, there is no need to call security key from other TEEs, so as to avoid the situation of security key leakage that may occur when calling security key from other TEEs, improve the security of writing data to RPMB in multi-TEE framework. Meanwhile, using the data storage method provided in the embodiment of the present application, each TEE is in the process of writing data to RPMB, there is no need to call security key each other, reduces the data interaction caused by calling security key, simplifies the process of writing data to RPMB. Further, due to the different security keys stored in each storage area in at least two storage areas, even if the first TEE appears when writing data to RPMB subregions, mistakenly sending data to other RPMB subregions (i.e., not the RPMB subregions corresponding to the first TEE), due to the different security keys stored in other RPMB subregions and the security keys stored in the first TEE, therefore other RPMB subregions are verified by the security keys stored thereon to write data and can cause verification not to pass, so that other RPMB subregions cannot store the data sent by the first TEE, improve the pertinence of writing data to RPMB, and further improve the security of the data of RPMB.

[0214] In one possible case, the data to be stored may be data required for encryption and decryption. These data have high security requirements and are usually stored in the RPMB.

[0215] For example, the data to be stored can be face recognition data, that is, data collected by a camera. Applications with encryption requirements running on the Android system, such as (Fingerprint CA), when receiving a face recognition registration request initiated by the user, sends a face recognition registration request to the face TA (also known as the first TA) in the first TEE. Based on the face recognition registration request, the face TA calls the camera to collect face recognition data and sends the collected face recognition data to the face TA. Then, the face TA can send the collected face recognition data to the corresponding RPMB partition (also known as the first storage area) for storage through the Hypervisor module in the Kernel.

[0216] The data storage method provided in the embodiment of the present application can be applied to Figure 8 In the electronic device shown. For example, Figure 8 As shown, the electronic device includes REE, TEE-0, TEE-1, kernel and storage device. Among them, the storage device includes two RPMB partitions, namely RPMB region0 and RPMB region1. It should be understood that Kernel refers to the core component in the operating system and is the main interface between the computer physical hardware and the processes running on it. Kernel can include multiple modules. For example, Figure 8 As shown, the Kernel includes a Hypervisor module, a TEE-0tz driver module, a TEE-1tz driver module, and a storage device driver module. The RPMB partition corresponding to TEE-0 is RPMB region0, and the RPMB partition corresponding to TEE-1 is RPMB region1. The same security key, namely securekey0, is stored in TEE-0 and RPMB region0, respectively, and the same security key, namely secure key1, is stored in TEE-1 and RPMB region1, respectively. It should be understood that secure key0 and secure key1 are usually different. The fingerprint TA and the first RPMB service module are running in TEE-0, wherein the first RPMB service module stores secure key0. The face TA and the second RPMB service module are running in TEE-1, wherein the second RPMB service module stores secure key1. The fingerprint TA can send the first data packet to RPMB region0 through the Hypervisor module. The face TA can send the first data packet to RPMBregion1 through the Hypervisor module. Fingerprint CA, face CA, TEE-0RPMB driver module and TEE-1RPMB driver module are running in REE. Optionally, the electronic device also includes an ATF module.

[0217] It should be understood that electronic devices can be divided into four operating levels, namely EL0, EL1, EL2 and EL3. Among them, the operating level of the application is EL0, that is to say, the application with encryption requirements in the Android system (fingerprint CA, face CA), fingerprint TA, the first RPMB service module, face TA, the second RPMB service module, TEE-0RPMB driver module and TEE-1RPMB driver module are running at EL0. The operating level of the TEE-0tz driver module, TEE-1tz driver module and storage device driver module is EL1. The operating level of the Hypervisor module is EL2. The operating level of the ATF module is EL3. The storage device and fingerprint sensor are at the hardware layer.

[0218] Among them, the Hypervisor module has the function of accessing all physical devices on the electronic device, including disks and memory. After the server is started, the Hypervisor module will load the operating systems of all virtual machine clients (including TEE-0, TEE-1 and storage devices) and allocate memory, disks and networks for the virtual machines. This allows the Hypervisor module to directly allocate data interfaces between TEE-0 and storage devices, as well as between TEE-1 and storage devices, so that data can be transferred between TEE-0 and storage devices, and between TEE-1 and storage devices.

[0219] It should be understood that the first TEE may refer to TEE-0 or TEE-1, and this embodiment of the present application does not limit this.

[0220] In the case where the first TEE refers to TEE-0, the first storage area may refer to RPMB region0, the first security key may refer to secure key0, and the first TA may include a fingerprint TA and a first RPMB service module.

[0221] In the case where the first TEE refers to TEE-1, correspondingly, the first storage area may refer to RPMB region1, the first security key may refer to secure key1, and the first TA may include a face TA and a second RPMB service module.

[0222] The following combination Figures 9 to 11 right Figure 8 The data storage method of the electronic device shown is described in detail.

[0223] Figure 9 A flow chart of a data storage method provided in one embodiment of the present application, which is applied to Figure 8The electronic device shown is used to illustrate the specific process of how the face TA writes data to the corresponding RPMB region0. Figure 10 The data flow diagram shown is used to assist in the explanation Figure 9 The embodiment shown. Figure 9 and Figure 10 As shown, the method includes:

[0224] S201. The face CA running in the Android system (REE) detects a face recognition registration operation (equivalent to the first operation).

[0225] Among them, the face recognition registration operation can be used to instruct the acquisition of face recognition data.

[0226] S202. Face CA responds to the face recognition registration operation and sends a face recognition registration request to the TEE-0tz driver module (equivalent to the first TEE tz driver module) in the Kernel.

[0227] S203. The TEE-0tz driver module sends a face recognition registration request to the Hypervisor module.

[0228] S204. The Hypervisor module sends a face recognition registration request to the face TA in TEE-0.

[0229] It should be understood that the first TA refers to an application running in the first TEE, which may refer to one TA or multiple TAs. Figure 8 As shown, the first TA may include a face TA and a first RPMB service module.

[0230] S205. Face TA responds to the face recognition registration request, calls the security camera, and collects face recognition data (data to be stored).

[0231] S206. The face TA sends the face recognition data and a request to store the face recognition data in RPMB region0 to the first RPMB service module in TEE-0.

[0232] For example, the face TA can be Figure 11 The format shown in FIG. 1 sends face recognition data to the first RPMB service module and requests to store face recognition data in RPMB region0. Figure 10 As shown, it includes RPMB write cmd id, RPMBdata data volume and RPMB data. Among them, RPMB data can be face recognition data.

[0233] S207. The first RPMB service module uses secure key0 to perform authentication calculation on the face recognition data to obtain first authentication data.

[0234] Optionally, the authentication calculation may refer to a hash calculation. The hash calculation may be a calculation method for calculating data through a hash-based message authentication code (HMAC), which is a method for message authentication based on a hash function and a key.

[0235] Exemplarily, the first RPMB service module can use the first security key to perform authentication calculations on the stored data through HMAC. Among them, HMAC is the method of providing authentication services selected by many current security protocols and is widely used. For example, in the Internet Protocol Security (IPSec) and other network protocols (such as SSL), HMAC is widely used and has withstood the test of various forms of attacks. Based on this, HMAC can also be called the existing Internet security standard.

[0236] In an embodiment of the present application, the first TA uses the first security key to perform authentication calculations on the data to be stored through a hash operation to obtain first authentication data. Since the hash operation is an encryption algorithm that is currently widely used and has withstood various forms of attacks, the first authentication data obtained through the hash operation is more reliable encrypted data, thereby improving the security of the first authentication data.

[0237] Exemplarily, the first RPMB service module may also use the first security key to calculate the data to be stored through a Cipher Block Chaining-Message Authentication Code (CMAC) to obtain first authentication data.

[0238] S208. The first RPMB proxy service module packages the first authentication data and the face recognition data to obtain a first data packet.

[0239] Optionally, the generated first data packet also includes a random number, a count value, a storage address of the face recognition data, an operation result on the face recognition data, and a write cmd id.

[0240] Among them, the random number may refer to a hardware random number generated by a random number generator, and the electronic device is encrypted by the hardware random number. Since there is an independent counter in each RPMB partition, the count value may refer to the count value of the counter in the first storage area at the current moment. The storage address of the face recognition data may refer to the storage address of the face recognition data in RPMB region0.

[0241] For example, the data format of the first data packet can be as follows: Figure 12 As shown, it includes MAC, RPMB data, random number, Write counter, storage address (Address), the operation result of the face recognition data and the write cmd id. Among them, MAC can refer to the first authentication data, RPMB data can be the face recognition data, and the storage address can be the storage address of the face recognition data in RPMB region0.

[0242] S209: The first RPMB proxy service module sends a first data packet to the Hypervisor module.

[0243] S210. The Hypervisor module sends a first data packet to the TEE-0tz driver module in the Kernel.

[0244] Optionally, the first data packet further includes a SECURITY PROTOCOL SPECIFIC parameter (equivalent to the first parameter). The SECURITY PROTOCOL SPECIFIC parameter is used to indicate the identifier of the RPMB partition to which the first data packet is sent.

[0245] Exemplarily, the SECURITY PROTOCOL SPECIFIC parameter is 0, where 0 is the identifier of RPMB region0, and the RPMB partition to which the first data packet is sent is RPMB region0.

[0246] S211. The TEE-0tz driver module sends a first data packet to the TEE-0RPMB driver module.

[0247] It should be understood that the TEE-0RPMB driver module is a module running in the REE. Therefore, when constructing the data channel for TEE-0 to send the first data packet to RPMBregion0, it can be constructed through the TEE-0RPMB driver module running in the REE. In this way, there is no need to modify the process in the Kernel to construct the data channel for TEE-0 to send the first data packet to RPMB region0.

[0248] It should be understood that modifying processes in the kernel requires obtaining the corresponding permissions. However, in one possible scenario, due to restrictions imposed by the chip manufacturer, it is impossible to obtain permissions to modify processes in the kernel. Therefore, by using the data storage method provided in the embodiment of the present application, it is possible to send the first data packet from the first TEE to the first storage area without modifying the processes in the kernel.

[0249] The data storage method provided in the embodiment of the present application is applied to an electronic device, which includes at least two TEEs and RPMBs, wherein the RPMB includes at least two storage areas, wherein one TEE in the at least two TEEs corresponds to a storage area in the RPMB, wherein the at least two TEEs include a first TEE, wherein a first TA is running in the first TEE, and wherein the at least two storage areas include a first storage area, wherein the first TEE corresponds to the first storage area, wherein a first security key is stored in the first TEE, wherein the first storage area stores the same first security key as that in the first TEE, and the first TA uses the first security key to perform authentication calculation on the data to be stored, obtains the first authentication data, and then uses the first data packet obtained based on the data to be stored and the first authentication data to send the first data packet to the first storage area, which is sent by the first TEE RPMB driver module running in the REE. Since the first TEE RPMB driver module runs in the REE, rather than in the Kernel, in the process of sending the first data packet to the first storage area, the first TEE does not need to modify the process in the Kernel, that is, it does not need to obtain the permission to modify the process in the Kernel, thereby improving the convenience of the first TEE sending the first data packet to the first storage area.

[0250] S212. The TEE-0RPMB driver module sends a first data packet to the storage device driver module.

[0251] Exemplarily, the storage device driver module is an eMMC driver module.

[0252] Exemplarily, the storage device driver module is a UFS driver module.

[0253] Optionally, the TEE-0tz driver module may also directly send the first data packet to the storage device driver module, without forwarding the first data packet to the storage device driver module through the TEE-0RPMB driver module.

[0254] S213. The storage device driver module sends a first data packet to RPMB region0.

[0255] S214. RPMB region0 (equivalent to the first storage area) uses secure key0 to perform authentication calculation on the data to be stored in the first data packet to obtain second authentication data.

[0256] S215. RPMB region0 stores the data to be stored when the first authentication data and the second authentication data match.

[0257] It should be understood that the first authentication data is obtained by performing an authentication calculation on the data to be stored using the first security key, and the second authentication data is also obtained by performing an authentication calculation on the data to be stored using the same first security key. In other words, if the first security key and the data to be stored are the same, and the authentication calculation method is the same, then the first authentication data and the second authentication data are obtained by performing the same calculation on the same data using the same security key, and the first authentication data and the second authentication data are also identical.

[0258] It should be understood that in the process of obtaining the first authentication data and the second authentication data, authentication calculations need to be performed on the data to be stored separately. To account for errors that may occur in the authentication calculations, the first authentication data and the second authentication data can be considered to match when the portion of the first authentication data and the second authentication data that is identical exceeds a preset threshold. If it is determined that the first authentication data and the second authentication data match, the first storage area can store the data to be stored.

[0259] In the data storage method provided in the embodiment of the present application, the electronic device includes at least two trusted execution environments TEE and a replay protection memory block RPMB, one TEE in at least two TEEs corresponds to a storage area in the RPMB, at least two TEEs include a first TEE, a first trusted application TA is running in the first TEE, RPMB includes a first storage area, the first TEE corresponds to the first storage area, wherein the first security key is stored in the first TEE, the first storage area stores the same first security key as the first TEE, the first TA uses the first security key to perform authentication calculation on the data to be stored, obtains the first authentication data, and then sends the first data packet obtained according to the data to be stored and the first authentication data to the first storage area, the first storage area uses the same first security key to perform the same authentication calculation on the data to be stored in the first data packet, obtains the second authentication data, and when the first authentication data and the second authentication data match, stores the data to be stored, and stores the data to be stored based on the same first security key. In this way, the data stored in the first storage area are all data that have been verified by the first storage area through an independent security key, which can effectively avoid data from unknown sources from attacking the data stored in the first storage area, thereby improving the security of the data stored in the first storage area.

[0260] In one possible case, the data to be stored may be data collected by a fingerprint sensor. Applications with encryption requirements running on the Android system, such as (Fingerprint CA), when receiving a fingerprint registration request initiated by the user, sends a fingerprint registration request to the fingerprint TA (also known as the first TA) in the first TEE. Based on the fingerprint registration request, the fingerprint TA calls the fingerprint sensor, collects fingerprint data, and sends the collected fingerprint data to the fingerprint TA. Then, the fingerprint TA can send the collected fingerprint data to the corresponding RPMB partition (also known as the first storage area) for storage through the Hypervisor module in the Kernel.

[0261] Figure 13 A flow chart of a data storage method provided in one embodiment of the present application, which is applied to Figure 8 The electronic device shown is used to illustrate the specific process of how the fingerprint TA writes data to the corresponding RPMB region1. Figure 14 The data flow diagram shown is used to assist in the explanation Figure 13 The embodiment shown.

[0262] It should be understood that the process of writing data from the face TA and fingerprint TA to the corresponding RPMB partitions respectively can be performed in response to the same operation or in response to different operations, and the embodiments of the present application do not limit this.

[0263] like Figure 13 and Figure 14 As shown, the method includes:

[0264] S301. The fingerprint CA running in the Android system (REE) detects a fingerprint registration operation (equivalent to the first operation).

[0265] The fingerprint registration operation may be used to instruct acquisition of fingerprint data.

[0266] It should be understood that the fingerprint registration request may include a VM id, and the VM id is used to indicate the recipient of the fingerprint registration request, that is, the fingerprint TA in TEE-1.

[0267] S302. In response to the fingerprint registration operation, the fingerprint CA sends a fingerprint registration request to the TEE-1tz driver module in the Kernel.

[0268] S303: The first TEE tz driver module sends a fingerprint registration request to the Hypervisor module.

[0269] S304: The Hypervisor module sends a fingerprint registration request to the ATF module.

[0270] The Hypervisor module determines that the recipient of the fingerprint registration request is the fingerprint TA in TEE-1 based on the VM id in the fingerprint registration request, and then establishes a data channel to send the fingerprint registration request to the fingerprint TA.

[0271] In some possible cases, data interaction between the Hypervisor module and the first TA running in the first TEE must go through the ATF module. In other words, the fingerprint registration request sent by the Hypervisor module to the fingerprint TA must go through the ATF module.

[0272] In some possible cases, the Hypervisor module can directly exchange data with the first TA running in the first TEE without going through the ATF module. In other words, the fingerprint registration request sent by the Hypervisor module to the fingerprint TA does not need to go through the ATF module.

[0273] Optionally, the Hypervisor module may send a fingerprint registration request to the ATF module.

[0274] S305. The ATF module sends a fingerprint registration request to the fingerprint TA in TEE-1.

[0275] It should be understood that Figure 13 In the illustrated embodiment, the first TEE is referred to as TEE-1.

[0276] It should be understood that the first TA refers to an application running in the first TEE, which may refer to one TA or multiple TAs. Figure 8 As shown, the first TA refers to the fingerprint TA running in TEE-1 and the second RPMB service.

[0277] S306. The fingerprint TA responds to the fingerprint registration request and instructs the fingerprint sensor to collect fingerprint data (data to be stored).

[0278] S307. Fingerprint TA sends the fingerprint data and a request to store it in RPMB region 1 to the second RPMB service module in TEE-1.

[0279] For example, the fingerprint TA can be Figure 10 The format shown in FIG. 1 sends fingerprint data to the second RPMB service module and requests to store fingerprint data in RPMB region1.

[0280] S308. The second RPMB service module uses secure key 1 to perform authentication calculation on the fingerprint data to obtain first authentication data.

[0281] It should be understood that when the first TEE is TEE-1, the first security key refers to secure key 1. The second RPMB service module can use secure key 1 to perform authentication calculation on the fingerprint data to obtain first authentication data.

[0282] S309. The second RPMB proxy service module packages the first authentication data and the fingerprint data to obtain a first data packet.

[0283] Optionally, the generated first data packet further includes a random number, a count value, a storage address of the fingerprint data, an operation result on the fingerprint data, and a write cmd id.

[0284] Among them, the random number may refer to a hardware random number generated by a random number generator, and the electronic device is encrypted by the hardware random number. Since there is an independent counter in each RPMB partition, the count value may refer to the count value of the counter in the first storage area at the current moment. The storage address of the fingerprint data may be the storage address of the fingerprint data in the first storage area.

[0285] For example, the data format of the first data packet can be as follows: Figure 11 As shown, it includes MAC, RPMB data, random number, Write counter, Address, operation result of fingerprint data and write cmd id. Among them, MAC can refer to the first authentication data, RPMB data can be fingerprint data, and storage address can be the storage address of fingerprint data in RPMB region1.

[0286] S310. The second RPMB proxy service module sends a first data packet to the ATF module.

[0287] S311: The ATF module sends a first data packet to the Hypervisor module.

[0288] S312. The Hypervisor module sends a first data packet to the TEE-1tz driver module (equivalent to the first TEE tz driver module) in the Kernel.

[0289] S313. The TEE-1tz driver module sends a first data packet to the TEE-1RPMB driver module.

[0290] It should be understood that the TEE-1RPMB driver module is a module running in the REE. Therefore, when constructing the data channel for TEE-1 to send the first data packet to RPMBregion1, it can be constructed through the TEE-1RPMB driver module running in the REE. In this way, there is no need to modify the process in the Kernel to construct the data channel for TEE-1 to send the first data packet to RPMB region1.

[0291] It should be understood that modifying processes in the kernel requires obtaining the corresponding permissions. However, in one possible scenario, due to restrictions imposed by the chip manufacturer, it is impossible to obtain permissions to modify processes in the kernel. Therefore, by using the data storage method provided in the embodiment of the present application, it is possible to send the first data packet from the first TEE to the first storage area without modifying the processes in the kernel.

[0292] S314. The TEE-1RPMB driver module sends a first data packet to the storage device driver module.

[0293] Exemplarily, the storage device driver module is an eMMC driver module.

[0294] Exemplarily, the storage device driver module is a UFS driver module.

[0295] S315: The storage device driver module sends a first data packet to the first storage area.

[0296] S316. RPMB region1 (equivalent to the first storage area) uses secure key1 to perform authentication calculation on the data to be stored in the first data packet to obtain second authentication data.

[0297] S317. RPMB region1 stores the data to be stored if the first authentication data and the second authentication data match.

[0298] In an embodiment of the present application, an electronic device includes at least two trusted execution environments TEE and a replay protection memory block RPMB, one of the at least two TEEs corresponds one-to-one to a storage area in the RPMB, and the at least two TEEs include a first TEE, a first trusted application TA runs in the first TEE, and the RPMB includes a first storage area, and the first TEE corresponds to the first storage area, wherein a first security key is stored in the first TEE, and the first storage area stores the same first security key as that in the first TEE. The first TA uses the first security key to perform authentication calculations on the data to be stored to obtain first authentication data, and then sends the first data packet obtained based on the data to be stored and the first authentication data to the first storage area. In the process of sending the first data packet to the first storage area, it can be sent to the first storage area through the ATF module. Usually, sending data to RPMB through the ATF module is a pre-set process, so the user does not need to set how to send data to RPMB, which improves the convenience of writing data to the first storage area to the first TEE.

[0299] It should be understood that, although the various steps in the flow chart in the above-described embodiment are shown in sequence according to the indication of the arrows, these steps are not necessarily performed in sequence according to the order indicated by the arrows. Unless clearly stated herein, the execution of these steps does not have strict order restrictions, and these steps can be performed in other orders. Moreover, at least a portion of the steps in the flow chart may include a plurality of sub-steps or a plurality of stages, and these sub-steps or stages are not necessarily performed at the same time, but can be performed at different times, and the execution order of these sub-steps or stages is not necessarily performed in sequence, but can be performed in turn or alternately with at least a portion of other steps or sub-steps or stages of other steps.

[0300] Figure 15 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.

[0301] It should be understood that electronic devices can perform Figures 6 to 14The data storage method shown; the electronic device includes at least two trusted execution environments TEE and a replay protection memory block RPMB, wherein the RPMB includes at least two storage areas, the security keys stored in each of the at least two storage areas are different, one of the at least two TEEs corresponds one-to-one to one of the at least two storage areas, the at least two TEEs include a first TEE, a first trusted application TA runs in the first TEE, the at least two storage areas include a first storage area, the first TEE corresponds to the first storage area, the first TEE and the first storage area store a first security key, the first security key is used for the first storage area and the first TA to perform authentication calculations on the data to be stored, the data to be stored is data written to the first storage area, and the electronic device also includes: an acquisition unit 610 and a processing unit 620.

[0302] The processing unit 620 is used to control the first TA to send a first data packet to the first storage area. The first data packet includes the data to be stored and the first authentication data. The first authentication data is the data obtained after the first TA uses the first security key to perform authentication calculation on the data to be stored; the first storage area stores the data to be stored based on the first security key.

[0303] Optionally, as an embodiment, the electronic device further includes a kernel, the kernel includes a hypervisor module, and the processing unit 620 is configured to control the first TA to send the first data packet to the hypervisor module; and the hypervisor module sends the first data packet to the first storage area.

[0304] Optionally, as an embodiment, the first data packet includes a first parameter, and the first parameter is used to indicate a first storage area; the processing unit 620 is used to control the Hypervisor module to determine the first storage area based on the first parameter; and the Hypervisor module sends the first data packet to the first storage area.

[0305] Optionally, as an embodiment, the Kernel further includes an ATF module, and the processing unit 620 is configured to control the first TA to send the first data packet to the ATF module; and the ATF module sends the first data packet to the Hypervisor module.

[0306] Optionally, as an embodiment, the electronic device further includes a rich execution environment REE, in which a first TEERPMB driver module runs, and the processing unit 620 is used to control the Hypervisor module to send a first data packet to the first TEE RPMB driver module; the first TEE RPMB driver module sends the first data packet to the first storage area.

[0307] Optionally, as an embodiment, the Kernel further includes a storage device driver module, and the processing unit 620 is used to control the first TEE RPMB driver module to send a first data packet to the storage device driver module; the storage device driver module sends the first data packet to the first storage area.

[0308] Optionally, as an embodiment, the Kernel includes a first TEE tz driver module, and the processing unit 620 is used to control the Hypervisor module to send a first data packet to the first TEE tz driver module; the first TEE tz driver module sends the first data packet to the first TEE RPMB driver module.

[0309] Optionally, as an embodiment, the processing unit 620 is used to control the first storage area to use the first security key to perform authentication calculations on the data to be stored in the first data packet to obtain second authentication data; when the first authentication data and the second authentication data match, the first storage area stores the data to be stored.

[0310] Optionally, as an embodiment, the electronic device further includes a rich execution environment REE and a first device, a first client application CA runs in the REE, the processing unit 620 is used to control the reception of a first operation, the first operation is used to instruct the acquisition of data to be stored; in response to the first operation, the first CA sends a first request to the first TA, the first request is used to instruct the first TA to acquire the data to be stored; in response to the first request, the first TA instructs the first device to collect the first data; the first TA obtains the data to be stored based on the first data.

[0311] Optionally, as an embodiment, the first device includes a fingerprint sensor.

[0312] Optionally, as an embodiment, the first device includes a camera.

[0313] Optionally, as an embodiment, the first TA includes a face TA and a first RPMB service module, the first RPMB service module stores a first security key, the data to be stored is face recognition data, the processing unit 620 is used to control the face TA to instruct the camera to collect face recognition data; the face TA sends the face recognition data to the first RPMB service module; the first RPMB service module generates a first data packet based on the face recognition data; the first RPMB service module sends the first data packet to the Hypervisor module.

[0314] Optionally, as an embodiment, the electronic device further includes a rich execution environment REE and a camera, and a face client application CA is running in the REE. Before the face TA instructs the camera to collect face recognition data, the processing unit 620 is used to control the face CA to detect a face recognition registration operation, and the face recognition registration operation is used to instruct the acquisition of face recognition data; in response to the face recognition registration operation, the face CA sends a face recognition registration request to the face TA, and the face recognition registration request is used to instruct the face TA to obtain face recognition data; in response to the face recognition registration request, the face TA instructs the camera to collect face recognition data.

[0315] Optionally, as an embodiment, the first TA includes a fingerprint TA and a second RPMB service module, the second RPMB service module stores a first security key, the data to be stored is fingerprint data, the processing unit 620 is used to control the fingerprint TA to instruct the fingerprint sensor to collect fingerprint data; the fingerprint TA sends the fingerprint data to the second RPMB service module; the second RPMB service module generates a first data packet based on the fingerprint data; the second RPMB service module sends the first data packet to the Hypervisor module.

[0316] Optionally, as an embodiment, the electronic device further includes a rich execution environment REE and a fingerprint sensor, wherein a fingerprint client application CA runs in the REE, and before the fingerprint TA instructs the fingerprint sensor to collect fingerprint data, the processing unit 620 is used to control the fingerprint CA to detect a fingerprint registration operation, and the fingerprint registration operation is used to instruct the acquisition of fingerprint data; in response to the fingerprint registration operation, the fingerprint CA sends a fingerprint registration request to the fingerprint TA, and the fingerprint registration request is used to instruct the fingerprint TA to obtain fingerprint data; in response to the fingerprint registration request, the fingerprint TA instructs the fingerprint sensor to collect fingerprint data.

[0317] Optionally, as an embodiment, the kernel further includes an ATF module, and the processing unit 620 is configured to control the second RPMB service module to send the first data packet to the ATF module; and the ATF module sends the first data packet to the Hypervisor module.

[0318] Optionally, as an embodiment, the authentication calculation includes a hash HMAC calculation.

[0319] The electronic device provided in this embodiment is used to execute the data storage method of the above embodiment. The technical principles and technical effects are similar and will not be described in detail here.

[0320] It should be noted that the above-mentioned data electronic device is embodied in the form of a functional unit. The term "unit" here can be implemented in the form of software and / or hardware, and is not specifically limited to this.

[0321] It is understandable that in order to implement the above functions, the electronic device includes hardware and / or software modules corresponding to the execution of each function. In combination with the algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application in combination with the embodiments, but such implementation should not be considered to be beyond the scope of this application.

[0322] The embodiment of the present application can divide the functional modules of the electronic device according to the above method example. For example, each functional module can be divided according to each function, or two or more functions can be integrated into one module. It should be noted that the division of modules in the embodiment of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation. It should be noted that the names of the modules in the embodiment of the present application are schematic and are not limited to the names of the modules in actual implementation.

[0323] For example, a "unit" may be a software program, a hardware circuit, or a combination of the two that implements the aforementioned functionality. The hardware circuit may include an application specific integrated circuit (ASIC), an electronic circuit, a processor (e.g., a shared processor, a dedicated processor, or a group processor) and memory for executing one or more software or firmware programs, combined logic circuits, and / or other suitable components that support the described functionality.

[0324] Therefore, the units of each example described in the embodiments of this application can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0325] Figure 16 A schematic structural diagram of an electronic device provided in this application is shown. Figure 16 The dotted line in the figure indicates that the unit or module is optional. The electronic device 700 can be used to implement the data storage method described in the above method embodiment.

[0326] The electronic device 700 includes one or more processors 701, which can support the data storage method in the method embodiment implemented by the electronic device 700. The processor 701 can be a general-purpose processor or a special-purpose processor. For example, the processor 701 can be a central processing unit (CPU), a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, such as discrete gates, transistor logic devices, or discrete hardware components.

[0327] The processor 701 can be used to control the electronic device 700, execute software programs, and process data of the software programs. The electronic device 700 can also include a communication unit 705 to implement signal input (reception) and output (transmission).

[0328] For example, the electronic device 700 may be a chip, the communication unit 705 may be an input and / or output circuit of the chip, or the communication unit 705 may be a communication interface of the chip, and the chip may be a component of a terminal device or other electronic device.

[0329] For another example, the electronic device 700 may be a terminal device, and the communication unit 705 may be a transceiver of the terminal device, or the communication unit 705 may be a transceiver circuit of the terminal device.

[0330] The electronic device 700 may include one or more memories 702 on which a program 704 is stored. The program 704 can be executed by the processor 701 to generate instructions 703, so that the processor 701 executes the impedance matching method described in the above method embodiment according to the instructions 703.

[0331] Optionally, data may be stored in the memory 702. Optionally, the processor 701 may read data stored in the memory 702. The data may be stored at the same storage address as the program 704, or may be stored at a different storage address than the program 704.

[0332] The processor 701 and the memory 702 may be provided separately or integrated together; for example, they may be integrated on a system on chip (SOC) of a terminal device.

[0333] Exemplarily, the memory 702 can be used to store the relevant program 704 of the data storage method provided in the embodiment of the present application, and the processor 701 can be used to call the relevant program 704 of the data storage method stored in the memory 702 when performing data storage, and execute the data storage method of the embodiment of the present application; including: the first TA sends a first data packet to the first storage area, the first data packet includes the data to be stored and the first authentication data, the first authentication data is the data obtained by the first TA after using the first security key to perform authentication calculation on the data to be stored; the first storage area stores the data to be stored based on the first security key.

[0334] The present application also provides a computer program product, which, when executed by the processor 701, implements the data storage method described in any method embodiment of the present application.

[0335] The computer program product may be stored in the memory 702 , for example, a program 704 , which is converted into an executable target file that can be executed by the processor 701 after undergoing preprocessing, compilation, assembly, and linking.

[0336] The present application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a computer, implements the data storage method described in any method embodiment of the present application. The computer program can be a high-level language program or an executable target program.

[0337] The computer-readable storage medium is, for example, memory 702. Memory 702 may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memory. The non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (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 rambus RAM (DR RAM).

[0338] In this application, "at least one" means one or more, and "plurality" means two or more. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b, or c can mean: a, b, c, ab, ac, bc, or abc, where a, b, and c can be single or plural.

[0339] It should be understood that in the various embodiments of the present application, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0340] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0341] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0342] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative; for example, the division of the units is merely a logical function division, and there may be other division methods in actual implementation; for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection of some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0343] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.

[0344] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0345] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.

Claims

1. A data storage method, characterized in that: The method is applied to an electronic device, the electronic device including at least two trusted execution environments (TEEs) and a replay protected memory block (RPMB), wherein the RPMB includes at least two storage areas, each of the at least two storage areas stores a different security key, one of the at least two TEEs corresponds one-to-one to one of the at least two storage areas, the at least two TEEs include a first TEE, a first trusted application (TA) runs in the first TEE, the at least two storage areas include a first storage area, the first TEE corresponds to the first storage area, the first TEE and the first storage area store a first security key, the first security key is used for the first storage area and the first trusted application (TA) to perform authentication calculations on data to be stored, and the data to be stored is data written to the first storage area. The method includes: The first trusted application TA sends a first data packet to the first storage area, where the first data packet includes the data to be stored and first authentication data, where the first authentication data is data obtained by the first trusted application TA performing the authentication calculation on the data to be stored using the first security key; The first storage area stores the data to be stored based on the first security key.

2. The method according to claim 1, characterized in that The electronic device further includes a kernel Kernel, the kernel including a Hypervisor module, and the first trusted application TA sending a first data packet to the first storage area includes: The first trusted application TA sends the first data packet to the Hypervisor module; The Hypervisor module sends the first data packet to the first storage area.

3. The method according to claim 2, characterized in that The first data packet includes a first parameter, and the first parameter is used to indicate the first storage area; The hypervisor module sending the first data packet to the first storage area includes: The hypervisor module determines the first storage area based on the first parameter; The Hypervisor module sends the first data packet to the first storage area.

4. The method according to claim 3, characterized in that The Kernel further includes an ATF module, and the first trusted application TA sends the first data packet to the Hypervisor module, including: The first trusted application TA sends the first data packet to the ATF module; The ATF module sends the first data packet to the Hypervisor module.

5. The method according to any one of claims 2 to 4, characterized in that The electronic device further includes a rich execution environment (REE), in which a first TEE RPMB driver module runs, and the hypervisor module sends the first data packet to the first storage area, including: The Hypervisor module sends the first data packet to the first TEE RPMB driver module; The first TEE RPMB driver module sends the first data packet to the first storage area.

6. The method according to claim 5, characterized in that The Kernel further includes a storage device driver module. The first TEE RPMB driver module sends the first data packet to the first storage area, including: The first TEE RPMB driver module sends the first data packet to the storage device driver module; The storage device driver module sends the first data packet to the first storage area.

7. The method according to claim 5, characterized in that The Kernel includes a first TEE tz driver module, and the Hypervisor module sends the first data packet to the first TEE RPMB driver module, including: The Hypervisor module sends the first data packet to the first TEE tz driver module; The first TEE tz driver module sends the first data packet to the first TEE RPMB driver module.

8. The method according to any one of claims 1 to 4, characterized in that The first storage area stores the data to be stored based on the first security key, including: The first storage area uses the first security key to perform the authentication calculation on the data to be stored in the first data packet to obtain second authentication data; In a case where the first authentication data and the second authentication data match, the first storage area stores the data to be stored.

9. The method according to any one of claims 1 to 4, characterized in that The electronic device further includes a rich execution environment (REE) and a first device, wherein a first client application (CA) runs in the REE. The method further includes: receiving a first operation, where the first operation is used to instruct acquisition of the data to be stored; In response to the first operation, the first client application CA sends a first request to the first trusted application TA, where the first request is used to instruct the first trusted application TA to obtain the data to be stored; In response to the first request, the first trusted application TA instructs the first device to collect first data; The first trusted application TA obtains the data to be stored based on the first data.

10. The method according to claim 9, characterized in that The first device includes a fingerprint sensor.

11. The method according to claim 9, characterized in that The first device includes a camera.

12. The method according to claim 2, characterized in that The first trusted application TA includes a face trusted application TA and a first RPMB service module, the first RPMB service module stores the first security key, the data to be stored is face recognition data, and the first trusted application TA sends the first data packet to the hypervisor module, including: The trusted face application TA instructs the camera to collect face recognition data; The trusted face application TA sends the face recognition data to the first RPMB service module; The first RPMB service module generates the first data packet based on the face recognition data; The first RPMB service module sends the first data packet to the Hypervisor module.

13. The method according to claim 12, characterized in that The electronic device further includes a rich execution environment (REE) and the camera, wherein a face client application (CA) runs in the REE. Before the trusted face application (TA) instructs the camera to collect face recognition data, the method further includes: The face client application CA detects a face recognition registration operation, where the face recognition registration operation is used to instruct acquisition of the face recognition data; In response to the face recognition registration operation, the face client application CA sends a face recognition registration request to the face trusted application TA, where the face recognition registration request is used to instruct the face trusted application TA to obtain face recognition data; The trusted face application TA instructs the camera to collect face recognition data, including: In response to the face recognition registration request, the face trusted application TA instructs the camera to collect the face recognition data.

14. The method according to claim 2, characterized in that The first trusted application TA includes a fingerprint TA and a second RPMB service module, the second RPMB service module stores the first security key, the data to be stored is fingerprint data, and the first trusted application TA sends the first data packet to the hypervisor module, including: The fingerprint trusted application TA instructs the fingerprint sensor to collect fingerprint data; The fingerprint trusted application TA sends the fingerprint data to the second RPMB service module; The second RPMB service module generates the first data packet based on the fingerprint data; The second RPMB service module sends the first data packet to the Hypervisor module.

15. The method according to claim 14, characterized in that The electronic device further includes a rich execution environment (REE) and the fingerprint sensor, wherein a fingerprint client application (CA) runs in the REE. Before the fingerprint trusted application (TA) instructs the fingerprint sensor to collect fingerprint data, the method further includes: The fingerprint client application CA detects a fingerprint registration operation, where the fingerprint registration operation is used to instruct acquisition of the fingerprint data; In response to the fingerprint registration operation, the fingerprint client application CA sends a fingerprint registration request to the fingerprint trusted application TA, wherein the fingerprint registration request is used to instruct the fingerprint trusted application TA to obtain fingerprint data; The fingerprint trusted application TA instructs the fingerprint sensor to collect fingerprint data, including: In response to the fingerprint registration request, the fingerprint trusted application TA instructs the fingerprint sensor to collect the fingerprint data.

16. The method according to claim 14, characterized in that The Kernel further includes an ATF module, and the second RPMB service module sends the first data packet to the Hypervisor module, including: The second RPMB service module sends the first data packet to the ATF module; The ATF module sends the first data packet to the Hypervisor module.

17. The method according to any one of claims 1 to 4, characterized in that The authentication calculation includes a hash HMAC calculation.

18. A chip, characterized in that: The method comprises a processor, wherein when the processor executes instructions, the processor performs the method according to any one of claims 1 to 17.

19. An electronic device, characterized in that: The electronic device includes a processor, which is coupled to a memory and reads instructions in the memory, and enables the electronic device to execute the method according to any one of claims 1 to 17 according to the instructions.

20. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, which, when executed by a processor, causes the processor to perform the method according to any one of claims 1 to 17.

Citation Information

Patent Citations

  • Root key processing method and related device

    CN108108631A

  • Secure storage implementation method and system supporting TEE extension

    CN111444553A