Random number detection device and method, storage medium, and electronic device
By cyclically inputting and discarding old data, combined with single-bit frequency, poker and repeated count detection, the missed detection and reporting problem in random number detection is solved, ensuring the accuracy and safety of random number detection.
Patent Information
- Application Number
- CN202410805966.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-21
- Publication Date
- 2024-12-10
- Estimated Expiration
- 2044-06-21
AI Technical Summary
In the prior art, random number detection has problems such as missed detection or missed detection, resulting in safety problems.
Through the connection between the entropy source module and the detection module, the data group of the target random number is input cycled, and the old data is discarded when receiving new data to ensure data continuity and updates, and the single-bit frequency detection module, poker detection module and repeated count detection are used. The module performs inspection to ensure the accuracy of the inspection.
It effectively solves the problem of missed detection or misreport, and can detect random number defects at the first time, avoid affecting the functions and security of subsequent modules, and eliminates time hysteresis.
Smart Images

Figure CN118377459B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computers, and more specifically, to a random number detection device and method, a storage medium, and an electronic device. Background Art
[0002] Random number generation is critical for any security device. Random numbers can be used in key generation, key exchange, digital signatures, encryption and decryption, and can be applied to typical security protocols such as IPsec, MACsec, TLS / SSL or wireless protocols. They are also used in the authentication / key exchange and data transmission stages. Random numbers play a vital role in cryptography, encryption and decryption, and information data security.
[0003] Random number generators are divided into two main types: true random number generators (TRNG) and pseudo random number generators (PRNG). Compared to PRNG, which is based on a fixed algorithm, TRNG uses the randomness of physical processes. The entropy source is generally uncertain, random events or some physical phenomena, such as thermal noise, circuit jitter or atomic fission. Random number sequences are generated through these unpredictable and uncontrollable phenomena in nature. This type of random number has no definite trend and significant regularity, and is not easy to be predicted and attacked, but it is also not easy to control, and its security is generally higher than that of pseudo random numbers.
[0004] An ideal TRNG is a process of taking values from discrete random variables that are independent and evenly distributed. The true random numbers output by TRNG generally need to meet the requirements of uniformity of distribution, correlation, randomness, and independence. The true random numbers output by TRNG generally need to meet the requirements of uniformity of distribution, correlation, randomness, and independence. Based on these requirements, different countries have different standards and inspection items for the quality of true random numbers.
[0005] In the related technology (including hardware and software detection), the true random numbers are first grouped, for example, into GROUP1 GROUP2... Each detection is performed within a GROUP. When the last data of a GROUP (at 2048 bits), the detection result is output, and then the next group is checked. According to the detection standard of random numbers, any segment of data should meet the various detection standards. When the data of GROUP1 and GROUP2 are detected separately, the detection requirements may be met, but when the second half of the data of GROUP1 and the first half of the data of GROUP2 are analyzed, the detection may fail. If the detection is performed according to the existing technology, there will be no detection error, so there is a problem of missed detection or missed detection, resulting in defective random number output, which leads to security issues.
[0006] Regarding the related technologies, there are problems of missed detection or missed detection in the detection of random numbers, and no effective solution has been proposed so far.
[0007] Therefore, it is necessary to improve the related technology to overcome the above-mentioned defects in the related technology. Summary of the invention
[0008] The embodiments of the present application provide a random number detection device and method, a storage medium, and an electronic device to at least solve the problem of missed detection or missed reporting in the detection of random numbers in the related art.
[0009] According to an embodiment of the present application, a random number detection device is provided, comprising: an entropy source module, and a detection module connected to the entropy source module, wherein the entropy source module is used to perform a first input step: input a first random number into the detection module, wherein the first random number is the Nth data group to the N+Mth data group in the target random number, the Nth data group includes: one or multiple consecutive bit values in the target random number, and the N+Mth data group includes: one or multiple consecutive bit values in the target random number, and N and M are positive integers; when N is 2, 3, ... Z in sequence, the first input step is executed cyclically until the detection module determines that the detection of the target random number fails, or the Zth data group is input into the detection module; the detection module is used to determine a first detection result of the first random number, and determine a second detection result of the target random number according to the first detection result.
[0010] In an exemplary embodiment, the random number detection device further includes: a first-in-first-out memory connected to the entropy source module and the detection module respectively, wherein the first-in-first-out memory is used to store a second random number, and after the detection module determines a first detection result of the first random number based on the Nth data group to the N+Mth data group, the Nth data group in the target random number is input into the detection module, wherein the second random number is the Nth data group to the N+Mth data group in the target random number.
[0011] In an exemplary embodiment, the entropy source module is further used to input the N+M+1th data group into the detection module after the detection module determines the first detection result of the first random number based on the Nth data group to the N+Mth data group; the detection module is further used to discard the Nth data group upon receiving the N+M+1th data group input by the entropy source module to determine the updated first random number; determine a third detection result of the updated first random number based on the N+M+1th data group and / or the Nth data group, and determine the second detection result based on the third detection result.
[0012] In an exemplary embodiment, the detection module includes at least one of the following: a single-bit frequency detection module, a poker detection module, and a repeated count detection module, wherein the single-bit frequency detection module is used to determine a third detection result of the updated first random number based on the N+M+1th data group and the Nth data group; the poker detection module is used to determine the third detection result of the updated first random number based on the N+M+1th data group and the Nth data group; the repeated count detection module is used to determine the third detection result of the updated first random number based on the N+M+1th data group.
[0013] In an exemplary embodiment, the single-bit frequency detection module is further used to determine whether the bit value in the N+M+1th data group is consistent with the bit value in the Nth data group, wherein the N+M+1th data group and the Nth data group both include: a bit value; when the bit value in the N+M+1th data group is consistent with the bit value in the Nth data group, it is prohibited to adjust the first count value and the second count value, and determine the third detection result of the updated first random number according to the first count value and the second count value, wherein the first count value is used to indicate the number of first bit values in the Nth data group to the N+Mth data group; the second count value is used to indicate the number of second bit values in the Nth data group to the N+Mth data group; when the bit value in the N+M+1th data group is inconsistent with the bit value in the Nth data group, the first count value and the second count value are adjusted, and the third detection result of the updated first random number is determined according to the adjusted first count value and the adjusted second count value.
[0014] In an exemplary embodiment, the single-bit frequency detection module is also used to determine whether the bit value in the N+M+1th data group is the first bit value; when the bit value in the N+M+1th data group is the first bit value, the first count value is added to a preset value, and the second count value is subtracted from a preset value; when the bit value in the N+M+1th data group is not the first bit value, the first count value is subtracted from a preset value, and the second count value is added to a preset value.
[0015] In an exemplary embodiment, the single-bit frequency detection module is also used to determine whether the adjusted first count value is or is equal to a first threshold, and to determine whether the second count value is or is equal to the first threshold; when the first count value is greater than or equal to the first threshold, or the second count value is greater than or equal to the first threshold, determine a third detection result of the updated first random number, wherein the third detection result indicates that the updated first random number fails the detection; when the first count value is less than the first threshold, and the second count value is less than the first threshold, determine a third detection result of the updated first random number, wherein the third detection result indicates that the updated first random number passes the detection.
[0016] In an exemplary embodiment, the poker detection module is further used to determine whether the bit value in the N+M+1th data group is consistent with the bit value in the Nth data group, wherein the N+M+1th data group and the Nth data group both include: multiple bit values; when the bit value in the N+M+1th data group is consistent with the bit value in the Nth data group, it is prohibited to adjust the count value in the count value set, and determine the third detection result of the updated first random number according to the count value in the third count value set, wherein the count value in the count value set is used to indicate the number of target numerical values from the Nth data group to the N+Mth data group; when the bit value in the N+M+1th data group is inconsistent with the bit value in the Nth data group, adjust the target count value in the count value set, and determine the third detection result of the updated first random number according to the adjusted target count value.
[0017] In an exemplary embodiment, the poker detection module is further used to determine a first numerical value corresponding to the bit value in the N+M+1th data group, and to determine a second numerical value corresponding to the bit value in the Nth data group; to determine a third count value corresponding to the first numerical value, and a fourth count value corresponding to the second numerical value in the count value set, wherein the target count value includes: the third count value and the fourth count value; to add a preset value to the third count value, and to subtract a preset value from the fourth count value.
[0018] In an exemplary embodiment, the poker detection module is further used to determine whether the adjusted target count value is greater than or equal to a second threshold; when the adjusted target count value is greater than or equal to the second threshold, determine a third detection result of the updated first random number, wherein the third detection result indicates that the updated first random number fails the detection; when the adjusted target count value is less than the second threshold, determine the third detection result of the updated first random number, wherein the third detection result indicates that the updated first random number passes the detection.
[0019] In an exemplary embodiment, the repeat count detection module includes: a shift register and a continuity comparison module, wherein the shift register is used to place the bit value in the N+M+1th data group at the lowest bit of the shift register, and to place the bit values in the N+1th data group to the N+Mth data group in the shift register at a high bit, wherein the N+M+1th data group includes: a bit value, and the bit width of the shift register is a judgment threshold for repeat count detection; the continuity comparison module is used to determine whether the bit values in the shift register are all consistent, and determine the third detection result of the updated first random number based on whether the bit values in the shift register are all consistent.
[0020] In an exemplary embodiment, the continuity comparison module is further used to determine a third test result of the updated first random number when it is determined that the bit values in the shift register are consistent, wherein the third test result indicates that the updated first random number fails the test; and to determine a third test result of the updated first random number when it is determined that the bit values in the shift register are inconsistent, wherein the third test result indicates that the updated first random number passes the test.
[0021] In an exemplary embodiment, the single-bit frequency detection module is also used to perform a determination step: when it is determined that the third detection result indicates that the updated first random number passes the detection, receive the N+M+2th data group sent by the entropy source module and the N+1th data group sent by the first-in-first-out memory; determine a fourth detection result of the first random number after the second update based on the N+M+2th data group and the N+1th data group; and loop through the determination step until the single-bit frequency detection module determines that the detection of the first random number after any update fails, or the single-bit frequency detection module determines that the detection of the first random number after each update passes.
[0022] In an exemplary embodiment, the detection module includes: the single-bit frequency detection module and the poker detection module, and when the single-bit frequency detection module determines that each detection of the updated first random number passes, the poker detection module is further used to determine a first detection result of the first random number, and determine a second detection result of the target random number according to the first detection result.
[0023] In an exemplary embodiment, the random number detection device also includes: a post-processing module connected to the entropy source module, wherein the post-processing module is used to receive the target random number sent by the entropy source module, and process the target random number according to a target algorithm to obtain a processed target random number.
[0024] In an exemplary embodiment, the post-processing module is also used to perform a second input step: input a third random number into the detection module, wherein the third random number is the Kth data group to the K+Jth data group in the processed target random number, the Kth data group includes: one or multiple consecutive bit values in the processed target random number, and the K+Jth data group includes: one or multiple consecutive bit values in the processed target random number, and K and J are positive integers; when K is 2, 3, ... Y in sequence, the second input step is executed in a loop until the detection module determines that the detection of the processed target random number fails, or the Yth data group is input into the detection module; the detection module is used to determine the detection result of the third random number, and determine the fourth detection result of the processed target random number according to the detection result of the third random number.
[0025] In an exemplary embodiment, the random number detection device also includes: an output module connected to the detection module, wherein the output module is used to determine the random number to be output based on the second detection result output by the detection module and the fourth detection result of the processed target random number.
[0026] In an exemplary embodiment, the output module is further used to determine that the random number to be output is the target random number when the second detection result indicates that the detection of the target random number has passed and the processed target random number has not passed; when the second detection result indicates that the detection of the target random number has not passed and the processed target random number has passed, determine that the random number to be output is the processed target random number; when the second detection result indicates that the detection of the target random number has passed and the processed target random number has passed, determine that the random number to be output is the processed target random number.
[0027] According to another embodiment of the present application, a random number detection method is provided, including: receiving a first random number input by an entropy source module, determining a first detection result of the first random number, and determining a second detection result of the target random number according to the first detection result, wherein the entropy source module performs a first input step: inputting the first random number into the detection module, wherein the first random number is the Nth data group to the N+Mth data group in the target random number, the Nth data group includes: one or multiple consecutive bit values in the target random number, the N+Mth data group includes: one or multiple consecutive bit values in the target random number, and N and M are positive integers; when N is 2, 3, ... Z in sequence, the first input step is executed cyclically until the detection module determines that the detection of the target random number fails, or the Zth data group is input into the detection module.
[0028] According to another embodiment of the present application, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when run.
[0029] According to another embodiment of the present application, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0030] According to another embodiment of the present application, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps in any of the above method embodiments are implemented.
[0031] Through the device in the present application, an entropy source module, and a detection module connected to the entropy source module, wherein the entropy source module is used to perform a first input step: input a first random number into the detection module, wherein the first random number is the Nth data group to the N+Mth data group in the target random number, the Nth data group includes: one or multiple consecutive bit values in the target random number, and the N+Mth data group includes: one or multiple consecutive bit values in the target random number, and N and M are positive integers; when N is 2, 3, ... Z in sequence, the first input step is executed cyclically until the detection module determines that the detection of the target random number fails, or the Zth data group is input into the detection module; the detection module is used to determine a first detection result of the first random number, and determine a second detection result of the target random number according to the first detection result. That is, in the present application, the Nth data group to the N+Mth data group in the target random number are input into the detection module according to the entropy source module cycle. The detection module receives a new data and discards an old data at the same time, thereby ensuring that the data is continuous and the data group is updated at any time to ensure that there will be no missed detection, thereby solving the problem of missed detection or missed reporting in the detection of random numbers in the related technology. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The exemplary embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0033] Figure 1 is a structural schematic diagram of a random number detection device according to an embodiment of the present application (I);
[0034] Figure 2 is a structural schematic diagram of a random number detection device according to an embodiment of the present application (II);
[0035] Figure 3 It is a schematic diagram of performing health detection in the related art;
[0036] Figure 4 is a schematic diagram of performing health detection according to an embodiment of the present application;
[0037] Figure 5 is a structural diagram of a health detection module according to an embodiment of the present application;
[0038] Figure 6 It is a hardware structure block diagram of a computer device of a random number detection method according to an embodiment of the present application;
[0039] Figure 7 It is a flowchart of a random number detection method according to an embodiment of the present application. DETAILED DESCRIPTION
[0040] The embodiments of the present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0041] It should be noted that the terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0042] In order to solve the problem of missed detection or missed reporting in the detection of random numbers in the above-mentioned related technologies, a hardware architecture is provided in this embodiment. Specifically, a random number detection device is provided in this embodiment. Figure 1 1 is a schematic diagram of the structure of a random number detection device according to an embodiment of the present application (I), such as Figure 1 As shown, the random number detection device includes the following modules:
[0043] An entropy source module 12, and a detection module 14 connected to the entropy source module, wherein:
[0044] The entropy source module 12 is used to perform a first input step: input a first random number to the detection module 14, wherein the first random number is the Nth data group to the N+Mth data group in the target random number, the Nth data group includes: one or multiple consecutive bit values in the target random number, and the N+Mth data group includes: one or multiple consecutive bit values in the target random number, and N and M are positive integers; when N is 2, 3, ... Z in sequence, the first input step is executed cyclically until the detection module 14 determines that the detection of the target random number fails according to the first random number, or the Zth data group is input to the detection module 14;
[0045] It should be noted that the above-mentioned data group is the minimum detection unit of the detection module. For example, the detection unit is used to detect the number of first values and second values in the target random number. At this time, the data group includes a bit value; for example, the detection unit is used to detect the number of decimal values of 0-15 in the target random number. At this time, the data group includes: four bit values, that is, determining the decimal values corresponding to four characteristic values, and then determining the number of decimal values 0-15.
[0046] The detection module 14 is used to determine a first detection result of the first random number, and determine a second detection result of the target random number according to the first detection result.
[0047] Through the device in the present application, the entropy source module is used to perform the first input step: input the first random number into the detection module, wherein the first random number is the Nth data group to the N+Mth data group in the target random number, the Nth data group includes: one or multiple consecutive bit values in the target random number, the N+Mth data group includes: one or multiple consecutive bit values in the target random number, and N and M are positive integers; when N is 2, 3, ... Z in sequence, the first input step is executed cyclically until the detection module determines that the detection of the target random number fails according to the first random number, or the Zth data group is input into the detection module; the detection module is used to determine the second detection result of the target random number according to the first random number. That is, in the present application, the Nth data group to the N+Mth data group in the target random number are input into the detection module according to the entropy source module cyclically, and the detection module ensures that the data is continuous and the data group is updated at any time by receiving a new data and discarding an old data at the same time, so as to ensure that there will be no missed detection, and solve the problem of missed detection or missed detection in the detection of random numbers in the related art.
[0048] Optionally, the random number detection device also includes: a first-in-first-out memory connected to the entropy source module and the detection module respectively, wherein the first-in-first-out memory is used to store a second random number, and after the detection module determines a first detection result of the first random number based on the Nth data group to the N+Mth data group, the Nth data group in the target random number is input into the detection module, wherein the second random number is the Nth data group to the N+Mth data group in the target random number.
[0049] It should be noted that the second random number can be understood as a random number of a continuous target data amount in the target random number, for example, 1024 continuous random numbers in the target random number.
[0050] During the initialization stage, that is, when the Nth to N+Mth data groups in the target random number have not yet been stored in the first-in-first-out memory (for example, only the first to fourth data groups are stored, and N+M is greater than 4 at this time), the first-in-first-out memory does not output the data group; the data group is output to the detection module only when the Nth to N+Mth data groups in the target random number are still stored in the first-in-first-out memory.
[0051] In the initialization stage, the entropy source module writes multiple random numbers into the first-in-first-out memory. At this time, the entropy source module synchronously inputs random numbers to the detection module, and the detection module performs corresponding detection operations according to the input random numbers.
[0052] Optionally, the entropy source module is further used to input the N+M+1th data group into the detection module after the detection module determines the first detection result of the first random number based on the Nth data group to the N+Mth data group; the detection module is further used to discard the Nth data group when receiving the N+M+1th data group input by the entropy source module to determine the updated first random number; determine a third detection result of the updated first random number based on the N+M+1th data group and / or the Nth data group, and determine the second detection result based on the third detection result.
[0053] In normal working mode, each time the entropy source module inputs a data group (i.e., the N+M+1th data group) to the detection module, the synchronous first-in-first-out memory also inputs a data group (i.e., the Nth data group) to the detection module, and when the detection module receives the N+M+1th data group input by the entropy source module, the Nth data group is discarded to determine the updated first random number, and a third detection result of the updated first random number is determined based on the N+M+1th data group and / or the Nth data group.
[0054] In an exemplary embodiment, the detection module includes at least one of the following: a single-bit frequency detection module, a poker detection module, and a repeated count detection module, wherein the single-bit frequency detection module is used to determine a third detection result of the updated first random number based on the N+M+1th data group and the Nth data group; the poker detection module is used to determine the third detection result of the updated first random number based on the N+M+1th data group and the Nth data group; the repeated count detection module is used to determine the third detection result of the updated first random number based on the N+M+1th data group.
[0055] Specifically, the single-bit frequency detection module detects the first random number in the following manner:
[0056] Determine whether the bit value in the N+M+1th data group is consistent with the bit value in the Nth data group, wherein the N+M+1th data group and the Nth data group both include: a bit value; when the bit value in the N+M+1th data group is consistent with the bit value in the Nth data group, prohibit adjusting the first count value and the second count value, and determine a third detection result of the updated first random number based on the first count value and the second count value, wherein the first count value is used to indicate the number of first bit values in the Nth data group to the N+Mth data group; the second count value is used to indicate the number of second bit values in the Nth data group to the N+Mth data group; when the bit value in the N+M+1th data group is inconsistent with the bit value in the Nth data group, adjust the first count value and the second count value, and determine the third detection result of the updated first random number based on the adjusted first count value and the adjusted second count value.
[0057] Furthermore, the single-bit frequency detection module is also used to determine whether the bit value in the N+M+1th data group is the first bit value; when the bit value in the N+M+1th data group is the first bit value, the first count value is increased by a preset value, and the second count value is decreased by a preset value; when the bit value in the N+M+1th data group is not the first bit value, the first count value is decreased by a preset value, and the second count value is increased by a preset value.
[0058] The single-bit frequency detection module is used to detect whether the total number of 1 and 0 bits in a piece of data is close, and then evaluate the uniformity of the target random number. For example, in a continuous 2048-bit data, when there are more than 1248 0s or 1s, it is considered that this test fails. The specific data length and judgment threshold parameters can be set according to the actual situation.
[0059] In the embodiment of the present application, the above-mentioned preset value can be 1, and the embodiment of the present application is not limited to this.
[0060] Taking the preset threshold value of 1 as an example, when the single-bit frequency detection module is just initialized, the first count value and the second count value are both 0. When the data group input by the entropy source module starts to be received, when the received data is 1, the first count value is increased by 1, and when the received data is 0, the second count value is increased by 1.
[0061] In normal working mode, it is necessary to synchronously judge the N+M+1th data group and the Nth data group.
[0062] When the bit value in the N+M+1th data group is equal to the bit value in the Nth data group, the first count value and the second count value remain unchanged. Assuming that the first count value in the first random number is 23, when the bit value in the N+M+1th data group is equal to the bit value in the Nth data group, the first count value in the updated first random number is also 23, so the first count value and the second count value can remain unchanged.
[0063] When the bit value in the N+M+1th data group is equal to 1, and the bit value in the Nth data group is equal to 0, the second count value is reduced by one, and the first count value is increased by one.
[0064] When the bit value in the N+M+1th data group is equal to 0, and the bit value in the Nth data group is equal to 1, the second count value is increased by one, and the first count value is decreased by one.
[0065] Furthermore, the single-bit frequency detection module is also used to determine whether the adjusted first count value is or is equal to a first threshold, and to determine whether the second count value is or is equal to the first threshold; when the first count value is greater than or equal to the first threshold, or the second count value is greater than or equal to the first threshold, determine a third detection result of the updated first random number, wherein the third detection result indicates that the updated first random number fails the detection; when the first count value is less than the first threshold, and the second count value is less than the first threshold, determine a third detection result of the updated first random number, wherein the third detection result indicates that the updated first random number passes the detection.
[0066] Each time a new data group is input, it is necessary to determine whether the first count value and the second count value exceed the first threshold value. When the first count value is greater than or equal to the first threshold value, or the first count value is greater than or equal to the first threshold value, it is considered that the data is defective, the detection fails, and a single-bit frequency detection error signal is output, and this signal is maintained until a clear error signal is received.
[0067] When detecting the target random number, the detection device in the related art first groups the target random number, and outputs the detection result when the last data in a group is received. It is impossible to output the detection result when the data in the complete group is not received. Therefore, in the related art, there is hysteresis in the detection method of the random number. However, through the embodiment of the present application, when a data group is received, it is possible to quickly determine whether the updated first random number has an error, and then output the detection result, eliminating the time hysteresis of the prior art, and can find the defects of the random number at the first moment, ensuring that the defective data is no longer output, avoiding affecting the function and security of the subsequent modules.
[0068] Optionally, the poker detection module is further used to determine whether the bit value in the N+M+1th data group is consistent with the bit value in the Nth data group, wherein the N+M+1th data group and the Nth data group both include: multiple bit values; when the bit value in the N+M+1th data group is consistent with the bit value in the Nth data group, it is prohibited to adjust the count value in the count value set, and determine the third detection result of the updated first random number according to the count value in the third count value set, wherein the count value in the count value set is used to indicate the number of target numerical values from the Nth data group to the N+Mth data group; when the bit value in the N+M+1th data group is inconsistent with the bit value in the Nth data group, adjust the target count value in the count value set, and determine the third detection result of the updated first random number according to the adjusted target count value.
[0069] Specifically, the poker detection module is further used to determine a first numerical value corresponding to the bit value in the N+M+1th data group, and to determine a second numerical value corresponding to the bit value in the Nth data group; to determine a third count value corresponding to the first numerical value, and a fourth count value corresponding to the second numerical value in the count value set, wherein the target count value includes: the third count value and the fourth count value; to add a preset value to the third count value, and to subtract a preset value from the fourth count value.
[0070] The poker detection module is used to detect the distribution of each 4-bit (0-15) in a piece of data. This evaluates uniformity and randomness. For example, in a continuous 2048-bit target random number, when the number of 4-bit blocks exceeds 156, this detection is considered to have failed. The specific data length and judgment threshold parameters can be set according to actual conditions.
[0071] It should be noted that the poker detection module contains 16 groups of registers, which are 4-bit block value (0-f) number registers, recorded as reg_p_cnt_0, reg_p_cnt_1, reg_p_cnt_2, reg_p_cnt_3, reg_p_cnt_4, reg_p_cnt_5, reg_p_cnt_6, reg_p_cnt_7, reg_p_cnt_8, reg_p_cnt_9, reg_p_cnt_a, reg_p_cnt_b, reg_p_cnt_c, reg_p_cnt_d, reg_p_cnt_e, reg_p_cnt_f.
[0072] In the initialization phase, all 16 parameters are 0. When the poker detection module starts to receive data, it determines the value of each data group (i.e., 4 consecutive bit values) received, and increases the corresponding reg_p_cnt_x value by 1. For example, if the value corresponding to the data group is 10, then the value of reg_p_cnt_a is increased by 1, and so on.
[0073] In the normal working mode, it is necessary to synchronously determine the first value corresponding to the bit value in the N+M+1th data group and the second value corresponding to the bit value in the Nth data group.
[0074] When the first value is equal to the second value, the values in the 16 registers remain unchanged.
[0075] When the first value is not equal to the second value, the reg_p_cnt_x value corresponding to the first value is increased by one; and the reg_p_cnt_x value corresponding to the second value is decreased by one.
[0076] Furthermore, the poker detection module is also used to determine whether the adjusted target count value is greater than or equal to a second threshold; when the adjusted target count value is greater than or equal to the second threshold, determine a third detection result of the updated first random number, wherein the third detection result indicates that the updated first random number fails the detection; when the adjusted target count value is less than the second threshold, determine a third detection result of the updated first random number, wherein the third detection result indicates that the updated first random number passes the detection.
[0077] Each time a new data group is input, it is necessary to determine whether the adjusted target count value is greater than or equal to the second threshold. When the adjusted target count value is greater than or equal to the first threshold, it is considered that the data is defective and the detection fails. The poker detection module outputs an error signal and maintains this signal until a clear error signal is received.
[0078] Optionally, the repeat count detection module includes: a shift register and a continuity comparison module, wherein the shift register is used to place the bit value in the N+M+1th data group at the lowest bit of the shift register, and to place the bit values in the N+1th data group to the N+Mth data group in the shift register at a high bit, wherein the N+M+1th data group includes: a bit value, and the bit width of the shift register is a judgment threshold for repeat count detection; the continuity comparison module is used to determine whether the bit values in the shift register are all consistent, and determine the third detection result of the updated first random number based on whether the bit values in the shift register are all consistent.
[0079] Optionally, the continuity comparison module is further used to determine a third test result of the updated first random number when it is determined that the bit values in the shift register are consistent, wherein the third test result indicates that the updated first random number fails the test; and to determine a third test result of the updated first random number when it is determined that the bit values in the shift register are inconsistent, wherein the third test result indicates that the updated first random number passes the test.
[0080] It should be noted that the repetition count detection module is used to detect the situation where more than a certain number of 0 or 1 are output continuously, and then evaluate the randomness and independence of the target random number. For example, when 24 bits of 0 or 1 are output continuously, it is considered that the detection fails. The specific judgment threshold parameters can be set according to the actual situation.
[0081] The repeat count detection module also includes a shift register, wherein the bit width of the shift register is equal to the judgment threshold of the repeat count detection (such as 24 bits used in the above example), and only the data group input by the entropy source module needs to be calculated, and the data group input by the first-in-first-out module is not required.
[0082] The repeat count detection module performs a shift operation on the input N+M+1th data group, places the N+M+1th data group at the lowest bit, and places the bit values from the N+1th data group to the N+Mth data group in the shift register at the high bit.
[0083] When every bit in the shift register is 1 or every bit in the shift register is 0, it is considered that the data is defective and the detection fails. A repeat count detection error signal is output and maintained until a clear error signal is received.
[0084] In an exemplary embodiment, the single-bit frequency detection module is also used to perform a determination step: when it is determined that the third detection result indicates that the updated first random number passes the detection, receive the N+M+2th data group sent by the entropy source module and the N+1th data group sent by the first-in-first-out memory; determine a fourth detection result of the first random number after the second update based on the N+M+2th data group and the N+1th data group; and loop through the determination step until the single-bit frequency detection module determines that the detection of the first random number after any update fails, or the single-bit frequency detection module determines that the detection of the first random number after each update passes.
[0085] In an exemplary embodiment, the detection module includes: the single-bit frequency detection module and the poker detection module, and when the single-bit frequency detection module determines that each detection of the updated first random number passes, the poker detection module is further used to determine a first detection result of the first random number, and determine a second detection result of the target random number according to the first detection result.
[0086] It should be noted that, when the detection module includes: a single-bit frequency detection module, a poker detection module, and a repeated count detection module, the single-bit frequency detection module, the poker detection module, and the repeated count detection module detect the random number based on a serial manner. For example, when the single-bit frequency detection module completes the detection of the target random number and the detection result indicates that the target random number passes the detection, the poker detection module detects the target random number; when the poker detection module completes the detection of the target random number and the detection result indicates that the target random number passes the detection, the repeated count detection module detects the target random number.
[0087] In addition, when the detection module includes: a single-bit frequency detection module, a poker detection module, and a repeat count detection module, the single-bit frequency detection module, the poker detection module, and the repeat count detection module can also detect the random number based on a parallel manner. For example, when the single-bit frequency detection module detects the random number, it receives a bit value and performs detection based on the received bit value. At this time, the repeat count detection module can also perform detection based on the received bit value, but the poker detection module needs to receive four bit values before performing detection. That is to say, the single-bit frequency detection module and the repeat count detection module detect four times, and the poker detection module detects once.
[0088] Optionally, the random number detection device also includes: a post-processing module connected to the entropy source module, wherein the post-processing module is used to receive the target random number sent by the entropy source module, and process the target random number according to a target algorithm to obtain a processed target random number.
[0089] In an embodiment of the present application, the post-processing module receives the data generated by the entropy source module and processes it. Commonly used methods include XOR chain correction, linear feedback shift register LFSR and hash function, etc. The quality of the processed target random number will be improved, and the processed target data will be synchronously transmitted to the detection module.
[0090] In an exemplary embodiment, the post-processing module is also used to perform a second input step: input a third random number into the detection module, wherein the third random number is the Kth data group to the K+Jth data group in the processed target random number, the Kth data group includes: one or multiple consecutive bit values in the processed target random number, and the K+Jth data group includes: one or multiple consecutive bit values in the processed target random number, and K and J are positive integers; when K is 2, 3, ... Y in sequence, the second input step is executed in a loop until the detection module determines that the detection of the processed target random number fails, or the Yth data group is input into the detection module; the detection module is used to determine the detection result of the third random number, and determine the fourth detection result of the processed target random number according to the detection result of the third random number.
[0091] It should be noted that, in the embodiment of the present application, the detection method for the processed target random number is the same as the detection method for the target random number. In actual use, the hardware can use two detection modules to simultaneously detect two groups of input data sources, or it can only implement one detection module and select any one group of data sources for detection through the internal selection switch.
[0092] Optionally, the random number detection device further includes: an output module connected to the detection module, wherein the output module is used to determine the random number to be output based on the second detection result output by the detection module and the fourth detection result of the processed target random number.
[0093] Furthermore, the output module is also used to determine that the random number to be output is the target random number when the second detection result indicates that the detection of the target random number has passed and the processed target random number has not passed; determine that the random number to be output is the processed target random number when the second detection result indicates that the detection of the target random number has failed and the processed target random number has passed; determine that the random number to be output is the processed target random number when the second detection result indicates that the detection of the target random number has passed and the processed target random number has passed.
[0094] That is to say, the output module decides whether to output a random number and which random number to output based on the health test result and the control logic. Specifically, if both fail, no random number is output; if the second test result indicates that the test of the target random number has passed and the processed target random number has failed, the target random number is output; if the second test result indicates that the test of the target random number has failed and the processed target random number has passed, the processed target random number is output; if the second test result indicates that the test of the target random number has passed and the processed target random number has passed, the processed target random number is output because the quality of the processed target random number will be improved.
[0095] Obviously, the above-described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. In order to better understand the above-mentioned random number detection method, the above-mentioned process is described below in conjunction with the embodiments, but it is not intended to limit the technical solutions of the embodiments of the present application, specifically:
[0096] like Figure 2 As shown, Figure 2 : is a structural schematic diagram (II) of a random number detection device according to an embodiment of the present application, which specifically includes: an entropy source (equivalent to the entropy source module in the above embodiment), a post-processing module, a health detection module (equivalent to the detection module in the above embodiment), and an output module, wherein:
[0097] The entropy source, i.e. the source of randomness of a true random number generator, is generally random physical information;
[0098] The post-processing module is used to process the source data through algorithms to improve the quality of the entropy source output data.
[0099] The health detection module is used to detect the quality of the source data and the processed data, and output the corresponding detection results to the output module;
[0100] The output module is used to determine whether to output the random number and which random number to output.
[0101] The workflow of the above entropy source, post-processing module, health detection module and output module is as follows:
[0102] The entropy source generates random numbers and synchronously transmits the random numbers to the health detection module, the post-processing module and the output module;
[0103] A post-processing module receives random numbers generated by an entropy source (equivalent to the target random numbers in the above embodiment) and processes the random numbers. Common methods include XOR chain correction, linear feedback shift register LFSR, and hash function, etc. The quality of the processed random numbers (equivalent to the processed target random numbers in the above embodiment) will be improved, and the post-processed random numbers will be synchronously transmitted to the health detection module and the output module;
[0104] The health detection module receives the source data output by the entropy source and the data output after post-processing, and detects them. In actual use, the hardware can use two health detection modules to check two sets of input data sources at the same time, or only use one health detection module to select any one of the data sources for detection through the internal selection switch. Whether it is one or two detection modules, the structure is exactly the same. The health detection detects the input data source and outputs the corresponding detection results to the output module.
[0105] The output module decides whether to output random numbers and which random numbers to output based on the health detection results and control logic.
[0106] In order to better understand the execution logic of the health detection module, we first briefly explain the idea of health detection in this application. Figure 3 As shown, in the prior art, when testing random numbers, the data is first grouped, for example, into GROUP1 GROUP2... Each test is performed within a GROUP. When the last data of a GROUP is (at 2048 bits), the test result is output, and then the next group is checked. According to the test standard for random numbers, any segment of data should meet the various test standards. When the data of GROUP1 and GROUP2 are tested separately, the test requirements may be met, but when the second half of the data of GROUP1 and the first half of the data of GROUP2 are analyzed, the test may fail. However, if the test is performed according to the prior art, no error will be reported, so there is a problem of missed detection or missed detection, resulting in defective random number output and security issues.
[0107] like Figure 4 As shown, when the present application is conducting detection, the detection group uses a progressive GROUP, and for the data in the detection group, a new data is received and an old data is discarded at the same time, so as to ensure that the data is continuous and the detection group is updated at any time, so as to ensure that there will be no missed detection. Moreover, the defects of random numbers can be discovered at the first moment, so that the defective data is no longer output, so as to avoid affecting the functions and security of subsequent modules, and eliminate the time hysteresis existing in the existing technology.
[0108] like Figure 5 As shown, Figure 5 It is a structural schematic diagram of a health detection module according to an embodiment of the present application, including: a single-bit frequency detection module, a poker detection module and a repeat count detection module.
[0109] It should be noted that the entropy source module synchronously transmits the source data input to the FIFO memory and the detection module, wherein the capacity of the FIFO memory is the length of a detection data segment, for example, 2048. After the FIFO memory is just powered on or reset, an initialization process is required, that is, receiving the first 2048 data in the source data. In this process, since the data segment length of the subsequent detection is not met, the detection result is invalid, and no data will be input to the detection module at this time. After receiving 2048 data, the normal detection process begins.
[0110] During initialization, the first 2048 data in the source data are written into the FIFO memory in sequence, but no read operation is performed until the FIFO space is full, and then the normal detection mode is entered. During initialization, the first 2048 data in the source data are synchronously transmitted to the three detection modules of the subsequent stage, and corresponding operations (count value calculation, update and shift register) are performed, but threshold comparison and continuity comparison are not performed, and the detection result is not output.
[0111] In normal operation mode, each time a source data (denoted as source_data) is input, a data (denoted as fifo_out) is synchronously read out from the FIFO memory and transmitted to the subsequent detection module.
[0112] Optionally, the workflow of the single-bit frequency detection module is as follows:
[0113] The single-bit frequency detection module includes: 2 groups of registers, namely, bit 1 frequency register reg_cnt_1_s and bit 0 frequency register reg_cnt_0_s.
[0114] During initialization, both parameters are 0. When the data source_data is received, if the received data is 1, the value of reg_cnt_1_s is increased by 1. If the received data is 0, the value of reg_cnt_0_s is increased by 1.
[0115] In normal working mode, source_data and fifo_out are synchronously judged.
[0116] When source_data = fifo_out, reg_cnt_0_s and reg_cnt_1_s remain unchanged.
[0117] When source_data=1 and fifo_out=0, reg_cnt_0_s is decremented by 1 and reg_cnt_1_s is incremented by 1.
[0118] When source_data=0 and fifo_out=1, reg_cnt_0_s is incremented by one and reg_cnt_1_s is decremented by one.
[0119] Each time it is updated, it is compared with the preset threshold. When reg_cnt_0_s>1248 or reg_cnt_1_s>1248, it is considered that the source data is defective and the detection fails. The single-bit frequency detection error signal (bit_err) is output as 1 and this signal is maintained until the clear error signal clear_bit_err is received to clear bit_err to zero; otherwise, no abnormality is found and bit_err remains at 0.
[0120] Optionally, the workflow of the poker detection module is as follows:
[0121] The poker detection module includes: 16 groups of registers, which are 4-bit block value (0-f) number registers, recorded as reg_p_cnt_0, reg_p_cnt_1, reg_p_cnt_2, reg_p_cnt_3, reg_p_cnt_4, reg_p_cnt_5, reg_p_cnt_6, reg_p_cnt_7, reg_p_cnt_8, reg_p_cnt_9, reg_p_cnt_a, reg_p_cnt_b, reg_p_cnt_c, reg_p_cnt_d, reg_p_cnt_e, reg_p_cnt_f.
[0122] At the beginning of initialization, all 16 parameters are 0. When receiving data, each 4 consecutive bits received are recorded as a group. The 4 consecutive source_data are recorded as source_4, and the 4 consecutive fifo_out are recorded as fifo_out_4.
[0123] When a continuous set of data (source_4) is received, its value is determined and the corresponding reg_p_cnt_x value is increased by 1. For example, if source_4 is a, the value of reg_p_cnt_a is increased by 1, and so on.
[0124] In normal working mode, source_4 and fifo_out_4 are synchronously judged.
[0125] When source_4 = fifo_out_4, the 16 4-bit block value (0-f) number registers remain unchanged.
[0126] When source_4 != fifo_out_4, determine the value of source_4 and increase the corresponding value of reg_p_cnt_x by 1. And determine the value of fifo_out_4 and decrease the corresponding value of reg_p_cnt_x by 1.
[0127] Each time an update is performed, the 16 updated register values are compared with the preset thresholds at the same time. When the value of any of them is >156, it is considered that there is a defect in the source data and the detection fails. The poker detection error signal (pok_err) is output as 1 and this signal is maintained until the clear error signal clear_pok_err is received to clear pok_err to zero; otherwise, no abnormality is found and pok_err remains at 0.
[0128] Optionally, the workflow of the duplicate count detection module is as follows:
[0129] The repeat count detection module includes: a group of shift registers, the bit width of the shift register is equal to the judgment threshold of the repeat count detection (for example, 24 bits), and only source_data data is needed for calculation, and fifo_out data is not needed.
[0130] Shift the input source_data, place source_data at the lowest bit, and assign the lower 23 bits of the original source_data_reg (i.e. source_data_reg[22:0]) to the upper 23 bits of source_data_reg (i.e. [23:1]), i.e. source_data_reg = {source_data_reg[22:0], source_data}.
[0131] If every bit of source_data_reg is 1 or every bit of source_data_reg is 0, the data is considered to be defective and the detection fails. The output repeat count detection error signal (rep_err) is 1 and this signal is maintained until the clear error signal clear_rep_err is received to clear rep_err to zero; otherwise, no abnormality is found and rep_err remains 0.
[0132] The present application proposes a design architecture and processing flow for random number quality detection, which realizes adaptive ratio detection, poker detection and repeatability counting detection of true random numbers, eliminates the time hysteresis existing in the existing technology, and can discover the defects of random numbers at the first moment to ensure that defective data is no longer output, so as to avoid affecting the function and security of subsequent modules.
[0133] In this embodiment, a random number detection method is also provided. The method embodiment provided in the embodiment of the present application can be executed in a random number detection device, which can be a computer device or a similar computing device. Taking running on a computer device as an example, Figure 6 1 is a hardware structure block diagram of a computer device for a random number detection method according to an embodiment of the present application. Figure 6 As shown, the computer device may include one or more ( Figure 6 Only one is shown in the figure) a processor 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, wherein the above-mentioned computer device may also include a transmission device 106 and an input and output device 108 for communication functions. It can be understood by those skilled in the art that Figure 6 The structure shown is only for illustration and does not limit the structure of the above-mentioned computer device. Figure 6 More or fewer components as shown, or with Figure 6 Different configurations shown.
[0134] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the random number detection method in the embodiment of the present application. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0135] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the computer device. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0136] In this embodiment, a random number detection method is provided, and the random number detection method is applied to a detection module in a hardware architecture, wherein the hardware architecture is located in a chip of the above-mentioned computer device, and the hardware architecture includes: an entropy source module, a detection module connected to the entropy source module, a post-processing module connected to the detection module, and an output module connected to the detection module, the post-processing module, and the entropy source module, wherein the entropy source module outputs random numbers to the detection module, the post-processing module, and the output module; the processing module, when receiving a random number, processes the random number and sends the processed random number to the detection module and the output module; the detection module detects the random number and the processed random number, and inputs the detection results of the random number and the processed random number to the output module, and the output module determines the random number to be output according to the detection result.
[0137] Figure 7 is a flow chart of a random number detection method according to an embodiment of the present application, such as Figure 7 As shown, the process includes the following steps:
[0138] Step S702, receiving a first random number input by an entropy source module;
[0139] Step S704, determining a first detection result of the first random number, and determining a second detection result of the target random number according to the first detection result, wherein the entropy source module executes a first input step: inputting the first random number into the detection module, wherein the first random number is the Nth data group to the N+Mth data group in the target random number, the Nth data group includes: one or multiple consecutive bit values in the target random number, the N+Mth data group includes: one or multiple consecutive bit values in the target random number, and N and M are positive integers; when N is 2, 3, ... Z in sequence, the first input step is executed in a loop until the detection module determines that the detection of the target random number fails, or the Zth data group is input into the detection module.
[0140] Through the above steps, the first random number input by the entropy source module is received, the first detection result of the first random number is determined, and the second detection result of the target random number is determined according to the first detection result, wherein the entropy source module performs a first input step: inputting the first random number into the detection module, wherein the first random number is the Nth data group to the N+Mth data group in the target random number, the Nth data group includes: one or multiple consecutive bit values in the target random number, the N+Mth data group includes: one or multiple consecutive bit values in the target random number, and N and M are positive integers; when N is 2, 3, ... Z in sequence, the first input step is executed cyclically until the detection module determines that the detection of the target random number fails, or the Zth data group is input into the detection module. That is, in the present application, the Nth data group to the N+Mth data group in the target random number are input into the detection module according to the entropy source module cycle. The detection module receives a new data and discards an old data at the same time, thereby ensuring that the data is continuous and the data group is updated at any time to ensure that there will be no missed detection, thereby solving the problem of missed detection or missed reporting in the detection of random numbers in the related technology.
[0141] In an exemplary embodiment, determining a first detection result of the first random number, and determining a second detection result of the target random number based on the first detection result, includes: after determining the first detection result of the first random number based on the Nth data group to the N+Mth data group, receiving the Nth data group sent by a first-in-first-out memory, wherein the first-in-first-out memory is used to store a second random number, and after the detection module determines the first detection result of the first random number based on the Nth data group to the N+Mth data group, inputting the Nth data group in the target random number into the detection module, the second random number being the Nth data group to the N+Mth data group in the target random number.
[0142] In an exemplary embodiment, determining a first detection result of the first random number, and determining a second detection result of the target random number based on the first detection result, includes: after the detection module determines the first detection result of the first random number based on the Nth data group to the N+Mth data group, receiving the N+M+1th data group input by the entropy source module; discarding the Nth data group to determine an updated first random number; determining a third detection result of the updated first random number based on the N+M+1th data group and / or the Nth data group, and determining the second detection result based on the third detection result.
[0143] In an exemplary embodiment, when the detection module includes at least one of the following: a single-bit frequency detection module, a poker detection module, and a repeated count detection module, determining the third detection result of the updated first random number according to the N+M+1th data group and / or the Nth data group includes at least one of the following:
[0144] Controlling the single-bit frequency detection module to determine a third detection result of the updated first random number according to the N+M+1th data group and the Nth data group;
[0145] Controlling the poker detection module to determine a third detection result of the updated first random number according to the N+M+1th data group and the Nth data group;
[0146] The repetition counting detection module is controlled to determine a third detection result of the updated first random number according to the N+M+1th data group.
[0147] In an exemplary embodiment, controlling the single-bit frequency detection module to determine the third detection result of the updated first random number according to the N+M+1th data group and the Nth data group includes: determining whether the bit value in the N+M+1th data group is consistent with the bit value in the Nth data group, wherein the N+M+1th data group and the Nth data group both include: a bit value; when the bit value in the N+M+1th data group is consistent with the bit value in the Nth data group, prohibiting adjustment of the first count value and the second count value, and adjusting the first count value and the second count value according to the first count value and the The second count value determines the third detection result of the updated first random number, wherein the first count value is used to indicate the number of first bit values in the Nth data group to the N+Mth data group; the second count value is used to indicate the number of second bit values in the Nth data group to the N+Mth data group; when the bit value in the N+M+1th data group is inconsistent with the bit value in the Nth data group, the first count value and the second count value are adjusted, and the third detection result of the updated first random number is determined based on the adjusted first count value and the adjusted second count value.
[0148] In an exemplary embodiment, adjusting the first count value and the second count value includes: determining whether the bit value in the N+M+1th data group is the first bit value; when the bit value in the N+M+1th data group is the first bit value, adding a preset value to the first count value and subtracting a preset value from the second count value; when the bit value in the N+M+1th data group is not the first bit value, subtracting a preset value from the first count value and adding a preset value to the second count value.
[0149] In an exemplary embodiment, determining a third detection result of an updated first random number based on an adjusted first count value and an adjusted second count value includes: determining whether the adjusted first count value is or is equal to a first threshold, and determining whether the second count value is or is equal to the first threshold; when the first count value is greater than or equal to the first threshold, or when the second count value is greater than or equal to the first threshold, determining a third detection result of the updated first random number, wherein the third detection result indicates that the updated first random number has not passed the detection; when the first count value is less than the first threshold, and the second count value is less than the first threshold, determining a third detection result of the updated first random number, wherein the third detection result indicates that the updated first random number has passed the detection.
[0150] In an exemplary embodiment, controlling the poker detection module to determine the third detection result of the updated first random number according to the N+M+1th data group and the Nth data group includes: determining whether the bit value in the N+M+1th data group is consistent with the bit value in the Nth data group, wherein the N+M+1th data group and the Nth data group both include: multiple bit values; when the bit value in the N+M+1th data group is consistent with the bit value in the Nth data group, prohibiting the adjustment of the count value in the count value set, and determining the third detection result of the updated first random number according to the count value in the third count value set, wherein the count value in the count value set is used to indicate the number of target values from the Nth data group to the N+Mth data group; when the bit value in the N+M+1th data group is inconsistent with the bit value in the Nth data group, adjusting the target count value in the count value set, and determining the third detection result of the updated first random number according to the adjusted target count value.
[0151] In an exemplary embodiment, adjusting the target count value in the count value set includes: determining a first numerical value corresponding to the bit value in the N+M+1th data group, and determining a second numerical value corresponding to the bit value in the Nth data group; determining a third count value corresponding to the first numerical value, and a fourth count value corresponding to the second numerical value in the count value set, wherein the target count value includes: the third count value and the fourth count value; adding a preset numerical value to the third count value, and subtracting a preset numerical value from the fourth count value.
[0152] In an exemplary embodiment, determining a third detection result of an updated first random number based on an adjusted target count value includes: determining whether the adjusted target count value is greater than or equal to a second threshold; when the adjusted target count value is greater than or equal to the second threshold, determining the third detection result of the updated first random number, wherein the third detection result indicates that the updated first random number fails the detection; when the adjusted target count value is less than the second threshold, determining the third detection result of the updated first random number, wherein the third detection result indicates that the updated first random number passes the detection.
[0153] In an exemplary embodiment, controlling the repeat count detection module to determine the third detection result of the updated first random number according to the N+M+1th data group includes: placing the bit value in the N+M+1th data group at the lowest bit of the shift register in the repeat count detection module, and placing the bit values in the N+1th data group to the N+Mth data group in the shift register at a high bit, wherein the N+M+1th data group includes: a bit value, and the bit width of the shift register is a judgment threshold for repeat count detection; determining whether the bit values in the shift register are all consistent, and determining the third detection result of the updated first random number according to whether the bit values in the shift register are all consistent.
[0154] In an exemplary embodiment, determining a third test result of the updated first random number based on whether the bit values in the shift register are all consistent includes: when it is determined that the bit values in the shift register are all consistent, determining the third test result of the updated first random number, wherein the third test result indicates that the updated first random number has not passed the test; when it is determined that the bit values in the shift register are inconsistent, determining the third test result of the updated first random number, wherein the third test result indicates that the updated first random number has passed the test.
[0155] In an exemplary embodiment, after controlling the single-bit frequency detection module to determine the third detection result of the updated first random number according to the N+M+1th data group and the Nth data group, the method further includes: executing a determination step: when it is determined that the third detection result indicates that the updated first random number passes the detection, receiving the N+M+2th data group sent by the entropy source module and the N+1th data group sent by the first-in-first-out memory; determining a fourth detection result of the first random number after the second update according to the N+M+2th data group and the N+1th data group; and looping through the determination step until the single-bit frequency detection module determines that the detection of any updated first random number fails, or the single-bit frequency detection module determines that each detection of the updated first random number passes.
[0156] In an exemplary embodiment, when the detection module includes: the single-bit frequency detection module and the poker detection module, and when the single-bit frequency detection module determines that each detection of the updated first random number passes, the poker detection module is controlled to determine a first detection result of the first random number, and a second detection result of the target random number is determined according to the first detection result.
[0157] In an exemplary embodiment, the method further includes: receiving a third random number input by a post-processing module; determining a detection result of the third random number, and determining a fourth detection result of the processed target random number based on the detection result of the third random number, wherein the post-processing module executes a second input step: inputting the third random number into the detection module, wherein the third random number is the Kth data group to the K+Jth data group in the processed target random number, the Kth data group includes: one or multiple consecutive bit values in the processed target random number, the K+Jth data group includes: one or multiple consecutive bit values in the processed target random number, and K and J are positive integers; when K is 2, 3, ... Y in sequence, the second input step is executed cyclically until the detection module determines that the detection of the processed target random number fails, or the Yth data group is input into the detection module.
[0158] In an exemplary embodiment, after determining the fourth detection result of the processed target random number according to the detection result of the third random number, the method further includes: inputting the second detection result and the fourth result into an output module, so that the output module determines the random number to be output according to the second detection result and the fourth detection result output by the detection module.
[0159] Among them, when the second detection result indicates that the detection of the target random number has passed and the processed target random number has not passed, the random number to be output is determined to be the target random number; when the second detection result indicates that the detection of the target random number has not passed and the processed target random number has passed, the random number to be output is determined to be the processed target random number; when the second detection result indicates that the detection of the target random number has passed and the processed target random number has passed, the random number to be output is determined to be the processed target random number.
[0160] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when run.
[0161] Optionally, in this embodiment, the storage medium may be configured to store a computer program for performing the following steps:
[0162] Step S1, receiving a first random number input by an entropy source module;
[0163] Step S2, determining a first detection result of the first random number, and determining a second detection result of the target random number based on the first detection result, wherein the entropy source module executes a first input step: inputting the first random number into the detection module, wherein the first random number is the Nth data group to the N+Mth data group in the target random number, the Nth data group includes: one or multiple consecutive bit values in the target random number, the N+Mth data group includes: one or multiple consecutive bit values in the target random number, and N and M are positive integers; when N is 2, 3, ... Z in sequence, the first input step is executed cyclically until the detection module determines that the detection of the target random number fails, or the Zth data group is input into the detection module.
[0164] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.
[0165] An embodiment of the present application further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0166] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:
[0167] Step S1, receiving a first random number input by an entropy source module;
[0168] Step S2, determining a first detection result of the first random number, and determining a second detection result of the target random number based on the first detection result, wherein the entropy source module executes a first input step: inputting the first random number into the detection module, wherein the first random number is the Nth data group to the N+Mth data group in the target random number, the Nth data group includes: one or multiple consecutive bit values in the target random number, the N+Mth data group includes: one or multiple consecutive bit values in the target random number, and N and M are positive integers; when N is 2, 3, ... Z in sequence, the first input step is executed cyclically until the detection module determines that the detection of the target random number fails, or the Zth data group is input into the detection module.
[0169] In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0170] An embodiment of the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps in any one of the above method embodiments are implemented.
[0171] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:
[0172] Step S1, receiving a first random number input by an entropy source module,
[0173] Step S2, determining a first detection result of the first random number, and determining a second detection result of the target random number based on the first detection result, wherein the entropy source module executes a first input step: inputting the first random number into the detection module, wherein the first random number is the Nth data group to the N+Mth data group in the target random number, the Nth data group includes: one or multiple consecutive bit values in the target random number, the N+Mth data group includes: one or multiple consecutive bit values in the target random number, and N and M are positive integers; when N is 2, 3, ... Z in sequence, the first input step is executed cyclically until the detection module determines that the detection of the target random number fails, or the Zth data group is input into the detection module.
[0174] An embodiment of the present application further provides another computer program product, including a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in any of the above method embodiments are implemented.
[0175] The embodiments of the present application also provide a computer program, which includes computer instructions, which 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 steps in any one of the above method embodiments.
[0176] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail herein.
[0177] Obviously, those skilled in the art should understand that the above modules or steps of the present application can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that herein, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present application is not limited to any specific combination of hardware and software.
[0178] The above description is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the principles of the present application shall be included in the protection scope of the present application.
Claims
1. A random number detection device, characterized in that: include: An entropy source module, and a detection module connected to the entropy source module, wherein: The entropy source module is used to perform a first input step: input a first random number into the detection module, wherein the first random number is the Nth data group to the N+Mth data group in the target random number, the Nth data group includes: one or multiple consecutive bit values in the target random number, and the N+Mth data group includes: one or multiple consecutive bit values in the target random number, and N and M are positive integers; when N is 2, 3, ... Z in sequence, the first input step is executed cyclically until the detection module determines that the detection of the target random number fails, or the Zth data group is input into the detection module; The detection module is used to determine a first detection result of the first random number, and determine a second detection result of the target random number according to the first detection result; Wherein, the entropy source module is also used to input the N+M+1th data group into the detection module after the detection module determines the first detection result of the first random number based on the Nth data group to the N+Mth data group; the detection module is also used to discard the Nth data group when receiving the N+M+1th data group input by the entropy source module to determine the updated first random number.
2. The device according to claim 1, characterized in that The random number detection device further includes: A first-in-first-out memory is connected to the entropy source module and the detection module respectively.
3. The device according to claim 2, characterized in that include: The detection module is further used to determine a third detection result of the updated first random number according to the N+M+1th data group and / or the Nth data group, and determine the second detection result according to the third detection result.
4. The device according to claim 3, characterized in that include: The detection module includes at least one of the following: a single-bit frequency detection module, a poker detection module, and a repeated count detection module, wherein: The single-bit frequency detection module is used to determine a third detection result of the updated first random number according to the N+M+1th data group and the Nth data group; The poker detection module is used to determine a third detection result of the updated first random number according to the N+M+1th data group and the Nth data group; The repetition count detection module is used to determine a third detection result of the updated first random number according to the N+M+1th data group.
5. The device according to claim 4, characterized in that include: The single-bit frequency detection module is further used to determine whether the bit value in the N+M+1th data group is consistent with the bit value in the Nth data group, wherein the N+M+1th data group and the Nth data group both include: a bit value; In the case where the bit value in the N+M+1th data group is consistent with the bit value in the Nth data group, it is prohibited to adjust the first count value and the second count value, and a third detection result of the updated first random number is determined according to the first count value and the second count value, wherein the first count value is used to indicate the number of first bit values in the Nth data group to the N+Mth data group; and the second count value is used to indicate the number of second bit values in the Nth data group to the N+Mth data group; When the bit value in the N+M+1th data group is inconsistent with the bit value in the Nth data group, the first count value and the second count value are adjusted, and the third detection result of the updated first random number is determined based on the adjusted first count value and the adjusted second count value.
6. The device according to claim 5, characterized in that include: The single-bit frequency detection module is further used to determine whether the bit value in the N+M+1th data group is the first bit value; When the bit value in the N+M+1th data group is the first bit value, adding a preset value to the first count value and subtracting a preset value from the second count value; When the bit value in the N+M+1th data group is not the first bit value, the first count value is subtracted from a preset value, and the second count value is increased from a preset value.
7. The device according to claim 5, characterized in that include: The single-bit frequency detection module is further used to determine whether the adjusted first count value is equal to or greater than the first threshold, and to determine whether the second count value is equal to or greater than the first threshold; When the first count value is greater than or equal to the first threshold, or the second count value is greater than or equal to the first threshold, determining a third detection result of the updated first random number, wherein the third detection result indicates that the updated first random number fails the detection; When the first count value is less than the first threshold value and the second count value is less than the first threshold value, a third detection result of the updated first random number is determined, wherein the third detection result indicates that the updated first random number passes the detection.
8. The device according to claim 4, characterized in that include: The poker detection module is further used to determine whether the bit value in the N+M+1th data group is consistent with the bit value in the Nth data group, wherein the N+M+1th data group and the Nth data group both include: a plurality of bit values; When the bit value in the N+M+1th data group is consistent with the bit value in the Nth data group, it is prohibited to adjust the count value in the count value set, and determine the third detection result of the updated first random number according to the count value in the third count value set, wherein the count value in the count value set is used to indicate the number of target values in the Nth data group to the N+Mth data group; When the bit value in the N+M+1th data group is inconsistent with the bit value in the Nth data group, the target count value in the count value set is adjusted, and the third detection result of the updated first random number is determined based on the adjusted target count value.
9. The device according to claim 8, characterized in that include: The poker detection module is further used to determine a first numerical value corresponding to a bit value in the N+M+1th data group, and to determine a second numerical value corresponding to a bit value in the Nth data group; Determine a third count value corresponding to the first value and a fourth count value corresponding to the second value in the count value set, wherein the target count value includes: the third count value and the fourth count value; The third count value is increased by a preset value, and the fourth count value is decreased by a preset value.
10. The device according to claim 8, characterized in that include: The poker detection module is further used to determine whether the adjusted target count value is greater than or equal to a second threshold; In a case where the adjusted target count value is greater than or equal to the second threshold, determining a third test result of the updated first random number, wherein the third test result indicates that the updated first random number fails the test; In a case where the adjusted target count value is less than the second threshold, a third detection result of the updated first random number is determined, wherein the third detection result indicates that the updated first random number passes the detection.
11. The device according to claim 4, characterized in that include: The repeat count detection module includes: a shift register and a continuity comparison module, wherein: The shift register is used to place the bit value in the N+M+1th data group at the lowest bit of the shift register, and to place the bit values in the N+1th data group to the N+Mth data group in the shift register at the high bit, wherein the N+M+1th data group includes: a bit value, and the bit width of the shift register is the judgment threshold of the repeat count detection; The continuity comparison module is used to determine whether the bit values in the shift register are all consistent, and determine the third detection result of the updated first random number according to whether the bit values in the shift register are all consistent.
12. The device according to claim 11, characterized in that include: The continuity comparison module is further configured to determine a third test result of the updated first random number when it is determined that the bit values in the shift register are all consistent, wherein the third test result indicates that the updated first random number fails the test; In a case where it is determined that the bit values in the shift register are inconsistent, a third detection result of the updated first random number is determined, wherein the third detection result indicates that the updated first random number passes the detection.
13. The device according to claim 4, characterized in that include: The single-bit frequency detection module is also used to perform a determination step: when it is determined that the third detection result indicates that the updated first random number passes the detection, receive the N+M+2th data group sent by the entropy source module and the N+1th data group sent by the first-in-first-out memory; determine a fourth detection result of the first random number after the second update according to the N+M+2th data group and the N+1th data group; and loop through the determination step until the single-bit frequency detection module determines that the detection of the first random number after any update fails, or the single-bit frequency detection module determines that the detection of the first random number after each update passes.
14. The device according to claim 13, characterized in that include: When the detection module includes: the single-bit frequency detection module and the poker detection module, and the single-bit frequency detection module determines that each detection of the updated first random number passes, the poker detection module is further used to determine a first detection result of the first random number, and determine a second detection result of the target random number according to the first detection result.
15. The device according to claim 1, characterized in that include: The random number detection device further includes: a post-processing module connected to the entropy source module, wherein: The post-processing module is used to receive the target random number sent by the entropy source module, and process the target random number according to a target algorithm to obtain a processed target random number.
16. The device according to claim 15, characterized in that include: The post-processing module is further used to perform a second input step: input a third random number into the detection module, wherein the third random number is the Kth data group to the K+Jth data group in the processed target random number, the Kth data group includes: one or multiple consecutive bit values in the processed target random number, and the K+Jth data group includes: one or multiple consecutive bit values in the processed target random number, and K and J are positive integers; when K is 2, 3, ..., Y in sequence, the second input step is executed cyclically until the detection module determines that the detection of the processed target random number fails, or the Yth data group is input into the detection module; The detection module is used to determine a detection result of the third random number, and determine a fourth detection result of the processed target random number according to the detection result of the third random number.
17. The device according to claim 1, characterized in that The random number detection device further includes: an output module connected to the detection module, wherein: The output module is used to determine the random number to be output according to the second detection result output by the detection module and the fourth detection result of the processed target random number.
18. The device according to claim 17, characterized in that include: The output module is further configured to determine that the random number to be output is the target random number when the second detection result indicates that the detection of the target random number has passed and the processed target random number has not passed; When the second detection result indicates that the detection of the target random number fails, and the processed target random number passes, determining that the random number to be output is the processed target random number; When the second detection result indicates that the detection of the target random number passes, and the processed target random number passes, the random number to be output is determined to be the processed target random number.
19. A method for detecting a random number, characterized in that: include: Receive a first random number input by an entropy source module, determine a first detection result of the first random number, and determine a second detection result of a target random number according to the first detection result, wherein the entropy source module performs a first input step: input the first random number into the detection module, wherein the first random number is the Nth data group to the N+Mth data group in the target random number, the Nth data group includes: one or multiple consecutive bit values in the target random number, the N+Mth data group includes: one or multiple consecutive bit values in the target random number, and N and M are positive integers; when N is 2, 3, ... Z in sequence, the first input step is executed cyclically until the detection module determines that the detection of the target random number fails, or the Zth data group is input into the detection module; Among them, determining the first detection result of the first random number, and determining the second detection result of the target random number based on the first detection result, includes: after the detection module determines the first detection result of the first random number based on the Nth data group to the N+Mth data group, receiving the N+M+1th data group input by the entropy source module; discarding the Nth data group to determine the updated first random number.
20. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program implements the steps of the method described in claim 19 when executed by a processor.
21. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to claim 19 are implemented.
22. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to claim 19 are implemented.
Citation Information
Patent Citations
Randomness testing method of pseudorandom sequence based on packet handling
CN101692616A
Random access response transmission and detection method, base station and user equipment
CN108289339A
