Data storage method and electronic device

By sending the data to be stored to a first TEE that does not store the security key to a second TEE that stores the security key for authentication calculation and packaging in a multi-TEE framework, the limitation of RPMB writing data in a multi-TEE environment is solved, and secure data storage and reliable transmission are achieved.

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

Patent Information

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

AI Technical Summary

Technical Problem

In a Trusted Execution Environment (TEE) framework, the security key can only be stored in one TEE, which prevents other TEEs from using the security key to authenticate data, and thus prevents each TEE from writing data to the Replay Protected Memory Block (RPMB).

Method used

The data to be stored is sent to the trusted application (first TA) in the second TEE that stores the security key by the trusted application (second TA) in the first TEE that does not store the security key. The second TA uses the security key to perform authentication calculation on the data to be stored, generates authentication data and generates a data packet, which is then sent to the RPMB for storage.

Benefits of technology

This enables any TEE in a multi-TEE framework to write data to the RPMB, improving the security and reliability of data storage and preventing data attacks from unknown sources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117492635B_ABST
    Figure CN117492635B_ABST
Patent Text Reader

Abstract

Embodiments of the present application are applicable to the field of data processing, and provide 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 without storing a security key, and the second TEE being a TEE storing a security key, and the method includes: the first TA sending a first data packet including to-be-stored data to the second TA, the second TA performing authentication calculation on the to-be-stored data by using the security key to obtain first authentication data, and obtaining a second data packet according to the first authentication data and the to-be-stored data; the second TA sending the second data to the RPMB; and the RPMB storing the to-be-stored data based on the second data packet. That is, the data storage method provided by the embodiments of the present application can enable the application programs running in each TEE in a multi-TEE architecture to store data to the RPMB.
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 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 terminal device using a multi-TEE framework, since the Secure Key can only be stored in one TEE, other TEEs cannot call the Secure Key to calculate the first authentication data, thus making the RPMB unable to 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 Secure Key, and the second TEE being a TEE that stores a Secure Key, the Secure Key being a key used by the Replay Protected Memory Block (RPMB) to authenticate stored data, and the method comprising:

[0007] The first trusted application TA sends a first data packet to the second trusted application, the first data packet comprising to-be-stored data, the to-be-stored data being data to be written to the RPMB, 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.

[0008] The second TA performs authentication calculation on the to-be-stored data in the first data packet by using the security key, to obtain first authentication data.

[0009] The second TA generates a second data packet according to the first authentication data and the to-be-stored data.

[0010] The second TA sends the second data packet to the RPMB.

[0011] The RPMB stores the to-be-stored data based on the second data packet.

[0012] The data storage method provided in the embodiments of the present application is applied to an electronic device comprising at least two TEEs, the at least two TEEs comprising a first TEE and a second TEE, the first TEE being a TEE in which no security key is stored, and the second TEE being a TEE in which a security key is stored, and the method comprises: a first TA sending a first data packet comprising to-be-stored data to a second 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; the second TA performing authentication calculation on the to-be-stored data by using the security key, to obtain first authentication data, and generating a second data packet according to the first authentication data and the to-be-stored data; the second TA sending the second data to the RPMB; and the RPMB storing the to-be-stored data based on the second data packet. That is, in the embodiments of the present application, since no security key is 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 first TA in the first TEE can send the to-be-stored data to the second TA in the second TEE, so that the second TA performs authentication calculation on the to-be-stored data by using the stored security key to obtain first authentication data, and generates a second data packet according to the first authentication data and the to-be-stored data, and the second TA can send the second data packet to the RPMB, so that the to-be-stored data in the first TEE in which no security key is stored is stored to the RPMB. Thus, it is realized that any one of the multiple TEEs in the electronic device can store data to the RPMB.

[0013] With reference to the first aspect, in some implementations of the first aspect, the first trusted application TA sending a first data packet to the second trusted application comprises:

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

[0015] The Hypervisor module sends the first data packet to the second TA.

[0016] With reference to the first aspect, in some implementations of the first aspect, the first data packet further includes a write request, wherein the write request is used to indicate that the to-be-stored data is to be stored in the RPMB, and the Hypervisor module sends the first data packet to the second TA, including:

[0017] The Hypervisor module sends the first data packet to the second TA based on the write request in the first data packet.

[0018] With reference to the first aspect, in some implementations of the first aspect, the RPMB stores the to-be-stored data based on the second data packet, including:

[0019] The RPMB performs authentication calculation on the to-be-stored data in the second data packet by using the security key to obtain second authentication data.

[0020] In a case where the first authentication data and the second authentication data match, the RPMB stores the to-be-stored data.

[0021] The data storage method provided in the embodiments of the present application is applied to an electronic device including at least two TEEs, including 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, and the method includes: a first TA sends a first data packet including to-be-stored data to a second TA, the second TA performs authentication calculation on the to-be-stored data in the first data packet by using a security key to obtain first authentication data, and generates a second data packet according to the first authentication data and the to-be-stored data, and then sends the second data packet to an RPMB. After receiving the second data packet, the RPMB performs authentication calculation on the to-be-stored data in the second data packet by using the security key to obtain second authentication data, and in a case where the second authentication data and the first authentication data match, 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, so that unknown data can be effectively prevented from attacking the data stored in the RPMB, and the security of the data stored in the RPMB is improved.

[0022] With reference to the first aspect, in some implementations of the first aspect, the method further includes:

[0023] The RPMB sends response information to the second TA, and the response information is used to indicate that the to-be-stored data has been stored in the RPMB.

[0024] In the embodiments of the present application, after the RPMB stores the to-be-stored data, the RPMB returns response information indicating that the to-be-stored data has been successfully stored to the second TA, so that the second TA does not need to send a second data packet to the RPMB again after receiving the response information, thereby avoiding unnecessary data transmission between the second TA and the RPMB.

[0025] With reference to the first aspect, in some implementations of the first aspect, the response information includes an updated count value, and further includes:

[0026] The RPMB updates the count value in the RPMB based on a storage state of the to-be-stored data, to obtain an updated count value.

[0027] 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 invoking the first sensor.

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

[0029] It should be understood that the first sensor being a fingerprint sensor is only an example.

[0030] In a possible case, the to-be-stored data is sound data, and the first sensor can be a microphone.

[0031] In a possible case, the to-be-stored data is eyeprint data, and the first sensor can be a camera.

[0032] In a possible case, the to-be-stored data is face data, and the first sensor can be a camera.

[0033] With reference to the first aspect, in some implementations of the first aspect, the method further includes:

[0034] In a case where a client application (CA) running in a rich execution environment (REE) detects a first operation, the CA sends a fingerprint data acquisition request to the first TA, the first operation being used to indicate acquisition of fingerprint data;

[0035] The first TA, in response to the fingerprint data acquisition request, invokes the fingerprint sensor to collect fingerprint data, and obtains the to-be-stored data according to the fingerprint data.

[0036] With reference to the first aspect, in some implementations of the first aspect, the authentication calculation includes a hash (HMAC) calculation.

[0037] In the embodiments of the present application, the second TA performs authentication calculation on the to-be-stored data by a hash operation using a security key 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 by the hash operation is more reliable encryption data, thereby improving the security of the obtained first authentication data.

[0038] In a second aspect, a data storage apparatus is provided, including units for performing any of the methods in the first aspect. The apparatus can be a server, a terminal device, or a chip in a terminal device. The apparatus can include an obtaining unit and a processing unit.

[0039] 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, which, when executed by the processor, causes the terminal device to perform any of the methods in the first aspect.

[0040] When the apparatus 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, which, when executed by the processor, causes the chip to perform any of the methods in the first aspect.

[0041] 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. When the computer program code stored in the memory is executed, the processor is configured to perform the following: a first trusted application (TA) sends a first data packet to a second TA, the first data packet including to-be-stored data, the to-be-stored data being data to be written to an RPMB, 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; the second TA performs authentication calculation on the to-be-stored data in the first data packet using a security key to obtain first authentication data; the second TA generates a second data packet according to the first authentication data and the to-be-stored data; the second TA sends the second data packet to the RPMB; and the RPMB stores the to-be-stored data based on the second data packet.

[0042] In a third aspect, a computer-readable storage medium is provided, which stores computer program codes. When the computer program codes are run by a data storage device, the data storage device performs any of the data storage methods in the first aspect.

[0043] In a fourth aspect, a computer program product is provided, which includes computer program codes. When the computer program codes are run by a data storage device, the data storage device performs any of the device methods in the first aspect.

[0044] In the embodiments of the present application, at least two TEEs can be run in the electronic device, and the at least two TEEs include a first TEE in which no security key is stored and a second TEE in which a security key is stored. Since no security key is stored in the first TEE, if a first TA running in the first TEE needs to store to-be-stored data in 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 in the RPMB. In the present solution, since the security key is stored in the second TEE, the first TA in the first TEE can send the to-be-stored data to a second TA in the second TEE, so that the second TA in the second TEE performs authentication calculation on the to-be-stored data by using the stored security key to obtain first authentication data, and generates a second data packet according to the first authentication data and the to-be-stored data. The second TA can send the second data packet to the RPMB, so that the to-be-stored data in the first TEE in which no security key is stored is stored in the RPMB. Thus, any one of the multiple TEEs running in the electronic device can store data in the RPMB. BRIEF DESCRIPTION OF DRAWINGS

[0045] Figure 1 FIG. 1 is a flow diagram of RPMB data writing;

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

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

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

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

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

[0051] Figure 7 FIG. 1 is a schematic diagram of an electronic device for data storage according to an embodiment of the present application;

[0052] Figure 8 FIG. 1 is a schematic diagram of an electronic device for data storage according to an embodiment of the present application;

[0053] Figure 9 FIG. 1 is a schematic diagram of an electronic device for data storage according to an embodiment of the present application;

[0054] Figure 10 FIG. 1 is a schematic diagram of an electronic device for data storage according to an embodiment of the present application;

[0055] Figure 11 FIG. 1 is a schematic diagram of an electronic device for data storage according to an embodiment of the present application;

[0056] Figure 12 FIG. 1 is a schematic diagram of an electronic device for data storage according to an embodiment of the present application;

[0057] Figure 13 FIG. 1 is a schematic diagram of an electronic device for data storage according to an embodiment of the present application;

[0058] Figure 14 FIG. 1 is a schematic diagram of an electronic device for data storage according to an embodiment of the present application. DETAILED DESCRIPTION

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

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

[0061] For ease of understanding, some examples are given below for reference.

[0062] 1. RPMB

[0063] RPMB refers to a separate physical partition in the memory, which is usually used to store data that needs to be protected from illegal tampering, such as public keys related to fingerprint payment on mobile phones, serial numbers, etc. Generally, RPMB will authenticate the write operation, but the read operation does not need to be authenticated.

[0064] It should be understood that in the process of producing electronic devices, a unique security key will be 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 will store the security key in a secure execution environment (for example, TEE). When the host writes data to the RPMB, the RPMB can authenticate using the security key.

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

[0066] 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 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 Write Cnt and the random number in the RPMB data packet using the security key to obtain a second MAC. Compare the values of the first MAC and the second MAC, and in the case that the values of the first MAC and the second MAC are consistent, compare the random number sent by the host to the device with the random number in the RPMB data packet, and in the case that the random number sent by the host to the device is consistent with the random number in the RPMB data packet, determine that the Write Cnt in the RPMB data packet is trusted.

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

[0068] 2. Trusted execution environment (TEE)

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

[0070] 3. Rich execution environment (REE)

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

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

[0073] 4. Trusted application (TA)

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

[0075] 5. Client Application (CA)

[0076] CA typically refers to applications that run on REE.

[0077] 6. Hypervisor

