A method, device, electronic device and medium for generating random number seeds

Through recursively generating pseudo -random sequences and generating secret seeds after initialization, the problem of low random number production efficiency in existing technologies has been solved, and the effect of faster seed updates and higher random number generation efficiency is achieved.

CN118113254BActive Publication Date: 2025-01-24BEIJING HAITAI FANGYUAN HIGH TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311873533.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-12-31
Publication Date
2025-01-24
Estimated Expiration
2043-12-31

AI Technical Summary

Technical Problem

The prior art requires calling a packet password or hash function algorithm when generating random numbers, resulting in slow seed updates and low random number generation efficiency.

Method used

By obtaining the first and secondary array, the byte segmented and using the pre -set non -linear transformation function, recursively generate pseudo -random sequences, generate the first number of array after the initialization as the secret seed, and finally based on secret seeds and second array array Generate random numbers.

Benefits of technology

When the grouping algorithm does not call the grouping algorithm, the seeds are updated faster, the random number has higher efficiency, and the algorithm design concept is clear, and the method is simple.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118113254B_ABST
    Figure CN118113254B_ABST
Patent Text Reader

Abstract

The present application discloses a method, device, electronic device and medium for generating a random number seed, and relates to the field of information security technology. The method for generating a random number seed is as follows: obtaining a first array and a second array, wherein the first array is used as a randomly changing secret seed, and the second array is a temporarily generated character for auxiliary calculation; performing byte segmentation on the first array and the second array, and recursively generating a pseudo-random sequence according to a pre-set nonlinear transformation function; combining the generated pseudo-random sequence to generate an initialized first array, and the initialized first array is used as an updated secret seed; generating a random number based on the updated secret seed and the second array. The present application does not need to call a grouping algorithm, so there is no need to set a key, the method is simple, and the random number generation efficiency is higher.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present application relate to the field of information security, and in particular, to a method, device, electronic device, and medium for generating a random number seed. Background Art

[0002] With the rapid development of computer systems and communication technologies, information security is becoming more and more important to people. In order to improve information security, data encryption and identity authentication are indispensable, which in turn requires the generation of random numbers, and the quality of random numbers directly affects key generation and digital signatures. In some scenarios, hardware-based random number generators are difficult to meet current practical application scenarios because they require corresponding hardware support. Pseudo-random number generators based on software have advantages in practicality, low cost, and easy implementation.

[0003] The classic pseudo-random number generator scheme ANSI X9.17 requires the storage and calling of DES or 3DES keys and random seeds, and three block encryption operations are required to generate each random number. The algorithm design concept of this application proposal is clear and the method is simple. It does not use block ciphers or hash function algorithms. Compared with the ANSI X9.17 scheme, the seed is updated faster and the random number generation efficiency is higher. Summary of the invention

[0004] The embodiments of the present application provide a method, device, and system for generating a random number seed. Without calling a grouping algorithm or setting a key, only a few byte seeds need to be properly stored, thereby improving the efficiency and convenience of random number generation.

[0005] In a first aspect, an embodiment of the present application provides a method for generating a random number seed, comprising:

[0006] Obtain a first array and a second array, wherein the first array serves as a randomly changing secret seed, and the second array is temporarily generated characters for auxiliary calculation; segment the first array and the second array into bytes, and recursively generate a pseudo-random sequence according to a preset nonlinear transformation function; combine the generated pseudo-random sequences to generate an initialized first array, and use the initialized first array as a secret seed; generate a random number based on the secret seed and the second array.

[0007] According to this method, random numbers and updated random seeds can be efficiently generated. If an appropriate nonlinear transformation function suitable for a 64-bit or 32-bit word length of a computer is selected, the efficiency can be several times faster than the ANSI X9.17 scheme because no grouping or hash function algorithm is called.

[0008] In one possible design, the first array includes Q bytes, and the first array is divided into n 8-byte groups, each 8-byte group is called a word, wherein the word representation A of the first array is: A=A n-1 |A n-2 …|A0, Q and n are positive integers, the symbol “|” represents concatenating two data into one; the second array includes P bytes, and the data of the second array is compressed into m 8-byte words, and the word representation B of the second array is: B=B m-1 |B m-2 …|B0, wherein P and m are natural numbers; and the byte segmentation of the first array and the second array, and recursively generating a pseudo-random sequence according to a preset nonlinear transformation function, comprises: using the nonlinear transformation function, concatenating the n words A of the first array and the m words B of the second array into an initial state A|B, and recursively converting the initial state A|B into a pseudo-random sequence of length N+1 words, wherein N is a natural number, and N>2(n+m).

[0009] According to this design, the seed security can be guaranteed. The random number is composed of r words of the N+1 word seed in the pseudo-random sequence. The correlation between these r words is complex. The initial state (including the current seed) cannot be obtained from these r words, nor can the updated random number seed be derived. Therefore, it can be assumed that the attacker can obtain a large number of random numbers. These random numbers are discontinuous and discrete words in the pseudo-random sequence. The relationship between the words is very complex, which makes it impossible for the attacker to obtain the seed from a large number of discrete words. Therefore, this design can ensure the security of the software random number generator algorithm.

[0010] In a possible design, the recursive conversion of the initial state A|B into a pseudo-random sequence of N+1 words in length further includes: setting Y0=A0, Y1=A1, Y2=A2, Y3=A3, Y (n-1) =A (n-1) , Y n =B0,Y n+1 =B1,……,Y n+m-1 =B m-1 For i=n+m, n+m+1, n+m+2, ..., N, calculate Y i =G(Y i-(n+m) ,Y i-(n+m-1) ,Y i-(n+m-2) ,,…,Y i-1 ). Wherein, G is the preset nonlinear transformation function, and Y is a recursively formed pseudo-random sequence with a length of N+1 words.

