Random number generation method and apparatus

By combining the data sources of REE and second TEE in a multi-TEE architecture to generate target random numbers, the robustness problem in the event of hardware random number generator failure is solved, and the reliability and security of random number generation are improved.

CN120428949BActive Publication Date: 2026-03-24HONOR DEVICE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-01-29
Publication Date
2026-03-24

AI Technical Summary

Technical Problem

Existing random number generation methods cannot generate random numbers when the hardware random number generator fails, and their robustness is poor, making them unable to pass some certifications and affecting the security of electronic devices.

Method used

In electronic devices with a multi-TEE architecture, a software-based random number generator is used to obtain physical entropy source data from sensors, system clocks, etc. in the REE, and combined with random numbers generated by a hardware random number generator in the second TEE to generate a target random number, ensuring that the data source is extensive and highly secure.

Benefits of technology

It improves the robustness and reliability of random number generation, ensuring that high-quality random numbers can still be generated when the hardware random number generator fails, thus enhancing the security of electronic devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120428949B_ABST
    Figure CN120428949B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a random number generation method and device, and relate to the technical field of terminals. The method comprises: transmitting first physical entropy source data in REE and a first random number in a second TEE to a first TEE, the first physical entropy source data being data generated by a first module, and the first physical entropy source data having randomness, the first module comprising one or more of the following: a system clock, a timer or a sensor; in the first TEE, mixing the first physical entropy source data and the first random number to obtain first processed data, the mixing comprising bit operation and / or hash calculation; in the first TEE, determining that the randomness of the first processed data meets randomness requirements, and generating a target random number using the first processed data. In this way, the robustness of the electronic device in generating random numbers is higher.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of terminal technology, and in particular to a method and apparatus for generating random numbers. Background Technology

[0002] With the development of mobile internet, the security of services and data in electronic devices is facing increasing threats. Therefore, encryption algorithms and security protocols can be used to provide security protection for electronic devices. As the foundation of encryption algorithms and security protocols, the reliability of random numbers is crucial to the security of services and data in electronic devices.

[0003] Currently, electronic devices can adopt an architecture of trusted execution environment (TEE) + rich execution environment (REE). In the TEE, a hardware-based random number generator is used to generate random numbers, and then the random numbers are used to encrypt or decrypt the data in the electronic device.

[0004] However, such random number generation methods may have poor robustness. Summary of the Invention

[0005] This application provides a random number generation method and apparatus, applicable to the field of terminal technology. Electronic devices can use physical entropy source data obtained from the REE (Reverse Entropy Source) and random numbers obtained from the TEE (Transient Electronic Equipment) to determine a random number seed, thereby generating a target random number, resulting in a highly robust random number generation method.

[0006] In a first aspect, embodiments of this application propose a random number generation method. Applied to an electronic device, the electronic device includes a general operating environment (REE), a first trusted execution environment (TEE), and a second TEE. The method includes: transmitting first physical entropy source data from the REE and a first random number from the second TEE to the first TEE. The first physical entropy source data is data generated by a first module and possesses randomness. The first module includes one or more of the following: a system clock, a timer, or a sensor; in the first TEE, mixing the first physical entropy source data and the first random number to obtain first processed data, the mixing process including bitwise operations and / or hash calculations; in the first TEE, determining that the randomness of the first processed data meets the randomness requirement, and using the first processed data to generate a target random number.

[0007] The random number generation method of this application is applied to electronic devices with a multi-TEE architecture. The first TEE in the multi-TEE can obtain physical entropy source data from sensors, system clocks, or timers in the REE, and can also obtain random numbers from the second TEE. The target random number is obtained by determining a random number seed based on the mixed physical entropy source data and the random numbers. In this way, the source of the random number seed is wide, the data types of physical entropy source data obtained from the REE are wide, the random numbers obtained from the first TEE have high security, and even if the first module that generates the physical entropy source data fails or the second TEE cannot generate random numbers, the random number seed can still be determined, making the random number generation method highly robust.

[0008] In one possible implementation, the method further includes: transmitting a first data to a first TEE, wherein the first data is a second physical entropy source data in the REE and / or a second random number in the second TEE; determining in the first TEE whether the randomness of the first data meets the randomness requirement; transmitting the first physical entropy source data in the REE and the first random number in the second TEE to the first TEE, including: if it is determined that the randomness of the first data does not meet the randomness requirement, transmitting the first physical entropy source data and the first random number to the first TEE.

[0009] By determining the randomness of the first data before processing it, the electronic device can refrain from processing the first data if its randomness does not meet the randomness requirements, thus reducing the power consumption of the electronic device.

[0010] In one possible implementation, the method further includes: transmitting a second data to a first TEE, wherein the second data is a third physical entropy source data in the REE or a third random number in the second TEE; processing the second data in the first TEE to obtain second processed data, wherein the data processing includes: removing a first part of the numbers in each unit length of the first target data, and / or performing bitwise operations on the second part and the third part of the numbers in each unit length of the second target data; wherein the first target data and the second target data belong to the second data, the unit length is N data storage units, and N is a positive integer; determining whether the randomness of the second processed data meets the randomness requirement in the first TEE; transmitting the first physical entropy source data in the REE and the first random number in the second TEE to the first TEE, including: if the randomness of the second processed data does not meet the randomness requirement, transmitting the first physical entropy source data and the first random number to the first TEE.

[0011] Because electronic devices may alter the randomness of data during data processing, this method allows electronic devices to determine the randomness of the processed data. Consequently, the devices can use the processed data, which exhibits higher randomness, to generate target random numbers, thereby improving the randomness of the target random numbers.

[0012] In one possible implementation, data processing is performed on the second data to obtain second processed data, including: in the first TEE, determining whether the randomness of the second data meets the randomness requirement; if the randomness of the second data meets the randomness requirement, data processing is performed on the second data to obtain second processed data. In this way, the electronic device can first determine the randomness of the second data; if the randomness of the second data does not meet the randomness requirement, the electronic device can choose not to process the second data, resulting in lower power consumption of the electronic device.

[0013] In one possible implementation, if the randomness of the second processed data does not meet the randomness requirement, the first physical entropy source data and the first random number are transmitted to the first TEE, including: if the randomness of the second processed data does not meet the randomness requirement, updating the first number in the first TEE; if it is determined that the first number is less than or equal to a preset number of times, transmitting the first physical entropy source data and the first random number to the first TEE; after determining that the randomness of the first processed data meets the randomness requirement, the method further includes: resetting the first number to the initial value.

[0014] In this way, the electronic device can determine the number of times that the processed data in the first TEE does not meet the randomness requirement by counting the first number, and can determine whether the first TEE is in a state where it can generate the target random number normally based on the number of counts.

[0015] In one possible implementation, the method further includes: transmitting a third data to a first TEE, wherein the third data is a fourth physical entropy source data in the REE and a fourth random number in the second TEE; performing a mixing process on the third data in the first TEE to obtain third processed data; determining in the first TEE whether the randomness of the third processed data meets the randomness requirement; transmitting the first physical entropy source data in the REE and the first random number in the second TEE to the first TEE, including: if the randomness of the third processed data does not meet the randomness requirement, transmitting the first physical entropy source data and the first random number to the first TEE.

[0016] In this way, the electronic device uses the physical entropy source data obtained from the REE and the random number obtained from the second TEE to determine the processed data. This makes it possible for the electronic device to generate the processed data in the first TEE even if the second TEE fails to generate random numbers, or if the timer, system clock or sensor fails. This makes the method more robust.

[0017] In one possible implementation, determining whether the randomness of the first processed data meets the randomness requirement includes: calculating the first minimum entropy of the first processed data; and determining whether the randomness of the first processed data meets the randomness requirement if the first minimum entropy is greater than or equal to a preset threshold. In this way, the electronic device can determine the randomness of the data through the minimum entropy, making the determination of whether the randomness of the data meets the randomness requirement highly efficient.

[0018] In one possible implementation, generating a target random number using the first processed data includes: performing an entropy source data health test on the first processed data, the entropy source data health test including a repeat count test and / or an adaptive ratio test; and generating a target random number using the first processed data if the entropy source data health test determines that the first processed data meets the reasonableness requirements.

[0019] In this way, if the data detected by the entropy source data health test does not meet the reasonableness requirements, the electronic device can reacquire the entropy source data. If the data detected by the entropy source data health test meets the reasonableness requirements, it indicates that the data quality is high and helps to generate high-quality target random numbers.

[0020] In one possible implementation, determining that the randomness of the first processed data meets the randomness requirement and generating a target random number using the first processed data includes: determining that the randomness of the first processed data meets the randomness requirement; performing duplicate data deletion processing on the first processed data to obtain deleted processed data, wherein the duplicate data deletion processing involves deleting a portion of the length units from multiple length units whose consecutive duplicate counts are greater than or equal to a first preset threshold, wherein the length unit is M data storage units, and M is a positive integer; and generating a target random number based on the deleted processed data.

[0021] This reduces the number of repeated length units in the first processed data, making it easier to further improve the randomness of the first processed data, thereby improving the quality of the target random number.

[0022] In one possible implementation, generating a target random number based on the deleted data includes: compressing the deleted data to obtain a random number seed; and using the random number seed to generate the target random number.

[0023] In one possible implementation, the second TEE includes a random number generator, and the first random number is generated by the random number generator.

[0024] It should be understood that the random number generator in the second TEE can be, for example, the first random number generator, random number generator 1, random number generator 2, or random number generator C mentioned below. That is, the random number generator in the second TEE can be a hardware-based random number generator, which facilitates the efficient acquisition of random numbers from the second TEE.

[0025] In one possible implementation, the first TEE includes a random number generation module, and the second TEE includes a random number generator; transmitting the first physical entropy source data in the REE and the first random number in the second TEE to the first TEE includes: obtaining the first physical entropy source data from the first module through the random number generation module; and obtaining the first random number from the random number generator through the random number generation module.

[0026] The random number generation module can be, for example, the second random number generator, random number generator A, random number generator B, or random number generator 3 mentioned below, and is a software-based random number generator. The random number generation module can obtain first physical entropy source data from a wide range of sources, as well as first random numbers with higher security, making the target random number determined using the first physical entropy source data and the first random number highly reliable.

[0027] In one possible implementation, the REE includes a first client application (CA); the first physical entropy source data is obtained from the first module via a random number generation module, including: obtaining the first physical entropy source data via the first CA and writing the first physical entropy source data into shared memory; and reading the first physical entropy source data from the shared memory via the random number generation module. This facilitates efficient acquisition of the first physical entropy source data by the random number generation module.

[0028] In one possible implementation, obtaining the first physical entropy source data through the first CA includes: instructing the first CA to obtain the physical entropy source data through the random number generation module, and obtaining the first physical entropy source data through the first CA; or, the first CA periodically obtains the measurement data of the first module from the first module, the measurement data including the first physical entropy source data.

[0029] It should be understood that the first CA can periodically obtain physical entropy source data from the first module. For example, after the electronic device is powered on, the first CA can periodically obtain physical entropy source data. In this way, the first CA can periodically update the physical entropy source data, and when the random number generation module needs to obtain physical entropy source data, it does not need to instruct the first CA to obtain physical entropy source data, making the random number generation module more efficient in obtaining physical entropy source data.

[0030] In addition, the first CA can also obtain physical entropy source data from the first module when the random number generation module needs to obtain physical entropy source data, so that the first CA obtains physical entropy source data from the first module less often, thereby reducing the power consumption of the electronic device.

[0031] In one possible implementation, the random number generation module includes a data acquisition module and a deterministic random number generator (DRNG). Reading first physical entropy source data from shared memory via the random number generation module includes: instructing the data acquisition module to acquire the first physical entropy source data through the DRNG; and reading the first physical entropy source data from shared memory through the data acquisition module. In this way, the data acquisition module can acquire the first physical entropy source data when the DRNG requires a random number seed.