[0078] The Hypervisor is an intermediate software layer running between the underlying physical server and the operating system. It provides access to all physical devices on the electronic device, including disks and memory. The Hypervisor coordinates hardware resource access and provides protection between virtual machines. After the server starts, the Hypervisor loads the operating system for all virtual machine clients and allocates memory, disk space, and network resources to the virtual machines. Based on the Hypervisor mechanism, multiple TEEs can run simultaneously on an electronic device.

[0079] 7. ATF

[0080] ATF( Trusted Firmware is a type of software designed for... 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.

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

[0082] An exemplary, 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.

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

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

[0085] Exemplarily, in the embodiments of the present application, the processor 110 can be used to execute the data storage method provided by the embodiments of the present application; for example, the first trusted application program TA sends a first data packet to the second trusted application program, the first data packet includes to-be-stored data, the to-be-stored data is data to be written to the RPMB, the first TA refers to a trusted application program running on the first TEE, and the second TA refers to a trusted application program running in the second TEE; the second TA performs authentication calculation on the to-be-stored data in the first data packet using a security key to obtain first authentication data; the second TA generates a second data packet according to the first authentication data and the to-be-stored data; the second TA sends the second data packet to the RPMB; and the RPMB stores the to-be-stored data based on the second data packet.

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

[0087] The processor 110 can also be provided with a memory 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 directly call from the memory. This avoids repeated access and reduces the waiting time of the processor 110, thereby improving the efficiency of the system.

[0088] The fingerprint sensor 180H is used to collect a fingerprint. The electronic device 100 can implement a fingerprint unlock, access an application lock, take a photo by fingerprint, answer a call by fingerprint, and the like, using a characteristic of the collected fingerprint.

[0089] The camera 193 is used to capture a still image or a video. An object generates an optical image through a lens and projects the optical image to a photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts an optical signal into an electrical signal, and then transmits the electrical signal to an ISP to convert the electrical signal into a digital image signal. The ISP outputs the digital image signal to a DSP for processing. The DSP converts the digital image signal into an image signal in a standard format such as RGB, YUV, and the like. In some embodiments, the electronic device 100 can include one or N cameras 193, N being a positive integer greater than 1.

[0090] The external memory interface 120 can be used to connect an external memory card such as a Micro SD card, to extend the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function. For example, files such as music and videos are stored in the external memory card.

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

[0092] Optionally, the memory in the electronic device includes eMMC and Universal File Store (UFS). Among them, the RPMB in the memory is usually used to store data with security requirements. When writing data into the RPMB, it needs to be encrypted by the pre-stored security key. The RPMB checks the written data with the security key stored thereon, and after the check passes, the written data is stored on the RPMB.

[0093] The electronic device 100 can realize audio functions through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the earphone interface 170D, and the application processor, etc. For example, music playing, recording, etc.

[0094] The audio module 170 is used to convert digital audio information into analog audio signals, and is also used to convert analog audio input into digital audio signals. The audio module 170 can also be used to encode and decode audio signals. In some embodiments, the audio module 170 can be disposed in the processor 110, or part of the functions of the audio module 170 can be disposed in the processor 110.

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

[0096] The receiver 170B, also known as a "earpiece", is used to convert audio electrical signals into sound signals. When the electronic device 100 answers a call or a voice message, the receiver 170B can be held close to the ear to listen to the voice.

[0097] The microphone 170C, also known as a "microphone", "sound transducer", is used to convert sound signals into electrical signals. When making a call or sending a voice message, the user can speak into the microphone 170C close to the mouth to input the sound signal into the microphone 170C. The electronic device 100 can be provided with at least one microphone 170C. In other embodiments, the electronic device 100 can be provided with two microphones 170C, in addition to collecting sound signals, it can also realize the noise reduction function. In other embodiments, the electronic device 100 can also be provided with three, four or more microphones 170C, which can realize the functions of collecting sound signals, noise reduction, and identifying sound sources, and realizing directional recording, etc.

[0098] The earphone interface 170D is configured to connect a wired earphone. The earphone interface 170D can be a USB interface 130, or a 3.5 mm open mobile terminal platform (OMTP) standard interface, or a cellular telecommunications industry association of the USA (CTIA) standard interface.

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

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

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

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

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

[0104] As shown in Figure 3 , the application packages can include camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message, and the like.

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

[0106] 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, and the like.

[0107] The window manager is configured to manage window programs. The window manager can obtain the size of the display screen, determine whether there is a status bar, lock the screen, and take a screenshot, and the like.

[0108] The content provider stores and retrieves data and makes the data accessible to the application programs. The data can include videos, images, audios, dialed and received phone numbers, browsing history and bookmarks, phone book, etc.

[0109] The view system includes visual controls, such as a control for displaying text, a control for displaying pictures, etc. The view system can be used to build an application program. A display interface can be composed of one or more views. For example, a display interface including a short message notification icon can include a view for displaying text and a view for displaying pictures.

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

[0111] The resource manager provides various resources for the application program, such as localized strings, icons, pictures, layout files, video files, etc.

[0112] The notification manager enables the application program to display notification information in the status bar, which can be used to convey a type of message that can automatically disappear after a short stay without user interaction. For example, the notification manager is used to notify the completion of downloading, message reminders, etc. The notification manager can also be a notification in the form of a chart or a scroll bar text appearing in the top status bar of the system, such as a notification of an application program running in the background, or a notification in the form of a dialogue window appearing on the screen. For example, a text message is prompted in the status bar, a prompt sound is emitted, the electronic device vibrates, the indicator light flashes, etc.

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

[0114] 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 Android.

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

[0116] The system library can include multiple 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), etc.

[0117] The Surface Manager is used to manage the display subsystem and provides the blending of 2D and 3D layers for multiple applications.

[0118] The media library supports playback and recording of various common audio and video formats, as well as still image files. It supports multiple audio and video encoding formats, such as MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG.

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

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

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

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

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