[0011] According to this design, the algorithm can be forward secure. The updated random number seed is composed of n words on the pseudo-random sequence. The relationship between these n words is complex, and the initial state cannot be obtained from these n words. Therefore, even if the attacker steals the random number seed, the previous random number cannot be derived. Therefore, this design can curb the adverse effects after the random number seed is lost.

[0012] In a possible design, the generated pseudo-random sequence is combined to generate an initialized first array, and the initialized first array is further used as an updated secret seed: n words are selected from a pseudo-random sequence Y with a length of N+1 words to form the initialized first array and used as the secret seed. The step includes: selecting a group of numbers (j1, j2, j3...jn), n+1≤j1, j2, j3,..., jn≤N, using Y j1 ,Y j2 ,Y j3 ,…Y jn These n words update the first array, and the words in the updated first array are represented as: A'=Y jn |…|Y j2 |Y j1 ; The word representation of the secret seed is A'=Y jn |…|Y j2 |Y j1 , convert A' into Q bytes and store them in the first array.

[0013] According to this design, the complex relationship between words can be increased, making it impossible for an attacker to obtain seeds from a large number of discrete words.

[0014] In one possible design, the method also includes: the generating of random numbers based on the secret seed and the second array further includes: recursively converting the secret seed and the second array into a pseudo-random sequence with a length of N+1 words; selecting another r 8-byte words different from the above-mentioned n word positions from the pseudo-random sequence with a length of N+1 words to generate a random number.

