Parallelized random number test method and device and related product
By adopting a parallelized random number testing method and utilizing multi-threaded parallel computing technology, the problem of low efficiency in large-sample random number detection is solved, and fast and accurate random number detection is achieved.
Patent Information
- Application Number
- CN202511964817.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-24
- Publication Date
- 2026-04-14
AI Technical Summary
Existing random number detection standards, such as NIST SP 800-22 and the domestic standard GB/T 32915, are inefficient in large-sample testing, resulting in excessively long testing times and failing to meet the needs of rapid testing.
A parallel random number testing method is adopted. Through multi-threaded parallel computing technology, test tasks are divided, thread-private variables and critical protection areas are set to achieve parallel detection and output test reports.
It significantly improves the efficiency of random number detection, supports testing requirements for samples of different lengths, has good configurability and portability, and shortens the detection time.
Smart Images

Figure CN121858437A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of information security cryptography, and in particular to a parallelized random number testing method, apparatus, and related products. Background Technology
[0002] Random number testing is crucial for the certification and security evaluation of cryptographic products and random number generators. Currently, the internationally and domestically accepted standards include the US NIST SP 800-22 "A Statistical Test Suite for Random and Pseudorandom Number Generators for Cryptographic Applications," the domestic cryptographic industry standard GM / T0005-2021 "Randomness Testing Specification," and the national standard GB / T32915 "Methods for Randomness Testing of Binary Sequences." Among these, GM / T0005-2021 is the latest domestic industry standard, while the newest national standard GB / T 32915 is about to be released. Both have a consistent overall framework and serve as important bases for randomness testing in China.
[0003] In the domestic commercial cryptography industry, financial industry testing and certification, and cryptographic algorithm evaluation fields, random number randomness testing is an essential testing item. However, the testing efficiency varies greatly depending on the randomness testing standard. For example, random number testing based on the NIST SP 800-22 standard takes about 40 minutes, and its official tool, NIST STS (Statistical Test Suite), only supports serial testing. Furthermore, testing large samples of 1000×10^8 bit random numbers based on the GM / T0005-2021 standard and the upcoming GB / T 32915 standard in a serial testing manner will take more than several weeks. Therefore, improving the efficiency of random number randomness testing is essential to shorten the product testing and certification cycle.
[0004] The NIST STS kit is often modified by most research institutions and cryptographic product design manufacturers for use in random number detection in national standard GB / T32915 and industry standard GM / T0005.
[0005] The NIST SP 800-22 standard defines a binary sequence detection length of 10^6 bits. The NIST STS suite detects 10^6 bits × 1000 binary sequence data. Because this suite lacks parallelization capabilities, its implementation is serial; a single thread executes the test on one file at a time, processing the next file only after the previous one is completed. The overall detection time is the sum of the times taken to complete the detection of all 1000 files. This results in a random number detection time of approximately 40 minutes. The domestic industry standard GM / T0005 and the upcoming national standard GB / T32915 define binary sequence detection lengths of 20000 bits, 10^6 bits, and 10^8 bits, respectively, with corresponding data volumes of 20000 bits × 1000, 10^6 bits × 1000, and 10^8 bits × 1000, respectively. The same serial implementation takes about 2 minutes to detect 20000 bits × 1000; about 40 minutes to detect 10^6 bits × 1000; and more than several weeks to detect 10^8 bits × 1000.
[0006] Industry standard GM / T0005 and 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.
[0007] To address the low efficiency of randomness detection for large samples of random numbers based on the cryptographic industry standard GM / T0005-2021 and the national standard GB / T32915, it is necessary to perform parallel optimization of the corresponding algorithm code for the randomness detection methods defined in the standards to achieve rapid randomness detection. Summary of the Invention
[0008] In view of the above problems, this application is made to provide a parallelized random number testing method, apparatus, and related products that overcome or at least partially solve the above problems. The technical solution is as follows: Firstly, a parallelized random number testing method is provided, the method comprising: Collect a sample set of target random numbers generated by the cryptographic product, with a sample size of m; Identify the bit length of a single sample in the target random number sample set, confirm the type of the target random number sample, and determine the target test algorithm based on the type of the target random number sample; The target test algorithm code is compiled into an executable file using preset instructions; The number of parallel threads n is determined based on computer hardware resources; The computation instructions are constructed based on the number of parallel threads and the executable file. The execution instructions run the executable file, initiating the test process; Random number testing is performed using parallel computing. 15 detection items are tested for each sample in the target random number sample set, and the test results for each sample are obtained. The test results are summarized and a test report containing the results is output.
[0009] In one possible implementation, the process includes identifying the individual sample bit length of the target random number sample, confirming the target random number sample type, and determining the target test algorithm based on the target random number sample type, including: When the bit length of a single sample of the target random number sample is identified as 20,000, the target random number sample type is the first type, and the target testing algorithm is the short sample detection algorithm. When the bit length of a single sample of the target random number sample is identified as 10^6, the target random number sample type is the second type, and the target test algorithm is the medium sample detection algorithm. When the bit length of a single sample of the target random number sample is identified as 10^8, the target random number sample type is the third type, and the target testing algorithm is a long sample detection algorithm.
[0010] In one possible implementation, computation instructions are constructed based on the number of parallel threads and the executable file, and these instructions include the following parameters: Executable file name; Storage path information of the target random number sample; Output path information for the test report; Tester identification information; Number of parallel threads.
[0011] In one possible implementation, random number testing is performed using parallel computing. Each sample in the target random number sample set undergoes 15 tests, yielding the test results for each sample, including: Based on the determined number of parallel threads n, the target random number sample is divided into n subtasks, each subtask containing m / n samples; Create n parallel threads using a parallel programming framework; The subtasks are assigned to the corresponding parallel threads to perform test calculations. Each sample in the target random number sample set is tested for 15 detection items, and the corresponding test results are obtained.
[0012] In one possible implementation, subtasks are assigned to corresponding parallel threads to perform test computations, including: Declare intermediate variables during the subtask computation process as private variables of the corresponding parallel thread to ensure that each thread has an independent copy of the subtask variables within the parallel region; Set a critical protection zone during the subtask computation process to ensure that only one thread can access the shared resources of the parallel region at any given time.
[0013] In one possible implementation, the test results are summarized, and a test report containing the test results is output, including: Set a thread synchronization point at the end of all subtask calculations. After all threads have finished executing, process the P_value and Q_value of the corresponding samples output by each thread for each detection item. Based on this, calculate the first-level detection pass rate and second-level distribution uniformity results of the target sample set under this detection item, and output a test report.
[0014] In one possible implementation, for each detection item, the P_value and Q_value of the corresponding sample output by each thread are processed. Based on this, the first-level detection pass rate and second-level distribution uniformity results of the target sample set under that detection item are calculated, and a test report is output, including: The P_value and Q_value values calculated by each parallel thread are processed, and the pass rate of the first-level detection and the uniformity of the distribution of the second-level detection are calculated based on the processing results. The calculated pass rate of the first-level test and the uniformity of the distribution of the second-level test will be output in the form of a report; Print out the failed test items and their corresponding test results to the display interface.
[0015] Secondly, a parallelized random number testing device is provided, the device comprising: The sample acquisition unit is used to collect a sample set of target random numbers generated by the cryptographic product, and the number of samples is m. The sample identification unit is used to identify the bit length of a single sample in the target random number sample set, confirm the type of the target random number sample, and determine the target test algorithm based on the type of the target random number sample. The algorithm compilation unit is used to compile the target test algorithm code into an executable file using preset instructions; Resource allocation unit, used to determine the number n of parallel threads based on computer hardware resources; Instruction building unit, used to build computation instructions based on the number of parallel threads and executable file; The test execution unit is used to execute computational instructions, run the executable file, and initiate the test process. The parallel computing unit is used to perform random number testing in a parallel computing manner, and completes 15 detection items for each sample in the target random number sample set to obtain the test result for each sample; The report output unit is used to summarize the test results and output a test report containing the test results.
[0016] Thirdly, an electronic device is provided, comprising a processor and a memory, wherein the memory stores a computer program, and the processor is configured to run the computer program to perform the parallelized random number testing method described in any of the preceding claims.
[0017] Fourthly, a storage medium is provided that stores a computer program, wherein the computer program is configured to execute the parallelized random number testing method described in any of the preceding claims at runtime.
[0018] By employing the above technical solutions, the parallelized random number testing method, apparatus, and related products provided in this application include: collecting random number samples generated by cryptographic products and importing them into a testing platform; determining the sample length to identify the corresponding testing algorithm; compiling the testing algorithm code into an executable file; initiating the testing process through an execution instruction containing multiple parameters; executing the test using parallel computing, including dividing test tasks, setting thread-private variables, establishing critical protection zones, and implementing synchronization mechanisms; and finally summarizing the test results and outputting a test report containing the detection results. This invention, based on multi-core parallel computing technology, significantly improves random number detection efficiency, supports testing requirements for samples of different lengths, and possesses good configurability and portability. Attached Figure Description
[0019] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the description of the embodiments of this application will be briefly introduced below.
[0020] Figure 1 A flowchart of the parallelized random number testing method provided in an embodiment of this application is shown; Figure 2 A flowchart of a parallelized random number testing method provided in a specific embodiment of this application is shown; Figure 3 This illustrates yet another flowchart of the parallelized random number testing method provided in a specific embodiment of this application; Figure 4 A structural diagram of the parallelized random number testing apparatus provided in an embodiment of this application is shown; Figure 5 A structural diagram of an electronic device provided in an embodiment of this application is shown. Detailed Implementation
[0021] Exemplary embodiments of the present application will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the present application are shown in the drawings, it should be understood that the present application may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this application will be thorough and complete, and will fully convey the scope of the present application to those skilled in the art.
[0022] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such use can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the term "comprising" and its variations should be interpreted as open-ended terms meaning "including but not limited to."
[0023] The inventors discovered through analysis that random number testing is crucial for the testing and certification of cryptographic products and the security evaluation of random number generators. Current domestic testing primarily relies on the GM / T 0005-2021 industry standard and the GB / T 32915 national standard, both of which cover various testing items and require processing random number samples of different lengths. However, current mainstream testing tools (such as the NIST STS suite) only support serial testing. Even after adjustments for use with domestic standards, serial testing can take several weeks when dealing with the large samples required by domestic standards, resulting in extremely low testing efficiency and significantly extending the product testing and certification cycle.
[0024] To address the aforementioned technical problems, embodiments of this application provide a parallelized random number testing method, such as... Figure 1 As shown, this parallelized random number testing method may include the following steps S101 to S108: Step S101: Collect a set of target random number samples generated by the cryptographic product, with the number of samples being m.
[0025] In this step, the target random number sample set contains 1000 samples. After collection, the target random number sample set is imported into the detection platform implemented by this method. It can be imported via wired or wireless means, and this embodiment does not limit this.
[0026] Step S102: Identify the bit length of a single sample in the target random number sample set, confirm the target random number sample type, and determine the target test algorithm based on the target random number sample type.
[0027] In this step, the number of samples in the target random number sample set is at least 1000. The bit length of a single sample in the target random number sample set can be identified in a variety of ways, including: obtaining the byte size of the sample file by calling the file system and converting it into bit length; reading the length identification information in the header of the sample file; or obtaining the length parameter by parsing the specific format metadata of the sample data. This embodiment does not limit this.
[0028] Step S103: Compile the target test algorithm code into an executable file using preset instructions.
[0029] In this step, the default command can be "g++ -fopenmp XXXX.cpp -o YYYY" to compile into an executable file, where "XXXX" represents one of the three random number sample types corresponding to the algorithm script, and "YYYY" represents the name of the executable file.
[0030] Step S104: Determine the number of parallel threads n based on computer hardware resources.
[0031] In this step, hardware resources include information such as the number of cores or threads supported by the computer, memory, and cache size. This embodiment does not impose any restrictions on these resources.
[0032] Step S105: Construct computation instructions based on the number of parallel threads and the executable file.
[0033] Step S106: Execute the operation instructions to run the executable file and start the test process.
[0034] Step S107: Random number testing is performed using parallel computing. 15 detection items are tested for each sample in the target random number sample set to obtain the test result for each sample.
[0035] In this step, the test results include the statistical values V, P_value, and Q_value obtained after calculating each sample in the target random number sample set.
[0036] Step S108: Summarize the test results and output a test report containing the test results.
[0037] In this step, the test report includes the location of the target random number sample set file, the location of the test result file, the number of parallel threads, the test start / end time, the testing personnel, the first-level pass rate calculation result and the second-level distribution uniformity calculation result of the target random number sample set under each testing item, as well as the statistical values V, P_value and Q_value obtained by each sample of the target random number sample set through the testing item, etc. This embodiment does not impose any restrictions on this.
[0038] This embodiment collects random number samples generated by cryptographic products and imports them into a testing platform; determines the corresponding test algorithm based on the sample length; compiles the test algorithm code into an executable file; initiates the testing process through an execution instruction containing multiple parameters; executes the test using parallel computing, including dividing test tasks, setting thread-private variables, establishing critical protection zones, and implementing synchronization mechanisms; finally, it summarizes the test results and outputs a test report containing the detection results. This invention, based on multi-core parallel computing technology, significantly improves the efficiency of random number detection, supports testing requirements for samples of different lengths, and has good configurability and portability.
[0039] This application embodiment provides a possible implementation method, and step S102 above may specifically include the following steps: When the bit length of a single sample of the target random number sample is identified as 20,000, the target random number sample type is the first type, and the target testing algorithm is the short sample detection algorithm. When the bit length of a single sample of the target random number sample is identified as 10^6, the target random number sample type is the second type, and the target test algorithm is the medium sample detection algorithm. When the bit length of a single sample of the target random number sample is identified as 10^8, the target random number sample type is the third type, and the target testing algorithm is a long sample detection algorithm.
[0040] This application embodiment provides a possible implementation method, and the operation instruction in step S105 above includes the following parameters: Executable file name; Storage path information of the target random number sample; Output path information for the test report; Tester identification information; Number of parallel threads.
[0041] In this embodiment, the operation instruction format can be ". / YYYY Path1 Path2 Name Number of Threads", where "YYYY" can be flexibly set according to the actual situation, representing the executable file name, "Path1" represents the file path of the target random number sample set, "Path2" represents the test report output path, "Name" represents the name of the tester, and "Number of Threads" represents the number of parallel threads. This embodiment integrates test configuration parameters with execution instructions, transforming abstract system resource information and test requirements into executable operation instructions, realizing one-click start and automated management of the test process, effectively improving the operational efficiency of the test process and the utilization rate of system resources.
[0042] This application embodiment provides a possible implementation method, and step S107 above may specifically include the following steps A1-A3: Step A1: Based on the determined number of parallel threads n, divide the target random number sample into n subtasks, each subtask containing m / n samples; Step A2: Create n parallel threads using a parallel programming framework; Step A3: Assign the subtask to the corresponding parallel thread to perform test calculations, complete 15 detection tests for each sample in the target random number sample set, and obtain the corresponding test results.
[0043] This embodiment establishes a mapping mechanism between task units and computing threads, transforming the overall test task into parallel executable task units. This achieves reasonable allocation and load balancing of computing resources, effectively improving the execution efficiency of large-scale random number testing, while ensuring the integrity and accuracy of the testing process.
[0044] This application embodiment provides a possible implementation method. In step A3 above, the subtask is assigned to the corresponding parallel thread to perform test calculations, which may specifically include the following steps: Declare intermediate variables during the subtask computation process as private variables of the corresponding parallel thread to ensure that each thread has an independent copy of the subtask variables within the parallel region; Set a critical protection zone during the subtask computation process to ensure that only one thread can access the shared resources of the parallel region at any given time.
[0045] This embodiment establishes a complete parallel computing protection mechanism, transforming abstract multi-threaded concurrent tasks into a safe and reliable parallel execution process. This fully leverages the advantages of multi-core architecture in parallel computing while effectively avoiding data contention and resource conflicts, thus ensuring the stability and data security of parallel computing.
[0046] This application embodiment provides a possible implementation method. Step S108 above, which summarizes the test results and outputs a test report containing the test results, specifically includes the following step B1: Step B1: Set thread synchronization points at the end of all subtask calculations. After all threads have finished executing, process the P_value and Q_value of the corresponding samples output by each thread for each detection item. Based on this, calculate the first-level detection pass rate and second-level distribution uniformity results of the target sample set under this detection item, and output the test report.
[0047] This embodiment establishes a synchronous coordination mechanism between parallel computing and result processing, integrating the dispersed parallel computing results into the input of the final computing result. This achieves a smooth transition from parallel computing to serial processing, ensuring the integrity and accuracy of the test results while improving the overall execution efficiency of the test process.
[0048] This application embodiment provides a possible implementation method, and step B1 above further includes the following steps: The test results of each sample calculated by each parallel thread are processed, and the first-level detection pass rate and second-level detection distribution uniformity results of the target sample set under each detection item are calculated based on the processing results. The calculated pass rate of the first-level test and the uniformity of the distribution of the second-level test will be output in the form of a report; Print out the failed test items and their corresponding test results to the display interface.
[0049] This embodiment achieves a comprehensive evaluation of the quality of random numbers by establishing a mechanism for integrating and presenting multi-dimensional test results. It provides accurate quantitative analysis data and enhances the readability of test results through visualization, thus providing sufficient evidence for the formation of test conclusions.
[0050] The above introduces Figure 1 The embodiments shown have various implementation methods for each stage. The parallelized random number testing method of this application will be further explained below through specific embodiments.
[0051] This specific embodiment mainly addresses the problem of low efficiency in random number testing. By using multi-threaded parallel computing technology based on OpenMP, it achieves efficient detection of 1000 10^6-bit random number samples, improving detection efficiency by tens of times compared to traditional serial detection methods.
[0052] The test environment configuration for this specific embodiment is as follows: Hardware environment: Processor: Intel Core i7-10700K CPU, 8 cores and 16 threads Memory: 16GB DDR4 3200MHz Storage: 512GB NVMe SSD Software environment: Operating System: Ubuntu Compiler: GCC Parallel computing library: OpenMP Programming language: C++ like Figure 2 and 3 As shown, the overall process of this specific embodiment is as follows: (1) Algorithm preparation stage 1. Sample collection phase: Collect a set of random number samples generated by the smart card, with a total data volume of 1000 samples and each sample having a length of 10^6 bits; 2. Sample identification stage: Perform Length judgment to determine whether Length=20000bit, Length=10^6bit, or Length=10^8bit. If the single sample bit length of the identified random number sample is 10^6, the target random number sample type is determined to be the second type, and a medium sample detection algorithm containing 15 detection items is selected. 3. Algorithm compilation stage: Under the Linux operating system environment, use the compilation command "g++ -fopenmpTest6.cpp -o Test6" to compile the algorithm code into the executable file Test6.
[0053] (2) Test execution phase 4. Resource allocation phase: Based on the computer hardware resources, the number of parallel threads that can be configured is 10; 5. Command Construction: Construct the operation command ". / Test6 path1 path2 name thread_nums ", where Test6 represents the executable file name, path1 represents the storage path of the random number sample to be tested, path2 represents the test report output path, name represents the tester's identifier, and thread_nums represents the number of parallel threads, which here refers to the number of threads in the resource configuration stage, 10; 6. Task division: Based on the determined number of threads (10), the 1000 random number samples to be tested are divided into 10 sub-tasks, each containing 100 samples. 7. Parallel computing: Create thread_nums parallel threads using the OpenMP parallel programming framework; Use "omp_set_num_threads(thread_nums)" to set the number of threads; Add "#pragma omp parallel" to enable parallelization in the compiler; Use "#pragma omp for private(V,P_value,Q_value)" to declare the computed variable as thread private; Add "#pragma omp critical" inside the loop to set up a critical protection zone; Add "#pragma omp barrier" at the end of the loop to achieve thread synchronization.
[0054] (3) Results processing stage 8. Results Summary: Summarize the 1000 statistical values V, P_value, and Q_value calculated from 1000 random number files, and calculate the first-level detection pass rate and the second-level detection distribution uniformity results; 9. Report Output: Print out the calculated pass rate of the first-level test and the uniformity of the distribution of the second-level test; The failed tests and their corresponding results will be displayed on the testing platform interface. Output a complete test report, including: the location of the tested sample file and the result file, the number of threads used, the start and end times of the test, the information of the test personnel, the first-level pass rate calculation results of 1000 samples under 15 test items, the second-level distribution uniformity calculation results of 1000 samples under 15 test items, and the statistical values V, P_value, and Q_value of 15 test items for each random number sample file.
[0055] This embodiment is based on OpenMP multi-core multi-threaded parallelization, which significantly improves the detection efficiency of large sample random numbers compared with traditional serial detection methods, while maintaining consistency with industry and national standards, and has good operability and portability.
[0056] It should be noted that the sequence numbers of the steps in the above embodiments do not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application. In practical applications, all the above possible implementation methods can be arbitrarily combined in a combined manner to form possible embodiments of this application, which will not be described in detail here.
[0057] Based on the parallelized random number testing methods provided in the above embodiments, and based on the same inventive concept, this application also provides a parallelized random number testing device.
[0058] Figure 4 This is a structural diagram of the parallelized random number testing device provided in the embodiments of this application. Figure 4 As shown, the parallelized random number testing device may specifically include a sample acquisition unit 210, a sample identification unit 220, an algorithm compilation unit 230, a resource configuration unit 240, an instruction construction unit 250, a test execution unit 260, a parallel computing unit 270, and a report output unit 280.
[0059] Sample acquisition unit 210 is used to acquire a sample set of target random numbers generated by the cryptographic product; The sample identification unit 220 is used to identify the bit length of a single sample in the target random number sample set, confirm the type of the target random number sample, and determine the target test algorithm based on the type of the target random number sample. Algorithm compilation unit 230 is used to compile the target test algorithm code into an executable file using preset instructions; Resource allocation unit 240 is used to determine the number of parallel threads n based on computer hardware resources; Instruction building unit 250 is used to build computation instructions based on the number of parallel threads and the executable file; Test execution unit 260 is used to execute arithmetic instructions to run the executable file and start the test process; Parallel computing unit 270 is used to perform random number testing in a parallel computing manner, complete 15 detection items for each sample in the target random number sample set, and obtain the test result for each sample; The report output unit 280 is used to summarize the test results and output a test report containing the test results.
[0060] This application embodiment provides a possible implementation, wherein the sample identification unit 220 is further configured to: When the bit length of a single sample of the target random number sample is identified as 20,000, the target random number sample type is the first type, and the target testing algorithm is the short sample detection algorithm. When the bit length of a single sample of the target random number sample is identified as 10^6, the target random number sample type is the second type, and the target testing algorithm is the medium sample detection algorithm. When the bit length of a single sample of the target random number sample is identified as 10^8, the target random number sample type is the third type, and the target testing algorithm is a long sample detection algorithm.
[0061] This application embodiment provides a possible implementation, wherein the parallel computing unit 270 is further configured to: Based on the determined number of parallel threads n, the target random number sample is divided into n subtasks, each subtask containing m / n samples; Create n parallel threads using a parallel programming framework; The subtasks are assigned to the corresponding parallel threads to perform test calculations. Each sample in the target random number sample set is tested for 15 detection items, and the corresponding test results are obtained.
[0062] This application embodiment provides a possible implementation, wherein the parallel computing unit 270 is further configured to: Declare intermediate variables during the subtask computation process as private variables of the corresponding parallel thread to ensure that each thread has an independent copy of the subtask variables within the parallel region; Set a critical protection zone during the subtask computation process to ensure that only one thread can access the shared resources of the parallel region at any given time.
[0063] This application embodiment provides a possible implementation, wherein the report output unit 280 is further configured to: Set a thread synchronization point at the end of all subtask calculations. After all threads have finished executing, process the P_value and Q_value of the corresponding samples output by each thread for each detection item. Based on this, calculate the first-level detection pass rate and second-level distribution uniformity results of the target sample set under this detection item, and output a test report.
[0064] This application embodiment provides a possible implementation, wherein the report output unit 280 is further configured to: The P_value and Q_value values calculated by each parallel thread are processed, and the pass rate of the first-level detection and the uniformity of the distribution of the second-level detection are calculated based on the processing results. The calculated pass rate of the first-level test and the uniformity of the distribution of the second-level test will be output in the form of a report; Print out the failed test items and their corresponding test results to the display interface.
[0065] Based on the same inventive concept, embodiments of this application also provide an electronic device, including a processor and a memory, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the parallelized random number testing method of any of the above embodiments.
[0066] In an exemplary embodiment, an electronic device is provided, such as Figure 5 As shown, Figure 5 The illustrated electronic device 300 includes a processor 301 and a memory 303. The processor 301 and the memory 303 are connected, for example, via a bus 302. Optionally, the electronic device 300 may also include a transceiver 304. It should be noted that in practical applications, the transceiver 304 is not limited to one type, and the structure of this electronic device 300 does not constitute a limitation on the embodiments of this application.
[0067] Processor 301 may be a CPU (Central Processing Unit), GPU (Graphics Processing Unit), DSP (Digital Signal Processor), ASIC (Application Specific Integrated Circuit), FPGA, or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. Processor 301 may also be a combination that implements computational functions, such as including one or more microprocessor combinations, a combination of a DSP and a microprocessor, etc.
[0068] Bus 302 may include a pathway for transmitting information between the aforementioned components. Bus 302 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. Bus 302 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 5 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0069] The memory 303 may be a ROM (Read Only Memory) or other type of static storage device capable of storing static information and instructions, RAM (Random Access Memory) or other type of dynamic storage device capable of storing information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), CD-ROM (Compact Disc Read Only Memory) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital universal optical discs, Blu-ray discs, etc.), magnetic disk storage media or other magnetic storage devices, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but not limited thereto.
[0070] The memory 303 stores computer program code that executes the scheme of this application, and its execution is controlled by the processor 301. The processor 301 executes the computer program code stored in the memory 303 to implement the content shown in the foregoing method embodiments.
[0071] Among them, electronic devices include, but are not limited to: mobile terminals such as mobile phones, laptops, digital radio receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), and in-vehicle terminals (such as in-vehicle navigation terminals), as well as fixed terminals such as digital TVs and desktop computers. Figure 5 The electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.
[0072] Based on the same inventive concept, this application also provides a storage medium storing a computer program, wherein the computer program is configured to execute the parallelized random number testing method of any of the above embodiments at runtime.
[0073] Those skilled in the art will clearly understand that the specific working process of the systems, devices, and modules described above can be referred to the corresponding process in the foregoing method embodiments. For the sake of brevity, it will not be repeated here.
[0074] Those skilled in the art will understand that the technical solution of this application, or all or part of it, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several program instructions to cause an electronic device (e.g., a personal computer, server, or network device) to execute all or part of the steps of the methods described in the embodiments of this application when running the program instructions. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, portable hard drive, read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0075] Alternatively, all or part of the steps of the foregoing method embodiments can be implemented by hardware (such as electronic devices like personal computers, servers, or network devices) associated with program instructions. The program instructions can be stored in a computer-readable storage medium. When the program instructions are executed by the processor of the electronic device, the electronic device executes all or part of the steps of the methods described in the embodiments of this application.
[0076] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit it. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that within the spirit and principles of this application, modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein; and these modifications or substitutions do not cause the corresponding technical solutions to leave the protection scope of this application.
Claims
1. A parallelized random number testing method, characterized in that, The method includes: Collect a sample set of target random numbers generated by the cryptographic product, with a sample size of m; Identify the bit length of a single sample in the target random number sample set, confirm the type of the target random number sample, and determine the target test algorithm based on the type of the target random number sample; The target test algorithm code is compiled into an executable file using preset instructions; The number of parallel threads n is determined based on computer hardware resources; The computation instructions are constructed based on the number of parallel threads and the executable file. The execution instructions run the executable file, initiating the test process; Random number testing is performed using parallel computing. 15 detection items are tested for each sample in the target random number sample set, and the test results for each sample are obtained. The test results are summarized and a test report containing the results is output.
2. The method according to claim 1, characterized in that, Identify the bit length of a single sample in the target random number sample, confirm the type of the target random number sample, and determine the target test algorithm based on the type of the target random number sample, including: When the bit length of a single sample of the target random number sample is identified as 20,000, the target random number sample type is the first type, and the target testing algorithm is the short sample detection algorithm. When the bit length of a single sample of the target random number sample is identified as 10^6, the target random number sample type is the second type, and the target test algorithm is the medium sample detection algorithm. When the bit length of a single sample of the target random number sample is identified as 10^8, the target random number sample type is the third type, and the target testing algorithm is a long sample detection algorithm.
3. The method according to claim 1, characterized in that, Based on the number of parallel threads and the executable file, the computation instructions include the following parameters: Executable file name; Storage path information of the target random number sample; Output path information for the test report; Tester identification information; Number of parallel threads.
4. The method according to claim 2, characterized in that, Random number testing is performed using parallel computing. Fifteen tests are conducted on each sample in the target random number sample set, yielding the test results for each sample, including: Based on the determined number of parallel threads n, the target random number sample is divided into n subtasks, each subtask containing m / n samples; Create n parallel threads using a parallel programming framework; The subtasks are assigned to the corresponding parallel threads to perform test calculations. Each sample in the target random number sample set is tested for 15 detection items, and the corresponding test results are obtained.
5. The method according to claim 4, characterized in that, Assign subtasks to the corresponding parallel threads to perform test calculations, including: Declare intermediate variables during the subtask computation process as private variables of the corresponding parallel thread to ensure that each thread has an independent copy of the subtask variables within the parallel region; Set a critical protection zone during the subtask computation process to ensure that only one thread can access the shared resources of the parallel region at any given time.
6. The method according to claim 5, characterized in that, The test results are summarized, and a test report containing the test results is output, including: Set a thread synchronization point at the end of all subtask calculations. After all threads have finished executing, process the P_value and Q_value of the corresponding samples output by each thread for each detection item. Based on this, calculate the first-level detection pass rate and second-level distribution uniformity results of the target sample set under this detection item, and output a test report.
7. The method according to claim 6, characterized in that, For each detection item, the P_value and Q_value of the corresponding samples output by each thread are processed. Based on these, the first-level detection pass rate and second-level distribution uniformity results of the target sample set under that detection item are calculated, and a test report is output, including: The P_value and Q_value values calculated by each parallel thread are processed, and the pass rate of the first-level detection and the uniformity of the distribution of the second-level detection are calculated based on the processing results. The calculated pass rate of the first-level test and the uniformity of the distribution of the second-level test will be output in the form of a report; Print out the failed test items and their corresponding test results to the display interface.
8. A parallelized random number testing device, characterized in that, The device includes: The sample acquisition unit is used to collect a sample set of target random numbers generated by the cryptographic product, and the number of samples is m. The sample identification unit is used to identify the bit length of a single sample in the target random number sample set, confirm the type of the target random number sample, and determine the target test algorithm based on the type of the target random number sample. The algorithm compilation unit is used to compile the target test algorithm code into an executable file using preset instructions; Resource allocation unit, used to determine the number n of parallel threads based on computer hardware resources; Instruction building unit, used to build computation instructions based on the number of parallel threads and executable file; The test execution unit is used to execute computational instructions, run the executable file, and initiate the test process. The parallel computing unit is used to perform random number testing in a parallel computing manner, and completes 15 detection items for each sample in the target random number sample set to obtain the test result for each sample; The report output unit is used to summarize the test results and output a test report containing the test results.
9. An electronic device, characterized in that, It includes a processor and a memory, wherein the memory stores a computer program, and the processor is configured to run the computer program to perform the parallelized random number testing method according to any one of claims 1 to 7.
10. A storage medium, characterized in that, The storage medium stores a computer program, wherein the computer program is configured to execute the parallelized random number testing method according to any one of claims 1 to 7 at runtime.