Data storage method and electronic device

By implementing cross-TEE transfer and authentication computation of security keys in a multi-TEE architecture, the problem that the Secure Key can only be stored in one TEE is solved, and the function of writing data to RPMB by each TEE is realized, thereby improving the security and reliability of data storage.

CN117492634BActive Publication Date: 2025-11-25HONOR DEVICE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210878228.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-25
Publication Date
2025-11-25
Estimated Expiration
2042-07-25

AI Technical Summary

Technical Problem

In a Trusted Execution Environment (TEE) framework, the Secure Key can only be stored in one TEE, which prevents other TEEs from calling the Secure Key to perform calculations on the data, and thus prevents them from writing data to the Replay Protected Memory Block (RPMB).

Method used

The security key is obtained from the second TEE that stores the security key by the first trusted application (TA) in the first TEE that does not store the security key, the authentication calculation is performed, a data packet is generated, and the data packet is sent to the RPMB for storage. The data is stored after the authentication is successful.

Benefits of technology

This enables each TEE in a multi-TEE architecture to write data to the RPMB, improving the security and reliability of data storage.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117492634B_ABST
    Figure CN117492634B_ABST
Patent Text Reader

Abstract

The embodiment of the application is suitable for the technical field of data processing, and provides a data storage method and an electronic device, which are applied to an electronic device including at least two TEEs, the at least two TEEs including a first TEE and a second TEE, the first TEE being a TEE in which a security key is not stored, and the second TEE being a TEE in which a security key is stored, and the method includes: sending, by a second TA, a security key to a first TA, the first TA being a trusted application running on the first TEE, and the second TA being a trusted application running in the second TEE; then, obtaining, by the first TA, a first data packet according to the security key and to-be-stored data; sending, by the first TA, the first data packet to an RPMB; and storing, by the RPMB, the to-be-stored data based on the first data packet. That is to say, the function that each application running in each TEE in a multi-TEE architecture can write data to the RPMB is realized.
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

[0002] The Replay Protected Memory Block (RPMB) generally refers to a separate physical partition in the memory, which is often used to store sensitive data such as keys. The memory can include Universal Flash Storage (UFS) and Embedded Multi Media Card (eMMC).

[0003] With the continuous progress of terminal technology, the multi- Trusted Execution Environment (TEE) architecture has become a common architecture. Generally, the Secure Key can only be stored in one TEE. In the case of a multi-TEE framework of a terminal device, since the Secure Key can only be stored in one TEE, other TEEs cannot call the Secure Key to calculate the first authentication data, so that the RPMB cannot complete the authentication of the data to be written, resulting in the RPMB being unable to store the data to be written, and further resulting in the inability to implement the function that each TEE can write data to the RPMB.

[0004] Therefore, how to implement the function that each TEE in the multi-TEE framework can write data to the RPMB has become a problem to be solved. SUMMARY

[0005] The present application provides a data storage method, which can implement the function that each TEE in the multi-TEE framework can write data to the RPMB.

[0006] In a first aspect, a data storage method is provided, which is applied to an electronic device, the electronic device comprising at least two Trusted Execution Environments (TEEs), the at least two TEEs comprising a first TEE and a second TEE, the first TEE being a TEE that does not store a security key, and the second TEE being a TEE that stores a security key, the security key being a key used by a Replay Protected Memory Block (RPMB) to verify stored data; the method comprising:

[0007] sending, by a second Trusted Application (TA), a security key to a first TA, the first TA being a Trusted Application running on the first TEE, and the second TA being a Trusted Application running on the second TEE;

[0008] The first TA obtains a first data packet according to the security key and the to-be-stored data;

[0009] The first TA sends the first data packet to the RPMB;

[0010] The RPMB stores the to-be-stored data based on the first data packet.

[0011] The data storage method provided in the embodiments of the present application is applied to an electronic device including at least two TEEs, the at least two TEEs including a first TEE and a second TEE, the first TEE being a TEE in which a security key is not stored, and the second TEE being a TEE in which a security key is stored, and the method includes: a second TA sending a security key to a first TA, the first TA being a trusted application program running on the first TEE, and the second TA being a trusted application program running in the second TEE, then the first TA obtaining a first data packet according to the security key and to-be-stored data, the first TA sending the first data packet to the RPMB, and the RPMB storing the to-be-stored data based on the first data packet. That is, in the embodiments of the present application, since the security key is not stored in the first TEE, if the first TA running in the first TEE needs to store to-be-stored data to the RPMB, the first TA cannot obtain the security key to perform authentication calculation on the to-be-stored data, so that the first TA cannot directly store the to-be-stored data to the RPMB; in the solution of the present application, since the security key is stored in the second TEE, the second TA in the second TEE can send the security key to the first TA running in the first TEE in which the security key is not stored, then the first TA performs authentication calculation on the to-be-stored data according to the security key to obtain a first data packet, and then the RPMB can perform calculation authentication on the first data packet using the security key after receiving the first data packet, and stores the to-be-stored data in the first data packet in the case of passing the authentication, so that the function that the application programs running in each TEE in the multi-TEE architecture can all write data to the RPMB is realized.

[0012] With reference to the first aspect, in some implementations of the first aspect, the first TA obtains a first data packet according to the security key and the to-be-stored data, including:

[0013] When the counter is in an idle state, the first TA obtains a first count value, the first count value being a count value of the counter at a current time;

[0014] The first TA obtains a first data packet according to the first count value, the security key and the to-be-stored data.

[0015] The data storage method provided in the embodiments of the present application is applied to an electronic device including at least two TEEs, the at least two TEEs including a first TEE and a second TEE, the first TEE being a TEE in which a security key is not stored, and the second TEE being a TEE in which a security key is stored, and the method includes: sending, by the second TA, the security key to the first TA, then determining, by the first TA, whether a counter is in an idle state, and when the counter is in the idle state, obtaining a count value of the counter, and when the counter is in a busy state, waiting for a state of obtaining the count value until the counter is in the idle state and the count value is obtained. The first TA performs authentication calculation on the count value and to-be-stored data by using the security key to obtain first authentication data, then obtains a first data packet according to the count value, the first authentication data, and the to-be-stored data, and sends the first data packet to the RPMB. In this way, the count value used by the first authentication data in the first data packet sent by the first TA to the RPMB is the same as the count value used by second authentication data obtained by the RPMB through verification. This avoids a case that, in a process in which the RPMB stores data sent by the second TA running in the second TEE, the RPMB sends a count value to the first TA running in the first TEE, and then the RPMB uses an updated count value to verify the first data packet sent by the first TA after storing the data sent by the second TA. That is, by using the data storage method provided in the embodiments of the present application, a case that the count value used by the first TA to obtain the first authentication data is different from the count value used by the RPMB to verify the first data, and then the authentication fails and the RPMB cannot store the to-be-stored data sent by the first TA, is avoided.

[0016] With reference to the first aspect, in some implementations of the first aspect, the counter being in the idle state includes the RPMB currently being in a state of not storing data.

[0017] It should be understood that, when the first TA obtains the count value from the counter, the counter can send a count value at a current time to the first TA, so that the first TA obtains the first authentication data by using the count value at the current time, and generates the first data packet sent to the RPMB according to the first authentication data, the count value at the current time, and the to-be-stored data.

[0018] With reference to the first aspect, in some implementations of the first aspect, the first TA obtaining the first data packet according to the security key and the to-be-stored data further includes:

[0019] When the counter is in the busy state, the first TA is in a state of waiting for obtaining the first count value, and the busy state includes a state in which the RPMB currently stores data of the second TA.

[0020] It should be understood that the busy state includes a state in which the RPMB currently stores data of another TA.

[0021] For example, such as Figure 1 As shown, the process of RPMB storing data can include at least three steps. From the moment the count value is returned (i.e., the second step), the counter begins to be busy until the RPMB completes the storage of the data to be stored (equivalent to...). Figure 1 After the third step shown, the counter's state changes from busy to idle.