[0124] With the continuous development of terminal technology, multi-TEE architecture has become a common architecture. For example, such as... Figure 4 As shown, the terminal device includes two TEEs and an RPMB, namely the first TEE, the second TEE, and the RPMB. The first TEE does not store the security key, while the second TEE stores the security key. When a first TA running in the first TEE needs to write data to the RPMB, the first TA can send the data to be stored to the second TA running in the second TEE. The second TA uses the security key stored in the second TEE to perform authentication calculations on the data to be stored, and then sends the authenticated data and the data to be stored to the RPMB for storage.

[0125] The data to be stored can be data collected by the first sensor when the first TA calls the first sensor. For example, the first sensor is a fingerprint sensor, and the data to be stored can refer to fingerprint data collected by the fingerprint sensor when the first TA calls the fingerprint sensor.

[0126] Generally, the fingerprint data is used for encryption and decryption in the terminal device, and thus the fingerprint data needs to be stored in a secure area, such as RPMB. In the case where the secure key for checking the data written in the RPMB is not stored in the first TA, the data to be stored can be sent to the second TA through the data channel between the first TEE and the second TEE, so that the second TA authenticates the data to be stored by using the secure key, obtains authentication data, and then sends the authentication data and the data to be stored to the RPMB for storage by the second TA.

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

[0128] The data storage method provided by the embodiments of the present application will be described in detail below. Figures 5 to 11 The data storage method provided by the embodiments of the present application will be described in detail below.

[0129] In the electronic device, a plurality of TEEs can be run, and the plurality of TEEs include a TEE storing a secure key and a TEE not storing a secure key. For the TEE storing the secure key, the secure key can be directly obtained to perform authentication calculation on the data to be stored to generate a data packet, and the data packet is sent to the RPMB so that the RPMB stores the data to be stored. For the TEE not storing the secure key, the data to be stored can be sent to the TEE storing the secure key, so that the TEE storing the secure key obtains the secure key and performs authentication calculation on the data to be stored based on the secure key to generate a data packet, and the TEE storing the secure key sends the data packet to the RPMB so that the RPMB stores the data to be stored. Thus, the TEE not storing the secure key can store the data to be stored in the RPMB. According to the scheme of the present application, when a plurality of TEEs are run in the electronic device, any one of the TEEs can store data in the RPMB.

[0130] The data storage method provided by the embodiments of the present application can be applied in an electronic device including at least two TEEs. For example, as shown in Figure 5 The electronic device includes a first TEE and a second TEE, the first TEE is a TEE not storing a secure key, and the second TEE is a TEE storing a secure key. A first TA running in the first TEE sends data to be stored to a second TA running in the second TEE, and the second TA performs encryption authentication on the data to be stored by using the secure key. The second TA sends the data to be stored and first authentication data obtained after the authentication calculation to the RPMB.

[0131] The data storage method applied in Figure 6 The data storage method applied in Figure 5 The data storage method applied in

[0132] Figure 6 A flowchart of a data storage method provided in an embodiment of the present application is shown in FIG. 1, which is applied in an electronic device as shown in FIG. 2. The method comprises the following steps. Figure 6 Figure 5 The method comprises the following steps.

[0133] S101, a first TA sends a first data packet to a second TA.

[0134] The first data packet comprises to-be-stored data, which is data to be written into the RPMB. The first TA refers to a trusted application running on the first TEE, and the second TA refers to a trusted application running in the second TEE.

[0135] It should be understood that, in the production process of the electronic device, a security key is burned into the memory of the electronic device, and the security key is also written into the TEE, so that the TEE can perform authentication calculation on the to-be-stored data by using the security key when writing data into the RPMB, to obtain authentication data, and then the RPMB can ensure the security of the written data by checking the authentication data when storing data. In the case where the electronic device comprises at least two TEEs, in order to avoid the situation that multiple TEEs write data into the RPMB at the same time and cause the counter conflict, the security key is usually written into only one TEE.

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

[0137] For example, the at least two TEEs comprise a first TEE and a second TEE, wherein the first TEE refers to a TEE that does not store the security key, and the second TEE refers to a TEE that stores the security key.

[0138] It should be understood that, in the case where the first TA running in the first TEE needs to write data into the RPMB, the first TEE does not store the security key. Therefore, the first TA cannot encrypt the to-be-stored data by using the security key, and thus the first TA cannot directly send the to-be-stored data to the RPMB for storage.

[0139] In this case, the first TA can send the to-be-stored data to the second TA running in the second TEE.

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

[0141] For example, the first TA in the first TEE is an application 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.

[0142] ​Exemplarily, the first TA in the first TEE is an application program requiring voice data for encryption and decryption. The data to be stored can be voice data collected by the first TA through a microphone.

[0143] Exemplarily, the first TA in the first TEE is an application program requiring character password for encryption and decryption. The data to be stored can be character data obtained by the first TA through receiving a click operation of a user on a display screen.

[0144] Exemplarily, the first TA in the first TEE is an application program requiring iris data for encryption and decryption. The data to be stored can be iris data collected by the first TA through a camera.

[0145] Exemplarily, the first TA in the first TEE is an application program requiring face for encryption and decryption. The data to be stored can be face data collected by the first TA through a camera.

[0146] Exemplarily, the first TA can also be an application program providing security services to the CA, and the data to be stored can be password data sent by the CA to the first TA, including but not limited to the above-mentioned fingerprint data, voice data, character data, iris data and face data.

[0147] In the process of sending the data to be stored to the second TA, the first TA can send a first data packet including the data to be stored to the second TA through a data channel between the first TA and the second TA.

[0148] It should be understood that the Hypervisor module has the function of accessing all physical devices on the electronic device, including disks and memories 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), and allocates memory, disk and network for the virtual machines. In this way, the Hypervisor module can directly allocate a data interface for the first TEE and the second TEE, so that the first TEE and the second TEE can transmit data. That is, the first TA can send the first data packet to the second TA.

[0149] S102, the second TA calculates the data to be stored in the first data packet using a security key to obtain first authentication data.