[0032] Secondly, embodiments of this application provide a random number generation apparatus, which can be an electronic device, or a chip or chip system within an electronic device. The random number generation apparatus may include a data acquisition unit and a processing unit. The data acquisition unit is used to perform the data acquisition step to enable the electronic device to implement a random number generation method described in the first aspect or any possible implementation of the first aspect. When the random number generation apparatus is an electronic device, the processing unit may be a processor. The random number generation apparatus may further include a storage unit, which may be a memory. The storage unit is used to store instructions, and the processing unit executes the instructions stored in the storage unit to enable the electronic device to implement a random number generation method described in the first aspect or any possible implementation of the first aspect. When the random number generation apparatus is a chip or chip system within an electronic device, the processing unit may be a processor. The processing unit executes the instructions stored in the storage unit to enable the electronic device to implement a random number generation method described in the first aspect or any possible implementation of the first aspect. The storage unit may be a storage unit within the chip (e.g., a register, cache, etc.), or a storage unit located outside the chip within the electronic device (e.g., a read-only memory, random access memory, etc.).

[0033] For example, the data acquisition unit is used to transmit the first physical entropy source data in the REE and the first random number in the second TEE to the first TEE.

[0034] The processing unit is used to mix the first physical entropy source data and the first random number to obtain the first processed data, determine whether the randomness of the first processed data meets the randomness requirements, and use the first processed data to generate the target random number.

[0035] Thirdly, embodiments of this application provide an electronic device including a processor and a memory, the memory for storing code instructions, and the processor for running the code instructions to perform the methods described in the first aspect or any possible implementation of the first aspect.

[0036] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program or instructions that, when executed on a computer, cause the computer to perform the methods described in the first aspect or any possible implementation thereof.

[0037] Fifthly, embodiments of this application provide a computer program product including a computer program, which, when run on a computer, causes the computer to perform the methods described in the first aspect or any possible implementation thereof.

[0038] Sixthly, this application provides a chip or chip system including at least one processor and a communication interface. The communication interface and the at least one processor are interconnected via a circuit. The at least one processor is used to run computer programs or instructions to perform the methods described in the first aspect or any possible implementation of the first aspect. The communication interface in the chip can be an input / output interface, pins, or circuits, etc.

[0039] In one possible implementation, the chip or chip system described above in this application further includes at least one memory storing instructions. The memory can be an internal storage unit of the chip, such as a register or cache, or it can be a storage unit of the chip itself (e.g., read-only memory, random access memory, etc.).

[0040] It should be understood that the second to sixth aspects of this application correspond to the technical solutions of the first aspect of this application, and the beneficial effects achieved by each aspect and the corresponding feasible implementation are similar, and will not be repeated here. Attached Figure Description

[0041] Figure 1 A schematic block diagram of the hardware structure of the electronic device provided in the embodiments of this application;

[0042] Figure 2 A schematic block diagram of the software architecture of an electronic device provided in the embodiments of this application;

[0043] Figure 3 A flowchart illustrating a random number generation method provided in an embodiment of this application;

[0044] Figure 4 This is a schematic diagram illustrating a random number generation method provided in an embodiment of this application;

[0045] Figure 5 A schematic diagram illustrating another random number generation method provided in this application embodiment;

[0046] Figure 6 A schematic diagram illustrating the process of another random number generation method provided in this application embodiment;

[0047] Figure 7 This is a schematic block diagram of a random number generation device provided in an embodiment of this application. Detailed Implementation

[0048] To facilitate a clear description of the technical solutions in the embodiments of this application, some terms and technologies involved in the embodiments of this application will be briefly introduced below:

[0049] 1. Rich Execution Environment (REE): Also known as a rich execution environment, ordinary execution environment, or untrusted execution environment, it refers to the system operating environment of a mobile device, in which operating systems such as Android, iOS, and Linux can run.

[0050] 2. A Trusted Execution Environment (TEE), also known as a secure side or secure zone, is an area that requires authorization to access. A TEE refers to an independent secure area established within the processor through hardware resource isolation. TEEs and REEs coexist in the operating environment of electronic devices, and TEEs can achieve isolation from REEs through hardware support.

[0051] The REE+TEE architecture refers to an architecture where TEE and REE work together to provide services to applications. In other words, TEE and REE coexist within the electronic device. For example, TEE, through hardware support, can achieve an isolated operating mechanism from REE. TEE has its own runtime environment, offering a higher level of security than REE, and can protect assets within the TEE (such as data and software) from software attacks. Only authorized security software can execute within the TEE, which also protects the confidentiality of the security software's resources and data. Compared to REE, due to its isolation and access control mechanisms, TEE can better protect the security of data and resources.

[0052] 3. Implementing a TEE based on TrustZone technology. TrustZone technology isolates system-on-chip (SoC) hardware and software resources, placing them in two separate areas (a normal area and a secure area). Components in the normal area cannot access resources in the secure area, thus achieving isolation between the two areas. The secure area can then function as a TEE.

[0053] 4. Implement TEE based on virtualization technology. Virtualization technology is a technology that runs multiple isolated operating systems on the same electronic device. Electronic devices can provide a secure business execution environment for business operations by building TEE on a virtual machine (hypervisor).

[0054] 5. Trusted Application (TA): This refers to an application running in a TEE that can provide security services to a CA running outside the TEE, such as password input, transaction signature generation, and facial recognition.

[0055] 6. Client Application (CA): This refers to the application running within the REE. The CA can invoke the TA and instruct the TA to perform corresponding security operations through the client application programming interface (API).

[0056] 7. Other terms

[0057] In the embodiments of this application, terms such as "first" and "second" are used to distinguish identical or similar items with substantially the same function and purpose. For example, "first chip" and "second chip" are used only to distinguish different chips and do not limit their order of execution. Those skilled in the art will understand that terms such as "first" and "second" do not limit the quantity or execution order, and that "first" and "second" do not necessarily imply that they are different.

[0058] It should be noted that, in the embodiments of this application, the terms "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design scheme described as "exemplary" or "for example" in this application should not be construed as being more preferred or advantageous than other embodiments or design schemes. Specifically, the use of terms such as "exemplary" or "for example" is intended to present the relevant concepts in a specific manner.

[0059] In this application embodiment, "at least one" refers to one or more, and "more than one" refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one of a, b, or c can represent: a, b, c, ab, a--c, bc, or abc, where a, b, and c can be single or multiple.

[0060] 8. Electronic equipment

[0061] The electronic devices in this application embodiment may include handheld devices with facial recognition function, vehicle-mounted devices, etc. For example, some electronic devices include: mobile phones, tablets, PDAs, laptops, mobile internet devices (MIDs), wearable devices, virtual reality (VR) devices, augmented reality (AR) devices, wireless terminals in industrial control, wireless terminals in self-driving vehicles, wireless terminals in remote medical surgery, wireless terminals in smart grids, wireless terminals in transportation safety, wireless terminals in smart cities, wireless terminals in smart homes, cellular phones, cordless phones, session initiation protocol (SIP) phones, wireless local loop (WLL) stations, personal digital assistants (PDAs), handheld devices with wireless communication capabilities, computing devices or other processing devices connected to a wireless modem, in-vehicle devices, wearable devices, terminal devices in 5G networks, or future evolution of public land mobile communication networks. Terminal devices in a network (PLMN), etc., are not limited to this in the embodiments of this application.

[0062] By way of example and not limitation, in this embodiment, the electronic device can also be a wearable device. Wearable devices, also known as wearable smart devices, are a general term for devices that utilize wearable technology to intelligently design and develop everyday wearables, such as glasses, gloves, watches, clothing, and shoes. Wearable devices are portable devices that are worn directly on the body or integrated into the user's clothing or accessories. Wearable devices are not merely hardware devices, but also achieve powerful functions through software support, data interaction, and cloud interaction. Broadly speaking, wearable smart devices include those that are feature-rich, large in size, and can achieve complete or partial functions without relying on a smartphone, such as smartwatches or smart glasses, as well as those that focus on a specific type of application function and require the use of other devices such as smartphones, such as various smart bracelets and smart jewelry for vital sign monitoring.

[0063] Furthermore, in this embodiment of the application, the electronic device can also be a terminal device in the Internet of Things (IoT) system. IoT is an important part of the future development of information technology. Its main technical feature is to connect objects to the network through communication technology, thereby realizing an intelligent network of human-machine interconnection and object-to-object interconnection.

[0064] The electronic devices in the embodiments of this application may also be referred to as: terminal equipment, user equipment (UE), mobile station (MS), mobile terminal (MT), access terminal, user unit, user station, mobile station, mobile station, remote station, remote terminal, mobile device, user terminal, terminal, wireless communication equipment, user agent, or user device, etc.

[0065] In this embodiment, the electronic device or various network devices include a hardware layer, an operating system layer running on top of the hardware layer, and an application layer running on top of the operating system layer. The hardware layer includes hardware such as a central processing unit (CPU), a memory management unit (MMU), and memory (also called main memory). The operating system can be any one or more computer operating systems that implement business processing through processes, such as Linux, Unix, Android, iOS, or Windows. The application layer includes applications such as browsers, address books, word processing software, and instant messaging software.

[0066] The core of random numbers is their randomness, which makes them unpredictable and unreproducible, and thus plays a crucial role in applications such as encryption algorithms and security protocols. For example, random numbers can be used as keys or to generate keys. Electronic devices can then use these keys to encrypt plaintext to obtain ciphertext; or, they can use them to decrypt ciphertext to obtain plaintext.

[0067] Currently, electronic devices can adopt an REE+TEE architecture. The REE+TEE architecture refers to an architecture where TEE and REE work together to provide services to applications. For example, TEE, with hardware support, can achieve an operating mechanism isolated from the REE. TEE has its own operating space, offering a higher level of security than REE, and can protect the confidentiality of resources and data within the TEE. Therefore, to improve key security, random numbers can currently be generated within the TEE using a random number generator.

[0068] To ensure the unpredictability of random numbers, the random number generator in a TEE should produce truly random numbers. Truly random numbers, also known as genuine random numbers, are random numbers generated based on physical phenomena. Therefore, the random number generator in a current TEE can be a hardware-based random number generator.

[0069] It should be understood that the hardware-based random number generator in the embodiments of this application can also be called a hardware random number generator, such as a true random number generator (TRNG), which is a device that generates random numbers based on physical processes rather than computer programs.

[0070] However, due to this random number generation method, electronic devices cannot generate random numbers when the hardware-based random number generator malfunctions. Furthermore, hardware-based random number generators may fail to pass certification for some standards, rendering the random numbers generated by them unusable in certain business applications. Therefore, this random number generation method has poor robustness.

[0071] In view of this, this application provides a random number generation method and apparatus. The method is applied to electronic devices with a multi-TEE architecture. A software-based random number generator in the first TEE of the multi-TEE can obtain first entropy source data from various sensors, system clocks, or other hardware within the REE. It can also obtain random numbers generated by a hardware-based random number generator in the second TEE of the multi-TEE, and use these random numbers as second entropy source data. The first entropy source data has a wide range of sources, while the second entropy source data has higher security.

[0072] Since entropy source data is widely available, software-based random number generators can determine highly random random number seeds based on first and second entropy source data. Furthermore, when a hardware-based random number generator fails, a software-based random number generator can still obtain entropy source data from the REE, making this random number generation method highly reliable.

[0073] The following is combined Figures 1 to 6 The technical solutions of this application and how they solve the aforementioned technical problems are described in detail with specific embodiments. The following specific embodiments can be implemented independently or in combination with each other. Identical or similar concepts or processes may not be described again in some embodiments.

[0074] The embodiments shown in this application can be executed by an electronic device, which may be a terminal device such as a mobile phone, tablet computer, or smart bracelet. The specific form and number of the devices shown are merely examples and should not constitute any limitation on the implementation of the methods provided in this application.