[0022] In conjunction with the first aspect, in some implementations of the first aspect, the aforementioned first data packet further includes first authentication data, which is data obtained by the first TA using a security key to authenticate the data to be stored. The RPMB stores the data to be stored based on the first data packet, including:

[0023] RPMB uses a security key to perform authentication calculations on the data to be stored in the first data packet to obtain the second authentication data.

[0024] If the second authentication data matches the first authentication data, the RPMB stores the data to be stored.

[0025] The data storage method provided in the embodiments of this application is applied to an electronic device including at least two TEEs, where the at least two TEEs include a first TEE and a second TEE. The first TEE refers to a TEE that does not store a security key, and the second TEE refers to a TEE that stores a security key. The method includes: a second TA sending a security key to a first TA; then, the first TA determining whether a counter is in an idle state, and if the counter is in an idle state, acquiring the counter's count value; if the counter is in a busy state, waiting to acquire the count value until the count value is acquired. The first TA uses the security key to perform authentication calculations on the returned count value and the data to be stored to obtain first authentication data, and then obtains a first data packet based on the count value, the first authentication data, and the data to be stored, and sends the first data packet to the RPMB. After receiving the first data packet, the RPMB uses the security key to perform authentication calculations on the data to be stored in the first data packet to obtain second authentication data, and stores the data to be stored if the second authentication data matches the first authentication data. This ensures that all data stored in the RPMB is data that has passed RPMB verification, improving the security of data stored in the RPMB.

[0026] In conjunction with the first aspect, in some implementations of the first aspect, the above authentication calculation includes HMAC calculation.

[0027] In the embodiments of the present application, the first TA performs authentication calculation on the to-be-stored data by using a security key through a hash operation to obtain first authentication data. Since the hash operation is a widely used encryption algorithm that has undergone various forms of attacks, the first authentication data obtained through the hash operation is more reliable encryption data, and the security of the first data packet obtained according to the first authentication data and the to-be-stored data is improved.

[0028] With reference to the first aspect, in some implementations of the first aspect, the to-be-stored data is data collected by the first TA by calling the first sensor.

[0029] In the data storage method provided in the embodiments of the present application, the to-be-stored data can be data collected by the first TA by calling the first sensor. The sensor usually needs to be called through the corresponding TA. Therefore, in the case where the first TA corresponding to the first sensor does not store a security key in the TEE, the data collected by the first sensor can be stored in the RPMB by using the data storage method provided in the embodiments of the present application, and the security of the data collected by the first sensor is improved.

[0030] With reference to the first aspect, in some implementations of the first aspect, the first sensor includes a fingerprint collector.

[0031] In the data storage method provided in the embodiments of the present application, since the first sensor includes a fingerprint collector, the to-be-stored data collected by the first TA by calling the fingerprint collector is fingerprint data. Since the fingerprint data is usually used for encryption and is data with relatively high security level, the fingerprint data needs to be stored in the RPMB. In the case where the TEE where the trusted application connected to the fingerprint sensor is located does not store a security key, the fingerprint data can be stored in the RPMB by using the data storage method provided in the embodiments of the present application, and the security of the fingerprint data is improved.

[0032] The second aspect provides a data storage apparatus, including units for performing any of the methods in the first aspect. The apparatus can be a terminal device, and can also be a chip in the terminal device. The apparatus can include an obtaining unit and a processing unit.

[0033] When the apparatus is a terminal device, the processing unit can be a processor, and the input unit can be a communication interface. The terminal device can further include a memory for storing computer program code, and when the processor executes the computer program code stored in the memory, the terminal device performs any of the methods in the first aspect.

[0034] When the device is a chip in a terminal device, the processing unit can be a processing unit inside the chip, and the input unit can be an output interface, a pin, or a circuit, etc. The chip can further include a memory, which can be a memory (e.g., a register, a cache, etc.) inside the chip, or a memory (e.g., a read-only memory, a random access memory, etc.) outside the chip. The memory is configured to store computer program code, and when the processor executes the computer program code stored in the memory, the chip is caused to perform any one of the methods in the first aspect.

[0035] In a possible implementation, the memory is configured to store computer program code; and the processor is configured to execute the computer program code stored in the memory, and when the computer program code stored in the memory is executed, the processor is configured to perform: sending, by a second trusted application (TA), a security key to a first TA, the first TA being a trusted application running on a first TEE, and the second TA being a trusted application running in a second TEE; obtaining, by the first TA, a first data packet according to the security key and to-be-stored data; sending, by the first TA, the first data packet to the RPMB; and storing, by the RPMB, the to-be-stored data based on the first data packet.

[0036] In a third aspect, a computer-readable storage medium is provided, and the computer-readable storage medium stores computer program code. When the computer program code is executed by a data storage device, the data storage device is caused to perform any one of the data storage methods in the first aspect.

[0037] In a fourth aspect, a computer program product is provided, and the computer program product includes computer program code. When the computer program code is executed by a data storage device, the data storage device is caused to perform any one of the device methods in the first aspect.

[0038] The data storage method provided in the embodiments of the present application is applied to an electronic device including at least two TEEs, the at least two TEEs including a first TEE and a second TEE, the first TEE being a TEE in which a security key is not stored, and the second TEE being a TEE in which a security key is stored, and the method includes: sending, by a second TA, a security key to a first TA, the first TA being a trusted application running on the first TEE, and the second TA being a trusted application running in the second TEE, then obtaining, by the first TA, a first data packet according to the security key and to-be-stored data, sending, by the first TA, the first data packet to an RPMB, and storing, by the RPMB, the to-be-stored data based on the first data packet. That is to say, in the embodiments of the present application, since the security key is not stored in the first TEE, if the first TA running in the first TEE needs to store to-be-stored data to the RPMB, the first TA cannot obtain the security key to perform authentication calculation on the to-be-stored data, so that the first TA cannot directly store the to-be-stored data to the RPMB; in the scheme of the present application, since the security key is stored in the second TEE, the second TA in the second TEE can send the security key to the first TA running in the first TEE in which the security key is not stored, then the first TA performs authentication calculation on the to-be-stored data according to the security key to obtain a first data packet, and then the RPMB can perform calculation authentication on the first data packet by using the security key after receiving the first data packet, and stores the to-be-stored data in the first data packet in the case of passing the authentication, so as to realize the function that the application programs running in each TEE in the multi-TEE architecture can all write data to the RPMB. BRIEF DESCRIPTION OF DRAWINGS

[0039] Figure 1 FIG. 1 is a flowchart of an RPMB data writing process;

[0040] Figure 2 FIG. 1 is a schematic diagram of a hardware system of an electronic device suitable for the present application;

[0041] Figure 3 FIG. 1 is a schematic diagram of a software system of an electronic device suitable for the present application;

[0042] Figure 4 FIG. 1 is a schematic diagram of an application scenario provided by the embodiments of the present application;

[0043] Figure 5 FIG. 1 is a schematic diagram of an electronic device for data storage provided by the embodiments of the present application;

[0044] Figure 6 FIG. 1 is a flowchart of a data storage method provided by the embodiments of the present application;

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

[0046] Figure 8 is a flowchart of another data storage method provided by an embodiment of the present application;

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

[0048] Figure 10 is a flowchart of another data storage method provided by an embodiment of the present application;

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

[0050] Figure 12 is a schematic diagram of an electronic device for data storage provided by the present application. DETAILED DESCRIPTION

[0051] The technical solutions in the embodiments of the present application will be described below with reference to the drawings in the embodiments of the present application. In the description of the embodiments of the present application, unless otherwise specified, " / " represents the meaning of or, for example, A / B can represent A or B; in this document, "and / or" only describes the association relationship of the associated objects, which means that there can be three relationships, for example, A and / or B, which means that there are three cases of A alone, A and B together, and B alone. In addition, in the description of the embodiments of the present application, "multiple" means two or more than two.

