Software random number generation method and device, equipment and storage medium

By combining the count value and model update time to determine whether the software random number generation model is updated, the entropy source and operating system status information are used to generate high-quality random numbers, which solves the problems of random number repetition and insufficient security in the existing technology, and improves the system Security.

CN119148981APending Publication Date: 2024-12-17CETC CYBERSPACE SECURITY TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411346749.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-26
Publication Date
2024-12-17

AI Technical Summary

Technical Problem

In the existing software random number generation method, multiple executions of the program may generate the same random number, which reduces the system security. Commonly used methods obtain random values ​​from runtime, CPU information, etc. through simple algorithms, resulting in insufficient system security.

Method used

By combining multiple state variables, including the current count value and the last model update time, we can determine whether the update conditions of the initial model are met. If so, randomly select the entropy source and operating system status information from the preset entropy pool to update the model to generate a random If the number is not satisfied, a random number will be generated based on the initial model.

Benefits of technology

It improves the quality of generating random numbers, enhances system security, avoids the problem of random number duplication, and can generate different random numbers through counting values ​​when the model is not required.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119148981A_ABST
    Figure CN119148981A_ABST
Patent Text Reader

Abstract

The invention discloses a software random number generation method and device, equipment and a storage medium, and relates to the technical field of information security, and the method comprises the following steps: judging whether an updating condition of an initial model is met or not according to a current count value and last model updating time; the current count value is used for representing the number of the historically generated random numbers; the initial model is a model used for generating random numbers; if the current condition meets the updating condition, randomly selecting an entropy source from a preset entropy pool to obtain a current entropy, and determining a current random factor of the operating system according to the state information of the operating system, so as to update the initial model by using the current entropy and the current random factor to obtain an updated model, so as to generate a current random number by using the updated model; and if the updating condition is not met currently, generating the current random number by using the initial model based on the current count value. In this way, the quality of the generated random number can be improved by combining a plurality of state variables.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of information security technology, and in particular to a software random number generation method, device, equipment and storage medium. Background Art

[0002] Random number generation methods can be divided into hardware random number generation and software random number generation. Software random number generation methods have the advantages of fast speed, low cost, and easy integration. They can better adapt to application scenarios such as mobile Internet, Internet of Things, and Internet of Vehicles. Software random numbers are increasingly widely used. Operating systems such as Windows, Linux, and Android, as well as some open source software, all provide software-based random number generation methods. However, the commonly used random number generation method uses the program running time as the seed. Multiple executions of the program may generate the same random number, thereby reducing the security of the system; some random number generation methods can restore random values ​​by obtaining running timestamps, CPU (Central Processing Unit) information, memory information, etc., and adding simple algorithms, thereby reducing the security of the system.

[0003] It can be seen that how to improve the quality of generated random numbers is a problem to be solved in this field. Summary of the invention

[0004] In view of this, the purpose of the present invention is to provide a software random number generation method, device, equipment and storage medium, which can improve the quality of the generated random numbers by combining multiple state variables. The specific scheme is as follows:

[0005] In a first aspect, the present application provides a software random number generation method, comprising:

[0006] Determine whether the update condition of the initial model is met according to the current count value and the last model update time; the current count value is used to characterize the number of random numbers generated historically; the initial model is a model for generating random numbers;

[0007] If the update condition is currently met, an entropy source is randomly selected from a preset entropy pool to obtain current entropy, and a current random factor of the operating system is determined according to the state information of the operating system, so as to update the initial model using the current entropy and the current random factor to obtain an updated model, so as to generate a current random number using the updated model;

[0008] If the update condition is not currently met, a current random number is generated based on the current count value and using the initial model.

[0009] Optionally, judging whether the update condition of the initial model is currently met according to the current count value and the last model update time includes:

[0010] Determine whether the current count value is not less than a preset numerical threshold, and determine whether the time difference between the last model update time and the current time is not less than a preset time threshold;

[0011] If the current count value is less than the preset value threshold, and the time difference is less than the preset time threshold, it is determined that the update condition is not met at present;

[0012] If the current count value is not less than the preset value threshold and / or the time difference is not less than the preset time threshold, it is determined that the update condition is currently met.