[0075] It should be understood that an electronic device can be the electronic device itself, or a chip, chip system, or processor that supports the electronic device in implementing image processing methods, or a logic module or software that can implement all or part of the functions of the electronic device.

[0076] To facilitate understanding this solution, we will first combine... Figure 1 Describe the hardware structure of the electronic device.

[0077] Figure 1 This is a schematic diagram of the structure of the electronic device 100 provided in an embodiment of this application. Figure 1As shown, the electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, antenna 1, antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a sensor module 180, buttons 190, a motor 191, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an accelerometer sensor 180E, a proximity sensor 180F, a proximity light sensor 180G, an image sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc. The audio module may include speakers, receivers, microphones, and headphone jacks.

[0078] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0079] Processor 110 may include one or more processing units, such as an application processor (AP) and a coprocessor (CP). The application processor includes the application framework layer, hardware abstraction layer, and kernel layer of the software architecture adopted by electronic device 100; the coprocessor includes a sensor hub. Different processing units may be independent devices or integrated into one or more processors.

[0080] In one possible implementation, the processor 110 may integrate a random number generator 192, which can generate random numbers.

[0081] In one possible implementation, the processor 110 can acquire sensor data measured by the sensor module 180.

[0082] Optionally, the sensor data includes, but is not limited to, data measured by one or more of the following sensors.

[0083] Pressure sensor 180A is used to sense pressure signals and can convert the pressure signals into electrical signals. In some embodiments, pressure sensor 180A may be disposed on display screen 194. When a touch operation is applied to display screen 194, electronic device 100 detects the intensity of the touch operation based on pressure sensor 180A.

[0084] The gyroscope sensor 180B can be used to determine the motion attitude of the electronic device 100. In some embodiments, the angular velocity of the electronic device 100 about three axes (i.e., the x, y, and z axes) can be determined by the gyroscope sensor 180B.

[0085] The barometric pressure sensor 180C is used to measure air pressure. In some embodiments, the electronic device 100 calculates altitude using the air pressure value measured by the barometric pressure sensor 180C to assist in positioning and navigation.

[0086] The 180D magnetic sensor can convert changes in the magnetic properties of the sensitive element caused by external factors such as magnetic field, current, stress and strain, temperature, and light into electrical signals.

[0087] The 180E accelerometer can detect the magnitude of acceleration of electronic device 100 in various directions (typically three axes). When electronic device 100 is stationary, it can detect the magnitude and direction of gravity. It can also be used to identify the posture of terminal devices, and can be applied to applications such as landscape / portrait switching and pedometers.

[0088] Distance sensor 180F is used to measure distance. Electronic device 100 can measure distance via infrared or laser.

[0089] Image sensor 180H is used to convert the light image on the photosensitive surface into an electrical signal that is proportional to the light image.

[0090] The 180L ambient light sensor is used to detect ambient light intensity.

[0091] The 180J temperature sensor is used to detect temperature.

[0092] The bone conduction sensor 180M can acquire vibration signals.

[0093] The controller can generate operation control signals based on the instruction opcode and timing signals to control the fetching and execution of instructions. The processor 110 can also include a memory for storing instructions and data.

[0094] Based on the above embodiments, the processor 110 may also include a system clock and a timer.

[0095] The system clock can be a circuit composed of an oscillator, a timer wake-up unit, and a frequency divider. The system clock can use an oscillator to measure local time and / or system time. The time measured by the system clock can be accurate to the nanosecond level. The last digit of the measured time is an estimate; for example, if the system clock measures the current time as 14:05:6.7 nanoseconds, the "7" is an estimate.

[0096] A timer can be a standalone device or integrated into the system clock, and can be used to record the duration of a period of time. The duration recorded by the timer can be accurate to the nanosecond level. The last digit of the duration recorded by the timer is an estimate; for example, if the timer records a duration of 10,000,000.8 nanoseconds, the "8" can be an estimate.

[0097] The processor 110 can obtain the time measured by the system clock from the system clock, and / or can obtain the duration recorded by the timer from the timer.

[0098] Optionally, the processor 110 can use one or more of the following as entropy source data: sensor data, random number, system clock measurement time, or timer recording duration, to generate a target random number. The target random number can be used as a key or to generate a key.

[0099] In some embodiments, the processor 110 may include one or more interfaces. It is understood that the interface connection relationships between the modules illustrated in the embodiments of this application are merely illustrative and do not constitute a structural limitation on the electronic device 100.

[0100] The electronic device adopts a multi-TEE architecture. The following explanation uses an electronic device that includes TEE I and TEE II as an example to illustrate the software architecture of the electronic device.

[0101] The software system of an electronic device can adopt a layered architecture, event-driven architecture, microkernel architecture, microservice architecture, or cloud architecture. This embodiment of the invention uses a layered architecture system as an example to illustrate the software structure of an electronic device.

[0102] In some embodiments, the software architecture of an electronic device can be as follows: Figure 2 As shown. The software architecture of an electronic device may include a layered architecture on the REE side, TEE I side, and various modules in TEE II.

[0103] I. The layered architecture on the REE side can be described as follows.

[0104] The layered architecture of the REE side of an electronic device divides the software and hardware into several layers, each with a clear role and division of labor. Layers communicate with each other through software interfaces. In some embodiments, the electronic device may include, for example, an application layer, an application framework layer, a hardware abstraction layer (HAL), a kernel layer, and a hardware layer. Of course, it may also include... Figure 2 Layers not shown in the diagram include, for example, runtime and system libraries.

[0105] 1. The application layer can include a series of applications. For example, it may include settings applications, a gallery, a physical entropy source acquisition module, etc. The physical entropy source acquisition module can instruct a random number generator (CA) to collect physical entropy source data.

[0106] 2. The application framework layer provides application programming interfaces (APIs) and a programming framework for applications in the application layer. The application framework layer includes some predefined functions. It may include native C / C++ libraries, which may contain interfaces for physical entropy source acquisition.

[0107] The physical entropy source acquisition interface can be an interface developed using C++.

[0108] 3. The hardware abstraction layer (HAL) can encapsulate drivers in the kernel layer and provide an interface for calling the application framework layer, shielding the implementation details of the low-level hardware.

[0109] For example, HAL includes at least a standard API for obtaining physical entropy sources and a random number CA.

[0110] Among them, the random number CA can obtain the physical entropy source driver of the standard API driver kernel layer by calling the physical entropy source acquisition interface.

[0111] 4. The kernel layer is the layer between hardware and software. The kernel layer contains at least the physical entropy source driver.

[0112] The physical entropy source driver is primarily responsible for interacting with various hardware components, including multiple sensors, timers, and the system clock. These various sensors include, but are not limited to, those mentioned above. Figure 1 The sensor module 180 in the middle includes sensors.

[0113] 5. The hardware layer includes various sensors, timers, and the system clock.

[0114] Among them, various sensors include but are not limited to Figure 1 The sensor module 180 includes various sensors. The function of each sensor is described above. The functions of the system clock and timer are also described above and will not be repeated here.

[0115] One or more sensors from a variety of sensors can feed back data detected by one or more sensors to a physical entropy source. For example, pressure sensor 180A can feed back pressure signals to a physical entropy source.

[0116] It is understandable that data obtained from multiple sensors is generated due to environmental changes, user operations, or the movement of electronic devices, and thus possesses unpredictability and randomness. Therefore, data obtained from multiple sensors constitutes physical entropy source data and can be used as entropy source data.

[0117] A timer can be used to keep track of time and can indicate the duration of recording to a physical entropy source.

[0118] It is understandable that the last digit of the duration recorded by the timer can be an estimated value, i.e., randomly generated data. For example, if the timer duration is 10,000,000.7 nanoseconds, the "7" can be a randomly generated value, making the duration recorded by the timer random and unpredictable. Therefore, the duration recorded by the timer is physical entropy source data and can be used as entropy source data.

[0119] The system clock can determine the time in real time; for example, the system clock determines the current time as 10:05:03 nanoseconds. The system clock can also indicate the time of measurement to the physical entropy source.

[0120] Similar to a timer, the last digit of the time determined by the system clock can also be an estimated value, i.e., randomly generated data. For example, the "3" in 0.3 nanoseconds could be a randomly generated value, making the time determined by the system clock random and unpredictable. Therefore, the time determined by the system clock is physical entropy source data and can be used as entropy source data.

[0121] II. The modules in TEE I can be described as follows.

[0122] TEE I includes at least a random number acquisition interface and a first random number generator.

[0123] The first random number generator can be a hardware-based random number generator, such as the random number generator 192 mentioned above. The first random number generator can be used to generate random numbers.

[0124] Optionally, TEE I can be a TEE developed by the chip manufacturer and implemented based on TrustZone technology.

[0125] III. The modules in TEE II can be described as follows.

[0126] TEE II includes at least one random number TA corresponding to the random number CA. The random number TA can interact with each other.

[0127] The random number TA may include a second random number generator. This second random number generator is a software-based random number generator.

[0128] Optionally, the random number generator TA may include a cryptographic module, and the second random number generator is part of the cryptographic module. When the operating system starts or the random number generator TA calls the cryptographic module, the cryptographic module can be initialized, and the cryptographic module can also instruct the second random number generator to initialize.

[0129] It should be noted that when the random number CA instructs the random number TA to generate a key, the random number TA can obtain a random number through the second random number generator in the cryptographic module. Alternatively, when the random number TA needs to use the key to decrypt ciphertext, or when it needs to use the key to encrypt plaintext, the random number TA can obtain a random number through the second random number generator in the cryptographic module. This application does not specifically limit the scenario in which the random number TA obtains a random number.

[0130] The second random number generator includes a first data acquisition module, a second data acquisition module, an entropy source data processing and evaluation module, a state module, and a deterministic random number generator (DRNG).

[0131] Specifically, the first data acquisition module can call the random number acquisition interface to obtain a random number generated by the first random number generator. The second data acquisition module can obtain physical entropy source data 1 from the random number CA. For example, the random number CA can write physical entropy source data 1 into shared memory; the second data acquisition module can read physical entropy source data 1 from the shared memory.

[0132] Among them, physical entropy source data 1 may include, but is not limited to, one or more of the following: sensor data, system clock measurement time, or timer recording duration.

[0133] The entropy source data processing and evaluation module is used to process the physical entropy source data 1 and / or the random numbers obtained from the first random number generator to determine the random number seed.

[0134] DRNG is used to output random numbers using a random number seed. For example, DRNG can be configured with the SM3 algorithm.

[0135] The status module can set the status of the second random number generator. The status of the second random number generator can be, for example, an error status or a normal status.

[0136] It should be noted that, Figure 2 The software architecture shown is merely an example. Electronic devices can include many more. Figure 2 Software modules not shown in the diagram, for example, may also include social applications, calling, camera, map, navigation, and other applications in the application layer. Figure 2 The software architecture shown does not constitute a limitation on the embodiments of this application.

[0137] The following is combined Figure 3 The method for generating random numbers is explained in detail.

[0138] Figure 3 This is a flowchart illustrating a random number generation method 300 provided in an embodiment of this application. Method 300 can be executed by an electronic device, and the hardware structure of the electronic device can be as follows... Figure 1 As shown, the software architecture of electronic devices can be as follows: Figure 2 As shown.

[0139] Method 300 includes the following steps:

[0140] S301, the physical entropy source acquisition module instructs random number CA to acquire physical entropy source data 1.

[0141] The physical entropy source data 1 may include one or more of the following: sensor data, timing data, or time data. Sensor data can be understood as... Figure 1 The data is obtained by one or more sensors in the sensor module 180; the timing data can be understood as the duration recorded by the timer; the time data can be understood as the time measured by the system clock.

[0142] S302, in response to the instruction of the physical entropy source acquisition module, the random number CA instructs the physical entropy source driver to acquire physical entropy source data 1 through the physical entropy source acquisition interface.