[0052] Hereinafter, the terms "first", "second", "third" are only for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of indicated technical features. Therefore, the features defined with "first", "second", "third" can explicitly or implicitly include one or more features.

[0053] For ease of understanding, some examples are given below for reference in relation to the concepts of the embodiments of the present application.

[0054] 1. RPMB

[0055] RPMB refers to an independent physical partition in the memory, which is usually used to store data with the need to prevent illegal tampering, such as public keys, serial numbers and the like related to fingerprint payment on mobile phones. Usually, RPMB will authenticate the write operation, but the read operation does not need to be authenticated.

[0056] It should be understood that in the process of producing an electronic device, a unique security key is generated for each electronic device and burned into the OTP area of the memory of the electronic device. The OTP area refers to an area that can only be burned once. At the same time, the host of the electronic device stores the security key in a secure execution environment (such as TEE). When the host writes data to the RPMB, the RPMB can authenticate using the security key.

[0057] For example, the host (trusted application TA in TEE) writes data to the device (such as UFS).

[0058] As shown in Figure 1 The host sends a read count value Write Cnt request and a random number to the device to obtain the count value Write Cnt in the device. After receiving the read count value Write Cnt request, the device performs HMAC calculation on the count value Write Cnt and the random number using the security key to generate a first MAC. Then the device fills the Write Cnt, the random number and the first MAC into the corresponding area of the RPMB data packet, generates the RPMB data packet, and sends the RPMB data packet to the host. When the host receives the RPMB data packet, it performs HMAC calculation on the Write Cnt and the random number in the RPMB data packet using the security key to obtain a second MAC. It compares whether the first MAC and the second MAC are consistent, and in the case that the first MAC and the second MAC are consistent, it compares whether the random number sent by the host to the device and the random number in the RPMB data packet are consistent, and in the case that the random number sent by the host to the device and the random number in the RPMB data packet are consistent, it determines that the Write Cnt in the RPMB data packet is trusted.

[0059] Further, the Host performs HMAC calculation on the destination address of the data to be stored, the data to be stored and the Write Cnt by using the security key, obtains a third MAC, fills the third MAC into the MAC area in the RPMB data packet, obtains an updated RPMB data packet, and then sends the updated RPMB data packet to the Device. The Device receives the updated RPMB data packet, performs HMAC calculation on the destination address of the data to be stored, the data to be stored and the Write Cnt by using the security key, obtains a fourth MAC, compares the fourth MAC with the third MAC, compares the Write Cnt in the updated RPMB data packet with the Write Cnt in the Device in the case that the fourth MAC is consistent with the third MAC, and in the case that the Write Cnt in the updated RPMB data packet is consistent with the Write Cnt in the Device, stores the data to be stored in the updated RPMB data packet into the destination address corresponding to the data to be stored, and performs the increment operation on the Write Cnt in the Device, obtains an updated Write Cnt.

[0060] 2. Trusted execution environment (TEE)

[0061] TEE refers to an independent secure running environment in a terminal device, and usually refers to a logically isolated running environment from a rich execution environment (REE). The TEE defines strict protection measures and can resist software attacks on the conventional REE side. Therefore, the TEE is usually used to process tasks with high security level.

[0062] 3. Rich execution environment (REE)

[0063] The REE usually refers to a general running environment on a terminal device, and is a running environment without specific security functions. For example, the Android system and the IOS system belong to the REE.

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

[0065] 4. Trusted application (TA)

[0066] The TA usually refers to an application running on the TEE. The TA can provide security services for applications running outside the TEE.

[0067] 5. Client Application (CA)

[0068] CA typically refers to applications running on REE.

[0069] 6. Hypervisor

[0070] A hypervisor is an intermediate software layer running between the underlying physical server and the operating system. Through the hypervisor, all physical devices on the electronic device, including disks and memory, can be accessed. The hypervisor coordinates hardware resource access and provides protection between virtual machines. After the server starts, the hypervisor loads the operating system of all virtual machine clients and allocates memory, disk, and network resources to the virtual machines. Based on the hypervisor mechanism, an electronic device can support multiple TEEs running simultaneously.

[0071] 7. ATF

[0072] ATF(ARM Firmware is a target The chip provides underlying open-source firmware code. The firmware divides the entire system into four run levels: EL0, EL1, EL2, and EL3. Specifically, the application runs at ELO, the driver at EL1, the hypervisor module at EL2, and the ATF module at EL3.

[0073] The data storage method provided by the embodiments of the present application can be applied to an electronic device. Optionally, the electronic device includes a terminal device, which can also be referred to as a terminal, a user equipment (UE), a mobile station (MS), a mobile terminal (MT), etc. The terminal device can be a mobile phone, a smart television, 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 of the terminal device.

[0074] Exemplarily, Figure 2 A structural schematic diagram of the electronic device 100 is shown. The electronic device 100 can 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 loudspeaker 170A, a receiver 170B, a microphone 170C, a headset interface 170D, a sensor module 180, a key 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 can include a pressure sensor 180A, a gyroscope sensor 180B, a barometric 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.

[0075] It can be understood that the structure shown in the embodiments of the present application does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 can include more or fewer components than shown, or combine certain components, or split certain components, or different arrangement of components. The components shown can be implemented in hardware, software, or a combination of software and hardware.

[0076] The processor 110 can include one or more processing units, for example: the processor 110 can 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), etc. Among them, different processing units can be independent devices, or can be integrated in one or more processors.

[0077] Among them, the controller can be the nerve center and command center of the electronic device 100. The controller can generate operation control signals according to instruction operation codes and timing signals to complete the control of fetching instructions and executing instructions.

[0078] The memory in the processor 110 can also be provided for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory can save instructions or data that the processor 110 has just used or repeatedly uses. If the processor 110 needs to use the instructions or data again, it can be directly called from the memory. Avoiding repeated access reduces the waiting time of the processor 110, thus improving the efficiency of the system.

[0079] The fingerprint sensor 180H is used to collect fingerprints. The electronic device 100 can use the collected fingerprint characteristics to realize fingerprint unlocking, access application lock, fingerprint shooting, fingerprint answering, etc.

[0080] Optionally, the memory in the electronic device includes eMMC and universal file storage (UFS). Among them, the RPMB in the memory is usually used to store data with security requirements. When writing data into the RPMB, it needs to be authenticated and encrypted through the pre-stored security key. The RPMB checks the written data with the security key stored thereon, and after the check is passed, the written data is stored on the RPMB.

[0081] It should be noted that any electronic device mentioned in the embodiments of the present application can include more or less modules in the electronic device 100.

[0082] 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. The embodiments of the present application take the Android system with a layered architecture as an example to exemplarily illustrate the software structure of the electronic device 100.

[0083] Figure 3 is a software structure block diagram of the electronic device 100 of the embodiments of the present application.

[0084] The layered architecture of the electronic device 100 divides the software into several layers, each layer has a clear role and division of labor. The layers communicate with each other through 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 the system library, and the kernel layer.

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

[0086] As shown in Figure 3 , the application package can include camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message, etc.

[0087] The application framework layer provides application programming interfaces (APIs) and programming frameworks for the applications of the application layer. The application framework layer includes some pre-defined functions.

[0088] As shown in Figure 3 , the application framework layer can include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, etc.

[0089] The window manager is used to manage the window program. The window manager can obtain the size of the display screen, determine whether there is a status bar, lock the screen, and intercept the screen, etc.

[0090] The content provider is used to store and obtain data, and make the data accessible to the application. The data can include video, image, audio, dialed and received calls, browsing history and bookmarks, phonebook, etc.

[0091] The view system includes visual controls, such as controls that display text, controls that display pictures, and the like. The view system can be used to build an application. A display interface can be composed of one or more views. For example, a display interface that includes a short message notification icon can include a view that displays text and a view that displays a picture.

[0092] The telephony manager is used to provide the communication function of the electronic device 100. For example, the management of the call state (including the connection, hang-up, and the like).