[0150] Among them, after receiving the first data packet sent by the first TA, the second TA can unpack the first data packet to obtain the data to be stored. Then the second TA performs authentication calculation on the data to be stored using a security key to obtain first authentication data.

[0151] Optionally, the authentication calculation can be a hash calculation. The hash calculation can be a calculation method of calculating data by a Hash-based Message Authentication Code (HMAC), which is a method of message authentication based on a Hash function and a key.

[0152] For example, the second TA can encrypt the to-be-stored data by the HMAC using a security key. The HMAC is a way of providing authentication services selected by many current security protocols and is widely used, for example, in the Internet Protocol Security (IPSec) and other network protocols (such as SSL), and has withstood various forms of attacks. Therefore, the HMAC can also be referred to as an existing Internet security standard.

[0153] In the embodiments of the present application, the second TA performs authentication calculation on the to-be-stored data by the hash operation using a security key to obtain the 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 by the hash operation is more reliable encryption data, and the security of obtaining the first authentication data is improved.

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

[0155] S103, the second TA generates a second data packet according to the first authentication data and the to-be-stored data.

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

[0157] For example, the second TA can package the first authentication data and the to-be-stored data by placing the first authentication data before the to-be-stored data to obtain the second data packet.

[0158] For example, the second TA can package the first authentication data and the to-be-stored data by placing the first authentication data after the to-be-stored data to obtain the second data packet.

[0159] In a possible case, the second TA can package the first authentication data, the to-be-stored data, and the write request to obtain the second data packet.

[0160] S104, the second TA sends the second data packet to the RPMB.

[0161] Optionally, the second TA can send the second data packet to the RPMB through the Hypervisor module.

[0162] Illustratively, the second TA in the second TEE can send the second data packet to the Hypervisor module, and the Hypervisor module sends the second data packet to the RPMB.

[0163] S105, the RPMB stores the to-be-stored data based on the second data packet.

[0164] Optionally, when the RPMB stores the to-be-stored data, it needs to use the security key to perform authentication calculation on the to-be-stored data to obtain second authentication data, and in the case that the first authentication data and the second authentication data match, it is determined that the second data packet is verified, and the to-be-stored data is stored.

[0165] In the embodiment of the present application, at least two TEEs can run in the electronic device, and the at least two TEEs include a first TEE which does not store a security key and a second TEE which stores a security key; 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, resulting in that the first TA cannot directly store the to-be-stored data to the RPMB; in the present scheme, since the security key is stored in the second TEE, the first TA in the first TEE can send the to-be-stored data to the second TA in the second TEE, so that the second TA in the second TEE calculates the first authentication data by using the stored security key to calculate the to-be-stored data, and generates the second data packet according to the first authentication data and the to-be-stored data, and the second TA can send the second data packet to the RPMB, so that the to-be-stored data in the first TEE which does not store the security key is stored to the RPMB; thereby realizing that any one of the multiple TEEs in the electronic device can store data to the RPMB.

[0166] In a possible case, the data transmission between the first TEE, the second TEE and the RPMB can be performed through the Hypervisor module. At the same time, after the RPMB stores the data, the current count value can be updated to obtain an updated count value, and then the updated count value is returned to the second TA, so that the second TA determines that the to-be-stored data has been stored to the RPMB based on the response information, so that the second TA does not need to send data to the RPMB again, avoiding unnecessary data transmission among the first TEE, the second TEE, the Hypervisor module and the RPMB, and further avoiding resource waste. Next, the data transmission between the first TEE, the second TEE and the RPMB will be described in detail. Figure 7 andFigure 8 The embodiments shown will be described in detail.

[0167] For example, the data storage method provided by the embodiments of the present application can be applied to the electronic device as shown in Figure 7 As shown in Figure 7 The electronic device includes a first TEE, a second TEE, a Hypervisor module and an RPMB. 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. A first TA running in the first TEE sends a first data packet including to-be-stored data to the Hypervisor module, the Hypervisor module sends the first data packet to a second TA running in the second TEE, the second TA performs authentication calculation on the to-be-stored data in the first data packet by using a security key to obtain first authentication data, and obtains a second data packet according to the first authentication data and the to-be-stored data. The second TA sends the second data packet to the Hypervisor module. The Hypervisor module sends the second data packet to the RPMB. The RPMB stores the to-be-stored data based on the second data packet.

[0168] The data storage method applied to the electronic device as shown in Figure 8 will be described in detail. Figure 7 The data storage method applied to the electronic device as shown in

[0169] Figure 8 A flowchart of the data storage method provided by an embodiment of the present application is shown in the figure. The method is applied to the electronic device as shown in Figure 7 As shown in Figure 8 The method includes the following steps.

[0170] S201, the first TA sends a first data packet to the Hypervisor module.

[0171] Optionally, the first data packet includes to-be-stored data and a write request. The write request can be used to indicate that the to-be-stored data is stored to the RPMB.

[0172] In a possible case, the write request can be a request obtained based on a secure monitor call (SMC) operation. It should be understood that the SMC can be used for switching between the first TEE and the second TEE. Generally, when the Hypervisor module receives a request based on the SMC, the data packet sent at the same time as the request can be sent to a trusted application in the second TEE (i.e. the second TEE described in the embodiments of the present application).

[0173] S202, the Hypervisor module sends the first data packet to the second TA.

[0174] Optionally, the Hypervisor module determines that the first data packet needs to be sent to the second TA based on that the write request in the first data packet is an SMC format request, and sends the first data packet to the second TA.

[0175] S203, the second TA performs authentication calculation on the to-be-stored data by using the security key to obtain first authentication data.

[0176] Optionally, after receiving the first data packet sent by the first TA, the second TA can unpack the first data packet to obtain the to-be-stored data. Then the second TA performs authentication calculation on the to-be-stored data by using the security key to obtain the first authentication data.

[0177] Optionally, the authentication calculation can be a hash calculation. The hash calculation can be a calculation method of calculating data by using a hash operation message authentication code (HMAC), which is a method of message authentication based on a hash function and a key.

[0178] For example, the second TA can perform authentication calculation on the to-be-stored data by using the security key through the HMAC. The HMAC is a way of providing authentication service selected by many current security protocols, and is widely used, for example, in the Internet Protocol Security (IPSec) and other network protocols (such as SSL), and has withstood various forms of attacks. Therefore, the HMAC can also be referred to as an existing Internet security standard.

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

[0180] S204, the second TA generates a second data packet according to the first authentication data and the to-be-stored data.

[0181] It should be understood that the second TA can pack the first authentication data and the to-be-stored data according to a preset data format to obtain the second data packet.

[0182] For example, the second TA can pack the first authentication data and the to-be-stored data to obtain the second data packet by placing the first authentication data before the to-be-stored data.

[0183] Exemplarily, the second TA can place the first authentication data after the to-be-stored data, and pack the to-be-stored data and the first authentication data to obtain the second data packet.

[0184] In a possible case, the second TA can pack the first authentication data, the to-be-stored data and the write request to obtain the second data packet.

[0185] S205, the second TA sends the second data packet to the RPMB.

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

[0187] It should be understood that, since the second TA can perform authentication calculation on the to-be-stored data by using different methods, exemplarily, the to-be-stored data can be calculated by using a hash operation message authentication code, or can be calculated by using a cipher block chaining message authentication code. Therefore, the RPMB usually needs to perform authentication calculation on the to-be-stored data in the second data packet by using the same authentication calculation as the second TA.

[0188] Exemplarily, the second TA calculates the to-be-stored data by using a hash operation message authentication code to obtain the first authentication data, and the RPMB also calculates the to-be-stored data by using a hash operation message authentication code to obtain the second authentication data.

[0189] Exemplarily, the second TA calculates the to-be-stored data by using a cipher block chaining message authentication code to obtain the first authentication data, and the RPMB also calculates the to-be-stored data by using a cipher block chaining message authentication code to obtain the second authentication data.

[0190] S207, in a case where the first authentication data and the second authentication data match, the RPMB stores the to-be-stored data.

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

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

[0193] 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 no security key is stored, and the second TEE being a TEE in which a security key is stored, and the method includes: sending, by the first TA, a first data packet including to-be-stored data to the second TA, performing, by the second TA, authentication calculation on the to-be-stored data in the first data packet by using the security key to obtain first authentication data, and generating a second data packet according to the first authentication data and the to-be-stored data, and then sending the second data packet to the RPMB. After receiving the second data packet, the RPMB performs authentication calculation on the to-be-stored data in the second data packet by using the security key to obtain second authentication data, and in a case where 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, so that the data stored in the RPMB can be effectively prevented from being attacked by data of unknown sources, and the security of the data stored in the RPMB is improved.

[0194] S208, the RPMB sends response information to the second TA.

[0195] The response information is used to indicate that the to-be-stored data has been stored in the RPMB.

[0196] In the embodiments of the present application, after the RPMB stores the to-be-stored data, the RPMB returns response information used to indicate that the to-be-stored data has been successfully stored to the second TA, so that the second TA does not need to send the second data packet to the RPMB again after receiving the response information, and unnecessary data transmission between the second TA and the RPMB is avoided.

[0197] It should be understood that, after the RPMB successfully writes data, the count value of the counter is usually updated, so that the RPMB sends the updated count value to the second TA in the next case of storing data, so that the second TA performs authentication calculation based on the updated count value. In a possible case, the updated count value can be included in the response information sent to the second TA, so that the second TA determines that the to-be-stored data has been stored in the RPMB.

[0198] Optionally, the response information includes the updated count value. Before S208, the method further includes:

[0199] S209, the RPMB updates the count value of the counter based on the storage state of the stored to-be-stored data to obtain an updated count value.

[0200] The updated count value is a count value updated by the RPMB based on the stored to-be-stored data. For example, the updated count value is obtained by adding 1 to the current count value after the RPMB stores the to-be-stored data.

[0201] In a possible case, the data to be stored can be the data collected by the fingerprint sensor. The application running in the Android system has the encryption requirement, for example The fingerprint CA sends a fingerprint registration request to the fingerprint TA (first TA) in the TEE (first TEE) without storing the security key in the case of receiving a fingerprint registration request initiated by the user, and the fingerprint TA invokes the fingerprint sensor based on the fingerprint registration request, collects the fingerprint data, and sends the collected fingerprint data to the fingerprint TA. Then, the fingerprint TA can send the collected fingerprint data to the proxy TA (second TA) running in the TEE (second TEE) storing the security key, and send the fingerprint data to the RPMB storage through the proxy TA. The following will be described in detail by Figure 9 and Figure 10 how the fingerprint TA running in the TEE without storing the security key stores the fingerprint data collected by the fingerprint sensor into the RPMB.

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

[0203] For example, the data storage method provided by the embodiment of the present application can be applied to the electronic device as shown in Figure 9 The fingerprint CA (for example ) runs in the Android (equivalent to REE). The fingerprint TA and the first RPMB service module run in the first TEE. The proxy TA and the second RPMB service module run in the second TEE. Among them, the security key is stored in the second RPMB service module. It should be understood that the running levels of the fingerprint CA, the fingerprint TA, the first RPMB service module, the proxy TA and the second RPMB service module are EL0. The Kernel includes the storage device driver module, the second TEE tz driver module, the Hypervisor module and the ATF module, wherein the running levels of the storage device driver module, the second TEE tz driver module and the first TEE tz driver module are EL1. The storage device can include eMMC and Ufs, and the corresponding storage device driver module can include eMMC driver module and Ufs driver module. The running level of the Hypervisor module is EL2. The running level of the ATF module is EL3. As shown in Figure 9As shown, Android (REE), a first TEE (first TEE) and a second TEE (second TEE) are running in the electronic device, wherein the first TEE does not store a security key, and the second TEE stores the security key. The fingerprint CA running in the Android can send a fingerprint registration request to the fingerprint TA in the first TEE in the case of receiving a fingerprint registration operation. The fingerprint TA responds to the fingerprint registration request, calls the fingerprint sensor to collect fingerprint data, and then sends the fingerprint data to the proxy TA running in the second TEE through the Hypervisor module, and further sends the fingerprint data to the RPMB through the proxy TA.