[0015] In a possible design, the secret seed and the second array are recursively converted into a pseudo-random sequence of N+1 words, further comprising: the second array is compressed into one word B'0, and Y'0=A'0, Y'1=A'1, Y'2=A'2, Y'3=A'3, Y' (n-1) =A' (n-1) , Y' n =B'0, Y'0 = A'0, for i = n+1, n+2, n+3, ..., N, calculate Y' i =G(Y' i-(n+1) ,Y i-(n) ,Y' i-(n-1),Y i-(n-2) ,Y' i-1 ); wherein G is the preset nonlinear transformation function, and Y' is N+1 8-byte words formed recursively.

[0016] In a possible design, the method further includes selecting r 8-byte words different from the positions of the n words from the pseudo-random sequence of length N+1 words to generate a random number, further comprising: selecting a set of numbers (i1, i2, i3…ir), n+1≤i1,i2,i3,…,in≤N, using Y i1 ,Y i2 ,Y i3 ,…Y ir These r words constitute a random number, and the word of the random number R represents R=Y ir |…|Y i2 |Y i1 , among which, there are large distance differences between i1,i2,i3…ir, and their positions are distributed irregularly.

[0017] In a possible design, when selecting r other words different from the above n word positions, the distance between the positions of the r bytes in the recursive sequence needs to be greater than a set threshold, and the position distribution is irregular.

[0018] In one possible design, when n words are selected from a pseudo-random sequence Y of length N+1 words, the selected n 8-byte positions satisfy that the distance difference between any two positions in the recursive sequence is greater than a given threshold, and the positions are irregularly distributed.

[0019] In one possible design, the data elements in the first array are determined by at least one of the following methods: (i) the first array is determined by converting random data into bytes using a conversion function; (ii) the random data is determined by randomly tapping the keyboard and / or dragging the mouse a number of times, and by recording keyboard input values, time intervals between taps, mouse movement speed and distance information to generate all or part of the random data; (iii) the random data is also determined by obtaining the current system time or the coordinate position value of the cursor on the screen; (iv) the random data is determined based on collected noise or sound information data.

[0020] In one possible design, the data elements in the second array are determined by at least one of the following methods: (i) obtaining the system time from the compilation system; (ii) obtaining the cursor position; (iii) calling an uncertain value related to the system status.

[0021] In the second aspect, the embodiment of the present application also provides a device for generating a random number seed, including an acquisition module, a processing module and a random number generation module. Among them: the acquisition module is used to acquire a first array and a second array, wherein the first array is used as a randomly changing secret seed, and the second array is a temporarily generated character for auxiliary calculation; the processing module is used to segment the first array and the second array into bytes, and recursively generate a pseudo-random sequence according to a pre-set nonlinear transformation function; the generated pseudo-random sequence is combined to generate an initialized first array, and the initialized first array is used as an updated secret seed; the random number generation module is used to generate a random number based on the updated secret seed and the second array.

[0022] In a possible design, the processing module is further configured to: the first array includes Q bytes, and the first array is divided into n 8-byte groups, each 8-byte group is called a word, wherein the word representation A of the first array is:

[0023] A=A n-1 |A n-2 …|A0, Q and n are positive integers, and the symbol “|” means concatenating two data into one;

[0024] The second array includes P bytes, and the data of the second array is compressed into m 8-byte words, and the word representation B of the second array is:

[0025] B=B m-1 |B m-2 …|B0, where P and m are natural numbers;

[0026] Furthermore, the step of performing byte segmentation on the first array and the second array and recursively generating a pseudo-random sequence according to a preset nonlinear transformation function includes:

[0027] Using the nonlinear transformation function, the n words A of the first array and the m words B of the second array are concatenated into an initial state A|B, and the initial state A|B is recursively converted into a pseudo-random sequence of N+1 words in length, where N is a natural number and N>2(n+m).

[0028] In a possible design, the processing module is further used to: recursively convert the initial state A|B into a pseudo-random sequence with a length of N+1 words, further comprising:

[0029] Let Y0=A0, Y1=A1, Y2=A2, Y3=A3, Y (n-1) =A (n-1) , Y n =B0,Y n+1 =B1,……,Yn+m-1 =B m-1 .

[0030] For i = n + m, n + m + 1, n + m + 2, ..., N, calculate

[0031] Y i =G(Y i-(n+m) ,Y i-(n+m-1) ,Y i-(n+m-2) ,,…,Y i-1 );

[0032] Wherein, G is the preset nonlinear transformation function, and Y is a recursively formed pseudo-random sequence with a length of N+1 words.

[0033] In a possible design, the random number generation module is further used to: combine the generated pseudo-random sequence to generate an initialized first array, and the initialized first array is further used as an updated secret seed:

[0034] Selecting n words from a pseudo-random sequence Y of length N+1 words to form the initialized first array and use it as a secret seed, the step comprises:

[0035] Select a set of numbers (j1, j2, j3…jn), n+1≤j1, j2, j3,…, jn≤N, and use Y j1 ,Y j2 ,Y j3 ,…Y jn These n words update the first array, and the words in the updated first array are represented as follows:

[0036] A'=Y jn |…|Y j2 |Y j1 ;

[0037] The updated secret seed is represented by A'=Y jn |…|Y j2 |Y j1 , convert A' into Q bytes and store them in the first array.

[0038] In a possible design, the random number generation module is further used to: the generating of the random number based on the secret seed and the second array further includes:

[0039] Recursively transforming the secret seed and the second array into a pseudo-random sequence of N+1 words in length;

[0040] Select another r words different from the above n word positions from the pseudo-random sequence with a length of N+1 words to generate a random number.

[0041] In a possible design, the random number generation module is further used to: recursively convert the secret seed and the second array into a pseudo-random sequence with a length of N+1 words, further comprising:

[0042] Let Y'0=A'0, Y'1=A'1, Y'2=A'2, Y'3=A'3, Y' (n-1) =A' (n-1) , Y' n =B'0, Y'0 = A'0, for i = n+1, n+2, n+3, ..., N, calculate Y' i =G(Y' i-(n+1) ,Y i-(n) ,Y' i-(n-1) ,

[0043] Y i-(n-2) ,Y' i-1 );

[0044] Wherein, G is the preset nonlinear transformation function, and Y' is N+1 8-byte words formed recursively.

[0045] In a possible design, the random number generation module further includes: selecting another r words different from the positions of the n words from the pseudo-random sequence of the length N+1 words to generate a random number, further comprising:

[0046] Select a set of numbers (i1,i2,i3…ir), n+1≤i1,i2,i3,…,in≤N, and use Y i1 ,Y i2 ,Y i3 ,…Y ir These r words constitute a random number, and the word representation of the random number R is R=Y ir |…|Y i2 |Y i1 .

[0047] In a possible design, the random number generation module is also used for: when selecting r other words different from the above n word positions, the distance between the positions of the r words in the recursive sequence needs to be greater than a set threshold, and the position distribution is irregular.

[0048] In one possible design, the processing module is also used for: when selecting n words from a pseudo-random sequence Y with a length of N+1 words, the selected n 8-word positions satisfy that the distance difference between any two positions in the recursive sequence is greater than a given threshold, and the position distribution is irregular.

[0049] In a possible design, the acquisition module further includes: determining the data elements in the first array by at least one of the following methods:

[0050] (i) the first array is determined by converting random data into bytes using a conversion function;

[0051] (ii) the random data is determined by randomly tapping the keyboard and / or dragging the mouse a certain number of times, and by recording the keyboard input value, the time interval between taps, the mouse movement speed and distance information to generate all or part of the random data;

[0052] (iii) the random data is also determined by obtaining the current system time or the coordinate position value of the cursor on the screen;

[0053] (iv) The random data is determined based on the collected noise or sound information data.

[0054] In a possible design, the acquisition module further includes: determining the data elements in the second array by at least one of the following methods:

[0055] (i) Get system time from the compilation system;

[0056] (ii) obtaining the cursor position;

[0057] (iii) Calling uncertain values ​​related to the system state.

[0058] In a third aspect, an embodiment of the present application further provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the computer program is executed by the processor, the processor implements the first aspect and any one of the designed methods thereof.

[0059] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method of the first aspect and any one of its designs is implemented.

[0060] The technical effects brought about by the second to fourth aspects and any one of their designs can refer to the technical effects brought about by the corresponding design of the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0062] Figure 1 A schematic diagram of a flow chart of a method for generating a random number seed provided in an embodiment of the present application;

[0063] Figure 2 A schematic diagram of a method for implementing a nonlinear transformation function provided in an embodiment of the present application;

[0064] Figure 3 A schematic diagram of a device structure provided in an embodiment of the present application;

[0065] Figure 4 A schematic diagram of another device structure provided in an embodiment of the present application. DETAILED DESCRIPTION

[0066] In order to make the purpose, technical scheme and advantages of the present application clearer, the technical scheme in the embodiment of the present application will be clearly and completely described below in conjunction with the drawings in the embodiment of the present application. Obviously, the described embodiment is only a part of the embodiment of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application. In the absence of conflict, the embodiments in the present application and the features in the embodiments can be arbitrarily combined with each other. In addition, although the logical order is shown in the flow chart, in some cases, the steps shown or described can be performed in an order different from that here.

[0067] The terms "first" and "second" in the specification and claims of the present application and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the term "comprising" and any of their variations are intended to cover non-exclusive protection. For example, a process, method, system, product or device comprising a series of steps or units is not limited to the listed steps or units, but optionally also includes steps or units that are not listed, or optionally also includes other steps or units inherent to these processes, methods, products or devices. "Multiple" in the present application can mean at least two, for example, two, three or more, and the embodiments of the present application are not limited.