[0013] Optionally, randomly selecting an entropy source from a preset entropy pool to obtain current entropy includes:

[0014] Randomly select an entropy source data from a preset entropy pool, and calculate a number of entropies in the preset entropy pool to obtain a minimum entropy;

[0015] Based on a preset length calculation formula, the entropy length of the current entropy is obtained by using the size of the entropy source data and the minimum entropy calculation;

[0016] Determine the size of the entropy source data and the numerical sum of the entropy length, and construct a Toeplitz matrix based on the numerical sum using a corresponding number of random bit seeds;

[0017] The entropy source data is multiplied by the Toeplitz matrix to obtain a current entropy matching the entropy length.

[0018] Optionally, determining the current random factor of the operating system according to the state information of the operating system includes:

[0019] Get some status information of the operating system;

[0020] The plurality of status information are concatenated in a character string to obtain a current random factor of the operating system.

[0021] Optionally, the updating the initial model by using the current entropy and the current random factor to obtain an updated model includes:

[0022] The current entropy, the current random factor, the current count value and the last model update time are concatenated, and the concatenated data is processed based on a preset block encryption algorithm to obtain processed information;

[0023] According to a preset interception quantity, data of a corresponding number of bytes before the processed information is intercepted to obtain an intermediate result;

[0024] The current entropy, the current random factor and the intermediate result are used to update the relevant parameters in the initial model to obtain a corresponding updated model.

[0025] Optionally, the generating a current random number using the updated model includes:

[0026] A hash operation is performed on the intermediate result to generate a current random number.

[0027] Optionally, the generating a current random number based on the current count value and using the initial model includes:

[0028] Using the current count value to update the intermediate result of the initial model to obtain a new intermediate result;

[0029] A hash operation is performed on the new intermediate result to generate a current random number.

[0030] In a second aspect, the present application provides a software random number generation device, comprising:

[0031] An update condition judgment module is used to judge whether the update condition of the initial model is met according to the current count value and the last model update time; the current count value is used to characterize the number of random numbers generated historically; the initial model is used to generate a model for random numbers;

[0032] A first random number generation module is used to randomly select an entropy source from a preset entropy pool to obtain current entropy if the update condition is currently met, and determine a current random factor of the operating system according to the state information of the operating system, so as to update the initial model using the current entropy and the current random factor to obtain an updated model, so as to generate a current random number using the updated model;

[0033] The second random number generation module is used to generate a current random number based on the current count value and using the initial model if the update condition is not currently met.

[0034] In a third aspect, the present application provides an electronic device, including:

[0035] Memory, used to store computer programs;

[0036] A processor is used to execute the computer program to implement the software random number generation method as described above.

[0037] In a fourth aspect, the present application provides a computer-readable storage medium for storing a computer program, wherein the computer program, when executed by a processor, implements the software random number generation method as described above.

[0038] It can be seen that the present application first determines whether the update condition of the initial model is met according to the current count value and the last model update time; the current count value is used to characterize the number of random numbers generated historically; the initial model is used to generate a model of random numbers; further, if the update condition is currently met, an entropy source is randomly selected from the preset entropy pool to obtain the current entropy, and the current random factor of the operating system is determined according to the state information of the operating system, so as to update the initial model using the current entropy and the current random factor to obtain an updated model, so as to generate the current random number using the updated model; correspondingly, if the update condition is not met at present, the current random number is generated based on the current count value and using the initial model. In this way, the present application can combine entropy, the random factor of the system, the count value of random number generation, and the update time of the initial model used to generate random numbers to determine whether the initial model can be used to generate random numbers; when the model needs to be updated, the entropy and random factor can be re-acquired to update the initial model, and the updated model can be used to generate random numbers; the quality of the generated random numbers can be improved by combining multiple state variables. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0040] Figure 1 A flowchart of a software random number generation method disclosed in this application;

[0041] Figure 2 A flowchart of a specific software random number generation method disclosed in this application;

[0042] Figure 3 This is a flow chart of another specific software random number generation method disclosed in this application;

[0043] Figure 4 This is a schematic diagram of the structure of a software random number generation device disclosed in this application;

[0044] Figure 5 This is a structural diagram of an electronic device disclosed in this application. DETAILED DESCRIPTION