[0143] Optionally, the random number CA can call the physical entropy source acquisition interface to obtain physical entropy source data from the first hardware in the hardware layer through the standard API driver of the physical entropy source. The first hardware includes one or more of the following: a sensor, a system clock, or a timer, where the sensor can be understood as... Figure 1 One or more sensors in the sensor module 180.

[0144] S303, the physical entropy source driver obtains physical entropy source data 1 from the first hardware and indicates physical entropy source data 1 to the random number CA through the physical entropy source acquisition interface.

[0145] Optionally, the physical entropy source driver can use the physical entropy source acquisition standard API to call the physical entropy source acquisition interface to indicate physical entropy source data 1 to the random number CA.

[0146] S304, random number CA writes physical entropy source data 1 into shared memory.

[0147] It should be understood that shared memory can be understood as shared memory between REE and TEE II, or it can be called a shared buffer, etc. Random numbers CA in REE and random numbers TA in TEE II can write data to shared memory and read data from shared memory.

[0148] Alternatively, the shared memory can be a ring buffer.

[0149] In this way, when the amount of physical entropy source data cached in shared memory reaches its limit, the shared memory can delete the oldest physical entropy source data stored in it and store the new physical entropy source data. This prevents the amount of data stored in shared memory from becoming too large, helping to reduce the load on electronic devices. Here, "earliest" can refer to the earliest time it was written to shared memory, and "newest" can be understood as data that has not yet been written to shared memory.

[0150] S305, DRNG indicates that the entropy source data processing and evaluation module acquires entropy source data.

[0151] Optionally, the entropy source data may include physical entropy source data 1 and / or physical entropy source data 2, wherein physical entropy source data 1 is physical entropy source data obtained from the REE; and physical entropy source data 2 is a random number generated by a first random number generator obtained from TEE I.

[0152] Optionally, if the DRNG is reseeded, and / or if the number of random number seeds required by the DRNG to generate random numbers is greater than the number of random number seeds cached in the DRNG, the SRNG may execute S305.

[0153] For example, if a DRNG can be reseeded periodically, then the DRNG needs to periodically instruct the entropy source data processing and evaluation module to obtain entropy source data. Alternatively, if the DRNG also caches a random number seed that can generate 10MB of random numbers, but the DRNG needs to generate 20MB of random numbers, then the DRNG can instruct the entropy source data processing and evaluation module to obtain entropy source data.

[0154] S306, the entropy source data processing and evaluation module instructs the second random number acquisition module to acquire physical entropy source data 1.

[0155] Optionally, S306 can be executed if the entropy source data in S305 is physical entropy source data 1. That is, the DRNG instructs the entropy source data processing and evaluation module to obtain physical entropy source data 1; then, the entropy source data processing and evaluation module executes S306. Alternatively, the physical entropy source data in S305 does not represent physical entropy source data 1 and / or physical entropy source data 2, that is, S305 indicates that the DRNG needs entropy source data, but the DRNG does not specify the source of the entropy source data; then, in response to the DRNG's instruction, the entropy source data processing and evaluation module determines the source of the entropy source data.

[0156] In a first possible implementation, steps S301 to S304 can be steps that are executed cyclically after the electronic device is powered on. That is, the random number CA can continuously write the acquired physical entropy source data 1 into the shared memory. In this way, when the second random number acquisition module needs to acquire physical entropy source data 1, it can acquire physical entropy source data 1 from the shared memory (i.e., the electronic device executes S307), which facilitates the efficient acquisition of physical entropy source data 1 by the random number TA.

[0157] It should be understood that S305 and S301 to S304 can be executed in parallel, and this application does not make specific limitations on this.

[0158] In a second possible implementation, S301 is optional, and S302 to S304 are executed after S306. For example, after S306, the second random number acquisition module instructs random number CA to acquire physical entropy source data 1; then the electronic device executes S302 to S304; then the electronic device executes S307.

[0159] In this way, S301 to S304 do not need to be executed in a loop, which reduces the number of times the random number TA obtains physical entropy source data from the first hardware, and the shared memory does not need to continuously store a large amount of physical entropy source data, thus reducing the load on the electronic device.

[0160] S307, the second random number acquisition module reads physical entropy source data 1 from shared memory.

[0161] S308, the second random number acquisition module instructs the physical entropy source data 1 to the entropy source data processing and evaluation module.

[0162] S309, the entropy source data processing and evaluation module performs data processing 1 on the physical entropy source data 1 to obtain data 1.

[0163] Among them, data processing 1 can be, for example, outputting the first part of the value in each unit length of each data; and / or performing bitwise operations such as XOR and addition on the second part and the third part of the value in each unit length of each data.

[0164] The unit length can be, for example, X bytes, Y bits, Z bits, etc. X, Y, and Z are positive integers. The first part of the value, the second part of the data, or the third part of the value can be, for example, the first n bytes, the first n bits, the last n bytes, the last n bits, the first n bits, the last n bits at positions a to b, the a to b bytes, the a to b bits, etc., within each unit length. n, a, and b are positive numbers.

[0165] In one example, assuming the unit length is 9 bits, physical entropy source data 1 includes 100000009, 100000007, and 100000005. The unit length is the length of each physical entropy source data 1. Some values ​​can be the last two digits. Therefore, 100000009, 100000007, and 100000005 are converted to 09, 07, and 05, and 09, 07, and 05 are data 1.

[0166] In another example, suppose the physical entropy source data 1 includes 11030094, 11010016, and 11060027. Bitwise operations are addition calculations, with a unit length of 4 bits. The second part of the value can be the first 2 bits, and the third part of the value can be the last 2 bits. In 11030094, 1103 is one unit length, and 0094 is one unit length. The first 2 bits (11) and the last 2 bits (03) of 1103 are added together; the first 2 bits (00) and the last 2 bits (94) of 0094 are added together. Thus, 11030094 is converted to 1494. Similarly, 11010016 is converted to 1216, and 11060027 is converted to 1727. 1494, 1216, and 1727 are data 1.

[0167] By performing data processing on the physical entropy source data 1, the part of the physical entropy source data 1 that can reflect the specificity of the data can be retained, and the amount of physical entropy source data 1 can be reduced. For example, 11010016 can be converted to 1216, which helps DRNG obtain high-quality random number seeds.

[0168] It should be noted that physical entropy source data 1 can also be binary data, and this application does not make specific restrictions on this.

[0169] S310, the entropy source data processing and evaluation module calculates the minimum entropy 1 of data 1 and determines whether the minimum entropy 1 is greater than or equal to the first threshold.

[0170] Optionally, the entropy source data processing and evaluation module can use the entropy estimator in the Nist 800-900 standard to calculate the minimum entropy 1 of the physical entropy source data 1.

[0171] It should be understood that the first threshold is a preset positive value, such as 80. Minimum entropy can be used to represent the randomness of physical entropy source data; the smaller the minimum entropy, the worse the randomness of the physical entropy source data. Therefore, if the minimum entropy 1 is less than or equal to the first threshold, it indicates that the randomness of physical entropy source data 1 is relatively poor.

[0172] It is understandable that the entropy in minimum entropy can refer to Shannon entropy, which is used to represent the randomness of data. For the sake of brevity, this will not be elaborated on further below.

[0173] When the minimum entropy 1 is greater than the first threshold, the entropy source data processing and evaluation module can indicate data 1 to the DRNG, and the DRNG uses data 1 to determine a random number.

[0174] If the minimum entropy 1 is less than or equal to the first threshold, the electronic device can execute S311 to S317.

[0175] S311, the entropy source data processing and evaluation module increments the entropy source data update count by 1 and determines whether the updated entropy source data update count is greater than or equal to the second threshold.

[0176] The second threshold is a preset positive number, such as 1 or 3. The entropy source data update count records the number of consecutive times the randomness of the entropy source data acquired by the entropy source data processing and evaluation module is relatively poor. If the minimum entropy of the physical entropy source data is less than or equal to the first threshold, it indicates that the randomness of the physical entropy source data is relatively poor, and the entropy source data processing and evaluation module can increment the entropy source data update count by 1. The updated entropy source data update count is the entropy source data update count obtained after incrementing by 1.

[0177] S312, the number of times the updated entropy source data is updated is less than the second threshold, and the entropy source data processing and evaluation module instructs the first random number acquisition module to acquire physical entropy source data 2.

[0178] For example, if the updated entropy source data can be 1 and the second threshold can be 1, then the number of updates to the updated entropy source data is less than the second threshold.

[0179] Among them, physical entropy source data 2 can be random numbers generated by a hardware-based first random number generator.

[0180] Optionally, the entropy source data processing and evaluation module can call the random number acquisition interface to obtain physical entropy source data 2 from the first random number generator. For example, the entropy source data processing and evaluation module can obtain physical entropy source data 2 through S313 and S314.

[0181] S313, the first random number acquisition module calls the random number acquisition interface to instruct the first random number generator to generate physical entropy source data 2.

[0182] S314, the first random number acquisition module calls the random number acquisition interface to obtain physical entropy source data 2 from the first random number generator.

[0183] S315, the first random number acquisition module instructs the physical entropy source data 2 to the entropy source data processing and evaluation module.

[0184] S316, the entropy source data processing and evaluation module performs data processing 2 on the physical entropy source data 2 to obtain data 2.

[0185] S317, the entropy source data processing and evaluation module calculates the minimum entropy 2 of data 2 and determines whether the minimum entropy 2 is greater than or equal to the first threshold.

[0186] It should be understood that the implementation methods of S316 and S309 are similar, and the implementation methods of S317 and S310 are similar. Please refer to the description above, and it will not be repeated here.

[0187] If the minimum entropy 2 is greater than the first threshold, the entropy source data processing and evaluation module can instruct data 2 to DRNG, and DRNG uses data 2 to determine a random number.

[0188] If the minimum entropy 2 is less than or equal to the first threshold, the electronic device can execute S318 to S326.

[0189] S318, the entropy source data processing and evaluation module increments the entropy source data update count by 1 and determines whether the updated entropy source data update count is greater than or equal to the second threshold.

[0190] It should be understood that the implementation methods of S318 and S311 are similar, and can be referred to the description above, which will not be repeated here.

[0191] For example, if the number of times the updated entropy source data is updated in S311 can be 1, then the number of times the updated entropy source data is updated in S318 can be 2.

[0192] S319, the number of updates to the updated entropy source data is less than the second threshold, and the entropy source data processing and evaluation module instructs the second random number acquisition module to acquire physical entropy source data 1.

[0193] S320, the second random number acquisition module reads new physical entropy source data 1 from shared memory.

[0194] It should be understood that physical entropy source data 1 in shared memory can be updated; therefore, the new physical entropy source data 1 can be different from physical entropy source data 1.

[0195] S321, the second random number acquisition module instructs the new physical entropy source data 1 to the entropy source data processing and evaluation module.

[0196] It should be understood that the implementation methods of S319 to S321 are similar to those of S306 to S308, and can be referred to the description above, which will not be repeated here.

[0197] S322, the entropy source data processing and evaluation module instructs the first random number acquisition module to acquire physical entropy source data 2.

[0198] S323, the first random number acquisition module calls the random number acquisition interface to instruct the first random number generator to generate physical entropy source data 2.

[0199] S324, the first random number acquisition module calls the random number acquisition interface to obtain new physical entropy source data 2 from the first random number generator.

[0200] Among them, the new physical entropy source data 2 can be a new random number generated by the first random number generator. Therefore, the new physical entropy source data 2 can be different from the physical entropy source data 2.

[0201] It should be understood that the implementation methods of S322 to S324 are similar to those of S312 to S314, and can be referred to the description above, which will not be repeated here.

[0202] It should be noted that S319 to S321 and S322 to S324 can be executed in parallel, and this application does not impose specific restrictions on this.

[0203] S325, the entropy source data processing and evaluation module performs mixed processing on the new physical entropy source data 1 and the new physical entropy source data 2 to obtain data 3.

[0204] Optionally, mixed processing includes, but is not limited to, bitwise operations and / or hash calculations.

[0205] This allows for a richer source of data 3, enhanced security, and further improved reliability of the random numbers generated by DRNG.

[0206] S326, the entropy source data processing and evaluation module calculates the minimum entropy 3 of data 3 and determines whether the minimum entropy 3 is greater than or equal to the first threshold.

[0207] It should be understood that the implementation of S326 is similar to that of S310, as described above, and will not be repeated here.

[0208] If the minimum entropy 3 is greater than the first threshold, the electronic device can execute S327 to S329.

[0209] S327, the entropy source data processing and evaluation module resets the number of entropy source data updates.

[0210] It should be understood that resetting the entropy source data update count can refer to resetting the entropy source data update count to its initial value. For example, the entropy source data processing and evaluation module can reset the entropy source data update count to 0, etc. This allows the entropy source data processing and evaluation module to recount when it next determines that the randomness of the physical entropy source data is poor. This facilitates the electronic device in recording the consecutive times that the acquired entropy source data has poor randomness.

[0211] S328, the entropy source data processing and evaluation module instructs data 3 to DRNG.

[0212] S329, DRNG uses data 3 to generate random numbers.

[0213] As an optional embodiment, the second random number generator may further include a state module for recording the state of the second random number generator. When the minimum entropy 3 is less than or equal to the first threshold, the entropy source data processing and evaluation module increments the entropy source data update count by 1 and determines whether the updated entropy source data update count is greater than or equal to the second threshold. If the updated entropy source data update count is greater than or equal to the second threshold, the entropy source data processing and evaluation module may instruct the state module to switch the state of the second random number generator to an error state.

[0214] In this way, random number TA can determine that the second random number generator has failed to generate a random number. Random number TA can instruct the second random number generator to obtain a random number again. Then the second random number generator can be initialized and determine a random number again through method 300.

[0215] Optionally, if the minimum entropy 3 is greater than the first threshold, the entropy source data processing and evaluation module can perform deduplication processing and entropy source health testing on data 3.

[0216] The deduplication process can involve deleting a portion of consecutively repeated length units. For example, a length unit can be one or more bits, one or more bytes, etc. A portion of the length unit can be, for example, the length units other than the first received length unit, according to the chronological order in which the entropy source data processing and evaluation module receives the length units in data 3. For instance, if the length unit is 4 bits and data 3 is 1000100111001100, then data 3 includes four length units: 1000, 1001, 1100, and 1100. Since 1100 and 1100 are consecutively repeated length units, the entropy source data processing and evaluation module can delete one of these length units, for example, deleting the 1100s after the first 1100. Therefore, data 3 after deduplication is 100010011100.

[0217] The deduplication processing can also be the process of deleting a portion of the length units from multiple length units where the number of consecutive repetitions is greater than or equal to a threshold of 1. For example, the threshold of 1 is a preset positive integer, such as 2 or 3. Assuming the threshold of 1 is 3, the length unit is 4 bits, and data 3 is 1100110010001001110011001100. Then data 3 includes 7 length units: 1100, 1100, 1000, 1001, 1100, 1100, and 1100. The first two 1100s have a consecutive repetition count of 2, and the last three 1100s have a consecutive repetition count of 3. The entropy source data processing and evaluation module can then delete 2 or 1 of the last three 1100s, resulting in data 3 as 11001100100010011100.

[0218] Entropy source health testing may include repeat count testing and / or adaptive scaling testing.

[0219] The repetition count test checks whether the maximum number of consecutively repeated bits in data 3 after deleting duplicate data is greater than or equal to threshold 2; if it is determined to be greater than, then data 3 is unreasonable; otherwise, data 3 is determined to be reasonable.

[0220] Threshold 2 is a preset positive number, such as 3 or 5. For example, suppose the data 3 after deleting duplicates is 110001, where 11 is repeated with 2,000 bits, and 3 bits are repeated. Then the maximum number of consecutively repeated bits in the data 3 after deleting duplicates is 3. Assume...

[0221] It should be understood that threshold 2 can be determined based on minimum entropy 3. For example, the larger the minimum entropy 3, the smaller the threshold 2 can be; the smaller the minimum entropy 3, the larger the threshold 2 can be.

[0222] The adaptive ratio test checks whether the number of 0s or 1s in each length unit of data 3 after deleting duplicate data is greater than or equal to threshold 3 and less than or equal to threshold 4. If so, the data 3 after deleting duplicate data is determined to be reasonable; otherwise, the data 3 after deleting duplicate data is determined to be unreasonable.

[0223] Thresholds 3 and 4 are preset positive numbers, with threshold 3 being less than threshold 4. For example, suppose threshold 3 is 400, threshold 4 is 600, and the length unit is 1024 bits. If the entropy source data processing and evaluation module determines that the number of 0s in a length unit is 700, then 700 is greater than threshold 4, and the entropy source data processing and evaluation module can determine that data 3 after deleting duplicate data is unreasonable.

[0224] Through adaptive scaling tests, electronic devices detect whether the distribution of 0s and 1s in data is reasonable. Since for data with high randomness, when the number of bits in the data is sufficiently large, the number of 0s in the data will be close to the number of 1s. Therefore, through adaptive scaling tests, electronic devices can further determine the reasonableness of the data.

[0225] The quality of random numbers generated by electronic devices can be improved by deduplicating data and performing entropy source health tests.

[0226] Optionally, if the entropy source data processing and evaluation module determines that data 3 after deduplication is reasonable through entropy source health testing, the module can compress the deduplicated data 3 to obtain compressed data; and transmit the compressed data to the DRNG, which uses the compressed data to generate random numbers. The compressed data can also be understood as a random number seed.

[0227] If the entropy source data processing and evaluation module determines through the entropy source health test that data 3 after deleting duplicate data is unreasonable, the entropy source data processing and evaluation module can instruct the first data acquisition module and / or the second data acquisition module to reacquire the entropy source data. For example, it can execute steps S311 to S317.

[0228] It should be noted that if other modules in the TEE II instruct the random number generator (TA) to generate random numbers, the random number generator (TA) can trigger the DRNG to generate random numbers, i.e., trigger S305 in method 300. For example, if an electronic device needs to use a payment TA in the TEE II to sign data obtained from the REE for authentication, and the payment TA needs to use random numbers during the signing process, then the payment TA can instruct the random number generator (TA) to generate random numbers. Alternatively, if the REE needs to use random numbers to encrypt plaintext or decrypt ciphertext, the random number generator (CA) in the REE can instruct the random number generator (TA) to generate random numbers. In this case, the random number generator (TA) can trigger the DRNG to generate random numbers, i.e., trigger S305 in method 300. Afterwards, the random number generator (TA) can instruct the random number generator (CA) to instruct the random number generator (CA). This application does not specifically limit this.

[0229] It should also be noted that in method 300, the method of determining random numbers is illustrated by taking the example of the entropy source data processing and evaluation module first obtaining physical entropy source data 1, and then obtaining physical entropy source data 2 when the randomness of physical entropy source data 1 is poor; then obtaining new physical entropy source data 1 and new physical entropy source data 2 when the randomness of physical entropy source data 2 is poor, and using the new physical entropy source data 1 and new physical entropy source data 2 to determine random numbers.

[0230] In some possible implementations, the entropy source data processing and evaluation module may first obtain physical entropy source data 2 from the first random number acquisition module, and then obtain physical entropy source data 1 if the randomness of physical entropy source data 2 is poor; alternatively, the entropy source data processing and evaluation module may obtain physical entropy source data 2 from the first random number acquisition module and obtain physical entropy source data 1 from the second random number acquisition module, that is, the entropy source data processing and evaluation module mixes physical entropy source data 2 and physical entropy source data 1, and uses the mixed data to determine a random number if the randomness of the mixed data is high; alternatively, the entropy source data processing and evaluation module may obtain physical entropy source data 2 and a new physical entropy source data 1 if the randomness of physical entropy source data 1 is determined to be poor. Regardless of the order in which the entropy source data processing and evaluation module obtains the physical entropy source data, its implementation is similar to that of method 300, as described above, and will not be listed here.

[0231] Furthermore, Method 300 illustrates a random number generation method using electronic devices including TEE I, TEE II, and REE as examples.

[0232] In some possible implementations, the electronic device may also include more TEEs. For example, Figure 4 A schematic diagram of the random number generation method 400 is shown. For example... Figure 4 As shown, assume that the electronic device includes REE, TEE 1, TEE 2 and REE 3.

[0233] TEE 1 and / or TEE 2 can be implemented by the chip manufacturer based on TrustZone technology, or they can run on a separate security processor or virtual machine. TEE 1 includes a random number acquisition interface 1 and a hardware-based random number generator 1, and TEE 2 includes a random number acquisition interface 2 and a hardware-based random number generator 2.

[0234] TEE 3 can be built on a virtual machine, and TEE 3 includes a random number generator TA, which includes a software-based random number generator 3.

[0235] The REE includes a random number CA and first hardware capable of providing physical entropy source data A. The first hardware may be one or more sensors, timers, or system clocks. The sensors may be one or more sensors in sensor module 180. Physical entropy source data A can be understood as physical entropy source data 1 mentioned above.

[0236] In REE, the random number TA can obtain the physical entropy source data A from the first hardware and write the physical entropy source data A into shared memory.

[0237] In TEE3, when the DRNG instructs the entropy source data processing and evaluation module to acquire entropy source data, the entropy source data processing and evaluation module can perform one or more of the following: the second data acquisition module acquires physical entropy source data A from shared memory; the first data acquisition module calls random number acquisition interface 1 to acquire random number 1 from random number generator 1; or, the first data acquisition module calls random number acquisition interface 2 to acquire random number 2 from random number generator 2. This results in the acquisition of entropy source data.

[0238] Optionally, the first data acquisition module may include a third data acquisition module and a fourth data acquisition module. The third data acquisition module may be used to call random number acquisition interface 1 to obtain random number 1 from random number generator 1; the fourth data acquisition module may call random number acquisition interface 2 to obtain random number 2 from random number generator 2.

[0239] Subsequently, the entropy source data processing and evaluation module can perform data processing and / or mixing processing on the entropy source data to obtain data 4. Then, the entropy source data processing and evaluation module can calculate the minimum entropy 4 of data 4. If the minimum entropy 4 is greater than or equal to a first threshold, the entropy source data processing and evaluation module can indicate data 4 to the DRNG so that the DRNG can use data 4 to determine a random number. The entropy source data may include one or more of the following: physical entropy source data A, random number 1, or random number 2.

[0240] Optionally, if the minimum entropy 4 is less than the first threshold, the entropy source data processing and evaluation module can reacquire the entropy source data.

[0241] It should be understood that Figure 4 The implementation of method 400 is similar to that of method 300, as shown in the description above, and will not be repeated here.

[0242] In other possible implementations, the electronic device may also include more TEEs. For example, Figure 5 A schematic diagram of the random number generation method 500 is shown. For example... Figure 5 As shown, assume that the electronic device includes REE, TEE A, TEE B and REE C.

[0243] TEE A and TEE B are similar to TEE II in method 300 or TEE3 in method 400. That is, TEE A and TEE B can be built on a virtual machine. TEE A includes a first random number generator (TA) module, which includes a software-based random number generator A. TEE B includes a second random number generator (TA) module, which includes a software-based random number generator B.

[0244] TEE C is similar to TEE I in method 300 or TEE1 or TEE2 in method 400. That is, TEE C can be implemented by the chip manufacturer based on TrustZone technology. And TEE C includes a hardware-based random number generator C.

[0245] In REE, the random number TA can obtain the physical entropy source data A from the first hardware and write the physical entropy source data A into shared memory.

[0246] In TEE A, random number generator A can obtain physical entropy source data A from shared memory and / or call random number acquisition interface C to obtain random numbers from random number generator C.

[0247] In TEE B, random number generator B can obtain physical entropy source data B from shared memory and / or call random number acquisition interface C to obtain random numbers from random number generator C.

[0248] It should be understood that the process by which random number generator A and random number generator B determine random numbers is similar to that of method 400 or method 300, as described above, and will not be repeated here.

[0249] Optionally, the shared memory may also include shared memory 1 and shared memory 2, and the random number CA may write the physical entropy source data A to shared memory 1 and shared memory 2 respectively. Random number generator A can obtain the physical entropy source data A from shared memory 1, and random number generator B can obtain the physical entropy source data A from shared memory 2. In this way, the random number CA can write different physical entropy source data to shared memory 1 and shared memory 2 according to the instructions of the first random number TA or the second random number TA, which helps to meet the needs of the first random number TA or the second random number TA.

[0250] It should also be noted that the number of TEEs included in the electronic device architecture can be even greater. The methods for determining random numbers in electronic devices are similar to those in Method 300, Method 400, or Method 500, as described above, and will not be repeated here.

[0251] Below, in conjunction with Figure 6 The process of generating random numbers using a software-based random number generator is explained.

[0252] Figure 6 This is a schematic diagram illustrating the process of a random number generation method 600 provided in an embodiment of this application. Method 600 can be executed by an electronic device, and the hardware structure of the electronic device can be as follows: Figure 1 As shown, the software architecture can be as follows: Figure 2 , Figure 4 or Figure 5As shown, the electronic device includes a software-based random number generator, which includes a first data acquisition module, a second data acquisition module, an entropy source data processing and evaluation module, a DRNG, and a status module.

[0253] Process 1: Obtain entropy source data, i.e., the first data acquisition module obtains physical entropy source data from the REE and / or the second data acquisition module obtains random numbers from a hardware-based random number generator. The entropy source data includes physical entropy source data obtained from the REE and / or random numbers obtained from the hardware-based random number generator.

[0254] Optionally, the acquisition of entropy source data can be implemented in the following ways: the DRNG or entropy source data processing and evaluation module can instruct the first data module to acquire physical entropy source data from the REE and / or instruct the second data acquisition module to acquire random numbers from a hardware-based random number generator.

[0255] Step 2: The entropy source data processing and evaluation module first processes the entropy source data to obtain processed data. Specifically, if the entropy source data is physical entropy source data obtained from the REE, then data processing 1 can be performed; if the entropy source data is random numbers obtained from a hardware-based random number generator, then data processing 2 can be performed; if the entropy source data is a mixture of physical entropy source data obtained from the REE and random numbers obtained from a hardware-based random number generator, then the entropy source data can be processed in a mixed manner.

[0256] It should be understood that the process of processing the entropy source data is similar to the process of processing physical entropy source data 1 and / or physical entropy source data 2 in method 300, as described above, and will not be repeated here.

[0257] Process 3: Entropy Source Data Processing and Evaluation Module - Minimum Entropy of Data After Bitwise Operations.

[0258] Process 4: The entropy source data processing and evaluation module determines whether the minimum entropy is greater than or equal to the first threshold.

[0259] If the minimum entropy is greater than or equal to the first threshold, the entropy source data processing and evaluation module can output entropy, that is, compress the processed data and transmit the compressed and processed data to DRNG.

[0260] Optionally, before the entropy source data processing and evaluation module outputs entropy, the processed data can be deduplicated and the entropy source health test can be performed.

[0261] The deduplication process and entropy source health test can be found in the description of Method 300, and will not be repeated here.

[0262] If the minimum entropy is less than the first threshold, the entropy source data processing and evaluation module updates the number of entropy source data updates and determines whether the updated entropy source data update here is greater than or equal to the second threshold.

[0263] If the updated entropy source data is greater than or equal to the second threshold, the entropy source data processing and evaluation module instructs the status module to set the status of the second random number generator to an error state.

[0264] If the updated entropy source data is less than the second threshold, the entropy source data processing and evaluation module can instruct the first data acquisition module and / or the second data acquisition module to acquire the entropy source data again.

[0265] It should be understood that the source of entropy source data acquired again by the entropy source data processing and evaluation module may differ from the source of entropy source data acquired in process 1. For example, if the entropy source data in process 1 is acquired by the first data acquisition module, then the entropy source data acquired again by the entropy source data processing and evaluation module may be: entropy source data acquired by the second data acquisition module, or entropy source data acquired by both the first and second data acquisition modules. In this way, when the randomness of one type of entropy source data is poor, entropy source data from another source can be used, making it easier to obtain entropy source data with higher randomness, thus helping to improve the randomness and security of random numbers generated using entropy source data.

[0266] Alternatively, the entropy source data acquired again by the entropy source data processing and evaluation module can come from the same source as the entropy source data acquired in process 1. For example, if the entropy source data in process 1 is acquired by both the first and second data acquisition modules, then if the minimum entropy is less than a first threshold and the updated entropy source data is less than a second threshold, the entropy source data processing and evaluation module can instruct both the first and second data acquisition modules to acquire entropy source data again. In this way, the entropy source data processing and evaluation module does not need to switch the source of the entropy source data, but the first and second data acquisition modules can acquire entropy source data different from that in process 1, thereby helping to acquire entropy source data with higher randomness.

[0267] Step 5: DRNG initializes the data obtained after compression and processing as a random number seed.

[0268] Optionally, an initialization function is set in the DRNG. The DRNG calls the initialization function and uses the processed data to assign values ​​to the internal state of the DRNG.

[0269] Step 6: DRNG re-seeds the processed data as the data obtained after compression and processing.

[0270] For example, DRNG can be reseeded periodically, meaning that process 6 and process 5 can be executed in parallel.

[0271] Alternatively, DRNG can utilize SM3 derived functions, such as SM3-df, for initialization and reseeding.

[0272] Step 7: DRNG generates and outputs random numbers.

[0273] For example, a random number output interface can be set up in the DRNG. When a software module outside the DRNG needs to obtain random numbers, it can call the random number output interface to obtain the random numbers generated by the DRNG.

[0274] Optionally, the DRNG may also include a self-test module, which can be used periodically and / or after the electronic device is powered on to perform DRNG testing. DRNG testing can, for example, test whether the random number generation algorithm in the DRNG is functioning correctly. If the random number generation algorithm in the DRNG fails to function correctly, such as failing to generate random numbers, the self-test module can set the DRNG's status to an error state and can indicate this error state to modules outside the DRNG.

[0275] In one possible implementation, before process 2, the entropy source data processing and evaluation module can first calculate the minimum entropy of the entropy source data; if it is determined that the minimum entropy of the entropy source data is less than a first threshold, the number of entropy source data updates is updated; and if it is determined that the number of entropy source data updates after the update is less than a second threshold, the first data acquisition module and / or the second data acquisition module are instructed to acquire the entropy source data again.

[0276] If the minimum entropy of the entropy source data is greater than or equal to the first threshold, the electronic device can execute process 2. In this way, the randomness of the entropy source data can be determined before processing it. If the randomness of the entropy source data is poor, there is no need to process it further, thus reducing the power consumption of the electronic device.

[0277] This application also provides a random number generation method 700. Method 700 can be executed by an electronic device, and the hardware structure of the electronic device can be as follows: Figure 1 As shown, the software architecture can be as follows: Figure 2 As shown. The electronic device includes a REE, a first TEE, and a second TEE.

[0278] Method 700 includes the following steps:

[0279] S701. Transmit the first physical entropy source data in the REE and the first random number in the second TEE to the first TEE. The first physical entropy source data is data generated by the first module and has randomness. The first module includes one or more of the following: system clock, timer or sensor.

[0280] S702. In the first TEE, the first physical entropy source data and the first random number are mixed to obtain the first processed data. The mixing process includes bit operations and / or hash calculations.

[0281] S703. In the first TEE, it is determined that the randomness of the first processed data meets the randomness requirement, and the target random number is generated using the first processed data.

[0282] The first TEE can be, for example, Figure 2 TEE II in the text, the second TEE can be, for example, Figure 2 In TEE I, the first physical entropy source data can be understood as the new physical entropy source data 1 in method 300, and the first random number can be understood as the new physical entropy source data 2 in method 300. The first processed data can be understood as data 3 in method 300, and the target random number can be understood as the random number determined by DRNG in method 300.

[0283] It should be understood that the implementation of S701 is similar to that of S319 to S324 in method 300, the implementation of S702 is similar to that of S325 in method 300, and the implementation of S703 is similar to that of S326 to S329. Please refer to the description above, and it will not be repeated here.

[0284] Alternatively, the first TEE can be, for example, TEE 3 in method 400, and the second TEE can be, for example, TEE 1 and TEE 2 in method 400. Then the first random number includes the random number generated by random number generator 1 and the random number generated by random number generator 2 in method 400.

[0285] Alternatively, the first TEE can be, for example, TEE A and TEE B in method 500, and the second TEE can be, for example, TEE C in method 500. Then the first random number includes the random number generated by random number generator C in method 500.

[0286] It should be noted that the first TEE may include one or more TEEs, and the second TEE may also include one or more TEEs; this application does not impose any specific limitations on this.

[0287] The random number generation method of this application is applied to electronic devices with a multi-TEE architecture. The first TEE in the multi-TEE can obtain physical entropy source data from sensors, system clocks, or timers in the REE, and can also obtain random numbers from the second TEE. The target random number is obtained by using a random number seed determined based on the mixed-processed physical entropy source data and the random numbers. In this way, the source of the random number seed is wide, the data types of physical entropy source data obtained from the REE are diverse, the random numbers obtained from the first TEE have high security, and even if the first module that generates the physical entropy source data fails or the second TEE cannot generate random numbers, the random number seed can still be determined, making the random number generation method highly robust.

[0288] Optionally, prior to S701, the electronic device may also perform the steps in Method 1, Method 2 or Method 3 below.

[0289] Method 1: Before S701, method 700 further includes: transmitting the first data to the first TEE, wherein the first data is the second physical entropy source data in the REE and / or the second random number in the second TEE; determining in the first TEE whether the randomness of the first data meets the randomness requirement; transmitting the first physical entropy source data in the REE and the first random number in the second TEE to the first TEE, including: if it is determined that the randomness of the first data does not meet the randomness requirement, transmitting the first physical entropy source data and the first random number to the first TEE.

[0290] The second physical entropy source data can be different from the first physical entropy source data. That is, the physical entropy source data generated by the first module in the REE can be updated. For example, the first physical entropy source data is the data generated by the first module at the first moment, and the second physical entropy source data is the data generated by the first module at the second moment, where the first moment is later than the second moment. Similarly, the second random number can be different from the first random number.

[0291] In method one, if the randomness of the first data does not meet the randomness requirements, the electronic device can re-obtain physical entropy source data from the REE and re-obtain random numbers from the second TEE. This helps to make the randomness of the random number seed higher and the reliability of the target random number stronger.

[0292] Furthermore, the randomness of the first data is determined before processing it. In this way, if the randomness of the first data does not meet the randomness requirements, the electronic device can choose not to process the first data, thereby reducing the power consumption of the electronic device.

[0293] Method 2, prior to S701, method 700 further includes: transmitting the second data to the first TEE, wherein the second data is the third physical entropy source data in the REE or the third random number in the second TEE; in the first TEE, processing the second data to obtain the second processed data, the data processing including: removing the first part of the numbers in each unit length of the first target data, and / or performing bitwise operations on the second part and the third part of the numbers in each unit length of the second target data; wherein the first target data and the second target data belong to the second data, the unit length is N data storage units, and N is a positive integer; in the first TEE, determining whether the randomness of the second processed data meets the randomness requirement; transmitting the first physical entropy source data in the REE and the first random number in the second TEE to the first TEE, including: if the randomness of the second processed data does not meet the randomness requirement, transmitting the first physical entropy source data and the first random number to the first TEE.

[0294] Compared to Method 1, in Method 2, before S701, the electronic device first obtains the third physical entropy source data from the REE or the third random number from the second TEE. Furthermore, the electronic device processes the second data and then determines the randomness of the processed data (the second processed data). Since data processing by the electronic device may alter the randomness of the data, this method allows the electronic device to determine the randomness of the processed data. Consequently, the electronic device can use the processed data with higher randomness to generate the target random number, thus improving the randomness of the target random number.

[0295] The third physical entropy source data can be different from the first physical entropy source data. For example, the first physical entropy source data is the data generated by the first module at the first moment, and the third physical entropy source data is the data generated by the first module at the third moment, where the first moment is later than the third moment. Similarly, the third random number can be different from the first random number. The third random number can be, for example, physical entropy source data 2 in method 300, and the first random number can be, for example, the new physical entropy source data 2 in method 300.

[0296] The data processing is similar to data processing 1 in method 300. The first target data or the second target data can be all or part of the data in the second data. For example, the second data is data generated by the system clock and data acquired by the accelerometer 180E, and the first target data can be data generated by the system clock. The data storage unit can be, for example, a bit, byte, or word. A bit can also be replaced by a digit. N can be, for example, 8, 10, etc. For each piece of data in the first or second target data, a unit length is formed by numbers in every N data storage units, from the most significant bit to the least significant bit, or from the least significant bit to the most significant bit. For example, for 10001110, if the unit length is 4 bits, then 1000 is one unit length, and 1110 is one unit length. The first part of the numbers can be part or all of the numbers in the unit length. The second or third part of the numbers can be a portion of the numbers in the unit length. For example, the first e% of the numbers in the unit length, the first d numbers in the unit length, the last f numbers in the unit length, etc., in order from the most significant bit to the least significant bit or from the least significant bit to the most significant bit. e is a positive number, and d and f are positive integers.

[0297] It should be understood that the implementation method of Method 2 is similar to that of Method 300, as can be seen in the description above, and will not be repeated here.

[0298] Optionally, the second data is processed to obtain the second processed data, which can be implemented in the following way: in the first TEE, it is determined whether the randomness of the second data meets the randomness requirement; if the randomness of the second data meets the randomness requirement, the second data is processed to obtain the second processed data.

[0299] In this way, the electronic device can first determine the randomness of the second data. If the randomness of the second data does not meet the randomness requirements, the electronic device can choose not to process the second data, thus reducing the power consumption of the electronic device.

[0300] Optionally, if the randomness of the second processed data does not meet the randomness requirement, the first physical entropy source data and the first random number are transmitted to the first TEE. This can be implemented in the following way: if the randomness of the second processed data does not meet the randomness requirement, the first number is updated in the first TEE; if the first number is determined to be less than or equal to a preset number of times, the first physical entropy source data and the first random number are transmitted to the first TEE; after determining that the randomness of the first processed data meets the randomness requirement, method 700 further includes: resetting the first number to the initial value.

[0301] In this way, the electronic device can determine the number of times the processed data determined in the first TEE fails to meet the randomness requirement by counting the first count, and can determine whether the first TEE is in a state where it can normally generate the target random number based on this count. For example, if the electronic device determines that the first count is greater than the preset number, it means that the randomness of the processed data determined by the electronic device multiple times is poor. The electronic device can determine that it cannot normally obtain the target random number at present, and then the electronic device can perform error reporting or initialization operations to facilitate the fault repair of the electronic device.

[0302] The second processed data can be, for example, data 2 from method 300. The first count can be, for example, the number of times the entropy source data is updated, as mentioned above, and the preset count can be, for example, the second threshold mentioned above. The initial value can be, for example, 0, 1, etc.

[0303] It should be understood that the implementation of this embodiment is similar to the implementation of S317 to S327 in method 300 or process 4 in method 600, and can be referred to the above description, which will not be repeated here.

[0304] Method 3, prior to S701, method 700 further includes: transmitting the third data to the first TEE, wherein the third data is the fourth physical entropy source data in the REE and the fourth random number in the second TEE; performing a mixing process on the third data in the first TEE to obtain the third processed data; determining in the first TEE whether the randomness of the third processed data meets the randomness requirement; transmitting the first physical entropy source data in the REE and the first random number in the second TEE to the first TEE, including: if the randomness of the third processed data does not meet the randomness requirement, transmitting the first physical entropy source data and the first random number to the first TEE.

[0305] The fourth physical entropy source data can be different from the first physical entropy source data. For example, the first physical entropy source data is the data generated by the first module at the first moment, and the fourth physical entropy source data is the data generated by the first module at the fourth moment, where the first moment is later than the fourth moment. Similarly, the fourth random number can be different from the first random number. The mixing process is similar to the mixing process in method 300.

[0306] Compared to Method 2, in Method 3, before executing S701, the electronic device first transmits the fourth physical entropy source data and the fourth random number to the first TEE. In this way, the electronic device uses the physical entropy source data obtained from the REE and the random number obtained from the second TEE to determine the random number seed. This ensures that even if the second TEE fails to generate random numbers, or if the timer, system clock, or sensor malfunctions, the electronic device can still generate the random number seed in the first TEE, making this method more robust.

[0307] As an optional embodiment, S703 can be implemented by: calculating a first minimum entropy of the first processed data; and determining that the randomness of the first processed data meets the randomness requirement if the first minimum entropy is greater than or equal to a preset threshold. In this way, the electronic device can determine the randomness of the data through the minimum entropy, making the determination of whether the randomness of the data meets the randomness requirement more efficient.

[0308] The first minimum entropy can be, for example, the minimum entropy 3 in method 300, and the preset threshold can be, for example, the first threshold in method 300.

[0309] It should be noted that in the embodiments of this application, the determination of whether the randomness of the data meets the randomness requirements can be made by judging the minimum entropy of the data and the preset threshold. For the sake of simplicity, the method by which the electronic device judges whether the randomness of other data (such as the first data) meets the randomness requirements will not be described in detail.

[0310] As a first optional embodiment, S703 can be implemented in the following way: performing deduplication processing on the first processed data to obtain deduplication processed data, wherein the deduplication processing involves deleting a portion of the length units among a plurality of length units in which the number of consecutive repetitions is greater than or equal to a first preset threshold, wherein the length unit is M data storage units, and M is a positive integer; and generating a target random number based on the deduplication processed data.

[0311] This reduces the number of repeated length units in the first processed data, making it easier to further improve the randomness of the first processed data, thereby improving the quality of the target random number.

[0312] The data after deletion can be, for example, the data 3 after deleting duplicate data in method 300. The implementation method of deleting duplicate data can be found in the description of method 300, and will not be repeated here.

[0313] In one possible implementation, generating a target random number based on the deleted data includes: performing an entropy source data health test on the deleted data, the entropy source data health test including a duplicate count test and / or an adaptive ratio test; and generating a target random number based on the deleted data if the entropy source data health test determines that the deleted data meets the reasonableness requirements.

[0314] In this way, if the data detected by the entropy source data health test does not meet the reasonableness requirements, the electronic device can reacquire the entropy source data. If the data detected by the entropy source data health test meets the reasonableness requirements, it indicates that the data quality is high and helps to generate high-quality target random numbers.

[0315] The implementation method of the entropy source data health test can be found in the description of method 300. When the entropy source data health test includes a repetition count test, the entropy source data health test detection data meets the reasonableness requirement if the maximum value of the number of consecutively repeated bits in method 300 is less than the threshold 2; the entropy source data health test detection data does not meet the reasonableness requirement if the maximum value of the number of consecutively repeated bits in method 300 is greater than or equal to the threshold 2.

[0316] When the entropy source data health test includes the adaptive scaling test, the entropy source data health test data meets the reasonableness requirement if the number of 0 or 1 in each length unit in method 300 is greater than or equal to threshold 3 and less than or equal to threshold 4; the entropy source data health test data does not meet the reasonableness requirement if the number of 0 or 1 in each length unit in method 300 is less than threshold 3 or greater than threshold 4.

[0317] The entropy source data health test includes adaptive scaling test and adaptive scaling test. For the entropy source data health test to meet the reasonableness requirements, the maximum number of consecutively repeated bits in method 300 must be less than threshold 2, and the number of 0s or 1s in each length unit must be greater than or equal to threshold 3 and less than or equal to threshold 4. Otherwise, the reasonableness requirements are not met.

[0318] In one possible implementation, generating a target random number based on the deleted data can be done by: compressing the deleted data to obtain a random number seed; and then using the random number seed to generate the target random number. Compression reduces the amount of deleted data, ensuring the random number seed's size meets the requirements of a DRG (Depthly Oscillating Generation Group).

[0319] It should be understood that entropy source data health testing can also be performed before deduplication, and its implementation method is similar to that of entropy source data health testing after deduplication. Please refer to the description above, which will not be repeated here.

[0320] As a second optional embodiment, S703 can be implemented in the following manner: performing an entropy source data health test on the first processed data, the entropy source data health test including a repeat count test and / or an adaptive ratio test; and generating a target random number based on the first processed data if the entropy source data health test determines that the first processed data meets the reasonableness requirements.

[0321] Optionally, generating a target random number based on the first processed data can be implemented by: compressing the first processed data to obtain a random number seed; and using the random number seed to generate the target random number.

[0322] Unlike the first optional embodiment, the electronic device can also directly perform entropy source data health testing on the first processed data. The implementation of this embodiment is similar to that of the first embodiment, as described above, and will not be repeated here.

[0323] As an optional embodiment, the second TEE includes a random number generator, and the first random number is generated by the random number generator.

[0324] The random number generator in the second TEE can be, for example, the first random number generator in method 300, random number generator 1 or random number generator 2 in method 400, or random number generator C in method 500. That is, the random number generator in the second TEE can be a hardware-based random number generator, which facilitates efficient acquisition of random numbers from the second TEE.

[0325] As an optional embodiment, the first TEE includes a random number generation module, and the second TEE includes a random number generator; S701 can be implemented in the following ways: obtaining first physical entropy source data from the first module through the random number generation module; obtaining a first random number from the random number generator through the random number generation module.

[0326] The random number generation module can be, for example, the second random number generator, random number generator A, random number generator B, or random number generator 3 mentioned above, and is a software-based random number generator. In this way, the electronic device can obtain the first physical entropy source data and the first random number through the random number generation module. The random number generation module can obtain both widely available first physical entropy source data and highly secure first random numbers, making the target random number determined using the first physical entropy source data and the first random number highly reliable.

[0327] Optionally, the REE includes a first CA; obtaining the first physical entropy source data from the first module through the random number generation module can be implemented in the following way: obtaining the first physical entropy source data through the first CA and writing the first physical entropy source data into shared memory; reading the first physical entropy source data from shared memory through the random number generation module. This facilitates the random number generation module to efficiently obtain the first physical entropy source data.

[0328] It should be understood that the first physical entropy source data can be, for example, the physical entropy source data 1 in method 300. The first CA can be, for example, the random number CA in method 300. The implementation of this embodiment is similar to the implementation of S304 to S307 in method 300, and can be referred to the description above, which will not be repeated here.

[0329] Optionally, obtaining the first physical entropy source data through the first CA includes: instructing the first CA to obtain physical entropy source data through the random number generation module, and obtaining the first physical entropy source data through the first CA; or, the first CA periodically obtains the measurement data of the first module from the first module, the measurement data including the first physical entropy source data.

[0330] It should be understood that the first CA can periodically obtain physical entropy source data from the first module. For example, after the electronic device is powered on, the first CA can periodically obtain physical entropy source data. In this way, the first CA can periodically update the physical entropy source data, and when the random number generation module needs to obtain physical entropy source data, it does not need to instruct the first CA to obtain physical entropy source data, making the random number generation module more efficient in obtaining physical entropy source data. In addition, the first CA can also obtain physical entropy source data from the first module when the random number generation module needs to obtain physical entropy source data, thus reducing the number of times the first CA obtains physical entropy source data from the first module and reducing the power consumption of the electronic device.

