Quick implementation method for random number detection, storage medium and computer equipment
By performing structured storage and bitstream length classification on random number sequences, constructing fast lookup tables and lookup functions, and optimizing the algorithms for three types of detection items, the problem of low efficiency in random number detection in existing technologies is solved, achieving fast and accurate random number detection, adapting to multiple scenario requirements, and improving the practicality and reliability of detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- 北京银联金卡科技有限公司
- Filing Date
- 2025-12-24
- Publication Date
- 2026-04-14
Smart Images

Figure CN121864293A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of information security cryptography technology, and in particular to a method for rapid random number detection, a storage medium, and a computer device. Background Technology
[0002] Random number testing is crucial for the testing and certification of cryptographic products and the security evaluation of random number generators. Whether it is commercial cryptography testing and certification or financial industry testing and certification, random number randomness testing is an essential test item. In order to shorten the product testing and certification cycle, it is necessary to improve the efficiency of random number randomness testing. Summary of the Invention
[0003] In view of this, this application provides a fast random number detection method, storage medium, and computer device, which can optimize the corresponding algorithm for each detection item in the randomness detection specification to achieve fast random number testing based on the algorithm and improve testing efficiency.
[0004] According to one aspect of this application, a fast method for random number detection is provided, the method comprising: For a single random number sequence generated by a cryptographic product, multiple sets of random number sequences to be tested are collected. In any set of random number sequences to be tested, each random number is stored in a structured manner in the form of bytes. In a set of random number sequences to be tested, each random number constitutes a bit stream in the form of bytes. In multiple sets of random number sequences to be tested, the length class to which the random number sequence to be tested belongs is determined according to the bit stream length of each set of random number sequences to be tested, and multiple sets of random number sequences to be tested belonging to the same length class are used as a set of input samples and input into the three types of detection items respectively; When the first type of detection item is input, the feature encoding of each random number bit block in the input sample is pre-calculated, and the pre-calculated integer value is used as an index to associate with the feature of the bit block to obtain a fast lookup table. The fast lookup table is used to locate the bit block by matching the feature of each bit block in the input sample when performing the first type of detection item on the input sample. When the input is a second type of detection item, the m-bit block of the bit stream is extracted by one traversal of the lookup function and the frequency array corresponding to the m-bit block is obtained, which is used to detect the second type of detection item on the input sample. When the third type of detection item is input, the original detection algorithm for the third type of detection item is optimized twice, and the third type of detection item is detected on the input sample by the second optimized algorithm. Based on the probability value output after the input sample is detected by the detection item, it is determined whether the input sample passes the detection item.
[0005] According to another aspect of this application, a storage medium is provided that stores a computer program thereon, which, when executed by a processor, implements the above-described method for rapid random number detection.
[0006] According to another aspect of this application, a computer device is provided, including a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, wherein the processor executes the program to implement the above-described method for rapid random number detection.
[0007] Using the above technical solution, this application provides a fast random number detection method, storage medium, and computer equipment. Multiple sets of random number sequences to be tested are categorized by bitstream length, with samples of the same length serving as input samples. Then, 15 detection items are performed: According to the optimization scheme for the detection items, the first type of detection item encodes the feature of the sample bit blocks, constructs a fast lookup table using pre-calculated integer values as indexes, and locates the data; the second type of detection item constructs a lookup function to quickly extract m-bit blocks from the bitstream; the third type of detection item performs detection after optimizing the sub-algorithm; additionally, the Discrete Fourier Transform (DFT) detection item still uses the FFT algorithm for detection. The probability value output by the detection item determines whether the binary sequence sample passes the detection. By changing the data processing mode, adding a fast lookup table, and adding a fast bit block acquisition method, combined with secondary algorithm optimization, the corresponding algorithms for the three types of detection items in the randomness detection specification can be optimized separately to achieve fast random number testing based on this method, improving testing efficiency.
[0008] The above description is only an overview of the technical solution of this application. In order to better understand the technical means of this application and to implement it in accordance with the contents of the specification, and to make the above and other objects, features and advantages of this application more obvious and understandable, the following are specific embodiments of this application. Attached Figure Description
[0009] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings: Figure 1 A flowchart illustrating a fast random number detection method provided in this application embodiment; Figure 2 This is a flowchart illustrating another fast random number detection method provided in an embodiment of this application. Detailed Implementation
[0010] The present application will be described in detail below with reference to the accompanying drawings and embodiments. It should be noted that, unless otherwise specified, the embodiments and features described in the embodiments of the present application can be combined with each other.
[0011] This embodiment provides a fast method for random number detection, the method including: Step 101: For the random number sequence generated by the cryptographic product in one go, collect multiple sets of random number sequences to be tested. In any set of random number sequences to be tested, each random number is stored in a structured manner in the form of bytes. In a set of random number sequences to be tested, each random number constitutes a bit stream in the form of bytes. Step 102: In multiple sets of random number sequences to be tested, determine the length class of the random number sequence to be tested according to the bit stream length of each set of random number sequences to be tested, and take multiple sets of random number sequences to be tested belonging to the same length class as a set of input samples, and input them into the three types of detection items respectively; Step 103: When the first type of detection item is input, the feature encoding of the bit blocks of each random number in the input sample is pre-calculated, and the pre-calculated integer value is used as an index to associate with the features of the bit blocks to obtain a fast lookup table. The fast lookup table is used to locate the bit blocks by matching the features of each bit block in the input sample when performing the first type of detection item on the input sample. Step 104: When the second type of detection item is input, a lookup function is constructed. The m-bit blocks of the bit stream are extracted through one traversal of the lookup function, and the frequency array corresponding to the m-bit blocks is obtained, which is used to detect the second type of detection item on the input sample. Step 105: When the third type of detection item is input, the original detection algorithm for the third type of detection item is optimized twice, and the third type of detection item is detected on the input sample by the second optimized algorithm. Step 106: Based on the probability value output after the input sample is detected by the detection item, determine whether the input sample passes the detection item.
[0012] In the above embodiments of this application, random numbers are stored in a structured manner in byte form, and samples of the same length are classified according to the bitstream length to ensure consistent detection conditions, avoid interference from different lengths, and lay the foundation for accurate detection. Regarding the efficiency of the first type of detection: bit block feature encoding is pre-calculated and a fast lookup table is constructed for direct feature matching and localization, reducing redundant calculations and improving detection speed. Regarding the adaptability of the second type of detection: the bitstream is converted into a quantizable frequency array through a lookup function, that is, the m-bit blocks of the bitstream are quickly extracted and the corresponding frequency arrays are obtained through a single traversal of the lookup function, connecting to the randomness verification logic to achieve adaptation between feature quantization and detection requirements. Regarding the adaptability of the third type of detection: the original algorithm is optimized a second time to enhance its computational efficiency and scene coverage, adapting to complex detection requirements. Finally, probability values are used as a unified quantitative standard to avoid subjective judgment and ensure the reliability of test results.
[0013] To this end, from sample preprocessing to detection execution and result judgment, accurate, efficient and standardized randomness detection of random numbers has been achieved. It not only adapts to the structured characteristics of random numbers in cryptographic products, but also covers the detection needs of multiple scenarios, effectively improving the practicality and reliability of random number detection.
[0014] Optionally, in step 103, the fast lookup table is: , LUT stands for Fast Lookup Table. The index i of the LUT corresponds to the non-overlapping index value in the input sample. Bit blocks, For the first The Hamming weight of bit blocks, where n is the total number of bit blocks in the input sample.
[0015] In the above embodiments of this application, such as Figure 1 As shown, this type of detection item is mainly optimized using a fast lookup table. Specifically, the integer values of all k-bit blocks in the input sample are pre-calculated and mapped to the indices of the lookup table. In practical engineering implementation, the block size can be set to k=8, then the size of the fast lookup table is... , that is An array. Finding an element in the table can be represented by the following formula: , in, The index value represents the non-overlapping index in the input samples. 8-bit block, Indicates the first The Hamming weight of an 8-bit block, that is, the number of "1"s.
[0016] Optionally, in step 104, extracting m-bit blocks of the bitstream and obtaining the frequency array corresponding to the m-bit blocks through a single traversal of the lookup function includes: Step 1041: The lookup function is used to create a frequency array of the input samples, wherein the size of the frequency array covers all possible m-bit blocks in the input samples, the initial frequency of all m-bit blocks is 0, and the m-bit block is a fixed m-bit binary subsequence set for frequency counting. Step 1042: Extract all overlapping m-bit blocks from the bit stream corresponding to the input sample using a sliding window, wherein each m-bit block is converted from binary to decimal and used as an integer index of the frequency array. Step 1043: For each extracted m-bit block, convert it into an index and then perform an incremental operation; Step 1044 continues until the frequency of occurrence of each m-bit block is calculated.
[0017] In the above embodiments of this application, for the second type of detection items, in order to speed up these tests, a lookup function can be constructed that can extract arbitrary bit blocks (m≤25) from a given bit stream (byte array). The upper bound of the block size can be set to 25, because the upper bound of m is... For 20MB of data, this upper limit can be m=24, so a lookup function can be used to retrieve the nth block. The lookup function retrieves the nth block very quickly; on a standard modern computer, it can return all m-bit blocks from a 100MB bitstream within one second.
[0018] In practical optimization implementations, an array H consisting of the frequencies of m-bit blocks indexed by the blocks themselves can be used. A lookup function is implemented to extract overlapping m-bit blocks from the bitstream. These blocks are used as an index for H and to increment the corresponding frequency. Because accessing array H and incrementing it are very fast operations.
[0019] In the original implementation, the time complexity of the test depends on the number of predefined search templates. (a template), and the frequency array H corresponding to any m-bit block is calculated exponentially with the parameter m. The implementation of the above embodiments of this application calculates the frequency array H of any m-bit block in only one pass in the same manner. Therefore, the complexity of the implementation of the above embodiments of this application is independent of m. Furthermore, the above embodiments of this application also calculate the frequency array H corresponding to all m-bit blocks, which can easily provide complete statistical data.
[0020] Furthermore, the specific steps are as follows: 1. The random number sequence to be tested: a bit stream of length n, S=s 0, s1 s n 1 (each s) i ∈{0,1}, representing the binary form of a random sequence.
[0021] 2. m-bit block: A substring of the bit stream divided into segments of length m (e.g., when m=3, the block is "010", "111", etc.). There are 2 possible values for an m-bit block. m Each bit can be 0 or 1 independently.
[0022] 3. Array H: Size is 2 m The frequency array, where the index corresponds to the integer form of the m-bit block, and the element stores the number of occurrences of that block (initialized to all 0s).
[0023] Specifically, construct lookup functions for fast bit block retrieval (such as...) Figure 1As shown in the figure, the core function of the lookup function is to extract all overlapping m-bit blocks from the bitstream and count the frequency of each block. The specific steps are as follows: 1. Initialization: Create the frequency array (H): Array size: 2 m (Cover all possible m-bit blocks. For example, when m=2, the size of H is 4, corresponding to blocks “00”, “01”, “10”, and “11”.)
[0024] Initial state: H[0], H[1], ,H[2 m 1]=0 (the initial frequency of all blocks is 0).
[0025] 2. Extracting overlapping m-bit blocks: Sliding window method: Extract all overlapping m-bit blocks from the bitstream using a sliding window (overlapping means shifting the window one bit to the right each time, rather than skipping m bits): Window range: for i=0,1, ,n m (total n) (m+1 windows), with each window covering s bits. i s i+1 s i+m 1, denoted as block b i .
[0026] For example, when n=5 and m=3, the overlapping blocks of the bit stream "s0s1s2s3s4" are b0=s0s1s2, b1=s1s2s3, and b2=s2s3s4.
[0027] 3. Block to Index Conversion: Each m-bit block bi needs to be converted into an integer index to be used as an index in H to access the corresponding frequency. The conversion rule is binary to decimal: For block b i =s i s i+1 , s i+m 1, its corresponding integer is: k=s i ×2 m 1 +s i+1 ×2 m 2 + +s i+m 1×2 0For example, the integer corresponding to block “011” (m=3) is 0×4+1×2+1×1=3, so H[3] stores the frequency of this block.
[0028] 4. Frequency Statistics: Update array (H): For each extracted block b i After converting it to index k, perform an incremental operation: H[k]+=1.
[0029] This step is to find the function's "execution action"—find the position in H by the block index, count the number of times the block appears, and in particular, "+=" means variable = variable + increment, which is a commonly used "addition assignment operator" in programming languages.
[0030] Through this process, the lookup function can convert the bit stream into a quantizable frequency array, further enabling the quality assessment of random number samples.
[0031] Optionally, the third type of detection items includes linear complexity detection items and matrix rank detection items. In step 105, after performing a secondary optimization on the original detection algorithm for the third type of detection items, the input sample is detected using the secondary optimized algorithm for the third type of detection items, including: Step 1051: In the third type of detection item, for the matrix rank detection item, the Boolean matrix is represented as an array of unsigned integers. Gaussian elimination and fast bit operations are used to calculate the array. If it is found that two columns of the array do not have a pivot during the calculation process, the calculation is stopped. When the stop calculation condition is met, the conclusion that the rank is less than a preset number is directly obtained. When the stop calculation condition is not met, the calculation continues until the specific value of the rank is determined. Here, each integer represents a row of the Boolean matrix. The fast bit operations include XOR operation for row addition, AND and shift operations for pivot lookup. Step 1052: For the linear complexity detection item, the Berlekamp-Massey algorithm, which is the core sub-algorithm, is optimized. The input sample is then tested for the third type of detection item using the second-optimized algorithm.
[0032] In the above embodiments of this application, the matrix rank detection item is further optimized in the third type of detection item. The optimized algorithm improves the detection accuracy and efficiency, enabling more precise identification of potential regularity defects in random number sequences. For the linear complexity detection item, the core sub-algorithm BM algorithm is optimized to maintain its fast response characteristics, ensuring efficient detection even in complex scenarios. This combination leverages the enhancement effect of the optimized algorithm on specific detection items while retaining the advantages of the original algorithm on those items, thus improving the overall comprehensiveness and reliability of the detection and providing strong support for the quality assessment of random number sequences in cryptographic products.
[0033] Furthermore, for the third type of detection, such as matrix rank detection, Gaussian elimination is used to check if the rank of a 32x32 Boolean matrix is 32, 31, or lower. Word operations are used instead of bit operations. Since the size of a square Boolean matrix is 32, it is represented as an array of 32 unsigned integers, each representing a row of the matrix. The rank of the matrix is calculated using fast bitwise operations XOR, AND, and shift. Row addition is implemented using XOR operations, and bitwise AND and shift are used for pivot lookup. A stopping condition is added: if two columns have no pivot (rank less than 31), the calculation stops, further saving computation time.
[0034] Optionally, in step 1052, the Berlekamp-Massey algorithm, which is the core sub-algorithm, is optimized, including: Step 10521: The Berlekamp-Massey algorithm is optimized into a non-inversion structure for binary sequences. The optimized Berlekamp-Massey algorithm calculates the difference value when checking the binary sequence bit by bit and performs operations based on the difference value. The difference value of each bit in the binary sequence represents whether the latest LFSR can generate the corresponding bit. If the corresponding bit is 0, it moves to the next bit. If the corresponding bit is 1, the operation is performed and then the loop is entered.
[0035] In the above embodiments of this application, the third type of detection item in the randomness detection specification has the following characteristics: slow and complex testing, including linear complexity detection items and matrix rank detection items; the linear complexity detection item uses a binary-oriented BM algorithm without inversion structure. This algorithm does not construct an LFSR, but only calculates the difference d. Here, the binary sequence no longer represents the LFSR; the value of each bit in the sequence represents whether the latest LFSR can generate that bit (difference value). The algorithm first checks the first bit of the sequence: if the bit is 0, it moves directly to the next bit without performing any other operations. If the bit is 1, after performing the necessary operations, the algorithm continues to search for subsequent bits, entering a loop. Compared to the original BM algorithm, the detection efficiency is greatly improved.
[0036] Furthermore, regarding the linear complexity detection item, due to the high computational complexity of the Berlekamp-Massey (BM) algorithm it relies on, this detection item is the least efficient compared to other detection items. Especially as the sample length increases, detection efficiency gradually becomes a bottleneck limiting its applicability. The main idea of the binary sequence BM algorithm is to iteratively update the coefficients of the LFSR polynomial while processing the input sequence. The algorithm starts with a zero polynomial and increases the polynomial series as the input sequence iterates. At each step, the algorithm checks whether the current LFSR can generate the observed sequence (difference value). d(Is it equal to 0?) If not, update the LFSR polynomial. This application proposes a binary-oriented BM algorithm without inversion structure, starting from an improved BM algorithm. This algorithm does not construct an LFSR, but only calculates the difference d. Here, the binary sequence no longer represents the LFSR; the value of each bit in the sequence represents whether the latest LFSR can generate that bit (difference value). The algorithm first checks the first bit of the sequence: if the bit is 0, it moves directly to the next bit without any other operation. If the bit is 1, after performing the necessary operations, the algorithm continues to search for subsequent bits, entering a loop. The improved BM algorithm has the following input: represent Bit-length sequences; and This array represents the difference values (d in the original BM algorithm). Output: Generate sequence The shortest LFSR.
[0037] Optionally, the first type of detection items includes detection items that need to process each bit in the bit stream, and the second type of detection items includes detection items that need to process m-bit blocks. The first type of detection items includes single-bit frequency detection items, intra-block frequency detection items, total run count detection items, maximum 0 / 1 run count within the block detection items, run distribution detection items, binary derivation detection items, autocorrelation detection items, and pre / post term summation detection items. The second type of detection items includes overlapping subsequence detection items, poker detection items, general statistics detection items, and approximate entropy detection items. The third type of detection items includes matrix rank detection items and linear complexity detection items.
[0038] In the above embodiments of this application, the first type of detection item in the randomness detection specification has the following characteristics: each bit in the bit stream is processed at one time, including single bit frequency detection item, block frequency detection item, total run count detection item, maximum "0 / 1" run count within the block detection item, run distribution detection item, binary derivation detection item, autocorrelation detection item, and "previous / after" term summation detection item.
[0039] The second type of randomness detection items in the randomness detection specification have the following characteristics: they are tests that process m-bit blocks, including overlapping subsequence detection items, poker detection items, general statistical detection items, and approximate entropy detection items.
[0040] The third category of testing items includes "slow and complex" testing items, which means that compared to other testing items, the computational complexity is the highest and the time consumption is the longest as the sample length increases.
[0041] Optionally, step 106, based on the probability value output after the input sample has been detected by the detection item, determines whether the input sample passes the detection item, including: Step 1061: Obtain the probability value output by each detection item under the detection of the same type of detection item for the input sample. If the probability value of each detection item meets its respective preset standard, then the input sample is determined to pass the detection item of the type.
[0042] In the above embodiments of this application, the probability values output by each detection item are obtained when the input sample is detected by the same type of detection items. If the probability values of each detection item meet their respective preset standards, the input sample is determined to pass the type of detection items. If any detection item fails to meet the standard, the overall detection will fail, which reflects the strictness of the detection items and the necessity of combined verification.
[0043] To this end, by comprehensively utilizing changes in sample data storage and processing models, optimizing detection algorithms and sub-algorithms, the efficiency of random number detection has been improved and the testing and certification cycle for cryptographic products has been further shortened. The overall solution balances easy import of sample data with high computational efficiency.
[0044] Currently, the publicly available official testing tool is mainly the NISTSTS suite. Most research institutions and cryptographic product design manufacturers often modify the suite code and apply it to random number detection in national standard GB / T32915 and industry standard GM / T0005-2021.
[0045] The NISTSTS suite is characterized by storing and processing data in bits, which is not only a very time-consuming conversion process, but also imposes very strict limitations on the maximum file size that can be processed in a single execution due to the data storage mode (bit array) and the restrictions in variable definitions. Because the total number of bits in the input file cannot exceed the maximum value of a 32-bit int type variable, the theoretical maximum file size is 256MB, but in practice, this value is typically reduced to 198MB in NIST implementations. Specifically, the domestic industry standard GM / T0005-2021 and the revised national standard GB / T32915 include a binary sequence length of 10^8 bits and a detection data volume of... Using the data storage method in the NISTSTS suite would lead to memory overflow, making random number detection impossible. This algorithm optimization introduces a byte processing mode, where bit-level operations are performed with the help of a special pre-computed lookup table. It also supports input files up to 1GB in size. Furthermore, regarding... Large-sample random number detection, if the algorithm implementation of the detection items continues to use the features of the NISTSTS suite, will cause the random number test to last for several weeks.
[0046] The industry standard GM / T0005-2021 and the soon-to-be-released national standard GB / T32915 each include 15 randomness detection items: single-bit frequency detection, intra-block frequency detection, total number of runs detection, maximum "0 / 1" run within a block detection, run distribution detection, binary derivation detection, "previous / next" term summation detection, overlapping subsequence detection, poker detection, matrix rank detection, autocorrelation detection, general statistical detection, linear complexity detection, approximate entropy detection, and discrete Fourier transform detection.
[0047] To address the issue of low efficiency in detecting the randomness of large sample random numbers under the cryptographic industry standard GM / T0005-2021 and the upcoming national standard GB / T32915, the corresponding algorithm code of the randomness detection method defined in the standards can be optimized to quickly achieve random number detection.
[0048] By applying the technical solution of this embodiment, the storage and processing mode of random numbers is changed from bit to byte; a fast lookup table is added for algorithm optimization; the processing method of m-bit blocks is optimized; and the sub-algorithms of matrix rank detection and linear complexity detection are optimized. This solves the problem of low efficiency in large-sample random number detection during cryptographic product testing and authentication.
[0049] In one specific embodiment, such as Figure 2 As shown, the development language is C++, and the testing environment is Linux. The algorithm is executed by testing the task through an executable file, which is compiled in the Linux environment using the command "g++XXXX.cpp -oYYYY". The algorithm execution command is ". / YYYY path1 path2 name", where "YYYY" represents the executable file name, "path1" represents the path of the random number sample to be tested, "path2" represents the output path of the test report, and "name" represents the name of the tester.
[0050] Specifically, random numbers generated by the cryptographic product are collected and imported into a sample of random numbers to be tested. The length of the input random number sample (20000 bits / 10^6 bits / 10^8 bits) is assessed to determine the appropriate algorithm for the random number test. This is because the testing methods defined in the GM / T0005-2021 industry standard and the upcoming GB / T32915 national standard differ for different random number sample lengths. In a Linux environment, the chosen algorithm script is compiled to generate an executable file. The executable file is then executed using computational instructions. Finally, rapid calculations for the random number test are performed. Finally, the test report is output: The output report covers detailed test results. In addition to basic information such as the location of the tested sample file, the location of the result file, the start / end time of the test, and the personnel conducting the test, the test report also includes the first-level pass rate calculation results and the second-level distribution uniformity calculation results of 1000 random number samples under each test item (a total of 15 test items), as well as the statistical values V, probability values P_value, and Q_value of the 15 test items under each random number sample file (a total of 1000 samples).
[0051] Furthermore, the process of collecting and importing random number samples to be tested includes: 1) Use a card reader to collect the random number generated by the password product. ; 2) Import the collected random number samples into a platform that supports random number testing; The sample length determination process includes: the random number length in this embodiment is 10^6 bits, and the corresponding algorithm script should be selected for compilation.
[0052] The algorithm script compilation process includes: 1) In the Linux environment, the algorithm code .cpp script with a random number length of 10^6 bits is compiled into the executable file Test6 using the command "g++Test6.cpp -oTest6".
[0053] The process of executing arithmetic instructions includes: 1) The algorithm execution command is ". / Test6 path1 path2 lyw", where "Test6" represents the executable file name, "path1" represents the path of the random number sample to be tested, "path2" represents the output path of the test report, and "lyw" represents the name of the tester.
[0054] The fast calculation process includes: A fast calculation method for random number testing is implemented based on the optimized implementation of the random number detection project.
[0055] The process of generating a test report includes: 1) According to the industry standard GM / T0005-2021 and the national standard GB / T32915, the failed test items and the corresponding first-level pass rate and second-level distribution uniformity results will be printed out on the test platform display interface.
[0056] By applying the technical solution of this embodiment, compared with the NISTSTS suite, the random number storage and processing mode is changed from bit to byte, solving the problem of memory overflow caused by excessively large test samples. Compared with the NISTSTS suite, the algorithm implementation adopts fast lookup table optimization and fast bit block acquisition optimization. This solves the problem of low detection efficiency when the computational complexity of the detection items increases exponentially with the increase of the sample size. Secondary algorithm optimization further shortens the computation time of the algorithm detection. This method supports random number detection of arbitrary length and arbitrary number of samples. When porting between detection platforms, only the .cpp file needs to be copied to the target platform, compiled once in the target platform's Linux environment, and then the executable file generated by compilation can be repeatedly executed for testing tasks, with strong portability. According to the GM / T0005-2021 industry standard and GB / T32915 national standard, the failed detection items and the corresponding first-level pass rate results and second-level distribution uniformity results will be printed on the detection platform display interface. The detailed results will be displayed in the detection report through " Marked with an asterisk (" "). The test results are highly readable.
[0057] Based on the above, Figures 1 to 2 Accordingly, this application also provides a storage medium storing a computer program, which, when executed by a processor, implements the above-described method. Figures 1 to 2 The method shown is a fast implementation of random number detection.
[0058] Based on this understanding, the technical solution of this application can be embodied in the form of a software product. The software product can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, or portable hard drive), and includes several instructions to cause a computer device (such as a personal computer, server, or network device) to execute the methods described in the various implementation scenarios of this application.
[0059] Based on the above, Figures 1 to 2 To achieve the above objectives, this application also provides a computer device, specifically a personal computer, server, network device, etc., as shown in the method. The computer device includes a storage medium and a processor; the storage medium stores a computer program; the processor executes the computer program to achieve the above-described objectives. Figures 1 to 2 The method shown is a fast implementation of random number detection.
[0060] Optionally, the computer device may also include a user interface, a network interface, a camera, radio frequency (RF) circuitry, sensors, audio circuitry, a Wi-Fi module, etc. The user interface may include a display screen, input units such as a keyboard, etc., and optional user interfaces may also include USB ports, card reader ports, etc. The network interface may optionally include standard wired interfaces, wireless interfaces (such as Bluetooth interfaces, Wi-Fi interfaces), etc.
[0061] Those skilled in the art will understand that the computer device structure provided in this embodiment does not constitute a limitation on the computer device, and may include more or fewer components, or combine certain components, or have different component arrangements.
[0062] The storage medium may also include an operating system and a network communication module. The operating system is a program that manages and stores the hardware and software resources of a computer device, supporting the operation of information processing programs and other software and / or programs. The network communication module is used to enable communication between the various components within the storage medium, as well as communication with other hardware and software within the physical device.
[0063] Through the above description of the implementation methods, those skilled in the art can clearly understand that this application can be implemented using software plus necessary general-purpose hardware tools, or it can be implemented using hardware to categorize multiple sets of random number sequences to be tested according to bit stream length, with samples of the same length as input samples, followed by three types of detection: the first type encodes the feature of the sample bit blocks, constructs a fast lookup table using pre-calculated integer values as indexes, and locates the data; the second type constructs a lookup function to quickly obtain m bit blocks and generates the corresponding frequency array, which is used to further verify the randomness of the binary sequence samples; the third type performs detection after optimizing the algorithm. The probability value output by the detection item determines whether the binary sequence sample passes the detection. By changing the data processing mode, adding a fast lookup table, and adding a fast bit block acquisition method, combined with secondary algorithm optimization, the corresponding algorithm for each detection item in the randomness detection specification can be optimized separately to achieve fast random number testing based on this method, thereby improving testing efficiency.
[0064] Those skilled in the art will understand that the accompanying drawings are merely schematic diagrams of a preferred embodiment, and the modules or processes shown in the drawings are not necessarily essential for implementing this application. Those skilled in the art will understand that the modules in the tools within the embodiment can be distributed within the tools of the embodiment as described, or they can be modified and located in one or more tools different from this embodiment. The modules of the above-described embodiment can be combined into one module, or further divided into multiple sub-modules.
[0065] The serial numbers in this application are for descriptive purposes only and do not represent the superiority or inferiority of any particular implementation scenario. The above disclosures are merely a few specific implementation scenarios of this application; however, this application is not limited thereto, and any modifications that can be made by those skilled in the art should fall within the protection scope of this application.
Claims
1. A fast method for random number detection, characterized in that, The method includes: For a single random number sequence generated by a cryptographic product, multiple sets of random number sequences to be tested are collected. In any set of random number sequences to be tested, each random number is stored in a structured manner in the form of bytes. In a set of random number sequences to be tested, each random number constitutes a bit stream in the form of bytes. In multiple sets of random number sequences to be tested, the length class to which the random number sequence to be tested belongs is determined according to the bit stream length of each set of random number sequences to be tested, and multiple sets of random number sequences to be tested belonging to the same length class are used as a set of input samples and input into the three types of detection items respectively; When the first type of detection item is input, the feature encoding of each random number bit block in the input sample is pre-calculated, and the pre-calculated integer value is used as an index to associate with the feature of the bit block to obtain a fast lookup table. The fast lookup table is used to locate the bit block by matching the feature of each bit block in the input sample when performing the first type of detection item on the input sample. When the input is a second type of detection item, a lookup function is constructed. The m-bit blocks of the bit stream are extracted by one traversal of the lookup function and the frequency array corresponding to the m-bit blocks is obtained. This array is used to detect the second type of detection item on the input sample. When the third type of detection item is input, the original detection algorithm for the third type of detection item is optimized twice, and the third type of detection item is detected on the input sample by the second optimized algorithm. Based on the probability value output after the input sample is detected by the detection item, it is determined whether the input sample passes the detection item.
2. The method according to claim 1, characterized in that, The fast lookup table is: , LUT stands for Fast Lookup Table. The index i of the LUT corresponds to the non-overlapping index value in the input sample. Bit blocks, For the first The Hamming weight of bit blocks, where n is the total number of bit blocks in the input sample.
3. The method according to claim 1, characterized in that, The step of extracting m-bit blocks from the bitstream and obtaining the frequency array corresponding to the m-bit blocks through a single traversal of the lookup function includes: The lookup function is used to create a frequency array of the input samples, wherein the size of the frequency array covers all possible m-bit blocks in the input samples, the initial frequency of all m-bit blocks is 0, and the m-bit block is a fixed m-bit binary subsequence set for frequency counting; Extract all overlapping m-bit blocks from the bit stream corresponding to the input sample using a sliding window. Each m-bit block is converted from binary to decimal and used as an integer index of the frequency array. For each extracted m-bit block, convert it into an index and then perform an incremental operation; This continues until the frequency of occurrence of each m-bit block is calculated.
4. The method according to claim 1, characterized in that, The third type of detection items includes linear complexity detection items and matrix rank detection items. The original detection algorithm for the third type of detection items undergoes secondary optimization, and the optimized algorithm is used to detect the third type of detection items on the input samples, including: In the third type of detection item, for the matrix rank detection item, the Boolean matrix is represented as an array of unsigned integers. Gaussian elimination and fast bit operations are used to calculate the array. If two columns of the array are found to be without a pivot during the calculation process, the calculation is stopped. When the stop calculation condition is met, the conclusion that the rank is less than a preset number is directly obtained. When the stop calculation condition is not met, the calculation continues until the specific value of the rank is determined. Here, each integer represents a row of the Boolean matrix. The fast bit operations include XOR operation for row addition, AND and shift operations for pivot lookup. For the linear complexity detection term, the Berkeley-Massey algorithm, which is the core sub-algorithm, is optimized. The second-optimized algorithm is used to detect the third type of detection term on the input sample.
5. The method according to claim 4, characterized in that, The optimization of the Berkeley-Massey algorithm, which is the core sub-algorithm, includes: The Berlykamp-Massey algorithm is optimized into an inversion-free structure for binary sequences. The optimized Berlykamp-Massey algorithm calculates the difference value when checking the binary sequence bit by bit and performs operations based on the difference value. The difference value of each bit in the binary sequence represents whether the latest LFSR can generate the corresponding bit. If the corresponding bit is 0, it moves to the next bit. If the corresponding bit is 1, the operation is performed and then the loop is entered.
6. The method according to claim 1, characterized in that, The first type of detection item includes detection items that need to process every bit in the bit stream, while the second type of detection item includes detection items that need to process m-bit blocks.
7. The method according to any one of claims 1 to 6, characterized in that, The first category of detection items includes single-bit frequency detection, intra-block frequency detection, total number of runs detection, maximum 0 / 1 run within a block detection, run distribution detection, binary derivation detection, autocorrelation detection, and summation of preceding and succeeding terms detection. The second category of detection items includes overlapping subsequence detection, poker detection, general statistics detection, and approximate entropy detection. The third category of detection items includes matrix rank detection and linear complexity detection.
8. The method according to claim 7, characterized in that, The determination of whether an input sample passes the detection item based on the probability value output after the input sample has been detected by the detection item includes: Obtain the probability value output by each detection item under the detection of the same type of detection item for the input sample. If the probability value of each detection item meets its own preset standard, then the input sample is determined to pass the detection item of the type.
9. A storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method for rapid random number detection as described in any one of claims 1 to 8.
10. A computer device, comprising a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, characterized in that, When the processor executes the computer program, it implements the method for rapid random number detection as described in any one of claims 1 to 8.