CN115714644B - Random number generation method and device - Google Patents

Random number generation method and device Download PDF

Info

Publication number
CN115714644B
CN115714644B CN202211345509.0A CN202211345509A CN115714644B CN 115714644 B CN115714644 B CN 115714644B CN 202211345509 A CN202211345509 A CN 202211345509A CN 115714644 B CN115714644 B CN 115714644B
Authority
CN
China
Prior art keywords
random number
array
numerical
value
segments
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202211345509.0A
Other languages
Chinese (zh)
Other versions
CN115714644A (en
Inventor
张玉安
蒋红宇
安晓江
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Haitai Fangyuan High Technology Co Ltd
Original Assignee
Beijing Haitai Fangyuan High Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Haitai Fangyuan High Technology Co Ltd filed Critical Beijing Haitai Fangyuan High Technology Co Ltd
Priority to CN202211345509.0A priority Critical patent/CN115714644B/en
Publication of CN115714644A publication Critical patent/CN115714644A/en
Application granted granted Critical
Publication of CN115714644B publication Critical patent/CN115714644B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Abstract

The application discloses a random number generation method and a device, wherein the method comprises the following steps: acquiring a first array and a second array; carrying out hash calculation on a first character string to obtain a first hash value, wherein the first character string is a combination of a first array and a second array; obtaining N first numerical segments according to the first hash value, wherein N is a positive integer; obtaining N second numerical segments according to the first array; and performing exclusive or shift processing on the N second numerical segments and the N first numerical segments to obtain a first random number seed, wherein the first random number seed is used for generating random numbers. The method can improve the random number generation efficiency.

Description

Random number generation method and device
Technical Field
The embodiment of the application relates to the field of information security, in particular to a random number generation method and device.
Background
Currently, in the field of information security, random number generators may generate random number seeds based on a logic structure like ANSI X9.17 standard. The ANSI X9.17 standard logic structure is an American pseudo-random number generator standard logic structure. Based on a logic structure like ANSI X9.17 standard, the 3DES algorithm needs to be used for each generation of a random number seed by the random number generator, i.e. three triple data encryption is required. When the 3DES algorithm is used by the software random number generator, two keys and seeds need to be stored securely, and the sampling entropy source is also called. Therefore, the current random number generator has the problem of low random number generation efficiency, and needs to be improved.
Disclosure of Invention
The embodiment of the application provides a random number generation method and device, which are used for improving random number generation efficiency.
In a first aspect, a method for generating a software random number provided by an embodiment of the present application includes:
acquiring a first array and a second array; carrying out hash calculation on a first character string to obtain a first hash value, wherein the first character string is a combination of the first array and the second array; obtaining N first numerical segments according to the first hash value, wherein N is a positive integer; obtaining N second numerical segments according to the first array; and performing exclusive or shift processing on the N second numerical segments and the N first numerical segments to obtain a first random number seed, wherein the first random number seed is used for generating random numbers.
According to the method, the first random number seed can be generated or updated according to the exclusive OR shift, and the random number generation efficiency can be improved.
In one possible design, the first array includes a first random number, the first random number determined according to a random input operation by a user; the second set includes random numbers associated with an operating system.
According to the design, the first array and the second array can be respectively obtained according to the random input operation of the user and the random number related to the operation system, the arrays are determined according to the user operation and the system operation, and the random number can be generated according to different network environments, so that the random number generation efficiency is improved.
In one possible design, the first array includes a second random number seed, the method further comprising: and outputting the first hash value.
According to the design, the first hash value can be output according to the second random number seed, at this time, the first array is the random number seed, and the first hash value is the output random number, so that the update of the random number seed can be realized after the random number is output according to the design.
In one possible design, the method includes: acquiring the numerical value of a third array; adding a process or subtracting a process to the value of the third array to obtain an updated third array; and when the numerical value of the updated third array belongs to a threshold value meeting the depth updating condition, performing depth updating on the first random number seed.
According to the design, the first random number seed is determined to be subjected to depth updating according to the numerical value of the third array, whether the random number seed needs to be subjected to depth updating or not can be accurately judged according to the threshold value of the depth updating condition, and whether the random number seed needs to be subjected to depth updating or not is flexibly determined.
In one possible design, the performing the depth update on the first random number seed includes: acquiring a fourth array; performing hash calculation on a second character string to obtain a second hash value, wherein the second character string is a combination of the first random number seed and the fourth array; obtaining N third numerical segments according to the second hash value; obtaining N fourth numerical segments according to the first random number seeds; and performing exclusive or shift processing on the N fourth numerical value segments and the N third numerical value segments to obtain a third random number seed.
According to the design, the first random number seed is subjected to deep updating, and the safety of the random number is improved through the deep updating.
In one possible design, the method further comprises: the value of the third array is set to 0 or a threshold.
According to the design, the numerical value of the third array is reset after the random number seed is initialized or the depth is updated, so that whether the depth is updated or not can be flexibly determined according to the third array.
In one possible design, the performing exclusive-or shift processing on the N second value segments and the N first value segments to obtain a first random number seed includes: the value A is obtained according to the following formula 8
A 8 =(A 0 A 3 ∪A 3 A 5 ∪A 5 A 6 )⊕H i
Wherein H is i Representing the (i+1) th first numerical segment, i=0, 1, 2, … …, (N-1), representing an exclusive-or operation, a a A b Representation of pair A a And A b Performing AND operation, A a ∪A b Representation of pair A a And A b Performing OR operation, wherein a and b are non-negative integers and a and b are less than or equal to (N-1), wherein when i=0, A j Representing the N second numerical segments, j=0, 1, 2, … …, (N-1); with A 1 To A 3 Numerical substitution a of (2) 0 To A 2 The numerical value of (A) is A 4 Shift left by 5 bits and replace A in the numerical cycle 3 Numerical values of (2), and A 5 To A 8 Numerical substitution a of (2) 4 To A 7 Is a numerical value of (2); according to a after replacement when i=n-1 0 To A 7 Is used to determine the first random number seed.
According to this design, the first random number seed is obtained from an exclusive-or operation.
In a second aspect, an embodiment of the present application further provides a random number generating device, including an acquisition module and a processing module. Wherein:
the acquisition module is used for acquiring the first array and the second array; the processing module is used for carrying out hash calculation on a first character string to obtain a first hash value, wherein the first character string is a combination of the first array and the second array; the processing module is further configured to obtain N first numerical segments according to the first hash value, where N is a positive integer; the processing module is further used for obtaining N second numerical segments according to the first array; the processing module is further configured to perform exclusive-or shift processing on the N second numerical segments and the N first numerical segments to obtain a first random number seed, where the first random number seed is used to generate a random number.
In one possible design, the first array includes a first random number, the first random number determined according to a random input operation by a user; the second set includes random numbers associated with an operating system.
In one possible design, the first array includes a second random number seed, and the processing module is specifically configured to: and outputting the first hash value.
In one possible design, the processing module is further configured to: acquiring the numerical value of a third array; adding a process or subtracting a process to the value of the third array to obtain an updated third array; and when the numerical value of the updated third array belongs to a threshold value meeting the depth updating condition, performing depth updating on the first random number seed.
In one possible design, the processing module is specifically configured to: acquiring a fourth array; performing hash calculation on a second character string to obtain a second hash value, wherein the second character string is a combination of the first random number seed and the fourth array; obtaining N third numerical segments according to the second hash value, wherein N is a positive integer; obtaining N fourth numerical segments according to the first random number seeds; and performing exclusive or shift processing on the N fourth numerical value segments and the N third numerical value segments to obtain a third random number seed.
In one possible design, the processing module is specifically configured to: the value of the third array is set to 0 or a threshold.
In one possible design, the n=8, and the processing module is specifically configured to: the value A is obtained according to the following formula 8
A 8 =(A 0 A 3 ∪A 3 A 5 ∪A 5 A 6 )⊕H i
Wherein H is i Representing the (i+1) th first numerical segment, i=0, 1, 2, … …, (N-1), representing an exclusive-or operation, a a A b Representation of pair A a And A b Performing AND operation, A a ∪A b Representation of pair A a And A b Performing OR operation, wherein a and b are non-negative integers and a and b are less than or equal to (N-1), wherein when i=0, A j Representing the N second numerical segments, j=0, 1, 2, … …, (N-1); with A 1 To A 3 Numerical substitution a of (2) 0 To A 2 The numerical value of (A) is A 4 Shift left by 5 bits and replace A in the numerical cycle 3 Numerical values of (2), and A 5 To A 8 Numerical substitution a of (2) 4 To A 7 Is a numerical value of (2); according to a after replacement when i=n-1 0 To A 7 Is used to determine the first random number seed.
In a third aspect, embodiments of the present application further provide a computer readable storage medium having a computer program stored therein, which when executed by a processor, implements the method of the first aspect and any one of its designs.
In a fourth aspect, an embodiment of the present application further provides an electronic device, including a memory and a processor, where the memory stores a computer program executable on the processor, and when the computer program is executed by the processor, causes the processor to implement the method of the first aspect and any one of the designs thereof.
The technical effects of the second aspect to the fourth aspect and any one of the designs thereof may be referred to as the technical effects of the corresponding designs in the first aspect, and will not be described herein.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the description of the embodiments will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
Fig. 1 is a schematic flow chart of a method for generating random numbers according to an embodiment of the present application;
FIG. 2 is a schematic diagram of a random number seed initialization process according to an embodiment of the present application;
FIG. 3 is a schematic diagram of a structure of a random number generating device according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
For the purpose of promoting an understanding of the principles and advantages of the application, reference will now be made in detail to the drawings, in which embodiments of the application are illustrated, some but not all of which are illustrated. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application. It should be appreciated that the specific methods of operation described in the method embodiments described below may also be applied in device embodiments or system embodiments.
Currently, in the field of information security, random number generators may generate random number seeds based on a logic structure like ANSI X9.17 standard. The ANSI X9.17 standard logic structure is an American pseudo-random number generator standard logic structure.
According to a logic structure like ANSI X9.17, the random number generator requires the use of the 3DES algorithm three times for each generation of a random number. The 3DES (or Triple Data Encryption Algorithm, TDEA) represents a triple data encryption algorithm. The 3DES algorithm may guarantee the strength of the password generated by the random number generator.
When the random number generator uses the 3DES algorithm, two keys and seeds need to be stored securely, and a sampling entropy source needs to be invoked. Therefore, the current random number generator has the problems of low random number generation efficiency, generation of only 8-byte random numbers and the like, and needs to be improved.
In order to solve the problems, the application provides a random number generation method which is used for solving the problems that the random number generation efficiency of the current random number generator is low, only 8 bytes of random numbers are generated, and the like.
In the embodiment of the application, a first array and a second array are obtained; carrying out hash calculation on a first character string to obtain a first hash value, wherein the first character string is a combination of the first array and the second array; obtaining N first numerical segments according to the first hash value, wherein N is a positive integer; obtaining N second numerical segments according to the first array; and performing exclusive or shift processing on the N second numerical segments and the N first numerical segments to obtain a first random number seed, wherein the first random number seed is used for generating random numbers. Optionally, the random number output according to the first random number seed is used for encryption or signing. The method can solve the problems of low random number generation efficiency, generation of only 8-byte random numbers and the like existing in the conventional random number generator.
Fig. 1 schematically shows a flow chart of a method for generating random numbers. Illustratively, the method is performed by a random number generator. The random number generator may be implemented by a processor or chip or logic circuit, etc. Illustratively, the random number generator provided by the application belongs to a deterministic random number generator. The deterministic random number generator (deterministic random number generator, DRNG) may comprise a sub-function of a cryptographic system.
Referring to the flow shown in fig. 1, the analysis method provided in the embodiment of the present application specifically includes the steps of:
step 101, a first array and a second array are obtained.
Alternatively, the first array is a 32-byte unsigned array, and may include a 32-byte string. The 1 byte may include an 8 bit character.
Optionally, the second array is a 2-byte (including 2-byte) to 24-byte (including 24-byte) unsigned array.
It is understood that the byte numbers of the first array and the second array may be changed according to the requirements of the application scenario, and are not limited to the above exemplified values.
As one example, the first array includes a first random number determined according to a random input operation of a user; the second set includes random numbers associated with an operating system.
For example, a first array is obtained, the first array comprising array a. The random number generator obtains a first array comprising: the random number generator obtains random input data of a user, and an initial value is given to the array A according to the random input data of the user. The acquiring the random input operation of the user comprises the following steps:
the user can tap the keyboard and drag the mouse for several times at will, and the random number generator generates random data by recording the keyboard input value, the time interval between the taps, the moving speed and distance of the mouse and other information. The random number generator also obtains corresponding system time, coordinate position values in a screen where a cursor is positioned or collected noise or sound and other information data during operation according to operations such as keyboard clicking, mouse dragging and the like of a user. The random number generator converts these data or values into bytes to form a first array. For example, the random number generator divides a 32-bit unsigned integer X by 8 bits, constituting 4 bytes. The random number generator may also perform some slightly complex operations, such as calculating Y from X, y=x 3 +5X+7mod2 32 Y is then split into 4 bytes by 8 bits, effecting conversion from a 32 bit word X to 4 bytes. The random number generator may also invoke if the random number generator has an initial value for array A in accordance with the various ways described above, but array A is less than 32 bytes Some compiling systems can generate random number functions, so that the array A can meet 32 bytes, for example, a random () function in C++ and C language is called, two bytes of random numbers can be generated after each call, and the call can be continuously repeated until the array A meets 32 bytes.
For another example, a second array is obtained, the second array comprising array B. The random number generator obtains a second array comprising: the random number generator acquires a random number related to the operating system, and assigns an initial value to the array B according to the random number related to the operating system. The acquiring the random number related to the operating system comprises the following steps:
after the array A obtains the initial value of 32 bytes from the aspects of a keyboard, a mouse or a system, the random number generator converts the information of system time, cursor position and the like into n bytes according to a conversion function and records the n bytes into the B array. For example, the random number generator obtains the system time, obtains the cursor position, or invokes a random number generation function or statement in the system, including the rand () function in the C language, and similar statements in Java and Python languages. The random number generator can be realized in a single form, and can also be combined in a plurality of data acquisition forms. The random number generator converts the generated data into character strings with a plurality of lengths according to a certain rule, the length is generally 2 to 24 bytes, and if higher security performance is pursued, 16 to 24 bytes are preferable. The array B is just a group of temporary storage units used for laying and assisting calculation and has no memory function.
Step 102, performing hash calculation on a first character string to obtain a first hash value, where the first character string is a combination of the first array and the second array.
Optionally, step 102 includes:
illustratively, the first array includes a string of 32 bytes. The second array includes strings of n bytes. And the random number generator splices the first array and the second array to generate a first character string. The first string includes a string of (32+n) bytes. And n is a natural number.
Illustratively, the random number generator computes the string of (32+n) bytes according to a hash function that includes a hash algorithm that outputs 32 bytes. The random number generator determines a first hash value according to the calculation result. The first hash value is 32 bytes.
It is understood that the number of bytes of the first hash value may be changed according to the requirements of the application scenario, and is not limited to the above exemplified values. The number of bytes of the first hash value is the same as the number of bytes of the first array.
For example, in step 102, array a and array B may be concatenated into a (32+n) byte string S, denoted s=a|b. S is calculated by a hash algorithm capable of outputting at least 32 bytes, and a first hash value of 32 bytes is obtained.
Step 103, obtaining N first numerical segments according to the first hash value, where N is a positive integer.
Optionally, step 103 includes:
illustratively, the random number generator equally processes the first hash value into 8 of the first numerical segments, each of which is 4 bytes (i.e., 32 bits) in length, according to the length of the first hash value. The processing includes the random number generator splitting the first hash value every 4 bytes to obtain 8 first numerical segments.
Step 104, obtaining N second value segments according to the first array.
Optionally, step 104 includes:
illustratively, the random number generator equally divides the first array into 8 of the second value segments according to the length of the first array, each second value segment having a length of 4 bytes (i.e., 32 bits). The processing includes the random number generator splitting the first array every 4 bytes to obtain 8 second value segments.
And 105, performing exclusive or shift processing on the N second numerical segments and the N first numerical segments to obtain a first random number seed.
Optionally, the first hash value is denoted as H, and the first array is denoted as a. H can be expressed as N bit words Combinations of groups, i.e. h= (H 0 ,H 1 ,…,H N-1 ). A may be represented as a combination of an array of N bit words, i.e., a= (a) 0 ,A 1 ,…,A N-1 )。
In the present application, the first numerical segment is N numerical segments obtained according to H, namely H 0 ,H 1 ,…,H N-1 . The second numerical segment is N numerical segments obtained according to A, namely A 0 ,A 1 ,…,A N-1
Illustratively, taking n=8 as an example, the exclusive or shift process includes: for the (i+1) th first numerical segment, the value A is obtained according to the following formula 8
A 8 =(A 0 A 3 ∪A 3 A 5 ∪A 5 A 6 )⊕H i (equation 1)
Wherein, when i=0, a j Representing the N second numerical segments, j=0, 1, 2, … …, (N-1). H i Representing the (i+1) th first numerical segment, i=0, 1, 2, … …, (N-1). Representing exclusive or operation, A a A b Representation of pair A a And A b Performing AND operation, A a ∪A b Representation of pair A a And A b And performing OR operation, wherein a and b are non-negative integers, and a and b are smaller than or equal to (N-1). Where j=0, 1, 2, … …, (N-1). The exclusive or shift process further includes: with A 1 To A 3 Numerical substitution a of (2) 0 To A 2 The numerical value of (A) is A 4 Shift left by 5 bits and replace A in the numerical cycle 3 Numerical values of (2), and A 5 To A 8 Numerical substitution a of (2) 4 To A 7 Is a numerical value of (2). I.e. newly obtained A 0 To A 7 Numerical value of (2) replaces A of previous processing output 1 To A 8 To implement the shift process. The numerical replacement operation may be performed each time a new A is obtained 8 And then executed once. Get a after replacement when i=n-1 0 To A 7 After the value of (A), according to the A 0 To A 7 Determining the first random number seed, e.g., A at this time 0 ,A 1 ,…,A 7 Make up of first followerAnd (5) counting seeds.
It will be appreciated that at i=0, 1,2, … …,7, respectively, according to H 0 、H 1 、H 2 、H 3 、H 4 、H 5 、H 6 And H 7 Pair (A) 0 A 3 ∪A 3 A 5 ∪A 5 A 6 ) Exclusive-or operation is carried out to obtain A 8 And after each exclusive or operation, use A 1 To A 3 Numerical substitution a of (2) 0 To A 2 The numerical value of (A) is A 4 Shift left by 5 bits and replace A in the numerical cycle 3 The numerical value of (A) is A 5 To A 8 Numerical substitution a of (2) 4 To A 7 Is a numerical value of (2).
For example, alternatively, the random number generator determines a at each time according to equation 1 8 Will A 1 To A 3 Numerical substitution a of (2) 0 To A 2 The numerical value of (A) is A 4 Shift left by 5 bits and replace A in the numerical cycle 3 The numerical value of (A) is A 5 To A 8 Numerical substitution a of (2) 4 To A 7 Is a numerical value of (2). Performing the exclusive OR process shown in equation 1 and the numerical replacement operation 8 times, at this time A 0 ,A 1 ,…,A 7 A first random number seed is composed.
The flow shown in fig. 2 above may be applied to the initialization of random number seeds. Illustratively, the random number seed initialization process is described below with n=8 as an example.
As shown in fig. 2, the second segment of values may be considered as an 8-stage shift register, or the second segment of values may be stored in an 8-stage shift register, where each stage of shift register stores a segment of the second segment of values. The shift register can be used for registering codes, and can also be used for realizing serial or parallel conversion of data, operation of numerical values, processing of the data and the like.
The random number generator performs feedback shift conversion of an 8-beat register. Wherein each beat adds a first segment of a 32-bit word, which is sequentially exclusive-or shifted into a second segment.
In particular, referring to fig. 2, "" indicates exclusive or of 32-bit words,“<<<5 "represents a 5-bit cyclic left shift of a 32-bit word. "<<<"means a binary shift operator. H in the figure 0 ,H 1 ,…,H 7 The hash value of 256 bits is divided into 32 bits from left to right, and 8 32-bit words are obtained. The feedback shift conversion method of the 8-stage register is as follows:
setting the initial state of the register as follows: a is that 0 ,A 1 ,……,A 7 . At this time, A 0 ,A 1 ,……,A 7 Representing 8 second segments.
The random number generator calculates the value A according to the following formula 8
A 8 =(A 0 A 3 ∪A 3 A 5 ∪A 5 A 6 )⊕H 0
Where "U" means an OR operation, i.e., two 32-bit words are OR operated on a bit-by-bit basis. "A" a 0 A 3 "means 32-bit word A 0 And A is a 3 And performing AND operation according to the bit. Then, the register is shifted by one beat to transfer A 0 Shift out register, note A 4 To A 3 With a 5-bit cyclic left shift, i.e. A 0 =A 1 ,A 1 =A 2 ,A 2 =A 3 ,A 3 =(A 4 <<<5),……,A 7 =A 8
H for next beat 1 Recalculating A 8
A 8 =(A 0 A 3 ∪A 3 A 5 ∪A 5 A 6 )⊕H 1
The register shifts one beat again.
Then sequentially using H 2 To H 7 Recalculating A 8 The method comprises the steps of carrying out a first treatment on the surface of the After each beat of calculation, the register is shifted one beat to the right.
When using H 7 Recalculating A 8 After the register is shifted by 8 beats, the initialized random number seeds are obtained or the seed update is realized in a normal working state.
Alternatively, the random number generator may also set the count value to an initial value of 0 or T. Thus, the random number seed initialization process is completed.
Wherein the count value is a third array. The third array may be used to determine whether to perform a depth update. For example, after each time the random number is calculated and output according to the random number seed, the random number generator performs an addition process or a subtraction process on the value of the third array to obtain an updated third array. And when the numerical value of the updated third array belongs to a threshold value meeting the depth updating condition, performing depth updating on the random number seed. Wherein, if it is judged that the depth update is not performed, the random number generator can perform the normal update on the random number seed. Compared with the deep updating, the common updating process is simpler and more convenient, the updating efficiency of the random number seeds is higher, and the seed safety after the deep updating is stronger.
For example, the random number generator sets the count value to 0 after obtaining the initialized random number seed. And after the random number generator outputs the random number obtained according to the random number seed each time, adding one to the numerical value of the third array to obtain an updated third array. When the value of the updated third array is T, the random number generator carries out deep updating on the first random number seed, wherein T is a threshold value meeting the deep updating condition. For another example, the random number generator sets the value of the count value to T after obtaining the initialized random number seed. And after the random number generator outputs the random number obtained according to the random number seed each time, subtracting one from the value of the third array to obtain an updated third array. When the value of the updated third array falls to 0, the random number generator performs deep update on the first random number seed, wherein 0 is a threshold value meeting the deep update condition.
Illustratively, the threshold value of the depth update condition belongs to the value of the third array. The random number generator may determine the threshold of the depth update condition based on user settings.
For example, the randomness generator may set the threshold of the depth update condition between 1 and 65535 depending on the security requirements of the application scenario. If an information system is very tightly protected and cannot be hacked, the threshold of the deep update condition can be set to be large, for example, the threshold of the deep update condition is 50000. If the system is vulnerable to hacking, the threshold of the deep update condition should be set small, such as a threshold of 5, 10, or 20. If a hacker attacks a certain information system to find out the seed, the hacker has a cracking capability on the random numbers generated subsequently. When the threshold value of the depth update condition is small, the seed will be updated quickly, so that it is difficult for a hacker to crack the depth updated seed unless he re-invades the system to re-acquire the depth updated seed.
Optionally, in step 101, the first array may be a random number seed (for distinguishing the first random number seed, the random number seed may be referred to as a second random number seed), and the random number generator may further output a first hash value, where the first hash value is a random number that needs to be output, and where the first random number seed is a new random number seed obtained by updating the second random number seed. The above process of obtaining the second random number seed may be referred to as a general update of the random number seed.
It can be appreciated that the second random number seed may be obtained through steps 101 to 105, and the foregoing description is specifically referred to, and will not be repeated here. Wherein the random number generator is configured to determine the first array based on a random input operation by the user when obtaining the second random number seed, the second array including random numbers associated with the operating system.
Optionally, in the present application, the random number generator may further perform a deep update on the random number seed when the deep update condition is satisfied. The depth update condition may include that the value of the third array belongs to a threshold value satisfying the depth update condition, and specifically, reference may be made to the foregoing description of the third array, which is not repeated herein. The depth update condition is, for example, that the value of the third array is T after one addition process, or that the value of the third array is 0 after one subtraction process.
The depth update may include the steps of: when the value of the third array is determined to belong to the threshold value meeting the depth updating condition, the random number generator can also acquire a fourth array, hash calculation is performed on a second character string to acquire a second hash value, and the second character string is a combination of the first random number seed and the fourth array. The random number generator obtains N third numerical value segments according to the second hash value, obtains N fourth numerical value segments according to the first random number seed, and carries out exclusive or shift processing on the N fourth numerical value segments and the N third numerical value segments to obtain a third random number seed, wherein the third random number seed is the random number seed subjected to deep updating. It can be understood that, for the manner in which the random number generator obtains the fourth array, reference may be made to the manner in which the random number generator obtains the initial first array and the second array, that is, the fourth array may adopt a numerical value obtaining manner similar to the initializing manner, which is not described herein again.
Illustratively, in the present example, the random number generator may perform the operations of initializing the random number seed, performing a normal update or a deep update on the random number seed, and the like by including steps 106 to 110, or including steps 111 to 117, or including steps 118 to 124.
Optionally, the random number generator initializes a random number seed according to the steps 106 to 110, including:
illustratively, in step 106, the random number generator determines a first random number based on the random input operation of the user and a second random number based on the random number associated with the operating system. The random number generator determines an array 1 from the first random number and the random number generator determines an array 2 from the second random number.
Illustratively, in step 107, the random number generator hashes a string 1 to obtain a hash value 1, where the string 1 is a combination of the array 1 and the array 2.
Illustratively, in step 108, the random number generator obtains 8 value segments 1 corresponding to the hash value 1 according to the hash value 1.
Illustratively, in step 109, the random number generator obtains 8 value segments 2 corresponding to the array 1 according to the array 1.
Illustratively, in step 110, the random number generator performs exclusive or shift processing on 8 value segments 1 corresponding to the hash value 1 and 8 value segments 2 corresponding to the array 1 to obtain a random number seed 1, thereby implementing random number seed initialization.
In addition, the random number generator sets the value of array 3 to 0.
In the above steps 106 to 110, the array 1 corresponds to the first array in the present application, the array 2 corresponds to the second array in the present application, the string 1 corresponds to the first string in the present application, the hash value 1 corresponds to the first hash value in the present application, the random number seed 1 corresponds to the first random number seed in the present application, the value segment 1 corresponds to the first value segment in the present application, the value segment 2 corresponds to the second value segment in the present application, and the array 3 corresponds to the third array in the present application.
Optionally, the random number generator performs a random number seed common update according to the steps 111 to 117, including:
illustratively, in step 111, the random number generator obtains an array 3, where the array 3 includes a threshold T according to a depth update condition set by a user.
Illustratively, at step 112, the random number generator determines array 4 from random number seed 1 and array 5 from the operating system related random number.
Illustratively, in step 113, the random number generator hashes the string 2 to obtain a hash value 2, where the string 2 is a combination of the array 4 and the array 5.
Illustratively, the random number generator performs an addition process to the values of the tuple 3 and outputs a hash value of 2, step 114.
Illustratively, the random number generator obtains 8 value segments 3 from the hash value 2, step 115.
Illustratively, at step 116, the random number generator obtains 8 numerical segments 4 from the random number seed 1.
Illustratively, in step 117, the random number generator exclusive-or shifts the 8 value segments 3 with the 8 value segments 4 to obtain the random number seed 2. The random number seed 2 is the random number seed 1 after the common updating is completed.
Optionally, in the normal updating process, the random number seed 1 in the steps 111 to 117 corresponds to a first random number seed in the present application, the array 4 corresponds to a first array in the present application, the array 5 corresponds to a second array in the present application, the string 2 corresponds to a first string in the present application, the hash value 2 corresponds to a first hash value in the present application, the value segment 3 corresponds to a first value segment in the present application, and the value segment 4 corresponds to a second value segment in the present application. The random number seed 2 corresponds to a second random number seed in the present application.
Optionally, the random number generator further determines whether the value of the array 3 belongs to a threshold value satisfying the depth update condition, and determines whether to perform the depth update of the random number seed according to the determination result.
For example, when the value of the group 3 is T, a depth update is required.
Optionally, the random number generator performs random number seed depth update according to steps 118 to 124, including:
illustratively, in step 118, the random number generator performs steps 101 through 105 to obtain the random number seed 3.
Illustratively, step 119 determines array 6 from the random numbers associated with the operating system and obtains string 3 from random number seed 3 and array 6.
Illustratively, in step 120, the random number generator hashes the string 3 to obtain a hash value 3.
Illustratively, the random number generator increments the value of the tuple 3, step 121.
Illustratively, the random number generator obtains 8 numerical segments 5 from the hash value 3, step 122.
Illustratively, the random number generator obtains 8 numerical segments 6 from the random number seed 3, step 123.
Illustratively, in step 124, the random number generator performs exclusive-or shift processing on the 8 value segments 5 and the 8 value segments 6 to obtain a random number seed. The random number seed is the random number seed after the deep update is completed.
Optionally, in the deep update process, the random number seed 3 in the steps 118 to 124 corresponds to the first random number seed in the present application, the array 6 corresponds to the fourth array in the present application, the array 3 corresponds to the third array in the present application, the string 3 corresponds to the second string in the present application, the hash value 3 corresponds to the second hash value in the present application, the value segment 5 corresponds to the third value segment in the present application, and the value segment 6 corresponds to the fourth value segment in the present application. The random number seed 4 corresponds to the first random number seed after the deep update is completed in the present application.
Based on the same inventive concept as the above-mentioned method embodiment, the embodiment of the present application also provides a random number generating device. The random number generating means may be adapted to perform the actions described in the method embodiments above. In this embodiment, the structure of the random number generating means may be as shown in fig. 3. As shown in fig. 3, the present application exemplarily provides a random number generating apparatus including an acquisition module 301 and a processing module 302.
The acquiring module 301 is configured to acquire a first array and a second array;
the processing module 302 is configured to perform hash computation on a first string to obtain a first hash value, where the first string is a combination of the first array and the second array;
The processing module 302 is further configured to obtain N first numerical segments according to the first hash value, where N is a positive integer;
the processing module 302 is further configured to obtain N second value segments according to the first array;
the processing module 302 is further configured to perform exclusive-or shift processing on the N second numerical segments and the N first numerical segments to obtain a first random number seed, where the first random number seed is used to generate a random number.
Optionally, the first array includes a first random number, and the first random number is determined according to a random input operation of the user; the second set includes random numbers associated with the operating system.
Optionally, the processing module 302 is further configured to output the first hash value.
Optionally, the obtaining module 301 is further configured to obtain a value of the third array;
the processing module 302 is further configured to perform an addition process or a subtraction process on the value of the third array to obtain an updated third array. And when the numerical value of the updated third array belongs to a threshold value meeting the depth updating condition, performing depth updating on the first random number seed.
Optionally, the obtaining module 301 is further configured to obtain a fourth array;
the processing module 302 is further configured to perform hash computation on a second string to obtain a second hash value, where the second string is a combination of the first random number seed and the fourth array. And obtaining N third numerical segments according to the second hash value, wherein N is a positive integer. Obtaining N fourth numerical values according to the first random number seeds; and the method is also used for carrying out exclusive or shift processing on the N fourth numerical value segments and the N third numerical value segments to obtain a third random number seed.
Optionally, the processing module 302 is further configured to set a value of the third array to 0 or a threshold value.
Optionally, the processing module 302 is further configured to:
the step of performing exclusive or shift processing on the N second numerical segments and the N first numerical segments to obtain a first random number seed, where n=8 includes: a is obtained according to the following formula 8
A 8 =(A 0 A 3 ∪A 3 A 5 ∪A 5 A 6 )⊕H i
Wherein H is i Representing the (i+1) th first numerical segment, i=0, 1, 2, … …, (N-1), representing an exclusive-or operation, a a A b Representation of pair A a And A b Performing AND operation, A a ∪A b Representation of pair A a And A b Performing OR operation, wherein a and b are non-negative integers and a and b are less than or equal to (N-1), wherein when i=0, A j Representing the saidN second numerical segments, j=0, 1, 2, … …, (N-1);
with A 1 To A 3 Numerical substitution a of (2) 0 To A 2 The numerical value of (A) is A 4 Shift left by 5 bits and replace A in the numerical cycle 3 Numerical values of (2), and A 5 To A 8 Numerical substitution a of (2) 4 To A 7 Is a numerical value of (2); according to a after replacement when i=n-1 0 To A 7 Is used to determine the first random number seed.
The embodiment of the application also provides electronic equipment based on the same conception as the embodiment of the method. The electronic device may be configured to perform the actions described in the method embodiments above. In this embodiment, the structure of the electronic device may include a memory 401 and one or more processors 402 as shown in FIG. 4.
A memory 401 for storing a computer program executed by the processor 402. The memory 401 may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, a program required for running an instant communication function, and the like; the storage data area can store various instant messaging information, operation instruction sets and the like.
The memory 401 may be a volatile memory (RAM) such as a random-access memory (RAM); the memory 401 may also be a nonvolatile memory (non-volatile memory), such as a read-only memory, a flash memory (flash memory), a Hard Disk Drive (HDD) or a Solid State Drive (SSD), or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer, but is not limited thereto. Memory 401 may be a combination of the above.
The processor 402 may include one or more central processing units (central processing unit, CPU) or digital processing units, etc. The processor 402 is configured to implement the above method when invoking a computer program stored in the memory 401.
The specific connection medium between the memory 401 and the processor 402 is not limited in the embodiment of the present application. As an example, the embodiment of the present application is shown in fig. 4, where the memory 401 and the processor 402 are connected by a bus 403, and the bus 403 is shown in fig. 4 with a thick line, and the connection between other components is merely illustrative, and not limited to the above. The bus 403 may be classified into an address bus, a data bus, a control bus, and the like. For ease of illustration, only one thick line is shown in fig. 4, but not only one bus or one type of bus.
Optionally, the processor 402 may be configured to perform the actions performed by any one or more of the acquisition module 301, the processing module 302, and the like.
According to one aspect of the present application, there is provided a computer program product or computer program comprising computer instructions stored in a computer readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device performs the method in the above-described embodiment.
The program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium can be, for example, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. Specific examples (a non-exhaustive list) of the readable storage medium would include: an electrical connection having one or more wires, a portable disk, a hard disk, random Access Memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
The foregoing is merely illustrative of the present application, and the present application is not limited thereto, and any person skilled in the art will readily recognize that variations or substitutions are within the scope of the present application.