[0045] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0046] See also Figure 1 As shown, an embodiment of the present invention discloses a software random number generation method, comprising:

[0047] Step S11, judging whether the update condition of the initial model is currently met according to the current count value and the last model update time; the current count value is used to characterize the number of random numbers generated historically; the initial model is a model for generating random numbers.

[0048] In the present application, the number of random numbers generated historically can be counted to obtain the current count value, and the time of initialization or last update of the initial model used to generate random numbers can be recorded; when it is necessary to generate random numbers, first determine whether the model update condition is currently met based on the current count value and the last model update time. In a specific embodiment, the determination of whether the initial model update condition is currently met based on the current count value and the last model update time can include: determining whether the current count value is not less than a preset numerical threshold, and determining whether the time difference between the last model update time and the current time is not less than a preset time threshold; if the current count value is less than the preset numerical threshold, and the time difference is less than the preset time threshold, it is determined that the update condition is not currently met; if the current count value is not less than the preset numerical threshold and / or the time difference is not less than the preset time threshold, it is determined that the update condition is currently met. Specifically, the relationship between the current count value and the corresponding preset numerical threshold value, as well as the relationship between the time difference between the current moment and the last model update time and the preset time threshold value can be determined; further, if the time difference between the current count value and the model update is less than the preset numerical threshold value and the preset time threshold value, then the current initial model does not need to be updated, that is, the update condition is not met; correspondingly, if any of the time difference between the current count value and the model update is not less than the corresponding threshold value, then the current initial model needs to be updated, that is, the update condition is met. For example, the model used to generate random numbers can be updated after every 100 random numbers are generated and every 60 seconds. The quality of the final generated random numbers can be improved through the update conditions of these two dimensions.

[0049] Step S12: If the update condition is currently met, an entropy source is randomly selected from a preset entropy pool to obtain a current entropy, and a current random factor of the operating system is determined according to the state information of the operating system, so as to update the initial model using the current entropy and the current random factor to obtain an updated model, so as to generate a current random number using the updated model.

[0050] In this application, the above steps can be used to determine whether the initial model used to generate random numbers needs to be updated. If the update conditions for the initial model are currently met, an entropy source data can be randomly selected from the preset entropy pool to obtain the current entropy; and the current random factor of the operating system can be determined based on the current operating system state information; in this way, the initial model that needs to be updated can be updated using the current entropy and current random factor to obtain the corresponding updated model. Further, the updated model can be used to generate the current random number later.

[0051] In a specific embodiment, the process of randomly selecting an entropy source from a preset entropy pool to obtain the current entropy may include: randomly selecting an entropy source data from the preset entropy pool, and calculating several entropies in the preset entropy pool to obtain the minimum entropy; based on a preset length calculation formula, the entropy length of the current entropy is calculated using the size of the entropy source data and the minimum entropy; determining the size of the entropy source data and the numerical sum of the entropy length, and constructing a Toeplitz matrix based on the numerical sum using a corresponding number of random bit seeds; multiplying the entropy source data with the Toeplitz matrix to obtain the current entropy matching the entropy length. Specifically, in the process of obtaining the current entropy, the quality of the entropy source data randomly selected from the preset entropy pool can be improved; in the process of quality improvement, the minimum entropy is first calculated from the preset entropy pool; then based on the preset length calculation formula, the size of the randomly selected entropy source data and the minimum entropy are used to calculate the final entropy length of the current entropy. For example, if the minimum entropy is x, the randomly selected entropy source data of size n, and the security parameter is ε, the output length can be determined to be:

[0052] ;

[0053] Furthermore, the size of the entropy source data and the numerical sum of the entropy length can be determined, which can be n+m-1; a Toeplitz matrix is ​​constructed using a random bit seed with n+m-1; and then a random bit string of length m is obtained by multiplying the entropy source data with the Toeplitz matrix to form high-quality entropy (entropyProcessed), which is the current entropy after the final quality improvement. It should be pointed out that the Toeplitz matrix is ​​a special banded matrix, and the elements on the same diagonal are equal, as shown below:

[0054] ;

[0055] Among them, the Toeplitz matrix has only When generating or storing a Toeplitz matrix, you need to generate or store the first column and the first row. .

[0056] In another specific embodiment, the determining the current random factor of the operating system according to the state information of the operating system may include: obtaining several state information of the operating system; splicing the several state information in the form of a character string to obtain the current random factor of the operating system. Specifically, in the process of determining the current random factor of the operating system, firstly obtain several state information of the operating system; such as the system interrupt number (signalNumber), CPU information (cpuInfo), memory information (memInfo), hard disk read and write status (diskInfo), network connection information (networkInfo), input and output information (ioInfo), sensor information (sensorInfo), etc.; then these state information may be spliced ​​in the form of a character string to obtain the system random factor, that is, the current random factor; for example, when "||" is used to represent data splicing, the current random factor of the current operating system systemRandomFator = (signalNumber || cpuInfo || memInfo || diskInfo || networkInfo || ioInfo || sensorInfo).

[0057] In a specific embodiment, the use of the current entropy and the current random factor to update the initial model to obtain an updated model may include: splicing the current entropy, the current random factor, the current count value and the last model update time, and processing the spliced ​​data based on a preset group encryption algorithm to obtain processed information; intercepting a corresponding number of bytes of data before the processed information according to a preset interception quantity to obtain an intermediate result; and using the current entropy, the current random factor and the intermediate result to update relevant parameters in the initial model to obtain a corresponding updated model. Specifically, in the process of updating the initial model for generating random numbers, the current entropy, the current random factor, the current count value and the last model update time can be spliced ​​to obtain the spliced ​​data; then the spliced ​​data is processed based on the preset block encryption algorithm to obtain the processed information; further, the processed information is intercepted, and the first several numbers of direct data in the processed information are intercepted according to the preset interception number to obtain the intermediate result; it should be pointed out that the initial model is updated by using the current entropy, the current random factor, the current count value and the last model update time, and the intermediate result is used to update the relevant parameters in the initial model to obtain the updated model. It should be pointed out that the block encryption algorithm used in this application can include SM4 (a block cipher algorithm issued by the Cryptography Bureau), ZUC (a word-oriented stream encryption), AES (Advanced Encryption Standard), 3DES (Triple Data Encryption Algorithm), etc.

[0058] In another specific embodiment, the generation of the current random number using the updated model may include: performing a hash operation on the intermediate result to generate the current random number. Specifically, the process of generating the current random number using the updated model is to perform a hash operation on the intermediate result in the model to obtain a random bit string, that is, to obtain the current random number. It should be noted that the hash algorithm may include SM3 (a commercial cryptographic hash algorithm issued by the Cryptography Bureau), SHA256 / 224 / 384 / 512 (Secure Hash Algorithm), etc.

[0059] Step S13: If the update condition is not currently met, a current random number is generated based on the current count value and using the initial model.

[0060] Furthermore, if it is determined through the above steps that the update condition of the initial model is not met at present, the current random number can be generated by the current count value through the initial model. In a specific embodiment, the current random number generated based on the current count value and using the initial model may include: updating the intermediate result of the initial model using the current count value to obtain a new intermediate result; performing a hash operation on the new intermediate result to generate the current random number. Specifically, in the process of generating the current random number using the current count value in the initial model, the intermediate result of the initial model is updated using the current count value to obtain a new intermediate result; and then a hash operation is performed on the new intermediate result to obtain the current random number. It can be understood that since the intermediate result is calculated based on multiple parameters, different random numbers can be obtained through the initial model using only the changed current count value without updating the model.

[0061] It can be seen that the present application can combine entropy, the random factor of the system, the count value of random number generation, and the update time of the initial model used to generate random numbers to determine whether the initial model can be used to generate random numbers; when the model does not need to be updated, the parameters in the model can also be changed only according to the count value of the random number, and the final random number can be obtained through further hashing operations. Correspondingly, when the model needs to be updated, the entropy and random factor can be re-acquired to update the initial model, and the updated model can be used to generate random numbers; multiple state variables can be combined to improve the quality of the generated random numbers.

[0062] like Figure 2 As shown, the embodiment of the present application discloses a software random number generation method, including:

[0063] In this embodiment, it can be divided into an entropy source quality improvement module, a system random factor acquisition module, and an uncertain state transition model (a model for generating random numbers, which is first initialized when used, and then maintained according to update conditions). Specifically, when initializing the model for generating random numbers, an entropy source is first randomly selected from the entropy pool, and the quality of the entropy source is improved by the entropy source quality improvement module using a post-processing algorithm. Specifically, the entropy of the input entropy source or the entropy in the entropy pool is evaluated, and the minimum entropy is calculated. The minimum entropy calculation method is as follows:

[0064] ;

[0065] x represents an element of the binary data distribution X, n represents the number of binary digits of the element in X, represents the probability of element x in X. Minimum entropy is the quantization x∈{0,1} nThe randomness of the probability distribution above. According to the minimum entropy x, given the entropy source data of size n, and the security parameter ε, the entropy length of the final current entropy can be determined; further, the Toeplitz matrix can be constructed based on the entropy length, and the randomly selected entropy source data can be multiplied with the Toeplitz matrix to obtain a random bit string of the same length as the entropy length, that is, the final current entropy.

[0066] Correspondingly, the system random factor acquisition module is used to obtain various state information of the operating system, and to splice the obtained state information to obtain the current random factor of the operating system. Furthermore, the framework of the uncertainty state transfer model in the present application is constructed based on five state variables: S_Entropy (entropy), S_RandomFator (system random factor), S_Counter (count value), S_Time (model last update time or initialization time) and S_Tmp (intermediate result); among them, S_Entropy: provided by the entropy source quality improvement module, with a minimum length of 64 and a maximum length of 65535, specified when the model is initialized or the state is updated; S_RandomFator: provided by the system random factor acquisition module, with a minimum length of 128 and a maximum length of 1024, specified when the model is initialized or the state is updated; S_Coun ter: The count value of the generated random number, which can be a state counter variable ranging from 0 to 65535, records the number of times the random number is generated, and is set to 0 during initialization or state update. When the number reaches 65535, an error message will be prompted, similar to "The maximum number of times generated has been reached, please re-initialize or update the state", and the model initialization or state update operation needs to be re-executed; S_Time: Records the time value of the last initialization or state update, which can be a state counter variable ranging from 0 to 60 seconds, which is set to 0 during initialization or state update. When the timing reaches 60 seconds, an error message will be prompted, similar to "The state update time has exceeded, please re-initialize or update the state", and the model initialization or state update operation needs to be re-executed. It should be pointed out that S_Tmp: A state variable with a length of 16 bytes, initialized to all 0, is obtained by concatenating (S_Entropy||S_RandomFator||S_Counter||S_Tmp) data, and executing the block encryption expansion algorithm on the concatenated data, and intercepting the first 16 bytes of data.In a specific embodiment, when initializing a model for generating random numbers, the quality-enhanced entropy entropyProcessed and the obtained system random factor systemRandomFator are used as initialization parameters of the model, and the internal states S_Entropy, S_RandomFator, S_Counter, and S_Tmp are updated to obtain an initial module; further, when S_Counter or S_Time reaches an upper limit, it is necessary to re-execute the acquisition of a high-quality entropy source entropyProcessed, re-acquire the system random factor systemRandomFator as a state update parameter, and update the internal states S_Entropy, S_RandomFator, S_Counter, and S_Tmp; the quality-enhanced entropy entropyProcessed and the system random factor systemRandomFator are used as the initialization and state update parameters of the model, and the intermediate result (i.e., S_Tmp) can be obtained by processing with a block cipher algorithm. In the process of generating random numbers, a hash operation is performed on S_Tmp in the model to obtain a random bit string, i.e., the current random number generated is obtained.

[0067] In another specific embodiment, Figure 3 As shown, firstly, entropy quality improvement is performed to obtain the entropy after quality improvement; and the random factors of the system are collected; then the model for generating random numbers is initialized using the entropy and the random factors to obtain the corresponding initial model. Further, when a random number request is subsequently generated, it can be determined whether the initial model needs to be updated according to the preset update conditions. If necessary, the parameters in the model are updated, that is, the internal state of the model is updated, and then the random number request is processed; correspondingly, if the initial model does not need to be updated, random numbers can be generated through the initial model; random numbers can be generated through the initial model cycle based on the preset update conditions.