[0204] The data storage method in the electronic device shown in the foregoing embodiment is described in detail below. Figure 10 The data storage method is applied to the electronic device shown in the foregoing embodiment. Figure 9 The data storage method in the electronic device shown in the foregoing embodiment is described in detail below.

[0205] Figure 10 The data storage method in the electronic device shown in the foregoing embodiment is described in detail below. Figure 9 The data storage method in the electronic device shown in the foregoing embodiment is described in detail below.

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

[0207] The fingerprint registration operation can be used to indicate acquisition of fingerprint data.

[0208] S302, the fingerprint CA responds to the fingerprint registration operation, and sends a fingerprint registration request to the kernel first TEE tz driver module.

[0209] S303, the first TEE tz driver module sends the fingerprint registration request to the Hypervisor module.

[0210] S304, the Hypervisor module sends the fingerprint registration request to the fingerprint TA (first TA) in the first TEE (first TEE).

[0211] S305, the fingerprint TA responds to the fingerprint registration request, calls the fingerprint sensor, and collects fingerprint data (to-be-stored data).

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

[0213] S307, the first RPMB service module in the first TEE generates a first data packet according to the fingerprint data and the RPMB write request.

[0214] Optionally, the generated first data packet can further include an RPMB operation cmd id and an RPMB write cmd id, wherein the RPMB operation cmd id is used to indicate that the operation corresponding to the current data is an RPMB operation. So that the application program confirms that the operation corresponding to the fingerprint data in the first data packet is the RPMB operation based on the RPMB operation cmd id. The RPMB write cmd id is used to indicate that the operation corresponding to the current data is a write operation of the RPMB. The RPMB can determine that the fingerprint data is the data written into the RPMB based on the RPMB write cmd id.

[0215] For example, the data format of the first data packet can be as shown in Figure 11 RPMB operation cmd id, RPMB write cmd id, data amount of RPMB data, and RPMB data. The RPMB data can be the fingerprint data.

[0216] S308, the first RPMB service module sends the first data packet to the Hypervisor module.

[0217] S309, the Hypervisor module sends the first data packet to the ATF module.

[0218] S310, the ATF module sends the first data packet to the proxy TA in the second TEE.

[0219] S311, the proxy TA sends the first data packet to the second RPMB proxy service module running in the second TEE.

[0220] S312, the second RPMB proxy service module unpacks the first data packet to obtain the fingerprint data and the RPMB write request.

[0221] S313, the second RPMB proxy service module performs authentication calculation on the fingerprint data using a secure key to obtain first authentication data.

[0222] S314, the second RPMB proxy service module packages the first authentication data and the fingerprint data to obtain a second data packet.

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

[0224] The random number can be a hardware random number generated by a random number generator, and the electronic device performs encryption through the hardware random number. The count value can be the count value of the counter at the current time in the storage device. The storage address of the fingerprint data can be the storage address of the fingerprint data in the RPMB.

[0225] Exemplarily, the data format of the second data packet can be as shown in the table below, including MAC, RPMB data, random number, Write counter, Address, operation result on the fingerprint data, and write cmd id. The MAC can be the first authentication data, the RPMB data can be the fingerprint data, and the storage address can be the storage address of the fingerprint data. Figure 12

[0226] S315, the second RPMB agent service module sends the second data packet to the ATF module.

[0227] S316, the ATF module sends the second data packet to the Hypervisor module.

[0228] S317, the Hypervisor module sends the second data packet to the second TEE tz driving module in the kernel.

[0229] S318, the second TEE tz driving module sends the second data packet to the storage device driving module.

[0230] S319, the storage device driving module sends the second data packet to the RPMB.

[0231] S320, the RPMB stores the fingerprint data based on the second data packet.

[0232] In the embodiment of the application, the fingerprint TA running in the first TEE sends the fingerprint data to the agent TA running in the second TEE, and then the agent TA sends the fingerprint data to the second RPMB service module in the second TEE, so that the second RPMB service module storing the security key can perform authentication calculation on the fingerprint data to obtain the first authentication data, and then the second RPMB service module generates a second data packet according to the first authentication data, the fingerprint data and the RPMB write request, and sends the second data packet to the RPMB through the ATF module, the Hypervisor module, the second TEE tz driving module and the storage device driving module. The RPMB stores the fingerprint data based on the second data packet. In this way, the fingerprint TA in the first TEE which does not store the security key can also store the fingerprint data in the RPMB through the above data channel, that is, the data storage method provided by the embodiment of the application realizes the function that each application program running in each TEE in the multi-TEE architecture can write data to the RPMB.

[0233] ​It should be understood that although the steps in the flowcharts in the above embodiments are shown in sequence according to the arrows, the steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, the execution of the steps is not strictly limited in sequence, and the steps can be executed in other orders. Moreover, at least part of the steps in the flowcharts 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 order of the sub-steps or stages is not necessarily sequential, but can be alternately executed with at least part of other steps or sub-steps or stages of other steps.

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

[0235] It should be understood that the electronic device can execute the data storage method shown in Figures 5 to 10 The electronic device includes an acquisition unit 610 and a processing unit 620.

[0236] The processing unit 620 is configured to control a first trusted application TA to send a first data packet to a second trusted application, the first data packet including to-be-stored data, the to-be-stored data being data to be written to the RPMB, 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; the second TA performs authentication calculation on the to-be-stored data in the first data packet using the secure key to obtain first authentication data; the second TA generates a second data packet according to the first authentication data and the to-be-stored data; the second TA sends the second data packet to the RPMB; and the RPMB stores the to-be-stored data based on the second data packet.