[0093] The resource manager provides various resources for the application, such as localized strings, icons, pictures, layout files, video files, and the like.

[0094] The notification manager enables the application to display notification information in the status bar, which can be used to convey a message of the notification type, which can automatically disappear after a short stay without user interaction. For example, the notification manager is used to notify the completion of the download, the message reminder, and the like. The notification manager can also be a notification that appears in the top status bar of the system in the form of a chart or a scrolling text, such as a notification of an application running in the background, and can also be a notification that appears on the screen in the form of a dialogue window. For example, the text information is prompted in the status bar, a prompt sound is emitted, the electronic device is vibrated, the indicator light is blinked, and the like.

[0095] The Android runtime includes the core library and the virtual machine. The Android runtime is responsible for the scheduling and management of the Android system.

[0096] The core library includes two parts: one part is the function function that the java language needs to call, and the other part is the core library of the Android.

[0097] The application layer and the application framework layer run in the virtual machine. The virtual machine executes the java file of the application layer and the application framework layer into a binary file. The virtual machine is used to perform the management of the object life cycle, the stack management, the thread management, the security and exception management, and the garbage collection, and the like.

[0098] The system library can include a plurality of functional modules. For example: the surface manager, the media library, the three-dimensional graphics processing library (for example: OpenGL ES), the 2D graphics engine (for example: SGL), and the like.

[0099] The surface manager is used to manage the display subsystem and provides the fusion of 2D and 3D layers for a plurality of applications.

[0100] The media library supports multiple commonly used audio, video format playback and recording, and static image files, etc. The media library can support multiple audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.

[0101] The three-dimensional graphics processing library is used to implement three-dimensional graphics drawing, image rendering, synthesis, and layer processing, etc.

[0102] The 2D graphics engine is a drawing engine for 2D drawing.

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

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

[0105] The application scenarios provided by the embodiments of the present application will be described below with reference to the accompanying drawings.

[0106] With the continuous development of terminal technology, the multi-TEE architecture has become a common architecture. For example, as shown in Figure 4 The terminal device includes two TEEs and an RPMB, i.e., a first TEE, a second TEE, and an RPMB. The first TEE does not store a security key, and the second TEE stores a security key. In the case where a first TA running in the first TEE needs to write data into the RPMB, the first TA running in the first TEE can obtain the security key stored in the second TEE from a first channel between the first TEE and the second TEE, then obtain a first data packet according to the security key and the data to be stored, and send the first data to the RPMB, so that the RPMB stores the data to be stored based on the first data.

[0107] The data to be stored can be data collected by the first TA calling a first sensor. For example, the first sensor is a fingerprint sensor, and the data to be stored can be fingerprint data collected by the first TA calling the fingerprint sensor.

[0108] Generally, fingerprint data is used for encryption and decryption in the terminal device, so the fingerprint data needs to be stored in a secure area, such as the RPMB. In the case where the first TA does not store a security key for verifying data written into the RPMB in the first TA, the first TA can obtain the security key through a data channel between the first TEE and the second TEE.

[0109] It should be understood that the above is an example of an application scenario, and does not limit the application scenarios of the present application.

[0110] The following will be describedFigures 5 to 11 The data storage method provided by the embodiment of the present application is described in detail.

[0111] As shown in the figure, the electronic device includes a first TEE and a second TEE, the first TEE refers to a TEE without storing a security key, and the second TEE refers to a TEE storing a security key, and there is a first channel between the first TEE and the second TEE for transmitting the security key. Figure 5

[0112] The data storage method provided by the embodiment of the present application is described in detail. Figure 6 The data storage method of the electronic device shown in the figure is described in detail. Figure 5

[0113] Figure 6 The flowchart of the data storage method provided by an embodiment of the present application is shown in the figure, and the method is applied to the electronic device shown in the figure. The method includes the following steps. Figure 6 Figure 5

[0114] S101, the second TA sends a security key to the first TA.

[0115] It should be understood that in the production process of the electronic device, the security key will be burned into the memory (such as RPMB) in the electronic device, and at the same time, the security key will be written into the TEE, so that the TA running in the TEE can call the security key to encrypt the data to be stored when writing data to the RPMB. In the case where the electronic device includes at least two TEEs, the security key will usually be written into only one TEE.

[0116] It should be understood that the security key can be stored in any of the at least two TEEs.

[0117] As an example, the at least two TEEs include a first TEE and a second TEE, wherein the first TEE refers to a TEE without storing a security key, and the second TEE refers to a TEE storing a security key. In the case where the first TA running in the first TEE needs to write data into the RPMB, since the first TEE does not store the security key. Therefore, the first TA cannot call the security key to perform authentication calculation on the data to be stored (i.e. the first data to be stored), and thus the first TA cannot directly send the data to be stored to the RPMB storage. In this case, the second TA can send the security key stored in the second TEE to the first TA through the first channel between the first TEE and the second TEE.

[0118] It should be understood that 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.

[0119] ​​​​It should be understood that the Hypervisor module has the function of accessing all physical devices on the electronic device, including the disk and the memory in the internal. After the server is started, the Hypervisor module loads the operating systems of all virtual machine clients (including the first TEE and the second TEE), allocates memory, disk and network for the virtual machine. In this way, the Hypervisor module can directly allocate a data interface for the first TEE and the second TEE, so that data can be transmitted between the first TEE and the second TEE. The first channel can refer to the data interface allocated by the Hypervisor module.

[0120] S102, the first TA obtains a first data packet according to the security key and the to-be-stored data.

[0121] The to-be-stored data can be data collected by the first TA on the first TEE.

[0122] For example, the first TA in the first TEE is an application program that needs to perform encryption and decryption on fingerprint data. The to-be-stored data can be fingerprint data collected by the first TA through a fingerprint collector.

[0123] For example, the first TA in the first TEE is an application program that needs to perform encryption and decryption on sound data. The to-be-stored data can be sound data collected by the first TA through a microphone.

[0124] For example, the first TA in the first TEE is an application program that needs to perform encryption and decryption on character password data. The to-be-stored data can be character data obtained by the first TA through receiving a user's click operation on the display screen.

[0125] For example, the first TA in the first TEE is an application program that needs to perform encryption and decryption on eyeprint data. The to-be-stored data can be eyeprint data collected by the first TA through a camera.

[0126] For example, the first TA in the first TEE is an application program that needs to perform encryption and decryption on face data. The to-be-stored data can be face data collected by the first TA through a camera.

[0127] For example, the first TA can also be an application program that provides a security service to the CA, and the to-be-stored data can be password data sent by the CA to the first TA, including but not limited to the above-mentioned fingerprint data, sound data, character data, eyeprint data and face data.

[0128] Optionally, the first TA can obtain a count value of a counter in the RPMB, and then perform an authentication calculation on the to-be-stored data and the count value using the security key to obtain first authentication data, and then pack the first authentication data, the to-be-stored data and the count value to obtain the first data packet.

[0129] S103. The first TA sends the first data packet to the RPMB.

[0130] S104. The RPMB stores the to-be-stored data based on the first data packet.

[0131] It should be understood that after receiving the first data packet, the RPMB can first verify the first data packet to ensure the security of the data stored in the RPMB, and store the to-be-stored data in the first data packet after the verification is passed.

[0132] For example, when storing the to-be-stored data, the RPMB needs to first perform a calculation on the to-be-stored data using a security key to obtain second authentication data, and determine that the first data packet is authenticated if the first authentication data and the second authentication data are the same, and store the to-be-stored data.