[0331] Optionally, the random number generation module includes a data acquisition module and a DRNG; reading the first physical entropy source data from the shared memory through the random number generation module includes: instructing the data acquisition module to acquire the first physical entropy source data through the DRNG; and reading the first physical entropy source data from the shared memory through the data acquisition module.

[0332] The DRNG can be referred to in the description above. Using the above scheme, the data acquisition module can obtain the first physical entropy source data when the DRNG needs to obtain a random number seed.

[0333] It should be understood that the implementation of method 700 is similar to that of method 300, method 400, method 500 or method 600, as described above, and will not be repeated here.

[0334] It should be noted that the module names involved in the embodiments of this application can all be defined as other names, as long as they can achieve the function of each module, and no specific restrictions are placed on the module names.

[0335] It should also be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in the embodiments of this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse.

[0336] The random number generation method of this application has been described above. The apparatus for performing the above method provided in this application is described below. Those skilled in the art will understand that the methods and apparatus can be combined and referenced together, and the related apparatus provided in this application can perform the steps in the above list sorting method.

[0337] Figure 7 This is a schematic block diagram of a random number generation device 700 provided in an embodiment of this application. The device 700 includes a processor 701, a communication interface 702, and a memory 703. The processor 701, communication interface 702, and memory 703 communicate with each other via internal connections. The memory 703 stores instructions, and the processor 701 executes the instructions stored in the memory 703. The communication interface 702 can be used to send signals to other devices (e.g., the processor 701 or a touchscreen of an electronic device) and to receive signals from other devices (e.g., the memory 703). Exemplarily, the communication interface 702 reads instructions stored in the memory 703 and sends the instructions to the processor 701.

[0338] It should be understood that the device 700 may specifically be an electronic device as described in the above embodiments, and may be used to perform the various steps and / or processes corresponding to the electronic device in the above method embodiments. Optionally, the memory 703 may include read-only memory and random access memory, and provide instructions and data to the processor. A portion of the memory may also include non-volatile random access memory. For example, the memory may also store device type information. The processor 701 may be used to execute instructions stored in the memory, and when the processor 701 executes instructions stored in the memory, the processor 701 is used to perform the various steps and / or processes of the above method embodiments.

[0339] It should be understood that, in the embodiments of this application, the processor may be a central processing unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.

[0340] In implementation, each step of the above method can be completed by integrated logic circuits in the processor's hardware or by instructions in software. The steps of the method disclosed in the embodiments of this application can be directly manifested as execution by a hardware processor, or as a combination of hardware and software modules within the processor. The software modules can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. This storage medium is located in memory, and the processor executes the instructions in the memory, combining them with its hardware to complete the steps of the above method. To avoid repetition, detailed descriptions are omitted here.

[0341] The random number generation method provided in this application can be applied to electronic devices with communication functions. Electronic devices include terminal devices, and the specific device form of the terminal device can be referred to the above-mentioned descriptions, which will not be repeated here.

[0342] This application provides a terminal device, which includes a processor and a memory; the memory stores computer execution instructions; the processor executes the computer execution instructions stored in the memory, causing the terminal device to perform the above-described method.

[0343] This application provides a chip. The chip includes a processor, which is used to call a computer program in memory to execute the technical solutions in the above embodiments. Its implementation principle and technical effects are similar to those in the related embodiments described above, and will not be repeated here.

[0344] This application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program. When the computer program is executed by a processor, it implements the methods described above. The methods described in the above embodiments can be implemented wholly or partially by software, hardware, firmware, or any combination thereof. If implemented in software, the functionality can be stored as one or more instructions or code on or transmitted over the computer-readable medium. The computer-readable medium can include computer storage media and communication media, and can also include any medium that can transfer a computer program from one place to another. The storage medium can be any target medium accessible by a computer.

[0345] In one possible implementation, a computer-readable medium may include RAM, ROM, compact disc read-only memory (CD-ROM) or other optical disc storage, disk storage or other magnetic storage devices, or any other medium targeted to carry or to store the required program code in the form of instructions or data structures, and accessible by a computer. Furthermore, any connection is appropriately referred to as a computer-readable medium. For example, if software is transmitted from a website, server, or other remote source using coaxial cable, fiber optic cable, twisted pair, DSL, or wireless technologies such as infrared, radio, and microwave, then coaxial cable, fiber optic cable, twisted pair, DSL, or wireless technologies such as infrared, radio, and microwave are included in the definition of medium. As used herein, disks and optical discs include optical discs, laser discs, optical discs, Digital Versatile Discs (DVDs), floppy disks, and Blu-ray discs, where disks typically reproduce data magnetically, while optical discs optically reproduce data using lasers. Combinations of the above should also be included within the scope of computer-readable media.

[0346] This application provides a computer program product, which includes a computer program that, when run, causes a computer to perform the above-described method.

[0347] This application describes embodiments of methods, apparatus (systems), and computer program products according to embodiments of this application with reference to flowchart illustrations and / or block diagrams. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processing unit of a general-purpose computer, special-purpose computer, embedded processor, or other programmable device to produce a machine, such that the instructions, which execute via the processing unit of the computer or other programmable data processing device, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0348] The above specific embodiments further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made on the basis of the technical solution of the present invention should be included within the scope of protection of the present invention.

Claims

1. A method for generating random numbers, characterized in that, Applied to an electronic device, the electronic device including a general-purpose runtime environment (REE), a first trusted execution environment (TEE), and a second TEE, the method includes: The first physical entropy source data in the REE and the first random number in the second TEE are transmitted to the first TEE. The first physical entropy source data is data generated by the first module and the first physical entropy source data has randomness. The first module includes one or more of the following: system clock, timer or sensor. In the first TEE, the first physical entropy source data and the first random number are mixed to obtain the first processed data. The mixing process includes bit operations and / or hash calculations. In the first TEE, it is determined that the randomness of the first processed data meets the randomness requirement, and the target random number is generated using the first processed data.

2. The method according to claim 1, characterized in that, The method further includes: The first data is transmitted to the first TEE, where the first data is the second physical entropy source data in the REE and / or the second random number in the second TEE; In the first TEE, it is determined whether the randomness of the first data meets the randomness requirement; The step of transmitting the first physical entropy source data in the REE and the first random number in the second TEE to the first TEE includes: If it is determined that the randomness of the first data does not meet the randomness requirement, the first physical entropy source data and the first random number are transmitted to the first TEE.

3. The method according to claim 1, characterized in that, The method further includes: The second data is transmitted to the first TEE, where the second data is the third physical entropy source data in the REE or the third random number in the second TEE; In the first TEE, the second data is processed to obtain the second processed data. The data processing includes: removing the first part of the numbers in each unit length of the first target data, and / or performing bitwise operations on the second part and the third part of the numbers in each unit length of the second target data. The first target data and the second target data belong to the second data. The unit length is N data storage units, where N is a positive integer. In the first TEE, it is determined whether the randomness of the second processed data meets the randomness requirement; The step of transmitting the first physical entropy source data in the REE and the first random number in the second TEE to the first TEE includes: If the randomness of the data after the second processing does not meet the randomness requirement, the first physical entropy source data and the first random number are transmitted to the first TEE.

4. The method according to claim 3, characterized in that, The process of processing the second data to obtain the second processed data includes: In the first TEE, it is determined whether the randomness of the second data meets the randomness requirement; If the randomness of the second data satisfies the randomness requirement, the second data is processed to obtain the second processed data.

5. The method according to claim 3 or 4, characterized in that, When the randomness of the data after the second processing does not meet the randomness requirement, transmitting the first physical entropy source data and the first random number to the first TEE includes: If the randomness of the data after the second processing does not meet the randomness requirement, the first number is updated in the first TEE; If it is determined that the first number of times is less than or equal to the preset number of times, the first physical entropy source data and the first random number are transmitted to the first TEE; After determining that the randomness of the first processed data meets the randomness requirement, the method further includes: Reset the first count to the initial value.

6. The method according to claim 1, characterized in that, The method further includes: The third data is transmitted to the first TEE, wherein the third data is the fourth physical entropy source data in the REE and the fourth random number in the second TEE; In the first TEE, the third data is subjected to the mixing process to obtain the third processed data; In the first TEE, it is determined whether the randomness of the third-processed data meets the randomness requirement; The step of transmitting the first physical entropy source data in the REE and the first random number in the second TEE to the first TEE includes: If the randomness of the data after the third processing does not meet the randomness requirement, the first physical entropy source data and the first random number are transmitted to the first TEE.

7. The method according to any one of claims 1 to 4, characterized in that, The determination that the randomness of the first processed data meets the randomness requirement includes: Calculate the first minimum entropy of the first processed data; If the first minimum entropy is greater than or equal to a preset threshold, it is determined that the randomness of the first processed data meets the randomness requirement.

8. The method according to any one of claims 1 to 4, characterized in that, The step of generating a target random number using the first processed data includes: The first processed data is subjected to an entropy source data health test, which includes a repeat count test and / or an adaptive ratio test. If the entropy source data health test determines that the first processed data meets the reasonableness requirements, the first processed data is used to generate a target random number.

9. The method according to any one of claims 1 to 4, characterized in that, The step of generating a target random number using the first processed data includes: The first processed data is subjected to deduplication processing to obtain deduplicated data. The deduplication processing involves deleting a portion of the length units from a plurality of length units in which the number of consecutive repetitions is greater than or equal to a first preset threshold. The length unit is M data storage units, where M is a positive integer. A target random number is generated based on the data after the deletion process.

10. The method according to claim 9, characterized in that, The generation of the target random number based on the data after deletion includes: The deleted data is compressed to obtain a random number seed; The target random number is generated using the random number seed.

11. The method according to any one of claims 1 to 4, characterized in that, The second TEE includes a random number generator, and the first random number is generated by the random number generator.

12. The method according to any one of claims 1 to 4, characterized in that, The first TEE includes a random number generation module, and the second TEE includes a random number generator; The step of transmitting the first physical entropy source data in the REE and the first random number in the second TEE to the first TEE includes: The first physical entropy source data is obtained from the first module through the random number generation module; The first random number is obtained from the random number generator through the random number generation module.

13. The method according to claim 12, characterized in that, The REE includes a first client application, CA. The step of obtaining the first physical entropy source data from the first module through the random number generation module includes: The first physical entropy source data is obtained through the first CA, and the first physical entropy source data is written into shared memory; The first physical entropy source data is read from the shared memory using the random number generation module.

14. The method according to claim 13, characterized in that, The step of obtaining the first physical entropy source data through the first CA includes: The random number generation module instructs the first CA to obtain physical entropy source data, and the first CA obtains the first physical entropy source data; or... The first CA periodically obtains measurement data from the first module, and the measurement data includes the first physical entropy source data.

15. The method according to claim 13 or 14, characterized in that, The random number generation module includes a data acquisition module and a deterministic random number generator (DRNG). The step of reading the first physical entropy source data from the shared memory through the random number generation module includes: The DRNG instructs the data acquisition module to acquire the first physical entropy source data. The data acquisition module reads the first physical entropy source data from the shared memory.

16. An electronic device, characterized in that, The electronic device includes: one or more processors and memory; The memory is coupled to the one or more processors, the memory being used to store computer program code, the computer program code including computer instructions, the one or more processors invoking the computer instructions to cause the electronic device to perform the method as described in any one of claims 1 to 15.

17. A chip system, characterized in that, The chip system is applied to an electronic device, the chip system including one or more processors, the one or more processors being used to invoke computer instructions to cause the electronic device to perform the method as described in any one of claims 1 to 15.

18. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes computer instructions that, when executed on an electronic device, cause the electronic device to perform the method as described in any one of claims 1 to 15.

19. A computer program product, characterized in that, The computer program product includes computer program code that, when run on an electronic device, causes the electronic device to perform the method as described in any one of claims 1 to 15.

Citation Information

Patent Citations

  • Random number generation device

    JP2003131867A

  • Method of real-time high-speed quantum random number generation based on chaos amplifying quantum noise

    US20210385064A1