[0068] In the technical solution of this application, the collection, dissemination, and use of data are in compliance with the requirements of relevant national laws and regulations.

[0069] Before introducing a method for generating a random number seed provided in an embodiment of the present application, for ease of understanding, the technical background of the embodiment of the present application is first introduced in detail below.

[0070] Nowadays, hardware-based random number generators and true random number generators based on physical noise have entered practical use. However, in some scenarios, they are difficult to meet the current practical application needs. The main characteristics of this type of product are high production costs and limited application scenarios, such as being inconvenient to use on smart mobile terminals. In contrast, pseudo-random number generators implemented based on software programming have advantages in practicality, low cost and easy implementation, and are even easier to meet randomness detection requirements. According to different application requirements and security concepts, many software random number generator solutions have emerged. Random number generators based on block cipher algorithms such as DES, 3DES, AES and MD5 hash function algorithms are more common, and generally adopt a logical structure similar to the American pseudo-random number generator standard ANSI X9.17.

[0071] The technical solution of pseudo-random number generator implemented by existing software programming is analyzed as follows:

[0072] Since the DES algorithm with only a 56-bit key is easily deciphered, the security of the ANSI X9.17 pseudo-random number generator implemented by DES is questionable, and the key and seed may be easily obtained. However, the ANSI X9.17 pseudo-random number generator implemented by the AES or TDEA algorithm (3DES) is considered to be a pseudo-random number generator with high cryptographic strength. In the ANSI X9.17 logical structure, each time a random number is generated, three block encryption operations need to be called, which is not efficient, and the encryption key and internal state seed data need to be securely stored. When using the 3DES algorithm, two keys and seeds need to be securely stored, and the sampling entropy source needs to be called. Not only is the computational efficiency low, but only 8 bytes of random number memory are generated each time, which consumes a lot of memory. Because my country does not have such detailed specifications and standards, the performance of products from different merchants varies greatly, and the security concepts are also different.

[0073] In order to solve the above problems, the scheme involved in this application has certain advantages in structural design, random number generation efficiency and seed update method. Compared with the ANSI X9.17 scheme, the algorithm design concept of this application proposal is clear, the method is simple, the seed update is faster, and the random number generation efficiency is higher. This application proposal does not call the grouping algorithm, so there is no need to set the key, only a few bytes of seeds need to be properly stored. In one embodiment of the present application, the proposed method can generate 32 bytes of random numbers at a time, which is suitable for use with the national secret algorithm SM2, and is also convenient for use in algorithms such as SM4 and ZUC.

[0074] Figure 1 A flowchart of a method for generating a random number seed is shown exemplarily.

[0075] refer to Figure 1The process shown in the figure, the method and steps provided in the embodiment of the present application include:

[0076] Step 101, obtaining a first array and a second array;

[0077] Step 102, segmenting the first array and the second array into bytes, and recursively generating a pseudo-random sequence according to a preset nonlinear transformation function;

[0078] Step 103, combining according to the generated pseudo-random sequence to generate an initialized first array, wherein the initialized first array is used as a secret seed;

[0079] Step 104: Generate a random number based on the secret seed and the second array.

[0080] Optionally, in step 101, a first array and a second array are obtained, wherein the first array is used as a randomly changing secret seed, and the second array is temporarily generated characters for auxiliary calculation.

[0081] Furthermore, the first array is used to store a number of pseudo-randomly changing byte secret seeds. The seed is the core security parameter in the random number generator and the main entropy source in the software random number generator described in this proposal. The first array can be written to a disk file, read into a memory unit when used, or stored in the memory unit for a long time.

[0082] Before the random number generator works, it is necessary to assign an initial value to the first array. The data elements in the first array are determined after the random data is converted into bytes using a conversion function. There are many ways to generate the random number data, which are not limited in this case. The random number data can be generated by the operator randomly tapping the keyboard and dragging the mouse several times, and / or by recording the keyboard input value, the time interval between taps, the mouse movement speed, distance and other information to generate all or part of the random data. It is also possible to generate all or part of the random number by obtaining the current system time and / or the coordinate position value of the cursor on the screen and / or the noise or sound collected and other types of information data.

[0083] Furthermore, the second array stores a string of temporarily generated characters, which may be generated in a variety of ways and is not limited in this case. The method for generating the data elements in the second array may be by obtaining the system time and / or the cursor position in the compilation system and / or calling an uncertain value related to the system status.

[0084] Optionally, in step 102, the first array and the second array are segmented into bytes, and a pseudo-random sequence is recursively generated according to a preset nonlinear transformation function.

[0085] Further, the first array includes Q bytes, and the first array is divided into n 8-byte groups, each 8-byte group is called a word, wherein the word representation A of the first array is:

[0086] A=A n-1 |A n-2 ...|A0, Q and n are positive integers, and the symbol "|" means to concatenate two data into one. n-1 When it is less than 8 bytes, it is also regarded as 8 bytes;

[0087] The second array includes P bytes, and the data of the second array is compressed into m 8-byte words, and the word representation B of the second array is:

[0088] B=B m-1 |B m-2 ...|B0, where P and m are natural numbers. When the last group B m-1 When it is less than 8 bytes, it is also regarded as 8 bytes;

[0089] Furthermore, the step of performing byte segmentation on the first array and the second array and recursively generating a pseudo-random sequence according to a preset nonlinear transformation function includes:

[0090] Using the nonlinear transformation function, the n-word representation A of the first array and the m-word representation B of the second array are concatenated into an initial state A|B, and the initial state A|B is recursively converted into a pseudo-random sequence of N+1 words in length, where N is a natural number and N>2(n+m).