[0133] The data storage method provided in the embodiments of the present application is applied to an electronic device including at least two TEEs, the at least two TEEs including a first TEE and a second TEE, the first TEE being a TEE in which a security key is not stored, and the second TEE being a TEE in which a security key is stored, and the method includes: sending, by the second TA, the security key to the first TA, the first TA being a trusted application running on the first TEE, and the second TA being a trusted application running in the second TEE, then obtaining, by the first TA, a first data packet according to the security key and to-be-stored data, sending, by the first TA, the first data packet to the RPMB, and storing, by the RPMB, the to-be-stored data based on the first data packet. That is to say, in the embodiments of the present application, since the security key is not stored in the first TEE, if the first TA running in the first TEE needs to store to-be-stored data to the RPMB, the first TA cannot obtain the security key to perform authentication calculation on the to-be-stored data, so that the first TA cannot directly store the to-be-stored data to the RPMB; in the scheme of the present application, since the security key is stored in the second TEE, the second TA in the second TEE can send the security key to the first TA running in the first TEE in which the security key is not stored, then the first TA performs authentication calculation on the to-be-stored data according to the security key to obtain a first data packet, and then the RPMB can perform calculation authentication on the first data packet by using the security key after receiving the first data packet, and stores the to-be-stored data in the first data packet in the case of passing the authentication, so as to realize the function that the application programs running in each TEE in the multi-TEE architecture can all write data to the RPMB.

[0134] The data storage method provided in the embodiment of the application can be used for the first TA running in the first TEE and the second TA running in the second TEE to write data into the RPMB. It should be understood that, when an application writes data into the RPMB, the application usually needs to obtain the count value of the counter in the RPMB at the current time. For example, in the process in which the first TA writes data into the RPMB, the first TA sends a write request to the RPMB through the kernel to obtain the count value of the counter in the RPMB. The kernel first confirms the state of the counter, and when the state of the counter is in an idle state, returns the count value at the current time to the application. The application performs authentication calculation on the count value at the current time and the data to be stored by using a security key, to obtain first authentication data, and then generates a first data packet according to the first authentication data and the data to be stored, and sends the first data packet to the RPMB. After the RPMB receives the first data packet, the RPMB performs verification on the first authentication data, and stores the data to be stored after the verification is passed, at which time the count value of the counter is increased by one. When the RPMB stores data next time, the count value increased by one is returned to the application, so that the application performs authentication calculation according to the returned count value increased by one. In the case where the first TA running in the first TEE and the second TA running in the second TEE can both write data into the RPMB, when the first TA writes data into the RPMB, the second TA requests to write data into the RPMB, at which time the count value of the counter has not been updated, and the count value of the counter sent to the second TA can be the count value that has not been updated, which can cause the authentication data obtained by the second TA by using the count value that has not been updated to be incorrect. In order to avoid the situation that the authentication data is incorrect due to the count value not being updated, one of the TAs can be caused to be in a state of waiting for the other TA to request to write data into the RPMB when the one of the TAs writes data into the RPMB. In this way, the situation that the authentication data obtained by the other TA by using the count value that has not been updated is incorrect can be effectively avoided. The following will be described in detail with reference to Figures 7 to 10 .

[0135] Figure 7 For a structure schematic diagram of an electronic device suitable for the embodiment of the application, as shown in Figure 7 , the electronic device includes a first TEE, a second TEE, a kernel, and an RPMB. The first TEE refers to a TEE in which a security key is not stored, and the second TEE refers to a TEE in which a security key is stored. The kernel includes a Hypervisor module. The RPMB includes a counter.

[0136] The following will be described in detail with reference to Figure 8 . Figure 7 The data storage method of the electronic device shown in

[0137] Figure 8 A flowchart of a data storage method provided in an embodiment of the present application is shown in FIG. 1, which is applied to an electronic device as shown in FIG. 2. As shown in FIG. 3, the method comprises the following steps. Figure 7 Figure 8

[0138] S201, the second TA sends a security key to the first TA.

[0139] S202, the first TA determines whether the counter is in an idle state or a busy state. If the counter is in the idle state, S204 is performed; if the counter is in the busy state, S203 is performed.

[0140] It should be understood that, in the process of storing data in the RPMB, the counter sends the count value at the current time to the TA that writes data in the RPMB, and then adds one to the count value of the counter to obtain an updated count value after the RPMB completes the data storage. It is equivalent to that, in the process of storing data in the RPMB, the counter is in the busy state, and when the RPMB stops storing data, the counter is in the idle state.

[0141] It can be seen that the process of storing data in the RPMB can include at least three steps, wherein, from the return of the count value (i.e., the second step), the counter starts to be in the busy state, and until the RPMB completes the storage of the data to be stored (equivalent to the third step shown in FIG. 1), the state of the counter changes from the busy state to the idle state. Figure 1 Figure 1

[0142] Optionally, the counter being in the idle state includes that the RPMB is currently in a state of not storing data.

[0143] It should be understood that the busy state includes that the RPMB is currently in a state of storing data of other TAs.

[0144] For example, in the case that the first TA sends a write request to the kernel, if the RPMB is currently in a state of storing data written by the second TA (i.e., other TA), the counter is in the busy state.

[0145] For example, in the case that the second TA sends a write request to the kernel, if the RPMB is currently in a state of storing data written by the first TA (i.e., other TA), the counter is in the busy state.

[0146] S203, the first TA is in a state of waiting for obtaining the count value until the counter is in the idle state.

[0147] S204, the first TA obtains the count value of the counter at the current time (equivalent to the first count value).

[0148] ​​​​It should be understood that, since the embodiment of the present application acquires the count value of the counter when the counter is in an idle state. In the case that the counter is in an idle state and the RPMB is in a state of not storing data, the count value of the counter will not change. In this case, the following situation will not occur, which leads to the case that the RPMB authentication fails:

[0149] For example, the count value N returned by the kernel to the first TA through the counter, the first TA uses the count value N to perform authentication calculation to obtain first authentication data. Since the RPMB stores data, the count value N of the counter is updated to N+1, which leads to the case that the RPMB uses the count value (N+1) to perform authentication calculation on the to-be-stored data sent by the first TA to obtain second authentication data. Since the first authentication data and the second authentication data are obtained by using different count values to perform authentication on the same to-be-stored data, the first authentication data and the second authentication data do not match. That is to say, the RPMB rejects to store the to-be-stored data sent by the first TA because of the authentication failure.

[0150] In a possible case, when the first TA writes data to the RPMB, the second TA sends a write request to the kernel, at this time, the kernel requests the RPMB to acquire the count value of the counter, and the RPMB is storing the to-be-stored data sent by the first TA, which is equivalent to that the counter in the RPMB is in a busy state. The updated count value of the counter needs to be returned to the second TA after the first TA completes the process of writing data to the RPMB.

[0151] For example, the first TA sends a write request to the RPMB, where the write request is used to request the count value of the counter. After receiving the write request, the kernel determines whether the state of the counter is the idle state. If yes, the kernel modifies the state of the counter to the busy state, and obtains the count value of the counter, and returns the count value of the counter to the first TA. At this time, if the second TA running in the second TEE sends a write request to the kernel. The kernel determines that the state of the counter is the busy state, and starts waiting for the state of the counter to be the idle state. Meanwhile, the first TA hashes the to-be-stored data and the count value using the security key to obtain first authentication data. The first TA further obtains a first data packet according to the first authentication data, the count value and the to-be-stored data, and sends the first data packet to the kernel. After the kernel sends the first data packet to the RPMB, the first TA reads the result of the kernel writing the RPMB. If the RPMB has successfully written the to-be-stored data, the state of the counter is set to the idle state, and a write success message is returned to the first TA, where the write success message includes an updated count value (for example, the count value is incremented to obtain the updated count value). Based on the returned message, the first TA determines that the to-be-stored data has been successfully written to the RPMB. At this time, the state of the counter is changed to the idle state, and the kernel returns the updated count value of the counter to the second TA.

[0152] It should be understood that after the counter returns the count value to the first TA, the state of the counter is usually set to the busy state. In the case where the state of the counter is the busy state, the TA running on the other TEE cannot obtain the count value. In this way, the TA running on the other TEE cannot obtain the count value during the process in which the first TA writes data to the RPMB, and thus cannot write data to the RPMB, that is, the conflict of the count value caused by the TA running on the other TEE and the first TA simultaneously writing data to the RPMB is avoided.