Claims (14)

1. A method for generating a random number, comprising:
acquiring a first array and a second array;
carrying out hash calculation on a first character string to obtain a first hash value, wherein the first character string is a combination of the first array and the second array;
Obtaining N first numerical segments according to the first hash value, wherein N is a positive integer;
obtaining N second numerical segments according to the first array;
performing exclusive-or shift processing on the N second numerical segments and the N first numerical segments to obtain first random number seeds, wherein the first random number seeds are used for generating random numbers;
the step of performing exclusive or shift processing on the N second numerical segments and the N first numerical segments to obtain a first random number seed, where n=8 includes:
the value A is obtained according to the following formula 8 :A 8 =(A 0 A 3 ∪A 3 A 5 ∪A 5 A 6 )⊕H i ;H i Representing the (i+1) th first numerical segment, i=0, 1, 2, … …, (N-1), representing an exclusive-or operation, a a A b Representation of pair A a And A b Performing AND operation, A a ∪A b Representation of pair A a And A b Performing OR operation, wherein a and b are non-negative integers and a and b are less than or equal to (N-1), wherein when i=0, A j Representing the N second numerical segments, j=0, 1, 2, … …, (N-1); with A 1 To A 3 Numerical substitution a of (2) 0 To A 2 The numerical value of (A) is A 4 Shift left by 5 bits and replace A in the numerical cycle 3 Numerical values of (2), and A 5 To A 8 Numerical substitution a of (2) 4 To A 7 Is a numerical value of (2); according to a after replacement when i=n-1 0 To A 7 Is used to determine the first random number seed.
2. The method of claim 1, wherein the first array comprises a first random number, the first random number determined based on a random input operation by a user;
The second set includes random numbers associated with an operating system.
3. The method of claim 1, wherein the first array comprises a second random number seed, the method further comprising:
and outputting the first hash value.
4. A method as recited in claim 3, further comprising:
acquiring the numerical value of a third array;
adding a process or subtracting a process to the value of the third array to obtain an updated third array;
and when the numerical value of the updated third array belongs to a threshold value meeting the depth updating condition, performing depth updating on the first random number seed.
5. The method of claim 4, wherein the deep updating the first random number seed comprises:
acquiring a fourth array;
performing hash calculation on a second character string to obtain a second hash value, wherein the second character string is a combination of the first random number seed and the fourth array;
obtaining N third numerical segments according to the second hash value;
obtaining N fourth numerical segments according to the first random number seeds;
and performing exclusive or shift processing on the N fourth numerical value segments and the N third numerical value segments to obtain a third random number seed.
6. The method of claim 5, wherein the method further comprises:
the value of the third array is set to 0 or a threshold.
7. A random number generation apparatus, comprising:
the acquisition module is used for acquiring the first array and the second array;
the processing module is used for carrying out hash calculation on a first character string to obtain a first hash value, wherein the first character string is a combination of the first array and the second array;
the processing module is further configured to obtain N first numerical segments according to the first hash value, where N is a positive integer;
the processing module is further used for obtaining N second numerical segments according to the first array;
the processing module is further used for performing exclusive-or shift processing on the N second numerical segments and the N first numerical segments to obtain first random number seeds, and the first random number seeds are used for generating random numbers;
the processing module is specifically configured to:
the value A is obtained according to the following formula 8 :A 8 =(A 0 A 3 ∪A 3 A 5 ∪A 5 A 6 )⊕H i The method comprises the steps of carrying out a first treatment on the surface of the Wherein H is i Representing the (i+1) th first numerical segment, i=0, 1, 2, … …, (N-1), representing an exclusive-or operation, a a A b Representation of pair A a And A b Performing AND operation, A a ∪A b Representation of pair A a And A b Performing OR operation, wherein a and b are non-negative integers and a and b are less than or equal to (N-1), wherein when i=0, A j Representing the N second numerical segments, j=0, 1, 2, … …, (N-1); with A 1 To A 3 Numerical substitution a of (2) 0 To A 2 The numerical value of (A) is A 4 Shift left by 5 bits and replace A in the numerical cycle 3 Numerical values of (2), and A 5 To A 8 Numerical substitution a of (2) 4 To A 7 Is a numerical value of (2); according to a after replacement when i=n-1 0 To A 7 Is used to determine the first random number seed.
8. The apparatus of claim 7, wherein the first array comprises a first random number, the first random number determined based on a random input operation by a user;
the second set includes random numbers associated with an operating system.
9. The apparatus of claim 7, wherein the first array comprises a second random number seed, the processing module further to:
and outputting the first hash value.
10. The apparatus of claim 9, wherein the processing module is further to:
acquiring the numerical value of a third array;
adding a process or subtracting a process to the value of the third array to obtain an updated third array;
and when the numerical value of the updated third array belongs to a threshold value meeting the depth updating condition, performing depth updating on the first random number seed.
11. The apparatus of claim 10, wherein the processing module is specifically configured to:
acquiring a fourth array;
performing hash calculation on a second character string to obtain a second hash value, wherein the second character string is a combination of the first random number seed and the fourth array;
obtaining N third numerical segments according to the second hash value;
obtaining N fourth numerical segments according to the first random number seeds;
and performing exclusive or shift processing on the N fourth numerical value segments and the N third numerical value segments to obtain a third random number seed.
12. The apparatus of claim 11, wherein the processing module is further to:
the value of the third array is set to 0 or a threshold.
13. An electronic device comprising a processor and a memory, wherein the memory stores program code that, when executed by the processor, causes the processor to perform the steps of the method of any of claims 1-6.
14. A computer readable storage medium, characterized in that it comprises a program code for causing an electronic device to perform the steps of the method according to any one of claims 1-6, when said program code is run on the electronic device.
CN202211345509.0A 2022-10-31 2022-10-31 Random number generation method and device Active CN115714644B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211345509.0A CN115714644B (en) 2022-10-31 2022-10-31 Random number generation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211345509.0A CN115714644B (en) 2022-10-31 2022-10-31 Random number generation method and device