[0091] Let Y0=A0, Y1=A1, Y2=A2, Y3=A3, Y (n-1) =A (n-1) , Y n =B0,Y n+1 =B1,……,Y n+m-1 =B m-1 .

[0092] For i = n + m, n + m + 1, n + m + 2, ..., N, calculate

[0093] Y i =G(Y i-(n+m) ,Y i-(n+m-1) ,Y i-(n+m-2) ,,…,Y i-1 );

[0094] Wherein, G is the preset nonlinear transformation function, and Y is a recursively formed pseudo-random sequence of length N+1 words. To ensure security, G is selected as a nonlinear balance function with cryptographic properties. For example, if the values ​​at several specific positions in the sequence are known, it is difficult to infer or obtain the values ​​at other positions.

[0095] In the recursive formula, the initial value of the pseudo-random number sequence Y is provided by the first array and the second array. If the first array is 32 bytes and the second array is compressed into one 8-byte B0, then the initial value of the pseudo-random number sequence Y is 5. If the first array is 40 bytes and the second array is compressed into two 8-bytes B1 and B0, the initial value of the pseudo-random number sequence Y can be increased by 1.

[0096] Optionally, in step 103, combining is performed according to the generated pseudo-random sequence to generate an initialized first array, and the initialized first array is used as an updated secret seed.

[0097] Further, n words are selected from a pseudo-random sequence Y of length N+1 words to form the initialized first array and used as a secret seed. The step includes:

[0098] Select a set of numbers (j1, j2, j3…jn), n+1≤j1, j2, j3,…, jn≤N, and use Y j1 ,Y j2 ,Y j3 ,…Y jn These n words update the first array, and the words in the updated first array are represented as follows:

[0099] A'=Y jn |…|Y j2 |Y j1 ;

[0100] The updated secret seed is represented by A'=Y jn |…|Y j2 |Y j1 , convert A' into Q bytes and store them in the first array.

[0101] When n words are selected from a pseudo-random sequence Y of length N+1 words, the positions of the n 8 bytes selected satisfy that the distance difference between any two positions in the recursive sequence is greater than a given threshold, and their positions are irregularly distributed. In other words, the selection of (j1, j2, j3 ... jn) is required, and the distance difference between numbers should be large, and two adjacent numbers cannot be selected.

[0102] Optionally, in step 104, a random number is generated based on the secret seed and the second array.

[0103] Further, the secret seed and the second array are recursively converted into a pseudo-random sequence with a length of N+1 words;

[0104] Select another r words different from the above n word positions from the pseudo-random sequence with a length of N+1 words to generate a random number.

[0105] The recursive conversion of the secret seed and the second array into a pseudo-random sequence of N+1 words in length further comprises:

[0106] Let Y'0=A'0, Y'1=A'1, Y'2=A'2, Y'3=A'3, Y' (n-1) =A' (n-1) , Y' n =B'0, Y'0 = A'0, for i = n+1, n+2, n+3, ..., N, calculate Y' i =G(Y' i-(n+1) ,Y i-(n) ,Y' i-(n-1) ,

[0107] Y i-(n-2) ,Y' i-1 );

[0108] Wherein, G is the preset nonlinear transformation function, and Y' is N+1 8-byte words formed recursively.

[0109] The step of selecting r other words different from the positions of the n words from the pseudo-random sequence of N+1 words in length to generate a random number is further as follows:

[0110] Select a set of numbers (i1,i2,i3…ir), n+1≤i1,i2,i3,…,in≤N, and use Y i1 ,Y i2 ,Y i3 ,…Y ir These r words constitute a random number, and the word of the random number R represents R=Y ir |…|Y i2 |Y i1 .

[0111] When selecting r words different from the above n word positions, the distance between the positions of the r words in the recursive sequence needs to be greater than the set threshold, and the position distribution is irregular. In other words, the selection of (i1, i2, i3…ir) has requirements, and there should be a large distance between the numbers, and two adjacent numbers cannot be selected.

[0112] Figure 2 A schematic diagram of a method for implementing a nonlinear transformation function is shown exemplarily.

[0113] The first array of the agreed number is 32 bytes, recorded as A3|A2|A1|A0. The second array is 16 bytes long, and the 16 bytes are compressed into 8 bytes, recorded as B0. Then, the recursive initial value (Y0, Y1, Y2, Y3, Y4) is assigned by A0, A1, A2, A3 and B0.

[0114] Exemplarily, the nonlinear transformation function is selected as:

[0115]

[0116] Among them, ∩ and ∪ are logical operators, ∩ is the bitwise AND of two 64-bit numbers, ∪ is the bitwise OR of two 64-bit numbers, ⊕ is the bitwise XOR of two 64-bit numbers, and mod is the modulus operation. The recursive formula uses a mixture of arithmetic operations and logical operations, and the recursive formula is an irreversible nonlinear function. Even if the attacker steals the random number seed, the previous random number cannot be derived. This design can avoid the adverse effects after the random number seed is lost.

[0117] (Y i-4 ) 3 As the f function. There are many options for this function, for example, i-4 Do bit transposition disorder, Y i-4 Do byte replacement, based on modulo operation with Y i-4 Perform some polynomial operations on the variables, etc. The f function is a sub-function in the preset nonlinear transformation function, and the function of the f function is to increase the complexity of this embodiment, thereby increasing the security of this embodiment.

[0118] For example, if (i1, i2, i3, i4) = (7, 17, 28, 37) and (j1, j2, j3, j4) = (11, 40, 31, 22) are selected, then when random numbers need to be output, the four 64-bit numbers Y7, Y17, Y28, and Y37 (a total of 32 bytes) will be output, and the first array will be updated to A0 = Y11, A1 = Y40, A2 = Y31, and A3 = Y22.

[0119] The above exemplary embodiment uses the first array of 32 bytes as a seed. Obviously, the number of bytes of the first array A can also be 24 bytes, 40 bytes, 48 ​​bytes, or even not a multiple of 8 bytes, such as 30, 36, 50 bytes, etc. After the second array B is compressed, it can also be compressed into two or three 64-bit numbers (not limited to only forming a 64-bit number B0). Finally, it is necessary to determine the recursive logic according to the scale of the arrays A and B. The number of recursive steps can be set according to comprehensive factors such as the complexity of the recursive logic, security strength requirements and performance requirements. If the total number of recursive steps is large, the values ​​selected from the sequence can be far apart, and the security will be better, but the efficiency of generating random numbers will be relatively low.

[0120] Based on the same technical concept, the present application exemplarily provides a random number seed generation device. The device can be used to perform the actions described in the above method embodiment. In this embodiment, the structure of the device can be as follows: Figure 3 shown.

[0121] like Figure 3 As shown, the present application exemplarily provides a random number seed generation device which may include an acquisition module 301 , a processing module 302 , and a random number generation module 303 .

[0122] When obtaining the first array and the second array, the obtaining module 301 is used to obtain the first array and the second array, wherein the first array is used as a randomly changing secret seed, and the second array is a temporarily generated character for auxiliary calculation;

[0123] The processing module 302 is used to perform byte segmentation on the first array and the second array, and recursively generate a pseudo-random sequence according to a preset nonlinear transformation function; combine the generated pseudo-random sequences to generate an initialized first array, and use the initialized first array as an updated secret seed;

[0124] Optionally, the processing module 302 is further configured to: the first array includes Q bytes, and the first array is divided into n 8-byte groups, each 8-byte group is called a word, wherein the word representation A of the first array is:

[0125] A=A n-1 |A n-2 ...|A0, Q and n are positive integers, and the symbol "|" means to concatenate two data into one. n-1 When it is less than 8 bytes, it is also regarded as 8 bytes;

[0126] The second array includes P bytes, and the data of the second array is compressed into m 8-byte words, and the word representation B of the second array is:

[0127] B=B m-1 |B m-2 ...|B0, where P and m are natural numbers. When the last group B m-1 When it is less than 8 bytes, it is also regarded as 8 bytes;

[0128] Furthermore, the step of performing byte segmentation on the first array and the second array and recursively generating a pseudo-random sequence according to a preset nonlinear transformation function includes:

[0129] Using the nonlinear transformation function, the n words A of the first array and the m words B of the second array are concatenated into an initial state A|B, and the initial state A|B is recursively converted into a pseudo-random sequence of N+1 words in length, where N is a natural number and N>2(n+m).

[0130] Optionally, the processing module 302 is further used to: recursively convert the initial state A|B into a pseudo-random sequence with a length of N+1 words, further comprising:

[0131] Let Y0=A0, Y1=A1, Y2=A2, Y3=A3, Y (n-1) =A (n-1) , Y n =B0,Y n+1 =B1,……,Y n+m-1 =B m-1 .

[0132] For i = n + m, n + m + 1, n + m + 2, ..., N, calculate

[0133] Y i =G(Y i-(n+m) ,Y i-(n+m-1) ,Y i-(n+m-2) ,,…,Y i-1 );

[0134] Wherein, G is the preset nonlinear transformation function, and Y is a recursively formed pseudo-random sequence with a length of N+1 words.

[0135] Optionally, the processing module 302 is further configured to: when selecting n words from the pseudo-random sequence Y having a length of N+1 words, select n 8-byte positions such that the distance difference between any two positions in the recursive sequence is greater than a given threshold.

[0136] The random number generation module 303 is used to generate a random number based on the updated secret seed and the second array.

[0137] Optionally, the random number generation module 303 is further used to: combine the generated pseudo-random sequence to generate an initialized first array, and the initialized first array is further used as a secret seed:

[0138] Selecting n words from a pseudo-random sequence Y of length N+1 words to form the initialized first array and use it as a secret seed, the step comprises:

[0139] Select a set of numbers (j1, j2, j3…jn), n+1≤j1, j2, j3,…, jn≤N, and use Y j1 ,Y j2 ,Y j3 ,…Yjn These n words update the first array, and the words in the updated first array are represented as follows:

[0140] A'=Y jn |…|Y j2 |Y j1 ;

[0141] The updated secret seed is represented by A'=Y jn |…|Y j2 |Y j1 , convert A' into Q bytes and store them in the first array.

[0142] Optionally, the random number generation module 303 is further configured to: generate a random number based on the secret seed and the second array further comprises:

[0143] Recursively transforming the secret seed and the second array into a pseudo-random sequence of N+1 words in length;

[0144] Select another r words different from the above n word positions from the pseudo-random sequence with a length of N+1 words to generate a random number.

[0145] Optionally, the random number generation module 303 is further used to: recursively convert the secret seed and the second array into a pseudo-random sequence with a length of N+1 words, further comprising:

[0146] Let Y'0=A'0, Y'1=A'1, Y'2=A'2, Y'3=A'3, Y' (n-1) =A' (n-1) , Y' n =B'0, Y'0 = A'0, for i = n+1, n+2, n+3, ..., N, calculate Y' i =G(Y' i-(n+1) ,Y i-(n) ,Y' i-(n-1) ,

[0147] Y i-(n-2) ,Y' i-1 );

[0148] Wherein, G is the preset nonlinear transformation function, and Y' is N+1 8-byte words formed recursively.

[0149] In a possible design, the random number generation module further includes: selecting r other words different from the above n positions from the pseudo-random sequence of N+1 words in length to generate a random number, further comprising:

[0150] Select a set of numbers (i1,i2,i3…ir), n+1≤i1,i2,i3,…,in≤N, and use Yi1 ,Y i2 ,Y i3 ,…Y ir These r words constitute a random number, and the word of the random number R represents R=Y ir |…|Y i2 |Y i1 .

[0151] Optionally, the random number generation module 303 is further configured to: when selecting r words different from the above n positions, the distance between the positions of the r words in the recursive sequence needs to be greater than a set threshold, and the positions are irregularly distributed. In other words, there should be a large gap between the numbers, and two adjacent numbers are not desirable.

[0152] Optionally, the acquisition module 301 is further configured to: determine the data elements in the first array by at least one of the following methods:

[0153] (i) the first array is determined by converting random data into bytes using a conversion function;

[0154] (ii) the random data is determined by randomly tapping the keyboard and / or dragging the mouse a certain number of times, and by recording the keyboard input value, the time interval between taps, the mouse movement speed and distance information to generate all or part of the random data;

[0155] (iii) the random data is also determined by obtaining the current system time or the coordinate position value of the cursor on the screen;

[0156] (iv) The random data is determined based on the collected noise or sound information data.

[0157] Optionally, the acquisition module 302 is further configured to: determine the data elements in the second array by at least one of the following methods:

[0158] (i) Get system time from the compilation system;

[0159] (ii) obtaining the cursor position;

[0160] (iii) Calling uncertain values ​​related to the system state.

[0161] Based on the same inventive concept as the above method embodiment, an electronic device is also provided in the embodiment of the present application. The electronic device can be used to perform the actions described in the above method embodiment. In this embodiment, the structure of the electronic device can be as follows: Figure 4 As shown, it includes a memory 401 and one or more processors 402 .

[0162] The memory 401 is used to store computer programs executed by the processor 402. The memory 401 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system and programs required for running the instant messaging function, etc.; the data storage area may store various instant messaging information and operation instruction sets, etc.

[0163] The memory 401 may be a volatile memory, such as a random-access memory (RAM); the memory 401 may also be a non-volatile memory, such as a read-only memory, a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD), or the memory 401 is any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory 401 may be a combination of the above memories.

[0164] The processor 402 may include one or more central processing units (CPU) or a digital processing unit, etc. The processor 402 is used to implement the above method when calling the computer program stored in the memory 401.

[0165] The specific connection medium between the memory 401 and the processor 402 is not limited in the embodiment of the present application. Figure 4 In the embodiment, the memory 401 and the processor 402 are connected via a bus 403. The bus 403 is connected to the processor 402 via a bus 403. Figure 4 The connections between other components are shown in bold lines, which are only for illustration and are not intended to be limiting. Bus 403 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 4 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0166] Optionally, the processor 402 may be configured to execute the above actions performed by any one or more of the acquisition module 301 , the processing module 302 , and the random number generation module 303 .

[0167] According to one aspect of the present application, a computer program product or computer program is provided, the computer program product or computer program includes computer instructions, the computer instructions are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the method in the above embodiment.

[0168] 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 may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0169] The above description is only a specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application.

Claims

1. A method for generating a random number seed, characterized in that: include: Obtain a first array and a second array, wherein the first array is used as a randomly changing secret seed, and the second array is temporarily generated characters for auxiliary calculation; Byte segmentation is performed on the first array and the second array, and a pseudo-random sequence is recursively generated according to a preset nonlinear transformation function; Wherein, the nonlinear transformation function is: AND i =[(And i-5 ∩And i-3 )∪(And i-3 ∩And i-2 )∪(And i-2 ∩And i-1 )]⊕[(And i-4 ) 3 mod 2 64 ] i=5,6,7,……,40; The ∩ and ∪ are logical operators, the ∩ is the bitwise AND of two 64-bit numbers, the ∪ is the bitwise OR of two 64-bit numbers, the ⊕ is the bitwise XOR of two 64-bit numbers, and the mod is a modulus operation; Selecting n words from a pseudo-random sequence Y of length N+1 words to form the initialized first array and serve as a secret seed; and the positions of the selected n 8-words satisfy that the distance difference between any two positions in the recursive sequence is greater than a given threshold, and the positions are irregularly distributed; Recursively transforming the secret seed and the second array into a pseudo-random sequence of N+1 words in length; Select r other words different from the positions of the n words from the pseudo-random sequence of N+1 words to generate a random number; and the distance between the positions of the r other words in the recursive sequence needs to be greater than a given threshold, and the position distribution is irregular.

2. The method according to claim 1, characterized in that The first array includes Q bytes, and the first array is divided into n 8-byte groups, each 8-byte group is called a word, wherein the word representation A of the first array is: A=A n-1 |A n-2 ...|A0, Q and n are positive integers, and the symbol "|" means to concatenate two data into one. n-1 When it is less than 8 bytes, it is also regarded as 8 bytes; The second array includes P bytes, and the data of the second array is compressed into m 8-byte words, and the word representation B of the second array is: B=B m-1 |B m-2 ...|B0, where P and m are natural numbers. When the last group B m-1 When it is less than 8 bytes, it is also regarded as 8 bytes; Furthermore, the step of performing byte segmentation on the first array and the second array and recursively generating a pseudo-random sequence according to a preset nonlinear transformation function includes: Using the nonlinear transformation function, the n-word representations of the first array and the m-word representations of the second array are concatenated into an initial state A|B, and the initial state A|B is recursively converted into a pseudo-random sequence of N+1 words in length, where N is a natural number and N>2(n+m).

3. The method according to claim 2, characterized in that The recursive conversion of the initial state A|B into a pseudo-random sequence of N+1 words in length further comprises: <h2 style=";text-align:left;direction:ltr">Y0=A0,Y1=A1,Y2=A2,Y3=A3,Y<h2 style=";text-align:left;direction:ltr"> (n-1) <h2 style=";text-align:left;direction:ltr"> =A<h2 style=";text-align:left;direction:ltr"> (n-1) <h2 style=";text-align:left;direction:ltr"> ,Y<h2 style=";text-align:left;direction:ltr"> n <h2 style=";text-align:left;direction:ltr"> =B0,Y<h2 style=";text-align:left;direction:ltr"> n+1 <h2 style=";text-align:left;direction:ltr"> =B1,……,Y<h2 style=";text-align:left;direction:ltr"> n+m-1 <h2 style=";text-align:left;direction:ltr"> =B<h2 style=";text-align:left;direction:ltr"> m-1 <h2 style=";text-align:left;direction:ltr"> ; For i = n + m, n + m + 1, n + m + 2, ..., N, calculate AND i =G(Y i-(n+m) ,AND i-(n+m-1) ,AND i-(n+m-2) ,,…,AND i-1 ); Wherein, G is the preset nonlinear transformation function, and Y is a recursively formed pseudo-random sequence with a length of N+1 words.

4. The method according to claim 1, characterized in that The method further comprises: selecting n words from a pseudo-random sequence Y having a length of N+1 words to form the initialized first array and serving as a secret seed; Select a set of numbers (j1, j2, j3…jn), n+1≤j1, j2, j3,…, jn≤N, and use Y j1 ,Y j2 ,Y j3 ,…Y jn These n words update the first array, and the words in the updated first array are represented as follows: A'=Y jn |…|And j2 |And j1 ; The updated secret seed is represented by A'=Y jn |…|Y j2 |Y j1 , convert A' into Q bytes and store them in the first array.

5. The method according to claim 4, characterized in that The recursive conversion of the secret seed and the second array into a pseudo-random sequence of N+1 words in length further comprises: Let Y'0 = A'0, Y'1 = A'1, Y'2 = A'2, Y'3 = A'3, Y' (n-1) = A' (n-1) , Y' n = B'0, Y'0 = A'0, for i = n + 1, n + 2, n + 3, ……, N, calculate Y' i = G(Y' i-(n+1) , Y i-(n) , Y' i-(n-1) , AND i-(n-2) ,AND' i-1 ); Wherein, G is the preset nonlinear transformation function, and Y' is N+1 8-byte words formed recursively.

6. The method according to claim 5, characterized in that The step of selecting r other words different from the positions of the n words from the pseudo-random sequence of N+1 words in length to generate a random number is further as follows: Select a set of numbers (i1,i2,i3…ir), n+1≤i1,i2,i3,…,in≤N, and use Y i1 ,Y i2 ,Y i3 ,…Y ir These r words constitute a random number, and the word representation of the random number R is R=Y ir |…|Y i2 |Y i1 .

7. The method according to claim 1, characterized in that The data elements in the first array are determined by at least one of the following methods: (i) the first array is determined by converting random data into bytes using a conversion function; (ii) the random data is determined by randomly tapping the keyboard and / or dragging the mouse a certain number of times, and by recording the keyboard input value, the time interval between taps, the mouse movement speed and distance information to generate all or part of the random data; (iii) the random data is also determined by obtaining the current system time or the coordinate position value of the cursor on the screen; (iv) The random data is determined based on the collected noise or sound information data.

8. The method according to claim 1, characterized in that The data elements in the second array are determined by at least one of the following methods: (i) Get system time from the compilation system; (ii) obtaining the cursor position; (iii) Calling uncertain values ​​related to the system state.

9. A random number seed generation device, characterized in that: An acquisition module, used to acquire a first array and a second array, wherein the first array is used as a randomly changing secret seed, and the second array is temporarily generated characters for auxiliary calculation; A processing module, configured to perform byte segmentation on the first array and the second array, and recursively generate a pseudo-random sequence according to a preset nonlinear transformation function; Wherein, the nonlinear transformation function is: AND i =[(And i-5 ∩And i-3 )∪(And i-3 ∩And i-2 )∪(And i-2 ∩And i-1 )]⊕[(And i-4 ) 3 mod 2 64 ] i=5,6,7,……,40; The ∩ and ∪ are logical operators, the ∩ is the bitwise AND of two 64-bit numbers, the ∪ is the bitwise OR of two 64-bit numbers, the ⊕ is the bitwise XOR of two 64-bit numbers, and the mod is a modulus operation; Selecting n words from a pseudo-random sequence Y of length N+1 words to form the initialized first array and use it as a secret seed; and the positions of the selected n 8-words satisfy that the distance difference between any two positions in the recursive sequence is greater than a given threshold, and the positions are irregularly distributed; recursively converting the secret seed and the second array into a pseudo-random sequence of length N+1 words; The random number generation module is used to select r other words different from the positions of the n words from the pseudo-random sequence of N+1 words in length to generate a random number; and the distance difference between the positions of the r other words in the recursive sequence needs to be greater than a given threshold, and the position distribution is irregular.

10. An electronic device, characterized in that: It comprises a processor and a memory, wherein the memory stores program codes, and when the program codes are executed by the processor, the processor executes the steps of any one of the methods in claims 1 to 8.

11. A computer-readable storage medium, characterized in that: The method comprises a program code, and when the program code is run on an electronic device, the program code is used to enable the electronic device to execute the steps of any method described in claims 1 to 8.

Citation Information

Patent Citations

  • Random number generation method and device, electronic equipment and storage medium

    CN115051798A

  • Power efficient codeword scrambling in non-volatile memory devices

    CN117149059A