[0153] It should be understood that the embodiments of the present application are described by taking the first TA storing data to the RPMB as an example. When the second TA stores data to the RPMB, similar to the first TA, it also needs to determine whether the counter is currently in the idle state or the busy state.

[0154] For example, the second TA determines whether the counter is in the idle state or the busy state. If it is the idle state, the second TA obtains the count value of the counter at the current time; if it is the busy state, the second TA is in a state of waiting for obtaining the count value until the counter changes from the busy state to the idle state, for example, the first TA completes the data storage to the RPMB.

[0155] In S205, the first TA obtains a first data packet according to the count value at the current time, the security key and the to-be-stored data.

[0156] In a possible case, the first TA can perform authentication calculation on the to-be-stored data by using the security key to obtain first authentication data, and then generate the first data packet according to the first authentication data.

[0157] For example, the first TA can perform authentication calculation on the to-be-stored data and the count value of the current time by using the security key to obtain first authentication data, and then packetize the first authentication data, the to-be-stored data and the count value of the current time to obtain the first data packet.

[0158] For example, the first TA can perform calculation on the to-be-stored data by using the security key through a Hash-based Message Authentication Code (HMAC) to obtain first authentication data. The HMAC is a method of message authentication based on a Hash function and a key, is a way of providing authentication services selected by many current security protocols, is widely applied, for example, the HMAC is widely applied in Internet Protocol Security (IPSec) and other network protocols (for example, SSL), and has withstood various forms of attacks. Therefore, the HMAC can also be referred to as an existing Internet security standard.

[0159] In the embodiment of the present application, the first TA performs authentication calculation on the to-be-stored data by using the security key through a Hash operation to obtain first authentication data. Since the Hash operation is a widely used encryption algorithm that has withstood various forms of attacks, the first authentication data obtained through the Hash operation is more reliable encrypted data, and the security of the first data packet obtained according to the first authentication data and the to-be-stored data is improved.

[0160] For example, the first TA can also perform calculation on the to-be-stored data by using the security key through a Cipher Block Chaining-Message Authentication Code (CMAC) to obtain first authentication data.

[0161] The data storage method provided in the embodiments of the present application is applied to an electronic device including at least two TEEs, the at least two TEEs including a first TEE and a second TEE, the first TEE being a TEE in which a security key is not stored, and the second TEE being a TEE in which a security key is stored, and the method includes: sending, by the second TA, the security key to the first TA, then determining, by the first TA, whether a counter is in an idle state, and when the counter is in the idle state, obtaining a count value of the counter, and when the counter is in a busy state, waiting for a state of obtaining the count value until the counter is in the idle state and the count value is obtained. The first TA performs authentication calculation on the count value and to-be-stored data by using the security key to obtain first authentication data, then obtains a first data packet according to the count value, the first authentication data, and the to-be-stored data, and sends the first data packet to the RPMB. In this way, the count value used by the first authentication data in the first data packet sent by the first TA to the RPMB is the same as the count value used by second authentication data obtained by the RPMB through verification. This avoids a case that, in a process in which the RPMB stores data sent by the second TA running in the second TEE, the RPMB sends the count value to the first TA running in the first TEE, and then the RPMB uses an updated count value to verify the first data packet sent by the first TA after storing the data sent by the second TA. That is, by using the data storage method provided in the embodiments of the present application, a case that the count value used by the first TA to obtain the first authentication data is different from the count value used by the RPMB to verify the first data, and then the verification fails and the RPMB cannot store the to-be-stored data sent by the first TA, is avoided.

[0162] S206, the first TA sends the first data packet to the RPMB.

[0163] S207, the RPMB performs authentication calculation on the to-be-stored data in the first data packet by using the security key to obtain second authentication data.

[0164] It should be understood that the security key stored in the RPMB is the same as the security key stored in the second TEE.

[0165] It should be understood that, after the RPMB returns the count value of the current time to the first TA, the counter is not updated. Therefore, when the RPMB receives the first data packet, the count value of the counter is the same as the count value of the current time returned to the first TA.

[0166] The RPMB performing authentication calculation on the to-be-stored data in the first data packet by using the security key to obtain second authentication data can mean that the RPMB performs authentication calculation on the to-be-stored data in the first data packet and the count value of the current time by using the security key to obtain the second authentication value.

[0167] Since the first TA performs authentication calculation, it can calculate the to-be-stored data by using a Hash-based Message Authentication Code (HMAC) or a Cipher Block Chaining-Message Authentication Code (CMAC).

[0168] For example, the first TA calculates the to-be-stored data by using a Hash-based Message Authentication Code to obtain first authentication data, and the RPMB also calculates the to-be-stored data by using a Hash-based Message Authentication Code to obtain second authentication data.

[0169] For example, the first TA calculates the to-be-stored data by using a Cipher Block Chaining-Message Authentication Code to obtain first authentication data, and the RPMB also calculates the to-be-stored data by using a Cipher Block Chaining-Message Authentication Code to obtain second authentication data.

[0170] S208, in a case where the second authentication data matches the first authentication data, the RPMB stores the to-be-stored data.

[0171] As described above, the first authentication data and the second authentication data are obtained by using the same authentication calculation on the same count value and the to-be-stored data. Therefore, in a case where the first authentication data matches the second authentication data, it is indicated that the first data packet is a secure data packet sent by the first TA to the RPMB for storage, rather than an attack data packet on the RPMB.

[0172] It should be understood that the matching of the first authentication data and the second authentication data can mean that the first authentication data and the second authentication data are completely the same, or that part of the data in the first authentication data and part of the data in the second authentication data are the same, where the proportion of the same data is greater than a preset threshold.

[0173] The data storage method provided in the embodiments of the present application is applied to an electronic device including at least two TEEs, the at least two TEEs including a first TEE and a second TEE, the first TEE being a TEE in which a security key is not stored, and the second TEE being a TEE in which a security key is stored, and the method includes: sending, by the second TA, the security key to the first TA, then determining, by the first TA, whether a counter is in an idle state, and when the counter is in the idle state, obtaining a count value of the counter, and when the counter is in a busy state, waiting for a state of obtaining the count value until the count value is obtained. The first TA performs authentication calculation on the returned count value and to-be-stored data by using the security key to obtain first authentication data, then obtains a first data packet according to the count value, the first authentication data and the to-be-stored data, and sends the first data packet to the RPMB. After receiving the first data packet, the RPMB performs authentication calculation on the to-be-stored data in the first data packet by using the security key to obtain second authentication data, and in the case that the second authentication data matches the first authentication data, stores the to-be-stored data. In this way, the data stored in the RPMB is all data that passes the verification of the RPMB, and the security of the data stored in the RPMB is improved.

[0174] In a possible case, the to-be-stored data can be data collected by a fingerprint sensor.

[0175] For example, the CA running in the Android system sends a fingerprint registration request to the fingerprint TA (the first TA) in the first TEE in the case that the fingerprint registration request is initiated by a user, the fingerprint TA invokes the fingerprint sensor based on the fingerprint registration request, collects fingerprint data, and sends the collected fingerprint data to the fingerprint TA. The following describes in detail how the fingerprint TA stores the fingerprint data collected by the fingerprint sensor into the RPMB. Figure 9 and Figure 10 The following describes in detail how the fingerprint TA stores the fingerprint data collected by the fingerprint sensor into the RPMB.

[0176] It should be understood that the electronic device can be divided into four running levels, which are EL0, EL1, EL2 and EL3. Among them, the running level of the application program is EL0, the running level of the driver is EL1, the running level of the Hypervisor module is EL2, and the running level of the ATF module is EL3.