[0237] Optionally, as one embodiment, the processing unit 620 is specifically configured to control the first TA to send the first data packet to a Hypervisor module; and the Hypervisor module sends the first data packet to the second TA.

[0238] Optionally, as one embodiment, the processing unit 620 is specifically configured to control the Hypervisor module to send the first data packet to the second TA based on the write request in the first data packet.

[0239] Optionally, as one embodiment, the processing unit 620 is specifically configured to control the Hypervisor module to send the first data packet to the second TA based on the write request in the first data packet.

[0240] Optionally, as one embodiment, the processing unit 620 is specifically configured to control the RPMB to perform the authentication calculation on the to-be-stored data in the second data packet using the security key, to obtain second authentication data.

[0241] In a case where the first authentication data and the second authentication data match, the RPMB stores the to-be-stored data.

[0242] Optionally, as one embodiment, the RPMB sends response information to the second TA, where the response information is used to indicate that the to-be-stored data has been stored in the RPMB.

[0243] Optionally, as one embodiment, the processing unit 620 is specifically configured to control the RPMB to update a count value in the RPMB based on a storage state of the to-be-stored data, to obtain an updated count value.

[0244] Optionally, as one embodiment, the to-be-stored data is data obtained by the first TA invoking a first sensor.

[0245] Optionally, as one embodiment, the first sensor includes a fingerprint sensor.

[0246] Optionally, as one embodiment, the processing unit 620 is specifically configured to control a client application CA running in a rich execution environment REE to send fingerprint data acquisition request to the first TA in a case where the CA detects a first operation, where the first operation is used to indicate to acquire fingerprint data.

[0247] The first TA acquires fingerprint data by invoking a fingerprint sensor in response to the fingerprint data acquisition request, and obtains the to-be-stored data according to the fingerprint data.

[0248] Optionally, as one embodiment, the authentication calculation includes hash HMAC calculation.

[0249] The electronic device provided in the embodiment is used to execute the data storage method in the above embodiments, and has similar technical principles and technical effects, which are not described here again.

[0250] It should be noted that the above electronic device is embodied in the form of a functional unit. The term "unit" herein can be implemented in the form of software and / or hardware, and is not specifically limited.

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

[0252] 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. Actual implementation can have another division method. 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 in actual implementation.

[0253] For example, the "unit" can be a software program, a hardware circuit, or a combination of the two, which implements 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) 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.

[0254] Therefore, the units of each example described in the embodiments of the present application can be implemented in electronic hardware or a combination of computer software and electronic hardware. Whether a certain function is implemented in hardware or software depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.

[0255] Figure 14 A structural schematic diagram of an electronic device provided by the present application is shown. Figure 14 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.

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

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

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

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

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

[0261] 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 program 704, or the data can be stored in a different storage address from the program 704.

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

[0263] 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 performing data storage, and execute the data storage method of the embodiments of the present application, including: a first trusted application TA sends a first data packet to a second trusted application, the first data packet including to-be-stored data, the to-be-stored data being data to be written to the RPMB, 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; the second TA performs authentication calculation on the to-be-stored data in the first data packet by using the security key, to obtain first authentication data; the second TA generates a second data packet according to the first authentication data and the to-be-stored data; the second TA sends the second data packet to the RPMB; and the RPMB stores the to-be-stored data based on the second data packet.

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

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

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

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

[0268] 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 (a). 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.

[0269] 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 their functions and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

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

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

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

[0273] 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. they can be located in one place or distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the embodiment.

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

[0275] 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 skilled person 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 authenticate stored data. The method includes: A first trusted application (TA) sends a first data packet to a second trusted application. The first data packet includes data to be stored, which is data to be written to the RPMB. 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 on the second TEE. The second trusted application TA uses the security key to perform authentication calculations on the data to be stored in the first data packet to obtain the first authentication data; The second trusted application (TA) generates a second data packet based on the first authentication data and the data to be stored; The second trusted application TA sends the second data packet to the RPMB; The RPMB stores the data to be stored based on the second data packet.

2. The method according to claim 1, characterized in that, The first trusted application TA sends a first data packet to the second trusted application, including: The first trusted application (TA) sends the first data packet to the Hypervisor module; The Hypervisor module sends the first data packet to the second trusted application TA.

3. The method according to claim 2, characterized in that, The first data packet also includes a write request, which instructs the data to be stored to be stored to the RPMB. The Hypervisor module sends the first data packet to the second TA, including: The Hypervisor module sends the first data packet to the second trusted application TA based on the write request in the first data packet.

4. The method according to any one of claims 1 to 3, characterized in that, The RPMB stores the data to be stored based on the second data packet, including: The RPMB uses the security key to perform the authentication calculation on the data to be stored in the second data packet to obtain the second authentication data. If the first authentication data and the second authentication data match, the RPMB stores the data to be stored.

5. The method according to claim 4, characterized in that, The method further includes: The RPMB sends a response message to the second trusted application TA, the response message indicating that the data to be stored has been stored in the RPMB.

6. The method according to claim 5, characterized in that, The response information includes the updated count value, and also includes: The RPMB updates the count value in the RPMB based on the storage status of the stored data to be stored, and obtains the updated count value.

7. The method according to any one of claims 1 to 6, 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 sensor.

9. The method according to any one of claims 1 to 8, characterized in that, The method further includes: When a client application CA running in a rich execution environment (REE) detects a first operation, the client application CA sends a fingerprint data acquisition request to the first trusted application TA, whereby the first operation is used to instruct the acquisition of fingerprint data. In response to the fingerprint data acquisition request, the first trusted application TA calls the fingerprint sensor to collect fingerprint data and obtains the data to be stored based on the fingerprint data.

10. The method according to any one of claims 1 to 9, characterized in that, The authentication calculation includes HMAC calculation.

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

12. 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 10 according to the instructions.

13. 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 10.

Citation Information

Patent Citations

  • Method and system for preventing mobile terminal from being unlocked

    CN106657551A

  • File storage method and apparatus, and storage medium

    CN112088376A