[0068] Specifically, the process of generating random numbers can be mainly divided into the following four parts: 1. By executing the entropy source quality improvement function, the entropy in the input entropy source or entropy pool is used as an input parameter to obtain the optimized entropy: entropyProcessed.

[0069] The entropy source quality improvement pseudo function can be defined as:

[0070] entropyProcess(

[0071] entropy,

[0072] entropyLen,

[0073] entropyProcessed,

[0074] entropyProcessedLen)

[0075] Input parameters:

[0076] -----entropy: represents the entropy of the input.

[0077] -----entropyLen: indicates the entropy length of the input.

[0078] Output parameters:

[0079] -----entropyProcessed: indicates the entropy after quality improvement.

[0080] -----entropyProcessedLen: indicates the entropy length after quality improvement.

[0081] 2. Get the random factor of the current system by executing the function of collecting the system random factor: systemRandomFator.

[0082] The acquisition system random factor pseudo function can be defined as:

[0083] getSystemRandomFator(

[0084] systemRandomFator,

[0085] systemRandomFatorLen)

[0086] Output parameters:

[0087] ----- systemRandomFator: represents the random factor of the current system.

[0088] ----- systemRandomFatorLen: indicates the random factor length of the current system.

[0089] 3. By executing the initialization random number generation model function, the entropyProcessed obtained by the entropy source quality improvement module and the systemRandomFator obtained by the system random factor acquisition module are used as input parameters to initialize the uncertainty state transfer model.

[0090] The pseudo function for initializing the random number generation model is defined as:

[0091] initRandomModel (can

[0092] entropyProcessed,

[0093] entropyProcessedLen,

[0094] systemRandomFator,

[0095] systemRandomFatorLen)

[0096] Input parameters:

[0097] -----entropyProcessed: indicates the entropy after quality improvement.

[0098] -----entropyProcessedLen: indicates the entropy length after quality improvement.

[0099] ----- systemRandomFator: represents the random factor of the current system.

[0100] ----- systemRandomFatorLen: indicates the random factor length of the current system.

[0101] 4. Execute the random number request function, and determine whether a status update is required based on the returned result. If an update is required, call the status update function. The random number request function can be called repeatedly to obtain random number outputs multiple times.

[0102] The state update pseudo function can be defined as:

[0103] updateRandomModel (

[0104] entropyProcessed,

[0105] entropyProcessedLen,

[0106] systemRandomFator,

[0107] systemRandomFatorLen)

[0108] Input parameters:

[0109] -----entropyProcessed: indicates the entropy after quality improvement.

[0110] -----entropyProcessedLen: indicates the entropy length after quality improvement.

[0111] ----- systemRandomFator: represents the random factor of the current system.

[0112] ----- systemRandomFatorLen: indicates the random factor length of the current system.

[0113] And, the pseudo function for generating random numbers can be defined as:

[0114] generateRandom(

[0115] random,

[0116] randomLen)

[0117] Input parameters:

[0118] ----- randomLen: The length of the generated random number.

[0119] Output parameters:

[0120] ----- random: The random number generated.

[0121] It can be seen that the present application can utilize the minimum entropy combined with the post-processing algorithm to improve the quality of the input entropy source randomly selected from the entropy source pool as the input parameter of the software random number generation method; and utilize the operating system time, interrupt, CPU and memory, input and output status, network connection and other runtime randomness as the system random factor, and also as the input parameter of the random number generation method. Further, the present application can utilize the quality-enhanced entropy and system random factors, combined with multiple internal state management variables, to form an uncertain state transfer model; then perform a hashing algorithm operation on the data output by the uncertain state transfer model to finally obtain a random number, further improving the quality of the generated random number.

[0122] like Figure 4 As shown, the embodiment of the present application provides a software random number generation device, including:

[0123] The update condition judgment module 11 is used to judge whether the update condition of the initial model is met according to the current count value and the last model update time; the current count value is used to characterize the number of random numbers generated historically; the initial model is used to generate a model of random numbers;

[0124] A first random number generating module 12 is used for randomly selecting an entropy source from a preset entropy pool to obtain current entropy if the update condition is currently met, and determining a current random factor of the operating system according to the state information of the operating system, so as to update the initial model using the current entropy and the current random factor to obtain an updated model, so as to generate a current random number using the updated model;

[0125] The second random number generating module 13 is used to generate a current random number based on the current count value and using the initial model if the update condition is not currently met.

[0126] It can be seen that the present application can combine entropy, the random factor of the system, the count value of random number generation, and the update time of the initial model used to generate random numbers to determine whether the initial model can be used to generate random numbers; when the model needs to be updated, the entropy and random factor can be re-acquired to update the initial model, and the updated model can be used to generate random numbers; multiple state variables can be combined to improve the quality of the generated random numbers.

[0127] In a specific embodiment, the update condition determination module 11 may include:

[0128] A threshold judgment unit, used to judge whether the current count value is not less than a preset numerical threshold, and to judge whether the time difference between the last model update time and the current time is not less than a preset time threshold;

[0129] A first determination unit, configured to determine that the update condition is not currently satisfied when the current count value is less than the preset numerical threshold and the time difference is less than the preset time threshold;

[0130] The second determination unit is configured to determine that the update condition is currently satisfied when the current count value is not less than the preset numerical threshold and / or the time difference is not less than the preset time threshold.

[0131] In a specific embodiment, the first random number generation module 12 may include:

[0132] An entropy selection unit, used to randomly select an entropy source data from a preset entropy pool, and calculate a number of entropies in the preset entropy pool to obtain a minimum entropy;

[0133] An entropy length calculation unit, configured to calculate the entropy length of the current entropy based on a preset length calculation formula and using the size of the entropy source data and the minimum entropy;

[0134] A matrix building unit, used for determining the size of the entropy source data and the numerical sum of the entropy length, and building a Toeplitz matrix based on the numerical sum using a corresponding number of random bit seeds;

[0135] The entropy calculation unit is used to multiply the entropy source data with the Toeplitz matrix to obtain a current entropy matching the entropy length.

[0136] In another specific embodiment, the first random number generation module 12 may include:

[0137] An information acquisition unit, used to acquire certain status information of the operating system;

[0138] The information splicing unit is used to splice the plurality of state information in a character string manner to obtain a current random factor of the operating system.

[0139] In another specific embodiment, the first random number generating module 12 may include:

[0140] A data processing unit, used for splicing the current entropy, the current random factor, the current count value and the last model update time, and processing the spliced ​​data based on a preset block encryption algorithm to obtain processed information;

[0141] An information interception unit, used to intercept a corresponding number of bytes of data before the processed information according to a preset interception quantity to obtain an intermediate result;

[0142] A parameter updating unit is used to update relevant parameters in the initial model using the current entropy, the current random factor and the intermediate result to obtain a corresponding updated model.

[0143] In a specific embodiment, the first random number generation module 12 may include:

[0144] The first random number generating unit is used to perform a hash operation on the intermediate result to generate a current random number.

[0145] In another specific embodiment, the second random number generation module 13 may include:

[0146] An intermediate result updating unit, used to update the intermediate result of the initial model using the current count value to obtain a new intermediate result;

[0147] The second random number generating unit is used to perform a hash operation on the new intermediate result to generate a current random number.

[0148] Furthermore, the present application also discloses an electronic device. Figure 5 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content in the diagram cannot be regarded as any limitation on the scope of use of the present application.

[0149] Figure 5 A schematic diagram of the structure of an electronic device 20 provided in an embodiment of the present application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the software random number generation method disclosed in any of the aforementioned embodiments. In addition, the electronic device 20 in this embodiment may specifically be an electronic computer.

[0150] In this embodiment, the power supply 23 is used to provide working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs and is not specifically limited here.

[0151] In addition, the memory 22, as a carrier for storing resources, can be a read-only memory, a random access memory, a disk or an optical disk, etc. The resources stored thereon can include an operating system 221, a computer program 222, etc., and the storage method can be temporary storage or permanent storage.

[0152] The operating system 221 is used to manage and control the hardware devices and computer program 222 on the electronic device 20, which can be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program that can be used to complete the software random number generation method executed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 222 can further include a computer program that can be used to complete other specific tasks.

[0153] Furthermore, the present application also discloses a computer-readable storage medium for storing a computer program; wherein the computer program, when executed by a processor, implements the software random number generation method disclosed above. The specific steps of the method can refer to the corresponding contents disclosed in the above embodiments, and will not be repeated here.

[0154] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.

[0155] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0156] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0157] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0158] The technical solution provided by the present application is introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for general technicians in this field, according to the idea of ​​the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A software random number generation method, characterized in that: include: Determine whether the update conditions of the initial model are met based on the current count value and the last model update time; The current count value is used to represent the number of random numbers generated historically; The initial model is a model for generating random numbers; If the update condition is currently met, an entropy source is randomly selected from a preset entropy pool to obtain current entropy, and a current random factor of the operating system is determined according to the state information of the operating system, so as to update the initial model using the current entropy and the current random factor to obtain an updated model, so as to generate a current random number using the updated model; If the update condition is not currently met, a current random number is generated based on the current count value and using the initial model.

2. The method for generating software random numbers according to claim 1, wherein: The determining whether the updating condition of the initial model is currently met according to the current count value and the last model update time includes: Determine whether the current count value is not less than a preset numerical threshold, and determine whether the time difference between the last model update time and the current time is not less than a preset time threshold; If the current count value is less than the preset value threshold, and the time difference is less than the preset time threshold, it is determined that the update condition is not met at present; If the current count value is not less than the preset value threshold and / or the time difference is not less than the preset time threshold, it is determined that the update condition is currently met.

3. The software random number generation method according to claim 1, characterized in that: The step of randomly selecting an entropy source from a preset entropy pool to obtain current entropy includes: Randomly select an entropy source data from a preset entropy pool, and calculate a number of entropies in the preset entropy pool to obtain a minimum entropy; Based on a preset length calculation formula, the entropy length of the current entropy is obtained by using the size of the entropy source data and the minimum entropy calculation; Determine the size of the entropy source data and the numerical sum of the entropy length, and construct a Toeplitz matrix based on the numerical sum using a corresponding number of random bit seeds; The entropy source data is multiplied by the Toeplitz matrix to obtain a current entropy matching the entropy length.

4. The method for generating software random numbers according to claim 1, wherein: The determining the current random factor of the operating system according to the state information of the operating system includes: Get some status information of the operating system; The plurality of status information are concatenated in a character string to obtain a current random factor of the operating system.

5. The method for generating software random numbers according to any one of claims 1 to 4, characterized in that: The method of updating the initial model by using the current entropy and the current random factor to obtain an updated model includes: The current entropy, the current random factor, the current count value and the last model update time are concatenated, and the concatenated data is processed based on a preset block encryption algorithm to obtain processed information; According to a preset interception quantity, data of a corresponding number of bytes before the processed information is intercepted to obtain an intermediate result; The current entropy, the current random factor and the intermediate result are used to update the relevant parameters in the initial model to obtain a corresponding updated model.

6. The method for generating software random numbers according to claim 5, characterized in that: The step of generating a current random number using the updated model comprises: A hash operation is performed on the intermediate result to generate a current random number.

7. The method for generating software random numbers according to claim 6, wherein: The generating a current random number based on the current count value and using the initial model includes: Using the current count value to update the intermediate result of the initial model to obtain a new intermediate result; A hash operation is performed on the new intermediate result to generate a current random number.

8. A software random number generator, characterized in that: include: An update condition judgment module is used to judge whether the update condition of the initial model is currently met based on the current count value and the last model update time; The current count value is used to represent the number of random numbers generated historically; The initial model is used to generate a model of random numbers; A first random number generation module is used to randomly select an entropy source from a preset entropy pool to obtain current entropy if the update condition is currently met, and determine a current random factor of the operating system according to the state information of the operating system, so as to update the initial model using the current entropy and the current random factor to obtain an updated model, so as to generate a current random number using the updated model; The second random number generation module is used to generate a current random number based on the current count value and using the initial model if the update condition is not currently met.

9. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to execute the computer program to implement the software random number generation method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: Used to store a computer program, which, when executed by a processor, implements the software random number generation method as described in any one of claims 1 to 7.

Citation Information

Cited By

  • Mobile payment encryption system based on data random algorithm

    CN120822954A

  • A mobile payment encryption system based on data random algorithm

    CN120822954B