[0177] For example, the data storage method provided in the embodiments of the present application can be applied to the electronic device as shown in Figure 9 For example, the data storage method provided in the embodiments of the present application can be applied to the electronic device as shown in The first TEE (equivalent to the first TEE) runs the fingerprint TA, the first proxy TA, and the first RPMB service module (equivalent to the first TA). It should be understood that the first TA can be multiple applications, including the fingerprint TA, the first proxy TA, and the first RPMB service module. The second TEE (equivalent to the second TEE) runs the second proxy TA and the second RPMB service module (equivalent to the second TA). It should be understood that the second TA can be multiple applications, including the second proxy TA and the second RPMB service module. Among them, the second RPMB service module stores a security key. It should be understood that the running levels of the fingerprint CA, the fingerprint TA, the first RPMB service module, the first proxy TA, the second proxy TA, and the second RPMB service module are EL0. The kernel includes a Hypervisor module and an ATF module, wherein the running level of the Hypervisor module is EL2, and the running level of the ATF module is EL3. As shown in Figure 9 The electronic device runs Android (REE), the first TEE, and the second TEE, the first TEE does not store a security key, and the second TEE stores a security key. The first proxy TA running in the second TEE sends the security key to the first proxy TA running in the first TEE.

[0178] The following describes in detail Figure 10 The data storage method applied to Figure 9 The electronic device shown in the figure.

[0179] Figure 10 Another flowchart of a data storage method provided by an embodiment of the present application is provided. The method is applied to the electronic device as Figure 9 described above, and includes the following steps.

[0180] S301, the second RPMB service module (equivalent to one second TA) running in the second TEE (second TEE) sends a security key to the second proxy TA (equivalent to one second TA).

[0181] S302, the second proxy TA sends the security key to the ATF module in the kernel.

[0182] S303, the ATF module in the kernel sends the security key to the first proxy TA running in the first TEE.

[0183] S304, the fingerprint CA running in Android (REE) responds to the fingerprint registration operation.

[0184] S305, the fingerprint CA sends a fingerprint registration request to the first TEE tz driver module in the kernel.

[0185] S306, the first TEE tz driver module sends a fingerprint registration request to the hypervisor module.

[0186] S307, the hypervisor module sends the fingerprint registration request to a fingerprint TA (first TA) running in the first TEE (first TEE).

[0187] S308, the fingerprint TA calls the fingerprint sensor to collect fingerprint data (to-be-stored data) in response to the fingerprint registration request.

[0188] S309, the fingerprint TA sends the fingerprint data and the RPMB write request type to the first RPMB service module in the first TEE.

[0189] S310, the first RPMB service module in the first TEE calls the security key in the first proxy TA to perform authentication calculation on the fingerprint data and the RPMB write request, and obtains first authentication data.

[0190] S311, the first RPMB service module generates a first data packet according to the first authentication data, the counter value of the counter and the fingerprint data.

[0191] S312, the first RPMB service module sends the first data packet to the hypervisor module in the kernel.

[0192] S313, the hypervisor module sends the first data packet to the first TEE tz driver in the kernel.

[0193] S314, the first TEE tz driver module in the kernel sends the first data packet to the storage device driver module in Android.

[0194] Illustratively, the storage device driver module refers to an eMMC driver module.

[0195] Illustratively, the storage device driver module refers to a UFS driver module.

[0196] S315, the storage device driver module sends the first data packet to the RPMB.

[0197] In the embodiment of the present application, the second agent TA running in the second TEE sends the security key to the first agent TA running in the first TEE, so that the fingerprint TA running in the first TEE can send the fingerprint data to the first RPMB service module, so that the first RPMB service module calls the security key in the first agent TA to perform authentication calculation on the fingerprint data, obtains first authentication data, and generates a first data packet according to the first authentication data and the fingerprint data, and then sends the first data packet to the RPMB, so that the first TEE which does not store the security key can also store the fingerprint data in the RPMB, that is, the data storage method provided by the embodiment of the present application realizes the function that the application program running in each TEE in the multi-TEE architecture can write data to the RPMB.

[0198] It should be understood that, although each step in the flowchart in the above embodiment is displayed in sequence according to the arrow, these steps are not necessarily executed in sequence according to the arrow. Unless otherwise specified herein, the execution of these steps is not strictly limited in sequence, and these steps can be executed in other sequences. Moreover, at least part of the steps in the flowchart can include multiple sub-steps or multiple stages, which are not necessarily executed at the same time, but can be executed at different times, and the execution sequence of these sub-steps or stages is not necessarily sequential, but can be executed in rotation or alternation with other steps or sub-steps or stages of other steps.

[0199] Figure 11 A structural schematic diagram of an electronic device provided by the embodiment of the present application.

[0200] It should be understood that the electronic device can execute Figures 6 to 10 The data storage method shown in the figure, the electronic device includes at least two trusted execution environments TEEs, and the at least two TEEs include a first TEE and a second TEE, the first TEE is a TEE that does not store a security key, the second TEE is a TEE that stores a security key, and the security key is a key for the replay protection memory block RPMB to verify the stored data; the electronic device includes an acquisition unit 610 and a processing unit 620.

[0201] The processing unit 620 is configured to control the second trusted application TA to send the security key to the first trusted application TA, the first TA being a trusted application running on the first TEE, and the second TA being a trusted application running in the second TEE;

[0202] The processing unit 620 is configured to control the first TA to obtain a first data packet according to the security key and the data to be stored;

[0203] The processing unit 620 is configured to control the first TA to send the first data packet to the RPMB.

[0204] The processing unit 620 is configured to control the RPMB to store the to-be-stored data based on the first data packet.

[0205] Optionally, as an embodiment, the processing unit 620 is configured to control the first TA to acquire a first count value when the counter is in an idle state, the first count value being a count value of the counter at a current time; and the first TA to obtain the first data packet according to the first count value, the security key and the to-be-stored data.

[0206] Optionally, as an embodiment, the idle state of the counter includes that the RPMB is currently in a state of not storing data.

[0207] Optionally, as an embodiment, the processing unit 620 is configured to control the first TA to be in a state of waiting for acquiring the first count value when the counter is in a busy state, the busy state including that the RPMB is currently in a state of storing data of the second TA.

[0208] Optionally, as an embodiment, the processing unit 620 is configured to control the first data packet to further include first authentication data, the first authentication data being data obtained by the first TA performing authentication calculation on the to-be-stored data by using the security key, and the processing unit 620 is specifically configured to control the RPMB to perform authentication calculation on the to-be-stored data in the first data packet by using the security key to obtain second authentication data; and the RPMB to store the to-be-stored data in a case where the second authentication data matches the first authentication data.

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

[0210] In the embodiment of the present application, the first TA performs authentication calculation on the to-be-stored data by using the security key through hash operation to obtain the first authentication data. Since the hash operation is a widely used encryption algorithm that has been subjected to various forms of attacks, the first authentication data obtained through the hash operation is more reliable encryption data, which improves the security of the first data packet obtained according to the first authentication data and the to-be-stored data.

[0211] Optionally, as an embodiment, the to-be-stored data is data obtained by the first TA calling the first sensor to collect.

[0212] Optionally, as an embodiment, the first sensor includes a fingerprint collector.

[0213] The data storage apparatus provided in the embodiment is used to execute the data storage method of the above-mentioned embodiments, and the technical principles and technical effects are similar, which will not be described here.

[0214] It should be noted that the electronic device is embodied in the form of functional units. The term "unit" herein can be realized by software and / or hardware, and is not limited in specific form.

[0215] For example, the "unit" can be a software program, a hardware circuit, or a combination of both, which realizes the above functions. The hardware circuit can include an application specific integrated circuit (ASIC), an electronic circuit, a processor (such as a shared processor, a dedicated processor, or a group processor, etc.) and a memory for executing one or more software or firmware programs, a combination logic circuit, and / or other suitable components that support the described functions.

[0216] Therefore, the units of each example described in the embodiments of the present application can be realized in electronic hardware or a combination of computer software and electronic hardware. Whether the functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. A person skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.