Publications (2)

Publication Number Publication Date
CN115714644A CN115714644A (en) 2023-02-24
CN115714644B true CN115714644B (en) 2023-08-15

Family

ID=85231824

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211345509.0A Active CN115714644B (en) 2022-10-31 2022-10-31 Random number generation method and device

Country Status (1)

Country Link
CN (1) CN115714644B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117093983B (en) * 2023-10-19 2024-02-02 紫光同芯微电子有限公司 Random number verification method and device, storage medium and electronic equipment

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1714377A (en) * 2002-10-07 2005-12-28 小林朗 Pseudo-random number generation method and pseudo-random number generator
CN1832396A (en) * 2005-11-07 2006-09-13 北京浦奥得数码技术有限公司 Pseudo-random number generation method
CN101140592A (en) * 2007-09-30 2008-03-12 华为技术有限公司 Keywords storing and researching method and apparatus
KR20130014003A (en) * 2011-07-29 2013-02-06 공주대학교 산학협력단 Non-linear binary random number generator using feedback carry shift register
CN103294447A (en) * 2013-05-30 2013-09-11 华为技术有限公司 Method and device for generating random numbers
CN108804011A (en) * 2018-06-06 2018-11-13 北京信任度科技有限公司 A kind of random-number generating method and generation system based on interactive curve
CN110266682A (en) * 2019-06-18 2019-09-20 杭州情咖网络技术有限公司 Data ciphering method, device, mobile terminal and decryption method
CN115051798A (en) * 2022-06-10 2022-09-13 北京海泰方圆科技股份有限公司 Random number generation method and device, electronic equipment and storage medium

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US11755373B2 (en) * 2020-10-07 2023-09-12 Oracle International Corporation Computation and storage of object identity hash values

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1714377A (en) * 2002-10-07 2005-12-28 小林朗 Pseudo-random number generation method and pseudo-random number generator
CN1832396A (en) * 2005-11-07 2006-09-13 北京浦奥得数码技术有限公司 Pseudo-random number generation method
CN101140592A (en) * 2007-09-30 2008-03-12 华为技术有限公司 Keywords storing and researching method and apparatus
KR20130014003A (en) * 2011-07-29 2013-02-06 공주대학교 산학협력단 Non-linear binary random number generator using feedback carry shift register
CN103294447A (en) * 2013-05-30 2013-09-11 华为技术有限公司 Method and device for generating random numbers
CN108804011A (en) * 2018-06-06 2018-11-13 北京信任度科技有限公司 A kind of random-number generating method and generation system based on interactive curve
CN110266682A (en) * 2019-06-18 2019-09-20 杭州情咖网络技术有限公司 Data ciphering method, device, mobile terminal and decryption method
CN115051798A (en) * 2022-06-10 2022-09-13 北京海泰方圆科技股份有限公司 Random number generation method and device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN115714644A (en) 2023-02-24