[0217] It can be understood that, in order to realize the above functions, the electronic device contains hardware and / or software modules corresponding to each function. The algorithm steps of each example described in conjunction with the embodiments disclosed herein can be realized in hardware or a combination of hardware and computer software. Whether a certain function is performed in hardware or computer software driven hardware depends on the specific application and design constraints of the technical solution. A person skilled in the art can use different methods to implement the described functions for each specific application in conjunction with the embodiments, but such implementation should not be considered beyond the scope of the present application.

[0218] The embodiments of the present application can divide the functional modules of the electronic device according to the above method examples. 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 embodiments of the present application is illustrative, and is only a logical functional division. When actually implemented, there can be another division manner. It should be noted that the names of the modules in the embodiments of the present application are illustrative, and the names of the modules are not limited when actually implemented.

[0219] Figure 12 A structural schematic diagram of an electronic device provided by the present application is shown. Figure 12 The dashed line in the electronic device 700 indicates that the unit or the module is optional. The electronic device 700 can be used to implement the data storage method described in the above method embodiments.

[0220] The electronic device 700 includes one or more processors 701 that can support the electronic device 700 to implement the data storage method in the method embodiments. 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 device such as a discrete gate or transistor logic device, or a discrete hardware component.

[0221] The processor 701 can be configured to control the electronic device 700, execute a software program, and process data of the software program. The electronic device 700 can further include a communication unit 705 configured to implement input (reception) and output (transmission) of signals.

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

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

[0224] The electronic device 700 can include one or more memories 702 having programs 704 stored thereon, and the programs 704 can be executed by the processor 701 to generate instructions 703, so that the processor 701 performs the impedance matching method described in the above method embodiments according to the instructions 703.

[0225] Optionally, the memory 702 can further store data. Optionally, the processor 701 can further read the data stored in the memory 702, and the data can be stored in the same storage address as the programs 704, or the data can be stored in different storage addresses from the programs 704.

[0226] The processor 701 and the memory 702 can be separately arranged or integrated together, for example, integrated on a system on chip (SOC) of the terminal device.

[0227] Exemplarily, the memory 702 can be configured to store a program 704 related to the data storage method provided in the embodiments of the present application, and the processor 701 can be configured to invoke the program 704 related to the data storage method stored in the memory 702 when data storage is performed, and execute the data storage method of the embodiments of the present application, including: sending, by a second trusted application TA, a security key to a first trusted application TA, the first TA refers to a trusted application running on a first TEE, and the second TA refers to a trusted application running in a second TEE; obtaining, by the first TA, a first data packet according to the security key and to-be-stored data; sending, by the first TA, the first data packet to the RPMB; and storing, by the RPMB, the to-be-stored data based on the first data packet.

[0228] 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.

[0229] The computer program product can be stored in the memory 702, for example, the program 704, which is finally converted into an executable object file capable of being executed by the processor 701 through preprocessing, compiling, assembling, and linking and other processing processes.

[0230] The present application also provides a computer readable storage medium, which stores a computer program, and the computer program, 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.

[0231] The computer-readable storage medium is, for example, the memory 702. The memory 702 can be a volatile memory or a nonvolatile memory, or the memory 702 can include both volatile and nonvolatile memory. The nonvolatile memory can be a read-only memory (ROM), a programmable ROM (PROM), an erasable PROM (EPROM), an electrically EPROM (EEPROM), or a flash memory, among others. The volatile memory can be a random access memory (RAM), which is used as the external cache. By way of example, and not limitation, many forms of RAM are available, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous dynamic RAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), Synchlink DRAM (SLDRAM), and direct rambus RAM (DR RAM), among others.

[0232] In this application, "at least one", "multiple", "plurality" mean one or more, unless otherwise indicated. "At least one of the following (a)" or the like means any combination of these items, including a single item (a) or a combination of multiple items. For example, at least one of a, b, or c can mean a, b, c, a-b, a-c, b-c, or a-b-c, where a, b, and c can be single or multiple.

[0233] It should be understood that the size of the sequence number of the above-mentioned processes in various embodiments of the present application does not mean the order of execution, and the execution order of the processes should be determined according to its function and inherent logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0234] Those skilled in the art can clearly understand that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be realized by electronic hardware or a combination of computer software and electronic hardware. Whether the functions are performed in hardware or software 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, but such implementation should not be considered beyond the scope of the present application.

[0235] Those skilled in the art can clearly understand that, for the convenience and brevity of the description, the specific working processes of the above-described system, device and unit can refer to the corresponding processes in the foregoing method embodiments, which will not be repeated here.

[0236] In several embodiments provided in the present 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 only schematic; for example, the division of the units is only a logical function division, and actual implementation can have another division manner; for example, a plurality of units or components can be combined or integrated into another system, or some features can be omitted or not executed. In addition, the coupling or direct coupling or communication connection between the units shown or discussed can be indirect coupling or communication connection through some interface, device or unit, and can be electrical, mechanical or other forms.

[0237] The units described as separate components can or can not be physically separated, and the components shown as units can or can not be physical units, i.e. can be located in one place, or can be distributed on a plurality of network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiment.

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

[0239] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto, and any person skilled in the art can easily think of changes or replacements within the technical scope disclosed in the present application, which should be covered in the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

Claims

1. A data storage method, characterized in that, The method is applied to an electronic device, which includes at least two Trusted Execution Environments (TEEs). The at least two TEEs include a first TEE and a second TEE. The first TEE is a TEE that does not store a security key, and the second TEE is a TEE that stores the security key. The security key is a key used by the Replay Protection Memory Block (RPMB) to verify stored data. The method includes: The second trusted application TA sends the security key to the first trusted application TA, where the first trusted application TA refers to a trusted application running on the first TEE, and the second trusted application TA refers to a trusted application running in the second TEE. The first trusted application TA obtains the first data packet based on the security key and the data to be stored; The first trusted application (TA) sends the first data packet to the RPMB; The RPMB stores the data to be stored based on the first data packet.

2. The method according to claim 1, characterized in that, The first trusted application TA obtains a first data packet based on the security key and the data to be stored, including: When the counter is in an idle state, the first trusted application TA obtains a first count value, which refers to the count value of the counter at the current moment; The first trusted application (TA) obtains the first data packet based on the first count value, the security key, and the data to be stored.

3. The method according to claim 2, characterized in that, The counter being in an idle state includes the RPMB currently being in a state where no data is stored.

4. The method according to claim 2 or 3, characterized in that, The first trusted application TA obtains a first data packet based on the security key and the data to be stored, and further includes: When the counter is in a busy state, the first trusted application TA is in a state of waiting to obtain the first count value. The busy state includes the RPMB being in a state of storing data of the second trusted application TA.

5. The method according to any one of claims 1 to 3, characterized in that, The first data packet also includes first authentication data, which is data obtained by the first trusted application TA authenticating the data to be stored using the security key. The RPMB stores the data to be stored based on the first data packet, including: The RPMB uses the security key to perform the authentication calculation on the data to be stored in the first data packet to obtain the second authentication data. If the second authentication data matches the first authentication data, the RPMB stores the data to be stored.

6. The method according to claim 5, characterized in that, The authentication calculation includes HMAC calculation.

7. The method according to any one of claims 1 to 3, characterized in that, The data to be stored is the data collected by the first sensor by the first trusted application TA.

8. The method according to claim 7, characterized in that, The first sensor includes a fingerprint scanner.

9. A chip, characterized in that, Includes a processor, which, when executing instructions, performs the method as described in any one of claims 1 to 8.

10. An electronic device, characterized in that, The electronic device includes a processor configured to be coupled to a memory, read instructions from the memory, and cause the electronic device to perform the method as described in any one of claims 1 to 8 according to the instructions.

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

Citation Information

Patent Citations

  • Digital signature method, system and device

    CN112287399A

  • Systems for provisioning universal integrated circuit cards

    US20140143534A1