Similar Documents

Publication Publication Date Title
US10467389B2 (en) Secret shared random access machine
WO2019114122A1 (en) Encryption method for login information, device, electronic device, and medium
CN107004084B (en) Multiplicative mask for cryptographic operations
CN115051798B (en) Random number generation method and device, electronic equipment and storage medium
KR102154164B1 (en) Method for generating a pseudorandom sequence, and method for coding or decoding a data stream
CN115714644B (en) Random number generation method and device
CN109683851A (en) The generation method of random number, generating random number device, computer storage medium
Liu et al. Eurus: Towards an efficient searchable symmetric encryption with size pattern protection
EP3930252A1 (en) Countermeasures for side-channel attacks on protected sign and key exchange operations
RU2598781C1 (en) Method of linear conversion (versions)
JP5427117B2 (en) Message authenticator generation device, message authenticator verification device, message authenticator generation method, message authenticator verification method, and program
JP2009169316A (en) Hash function operational device, signature device, program and hash function operational method
CN115567199B (en) Random number seed generation method and device, electronic equipment and storage medium
CN112559497B (en) Data processing method, information transmission method, device and electronic equipment
US11281688B2 (en) Ranking and de-ranking data strings
CN116243887B (en) Software random number generation method and device
CN116301721B (en) Random number generation method and device, electronic equipment and medium
CN116055039B (en) Random number generation method and device based on block cipher algorithm
Mood et al. PAL: A pseudo assembly language for optimizing secure function evaluation in mobile devices
CN117891432A (en) Random number generation method and device and electronic equipment
KR102236242B1 (en) Method for Generating Public Value Using Fuzzy Extractor and Generating Secret Key Using the same Public Value and Second Input
WO2021131667A1 (en) Secret calculation device, secret calculation method, and program
CN109787755B (en) Key generation method, key generation device and electronic equipment
US10503475B1 (en) Forensically reproducible random number generator and associated method of use
CN117827149A (en) Random number generation method, device and equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant