A method and device for detecting randomness of a sequence

By storing only part of the bits and values ​​and numerical distribution information of the sequence to be detected in random number detection, the problem of excessive memory usage in the prior art is solved, and efficient random detection is achieved, which is suitable for resource-condensing equipment.

CN117785449BActive Publication Date: 2025-03-21BEIJING HAITAI FANGYUAN HIGH TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311745097.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-12-18
Publication Date
2025-03-21
Estimated Expiration
2043-12-18

AI Technical Summary

Technical Problem

The existing random number detection methods occupy too much memory, making it difficult to meet the needs of resource-squeezing equipment such as IoT security equipment and industrial control security equipment.

Method used

By obtaining the sum of some bits of the sequence to be detected, only the bits and value and numerical distribution information are stored, all the sequences are traversed to obtain numerical distribution information, and determining whether the sequence to be detected passes random detection, reducing the memory footprint and the time when the device reads memory space data in allocated memory.

Benefits of technology

It achieves the reduction of memory usage and improves the efficiency of random detection, and is suitable for resource-squeezing equipment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117785449B_ABST
    Figure CN117785449B_ABST
Patent Text Reader

Abstract

The present application discloses a method and device for detecting randomness of a sequence, which includes: obtaining a sequence to be detected of N bytes, where N is a positive integer greater than 1; determining at least one bit set according to the bit sum value of the bits in the first K bytes in the sequence to be detected, wherein any bit set contains multiple consecutive bits in the first K bytes, the bit sum value corresponding to the last bit in the multiple consecutive bits is a set value, and the bit sum value corresponding to the bits other than the last bit in the multiple consecutive bits is not the set value, and K is a positive integer less than N; determining whether the sequence to be detected passes the randomness detection according to the numerical distribution information of the bit sum value of the bits in the bit set. The method can reduce the memory usage of the randomness detection process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of information security, and in particular to a method and device for detecting randomness of a sequence. Background Art

[0002] At present, with the development of informatization and computer technology, while people are enjoying the many benefits brought by informatization, network security issues have become a common challenge faced by mankind in the information age. The output of a random number generator is called a random number, which is widely used in various fields. Therefore, in order to ensure that the random number generator generates high-quality and stable random numbers, it is necessary to test the randomness of the random number.

[0003] At present, the random number detection process takes up too much memory, which makes it difficult to meet the needs of resource-constrained devices such as IoT security equipment and industrial control security equipment. Summary of the invention

[0004] The embodiments of the present application provide a sequence randomness detection method and device to reduce memory usage.

[0005] In a first aspect, an embodiment of the present application provides a method for detecting randomness of a sequence, comprising:

[0006] Obtain an N-byte sequence to be detected, where N is a positive integer greater than 1; determine at least one bit set according to the bit sum value of the bits in the first K bytes in the sequence to be detected, wherein any of the bit sets includes multiple consecutive bits in the first K bytes, the bit sum value corresponding to the last bit of the multiple consecutive bits is a set value, and the bit sum values ​​corresponding to the bits other than the last bit of the multiple consecutive bits are not the set value, and K is a positive integer less than N; determine whether the sequence to be detected passes the randomness test according to the numerical distribution information of the bit sum value of the bits in the bit set.

[0007] According to this method, during the detection process, the present application does not need to convert all bytes into bits at once, but obtains a bit sequence based on the sum of some bits in the sequence to be detected, only stores the bit sum value obtained by summing some bits, and obtains the numerical distribution information corresponding to the bit sum value, and obtains the numerical distribution information corresponding to the bit sum value after traversing all sequences, and determines whether the sequence to be detected passes the randomness test based on the numerical distribution information. This process does not need to repeatedly traverse all bits in the sequence to be detected, which can reduce memory usage and reduce the time for the device to read memory space data when allocating memory.

[0008] In one possible design, the bit sum value of the sequence to be detected is determined according to the bit value of the sequence to be detected and the adjustment value corresponding to the bit value, wherein different bit values ​​correspond to different adjustment values ​​and the same bit values ​​correspond to the same adjustment values.

[0009] According to the design, in this application, the adjustment value corresponding to the bit value of 0 is -1, and the adjustment value corresponding to the bit value of 1 is 1. The adjustment value corresponding to the bit value is determined according to the bit value (for example, the bit value is b1=0, b2=1, b3=1) (for example, the adjustment value is d1=-1, d2=1, d3=1). This design is used to ensure that there are no two adjacent values ​​of the bit sum value that are both 0, avoid additional calculation of redundant laps when subsequently calculating the number of laps, ensure the accuracy of the statistical laps, and improve the detection efficiency.

[0010] In one possible design, the numerical distribution information corresponding to any bit set is used to indicate the number of bits and values ​​corresponding to the bit set whose values ​​are target values, and the target value does not include the set value.

[0011] According to the design, after obtaining the bit sum value based on multiple bits, the number of bit sum values ​​equal to the target value is determined as the numerical distribution information of the bit sum value, and the range of the target value does not include the set value. For example, the bit sum value sequence determined by multiple bits is {1,2,1,2,1,2}, the number of bit sum values ​​with a target value of 1 is 3, and the number of bit sum values ​​with a target value of 2 is 3. The numerical distribution information is recorded as state(x), where x is the target value, state(1)=3, and state(2)=3. Therefore, after calculating the bit sum value, the number of bit sum values ​​equal to the target value can be obtained as the numerical distribution information, and a series of bit sum value sequences can be converted into numerical distribution information represented by numerical values, further reducing the memory usage of the device.

[0012] In one possible design, determining whether the sequence to be detected passes the randomness test based on the numerical distribution information of the bit sum of the bits in the bit set includes: determining a second numerical value corresponding to the target value based on the numerical distribution information, the number of the bit set and the target value; and determining that the sequence to be detected passes the randomness test when the second numerical value corresponding to the target value satisfies the randomness condition.

[0013] According to the design, the present application can determine the second numerical value corresponding to the target value according to the numerical distribution information, the number of bit sets, and the target value, and perform statistical operations on the second numerical value of the target value. If the calculation results of the second numerical values ​​of multiple target values ​​obtained in the same way are compared with the threshold, if the comparison results of the second numerical values ​​of all target values ​​with the threshold meet the randomness condition, then it is determined that the sequence to be detected passes the randomness test. The use of this design can improve the accuracy of determining whether the sequence to be detected passes the randomness test.

[0014] In one possible design, determining the second numerical value corresponding to the target value based on the numerical distribution information, the number of the bit sets and the target value includes: determining the number of bit sets corresponding to the target value based on the numerical distribution information and the number of the bit sets; determining the second numerical value corresponding to the target value based on the number of bit sets corresponding to the target value, the number of the bit sets and the target value.

[0015] According to this design, a second numerical value corresponding to the target value is obtained based on the bit set corresponding to the target value. For example, the second numerical value is obtained by counting the number of bit sets corresponding to the bit value. The statistical method used can improve the accuracy of obtaining the second numerical value.

[0016] In one possible design, the second numerical value corresponding to the target value satisfies the randomness condition including: the second numerical value corresponding to any target value is greater than or equal to a threshold.

[0017] According to the design, it is determined whether the second numerical values ​​corresponding to multiple target values ​​meet the randomness condition. Only when the second numerical values ​​corresponding to all the target values ​​meet the randomness condition, it is determined that the sequence to be detected passes the randomness test. If the second numerical value corresponding to any target value does not meet the randomness condition, it is determined that the sequence to be detected does not pass the randomness test. The use of this design can improve the accuracy of the randomness test of the sequence to be detected.

[0018] In a second aspect, an embodiment of the present application provides a sequence random number detection device, comprising:

[0019] An acquisition module is used to acquire an N-byte sequence to be detected, where N is a positive integer greater than 1; a processing module is used to determine at least one bit set according to the bit sum value of the bits in the first K bytes in the sequence to be detected, any of the bit sets contains multiple consecutive bits in the first K bytes, the bit sum value corresponding to the last bit of the multiple consecutive bits is a set value, and the bit sum value corresponding to the bits other than the last bit of the multiple consecutive bits is not the set value, and K is a positive integer less than N; the processing module is also used to determine whether the sequence to be detected passes the randomness test according to the numerical distribution information of the bit sum value of the bits in the bit set.

[0020] In one possible design, the bit sum value of the sequence to be detected is determined according to the bit value of the sequence to be detected and the adjustment value corresponding to the bit value, wherein different bit values ​​correspond to different adjustment values ​​and the same bit values ​​correspond to the same adjustment values.

[0021] In one possible design, the numerical distribution information corresponding to any bit set is used to indicate the number of bits and values ​​corresponding to the bit set whose values ​​are target values, and the target value does not include the set value.

[0022] In one possible design, the processing module is specifically used to: determine a second numerical value corresponding to the target value based on the numerical distribution information, the number of the bit sets and the target value; and determine that the sequence to be detected passes the randomness test when the second numerical value corresponding to the target value satisfies the randomness condition.

[0023] In one possible design, the processing module is specifically used to: determine the number of bit sets corresponding to the target value based on the numerical distribution information and the number of bit sets; determine a second numerical value corresponding to the target value based on the number of bit sets corresponding to the target value, the number of bit sets and the target value.

[0024] In one possible design, the second numerical value corresponding to the target value satisfies the randomness condition including: the second numerical value corresponding to any target value is greater than or equal to a threshold.

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

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

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

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

[0029] Figure 1 A schematic diagram of a sequence randomness detection method provided in an embodiment of the present application;

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

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

[0032] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present application. It should be understood that the specific operating methods in the method embodiments described below can also be applied to device embodiments or system embodiments.

[0033] At present, with the development of informatization and computer technology, while people are enjoying the many benefits brought by informatization, network security issues have become a common challenge faced by mankind in the information age. The output of a random number generator is called a random number, which is widely used in various fields. Therefore, if a random number generator is required to generate high-quality and stable random numbers, the randomness of the random numbers needs to be tested.

[0034] The existing general detection method needs to read all the bits in the byte sequence to be detected and store all the bits. In addition, it is necessary to generate a bit sum from the bits, and determine at least one circle based on the bit sum. Each circle contains one or multiple consecutive bits in all the bits, and the random number detection is performed based on the bit sum value corresponding to the bits in the circle. Among them, there are n bits in the N-byte random number, n=8N. Therefore, the detection device needs to allocate n bytes of memory space, recorded as the bit storage area, for storing the bit sequence converted from the byte sequence to be detected. In addition, it is necessary to allocate 4n bytes of memory space, recorded as the partial sum storage area, for storing the bit sum value corresponding to the n bits. In addition, it is necessary to allocate n / 25 bytes of memory space, recorded as the circle number storage area, for storing the number of circles.

[0035] It can be seen that the above random number detection process needs to occupy at least (n+4n+n / 25) bytes of memory space of the detection device, so it occupies a lot of memory and is difficult to meet the needs of resource-constrained devices such as IoT security equipment and industrial control security equipment.

[0036] In order to solve the above problems, the present application provides a sequence randomness detection method to reduce memory usage.

[0037] In the present application, a circle may refer to one or more consecutive bits between two bits whose corresponding bit and value are set values ​​among multiple bits to be detected. The set value is 0. For example, the bit and values ​​corresponding to multiple bit values ​​{b0, b1, b2, b3, b4} are {-1, 0, 1, 0, 1} respectively. In other words, a set of bit and value sets composed of the multiple bits is {0, -1, 0, 1, 0, 1}, wherein the first "0" may not correspond to any of the bits, but represents the initial value of the bit and value, which may be a set value. If the set value is 0, the three bit and values ​​of "0, -1, 0" in the bit and value set correspond to a circle, wherein the bits corresponding to the three bit and values ​​are b0 and b1, i.e., the two bits are regarded as a circle. Similarly, the three bit and values ​​of "0, 1, 0" correspond to a circle, wherein the bits corresponding to the three bit and values ​​are b2 and b3, i.e., the two bits are regarded as a circle. Therefore, the number of circles J=2 contained in the above multiple bit values. In addition, in the present application, bits belonging to the same circle may be referred to as a bit set. Taking the above example, bits b0 and b1 belong to one bit set, and bits b2 and b3 belong to another bit set.

[0038] The following is an introduction to the sequence randomness detection method provided in the embodiment of the present application.

[0039] In order to reduce memory usage, an embodiment of the present invention provides a sequence randomness detection method and device. The method can be performed by a first device. The first device can be a computer system for performing the method shown in the present application, or can be a processing device in a computer system for performing the method shown in the present application, such as a processor or a processing module, etc., without specific limitation.

[0040] Figure 1 A flow chart of a sequence randomness detection method is shown exemplarily.

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

[0042] Step 101: The first device obtains a sequence to be detected of N bytes, where N is a positive integer greater than 1.

[0043] The sequence to be detected may be a random sequence of N bytes. The sequence to be detected may be a byte sequence, that is, the sequence to be detected is a sequence composed of N bytes.

[0044] The first device can read multiple bits in the sequence to be detected. The sequence to be detected can be represented as B0, B1, ..., B N-1 , B0 to B N-1Each represents a byte, and N is a natural number. It can be understood that if each byte is converted into a bit, the sequence can be expressed as: b0, b1, ..., b n-1 . Wherein, n=8N.

[0045] Step 102: The first device determines at least one bit set according to the bit sum values ​​of the bits in the first K bytes in the sequence to be detected.

[0046] Optionally, the first device may determine at least one bit sum value based on the bits in the first K bytes in the sequence to be detected. The bits in the first K bytes may include 8K bits. The next bit sum value may be determined based on the previous bit sum value and the bit corresponding to the previous bit sum value.

[0047] In the present application, the process of determining the bit sum value is, for example: the bits in the first K bytes may have a bit sequence of length p. The first device obtains a bit sequence of length p. The bit sequence includes the 1st bit to the i-th bit, and the bit sum value corresponding to the i-th bit can be determined according to the bit value of the i-th bit and the bit values ​​of all bits before (or to the left of) the i-th bit in the sequence. i=1..., p. For example, the first device can sum the bit values ​​of the i-th bit and all bits before the i-th bit in the sequence as the bit sum value corresponding to the i-th bit, that is, the bit sum value corresponding to the sequence {0,1,1,0} is {0,1,2,2}. It should be noted that only the concept of "sum" in the bit sum value is explained here. In the process of determining the bit sum value in the present application, it is also possible to consider adjusting the bits based on the adjustment value, that is, it is necessary to determine the adjustment value as described below.

[0048] Optionally, in the present application, the bit sum value corresponding to the i-th bit can also be determined based on the adjustment value corresponding to the bit value of the i-th bit and the adjustment value corresponding to the bit values ​​of all bits in the sequence located before (or to the left of) the i-th bit.

[0049] Among them, the adjustment value is used by the first device to obtain the bit sum value corresponding to the i-th bit value. The first device can determine the adjustment value corresponding to the i-th bit value based on the value relationship between the i-th bit value and the adjustment value. The value relationship can be expressed as a characteristic value table. The characteristic value can be used to ensure that there are no two adjacent values ​​of the bit sum value that are both 0, avoid additional calculation of redundant laps when subsequently calculating the number of laps, ensure the accuracy of the statistical laps, and improve the detection efficiency. For example, the adjustment value corresponding to the bit value 0 is -1, and the adjustment value corresponding to the bit value 1 is 1. The adjustment value can also be expressed as T(0)=-1, T(1)=1.

[0050] Exemplarily, the first device may sum the adjustment value corresponding to the ith bit and the adjustment values ​​corresponding to the bit values ​​of all bits in the sequence before the ith bit, as the bit sum value corresponding to the ith bit. For example, the bit sum values ​​determined by summing the adjustment values ​​of the four bits of the sequence {0, 1, 1, 0} are {-1, 0, 1, 0} respectively.

[0051] In addition, the formula is used to express that the i-th bit and value can satisfy the following relationship:

[0052] S i =S i-1 +d i ;

[0053] Where S i represents the i-th bit and value, S i-1 represents the i-1th bit and value, d i Indicates the adjustment value corresponding to the i-th bit. Wherein, S0=0, that is, the initial value of the bit sum is 0.

[0054] After the first device obtains the bit sum value corresponding to the i-th bit value, the first device may determine at least one circle according to the magnitude relationship between the bit sum value and the set value. The bits contained or corresponding to any circle constitute a bit set, wherein the bit sum value corresponding to the last bit of any circle is the set value.

[0055] The setting value may be used by the first device to determine a bit in the bit set. The setting value may be 0.

[0056] In implementation, the first device may determine the bits in at least one bit set according to the bit values ​​and set values ​​respectively corresponding to the bits in the first K bytes. Among them, the initial value of the bit and value may be a set value, and starting from the first bit, the first device may determine the bit and value of at least one bit in sequence. When the bit and value of a bit is a set value for the first time, the first device may treat the bit and the previous bit as bits in the same bit set, and thus a circle may be determined. Thereafter, the first device may determine the bit and value of at least one bit starting from the next bit, and when the bit and value of a bit is a set value for the next time, the first device may treat the bit and the previous bit as bits in the same bit set, and thus a second circle may be determined. And so on, until the first device determines all the circles.

[0057] When the set value is 0, the bit and value set corresponding to the sequence {0,1,1,0} determined according to the adjustment value is {-1,0,1,0}, and the initial bit and value S0 can be 0. Since the set value is 0, it can be known that the second bit and value is equal to the set value, so the first device can use the first bit value 0 and the second bit value 1 as the first bit set. Similarly, the third bit value 1 and the fourth bit value 0 can be used as the second bit set.

[0058] It can be understood that in 102, the first device can convert K bytes of the N bytes to be detected, that is, a portion of the bytes, into bits, and perform a bit and value determination action for the bytes in this portion. Since it is not necessary to convert all N bytes into bits and store them at one time, and it is not necessary to store all bits and values ​​corresponding to all bits, memory usage can be reduced.

[0059] Step 103: The first device determines whether the sequence to be detected passes the randomness test according to the numerical distribution information of the bit sum of the bits in the bit set.

[0060] In step 103, the first device may determine the value distribution information of the bit sum of the bits in the bit set according to the target value, so as to determine whether the sequence to be detected passes the randomness test according to the value distribution information in step 103. The target value is different from the set value, for example, when the set value is 0, the target value is a value other than 0.

[0061] The first device may set a value range of the target value. If a bit sum value exceeds the value range of the target value, the first device may discard the original sequence to be detected, or determine that the sequence to be detected fails the randomness test.

[0062] For example, the target value range is [-4, 4], that is, the target value may be -4, -3, -2, -1, 0, 1, 2, 3, or 4. When the set value is 0, the target value may be -4, -3, -2, -1, 1, 2, 3, or 4. If the absolute value of the bit sum is greater than 4, the first device may discard the original sequence to be detected, or determine that the sequence to be detected fails the randomness test.

[0063] Optionally, the numerical distribution information may be used to indicate the number of bit sum values ​​that are target values ​​in the bit sum corresponding to at least one bit of the bit set of the first K bytes.

[0064] For example, taking the target value of -4, -3, -2, -1, 1, 2, 3 or 4 as an example, the numerical distribution information includes the following values: the number of bits and values ​​with the value of -4, the number of bits and values ​​with the value of -3,..., the number of bits and values ​​with the value of 3 and the number of bits and values ​​with the value of 4.

[0065] Still taking the sequence {0,1,1,0,1,1,0,1,0,1} as an example, the bit sum value set corresponding to the sequence is {-1,0,1,0,1,2,1,2,1,2,0}. When the set value is 0, the bit sum value corresponding to the first circle (or circle 1) is {-1, 0}. It can be seen that the number of bit sum values ​​with a value of -1 in the first circle is 1, and the number of bit sum values ​​with values ​​from -4 to -2 and from 1 to 4 is 0. Therefore, the number of bit sum values ​​in the bit sum value set that are equal to the target value -1 is recorded as 1, and the number of bit sum values ​​that are equal to the remaining target values ​​(target values ​​are -4, -3, -2, 1, ... and 4) is recorded as 0.

[0066] Similarly, the numerical distribution information corresponding to the second circle (or circle 2) and the third circle (or circle 3) of the above sequence can be determined, as shown in Table 1.

[0067] Table 1

[0068]

[0069] In Table 1, in the bit sum value sets of the first, second and third rounds, the first 0 represents the initial value of the bit sum value.

[0070] In Table 1, State(x) can represent a counter, which is used to count the number of bits and values ​​corresponding to the target value x, and the counting result is the value distribution information. For example, the value at the intersection of the column where the first circle is located and the row where x=-1 is located in the table is 1, indicating that in the bit and value set corresponding to the first circle {-1,0}, the number of bits and values ​​-1 is 1.

[0071] The above Table 1 can also be expressed as: State(-4)=0, ..., State(-1)=1, ..., State(4)=0.

[0072] Optionally, after obtaining the value distribution information corresponding to the first round, the first device may set the counter State(x) to an initial value to avoid repeatedly counting the number of the i-th bit and value in the next round.

[0073] For example, after obtaining the numerical distribution information corresponding to the first circle, the first device resets the counter State(x) to 0, for example, resets State(-4)=0, ..., State(-1)=0, ..., State(4)=0, and then counts the numerical distribution information corresponding to the second circle.

[0074] Optionally, through step 103, the first device can convert a sequence of bits and values ​​(ie, any set of bits and values) into numerical distribution information represented by numerical values ​​(ie, State (x) = 0), thereby further reducing memory usage.

[0075] Optionally, the first device may determine a second value corresponding to the target value according to the value distribution information of the bit and value, the number of the bit set and the target value. The second value is used to determine whether the sequence to be detected passes the randomness test. The value distribution information may be used to indicate the value distribution of the bit and value corresponding to the bit set, and the second value may represent the distribution of the bit set with different value distributions. The second value is introduced below in conjunction with the determination process of the second value.

[0076] For example, the second value is determined as follows:

[0077] (1) The first device may determine, according to the numerical distribution information corresponding to the multiple bit sets, the number of bit sets (or circles) containing k bits and values ​​having the value x among the multiple bit sets (or circles), which is called the number of bit sets corresponding to the target value and may be denoted by v in symbolic representation. k (x). k is a non-negative integer, which indicates the number of times the bit sum value of the target value x appears in the bit sum value corresponding to a bit set (or circle).

[0078] For example, using the examples of circles 1 to 3 in Table 1, Table 2 shows the values ​​of v when x and k take different values ​​in circles 1 to 3. k The numerical value of (x).

[0079] Table 2

[0080]

[0081]

[0082] For example, v0(-4)=3, which means that from the first to the third round, the number of rounds containing 0 bits and values ​​with a value of -4 is 3, that is, from the first to the third round, none of the bits and values ​​with a value of -4 is included. For another example, v1(1)=1, which means that from the first to the third round, the number of rounds containing 1 bit and value with a value of 1 is 1, that is, from the first to the third round, only the State(1) corresponding to the second round is 1.

[0083] (2) The first device calculates the number v of bit sets corresponding to the target value. k (x), the number of bit sets and the target value determine the second value. The second value can be a P value representing the distribution of bit sets with different value distributions. The P value refers to the probability of an event that a statistical summary (such as the mean difference between two groups of samples) is the same as or even greater than the actual observed data in a probability model.

[0084] For example, the second value P x The following formula can be satisfied:

[0085] P x= igamc(5 / 2, V x / 2). (Formula 1)

[0086] Here, igamc represents the incomplete gamma function (IGF).

[0087] In addition, in the above formula, "5" is the maximum value of k, and can be replaced by other positive integers in implementation. x With v k (x), the number of bit sets J and the target value.

[0088] Optional, V x Can meet:

[0089]

[0090] Where J is the number of circles, π k (x) can be the same as v k (x) related parameters. Among them, π k (x) can represent the v corresponding to different k and x in the sequence to be detected k The probability of (x) occurring. π k The method for determining (x) can refer to the description in Chapter 3.14 of the document "A Statistical Test Suite for Random and Pseudorandom Number Generators for Cryptographic Applications" of the National Institute of Standards and Technology (NIST) Special Publication 800-22 Revision 1a.

[0091] Optionally, some exemplary π k (x) can satisfy Table 3:

[0092] Table 3

[0093] <![CDATA[π0(x)]]> <![CDATA[π1(x)]]> <![CDATA[π2(x)]]> <![CDATA[π3(x)]]> <![CDATA[π4(x)]]> <![CDATA[π5(x) <!-- 8 -->]]> x=1 0.5000 0.2500 0.1250 0.0625 0.0312 0.0312 x=2 0.7500 0.0625 0.0469 0.0352 0.0264 0.0791 x=3 0.8333 0.0278 0.0231 0.0193 0.0161 0.0804 x=4 0.8750 0.0156 0.0137 0.0120 0.0105 0.0733 x=5 0.9000 0.0100 0.0090 0.0081 0.0073 0.0656 x=6 0.9167 0.0069 0.0064 0.0058 0.0053 0.0588 x=7 0.9286 0.0051 0.0047 0.0044 0.0041 0.0531

[0094] Optionally, the first device may determine a randomness condition that the second value corresponding to any target value should satisfy. The randomness condition includes: the second value corresponding to any target value is greater than or equal to a threshold. When the second values ​​corresponding to all target values ​​satisfy the randomness condition, the first device may determine that the sequence to be detected passes the randomness test.

[0095] For example, if x=-4,-3,-2,-1,1,2,3,4, the first device may first determine P when x=1. x , judge P when x=1 x Is it greater than or equal to the threshold? Further, determine when x=-3 P x , judge P when x=3 x Is it greater than or equal to the threshold? And so on, until x=4 is determined... If x=-4 to 4, P x If all values ​​are greater than or equal to the threshold, it means that the sequence to be tested passes the randomness test.

[0096] As an exemplary implementation, the process of a sequence randomness detection method involved in this application is described:

[0097] Step 1: The first device performs initialization settings.

[0098] The first device may set the initial bit and value S0=0, i0=0, the number of turns J0=0, the initial State(x)=0, x=-4, -3, -2, -1, 0, 1, 2, 3, 4, the characteristic value table (T(0)=-1, T(1)=1), the initial v k (x) = 0, set k = 0, 1, 2, 3, 4 or 5. The number of bit sets (or circles) of all bits and values ​​when k is greater than 5 is recorded in v with k = 5. k (x) in.

[0099] Step 2: The first device determines whether the iterative process of randomness detection is completed.

[0100] Specifically, the first device may read the i-th bit b in the sequence to be detected. i , i starts from an initial value of zero. The first device may determine the size of the compared i and 8N, and if it is determined that i<8N, continue to execute step 3. If it is determined that i≥8N, execute step 6.

[0101] For example, the first device may start scanning the sequence to be detected byte by byte (or bit by bit) starting from the first bit of the first byte, that is, i=1.

[0102] Step 3: The first device performs the following operations according to b. i Determine the current bit and value: S i+1 =S i +T(b i+1 ), get the current S i+1 , and proceed to step 4. T(b i+1 ) is b i+1 The corresponding adjustment value.

[0103] Step 4: If S i+1The absolute value of does not exceed 4, then the first device updates S i+1 The corresponding numerical distribution information State(S i+1 )=State(S i )+1. Among them, 4 is the maximum absolute value of the target value x.

[0104] Step 5: The first device can determine the current S i+1 Is it equal to 0?

[0105] If the current S i+1 If it is not equal to 0, then i is incremented by 1 and the process returns to step 2.

[0106] If the current S i+1 If it is equal to 0, the first device can execute:

[0107] Step 5.1, add one to the number of turns, that is, let J i+1 =J i +1.

[0108] Step 5.2, determine v k (x), k = 0, 1, 2, 3, 4 and 5,

[0109] Step 5.3, set the current State(x) to 0.

[0110] Step 6: At this time, the first device knows that i is greater than or equal to 8K. The first device can determine whether the i-th bit just forms a circle with one or more bits before the bit, that is, determine S i+1 Is it equal to 0?

[0111] If the current S i+1 If it is not equal to 0, the first device may execute step 7.

[0112] If the current S i+1 If it is equal to 0, the first device can execute:

[0113] Step 6.1 (refer to step 5.1), add one to the number of turns to get J i+1 =J i +1.

[0114] Step 6.2 (refer to step 5.2), determine v k (x), k = 0, 1, 2, 3, 4 and 5,

[0115] Step 6.3 (refer to step 5.3), set the current State (x) to 0.

[0116] The first device may continue to read bytes in the subsequent sequence to be detected until the last bit in the sequence to be detected, that is, the 8Nth bit, is read. At this point, the first device can obtain v shown in Table 2 k (x) Statistics table. The first device can k (x) The statistics table is stored in the memory.

[0117] Step 7: The first device may k (x) Statistics table, determine the second value P corresponding to x=-4, -3, -2, -1, 1, 2, 3, 4 respectively x .

[0118] The second numerical value may satisfy Formula 1, please refer to the description in this application, which will not be repeated here.

[0119] The first device executes step 8.

[0120] Step 8: The first device may determine whether the second values ​​corresponding to all target values ​​are not less than a threshold value. When the second values ​​corresponding to the target values ​​x=-4, -3, -2, -1, 1, 2, 3, 4 are not less than the threshold value, the first device may determine that the sequence to be detected passes the randomness test.

[0121] The threshold value may be the significance level α, which may be 0.01.

[0122] If any P x If the value is less than α, the sequence to be tested fails the randomness test.

[0123] If all P x If the value is not less than α, the sequence to be tested passes the randomness test.

[0124] It can be understood that the present application can reduce the memory usage in the randomness detection process. Specifically, after the first device converts the byte to be detected into bits, it only scans the bit value once. During the scanning process, the bit sum value is determined according to the first bit value to the Nth bit value read, that is, at least one circle is determined according to the bit sum value, and then v is determined according to at least one weight. k (x), store v k (x) Statistics table. That is, the first device does not need to store the converted bits and the calculated bit sum values ​​in the memory, which can reduce memory reuse. In addition, the first device does not need to perform a second scan on the bit sequence obtained after the conversion to calculate the bit sum value, nor does it need to scan the bit sum value again to determine v k(x), the efficiency of randomness detection can be improved. Therefore, this detection method is suitable for resource-constrained devices and improves the efficiency of randomness detection. For example, 100 groups of samples (125,000 bytes per group) were tested using the method shown in this application, and the test processor was the 11th GenIntel(R)Core(TM)i5-1135G7. According to statistics, the existing implementation scheme requires 2.675 milliseconds to execute a set of detections, while the method shown in this application only requires 0.718 milliseconds, that is, the execution efficiency is 3.73 times that of the existing scheme. Therefore, resource-constrained devices can use more valuable computing resources for other security protection functions.

[0125] Based on the same technical concept, the present application exemplarily provides a sequence random number detection device, such as Figure 2 As shown, the device comprises:

[0126] The acquisition module 201 is used to acquire an N-byte sequence to be detected, where N is a positive integer greater than 1; the processing module 202 is used to determine at least one bit set according to the bit sum value of the bits in the first K bytes in the sequence to be detected, any of the bit sets includes multiple consecutive bits in the first K bytes, the bit sum value corresponding to the last bit of the multiple consecutive bits is a set value, and the bit sum value corresponding to the bits other than the last bit of the multiple consecutive bits is not the set value, and K is a positive integer less than N; the processing module 202 is also used to determine whether the sequence to be detected passes the randomness test according to the numerical distribution information of the bit sum value of the bits in the bit set.

[0127] Optionally, the bit sum value of the sequence to be detected is determined according to the bit value of the sequence to be detected and an adjustment value corresponding to the bit value, wherein different bit values ​​correspond to different adjustment values, and the same bit value corresponds to the same adjustment value.

[0128] Optionally, the numerical distribution information corresponding to any bit set is used to indicate the number of bits and values ​​corresponding to the bit set whose values ​​are target values, and the target value does not include the set value.

[0129] Optionally, the processing module 202 is specifically used to: determine a second numerical value corresponding to the target value according to the numerical distribution information, the number of the bit sets and the target value; and determine that the sequence to be detected passes the randomness test when the second numerical value corresponding to the target value satisfies the randomness condition.

[0130] Optionally, the processing module 202 is specifically used to: determine the number of bit sets corresponding to the target value based on the numerical distribution information and the number of bit sets; determine a second numerical value corresponding to the target value based on the number of bit sets corresponding to the target value, the number of bit sets and the target value.

[0131] Optionally, the second numerical value corresponding to the target value satisfies the randomness condition, including: the second numerical value corresponding to any target value is greater than or equal to a threshold.

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

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

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

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

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

[0137] Optionally, the processor 302 may be configured to execute any one or more of the above actions executed by the acquisition module 201 and the processing module 202 .

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

[0139] The program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof.

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

Claims

1. A method for detecting randomness of a sequence, characterized in that: include: Obtain an N-byte sequence to be detected, where N is a positive integer greater than 1; Storing the bits in the first K bytes of the sequence to be detected in a bit storage area, where K is a positive integer less than N; Determine at least one bit sum value according to the bits in the first K bytes of the sequence to be detected, and store the at least one bit sum value in a partial sum storage area; Determine at least one bit set according to the bit sum value of the bits in the first K bytes in the sequence to be detected, any of the bit sets includes a plurality of consecutive bits in the first K bytes, the bit sum value corresponding to the last bit in the plurality of consecutive bits is a set value, and the bit sum values ​​corresponding to the bits other than the last bit in the plurality of consecutive bits are not the set value; the bit sum value of the bit is used to indicate the sum of the bit values ​​of the bit and the bit before the bit; Determining whether the sequence to be detected passes the randomness test according to the bit sum value distribution information of the bits in the bit set; The determining whether the sequence to be detected passes the randomness test according to the bit sum value distribution information of the bits in the bit set includes: Determining the number of bit sets corresponding to the target value according to the numerical distribution information and the number of bit sets, wherein the value range of the target value is set; the numerical distribution information is a counting result of using a counter to count the number of bits and values ​​corresponding to the target value; Determine a second value corresponding to the target value according to the number of bit sets corresponding to the target value, the number of bit sets and the target value; the second value is used to represent a P value of the distribution of bit sets with different value distributions, and the P value is used to indicate the probability of an event that a statistical summary is the same as or even greater than actual observed data in a probability model; When the second numerical value corresponding to the target value satisfies the randomness condition, it is determined that the sequence to be detected passes the randomness test.

2. The method according to claim 1, characterized in that The bit sum value of the sequence to be detected is determined according to the bit value of the sequence to be detected and the adjustment value corresponding to the bit value, wherein different bit values ​​correspond to different adjustment values, and the same bit value corresponds to the same adjustment value.

3. The method according to claim 1, characterized in that The numerical distribution information corresponding to any bit set is used to indicate the number of bits and values ​​corresponding to the bit set whose values ​​are the target value, and the target value does not include the set value.

4. The method according to claim 1, characterized in that The second numerical value corresponding to the target value satisfies the randomness condition, including: the second numerical value corresponding to any target value is greater than or equal to a threshold.

5. A sequence randomness detection device, characterized in that: include: An acquisition module is used to acquire a sequence to be detected of N bytes, where N is a positive integer greater than 1; A processing module, used for storing the bits in the first K bytes of the sequence to be detected into a bit storage area, where K is a positive integer less than N; The processing module is further used to determine at least one bit sum value according to the bits in the first K bytes of the sequence to be detected, and store the at least one bit sum value in the partial sum storage area; The processing module is further used to determine at least one bit set according to the bit sum value of the bits in the first K bytes in the sequence to be detected, any of the bit sets includes multiple consecutive bits in the first K bytes, the bit sum value corresponding to the last bit of the multiple consecutive bits is a set value, and the bit sum values ​​corresponding to the bits other than the last bit of the multiple consecutive bits are not the set value, K is a positive integer less than N; the bit sum value of the bit is used to indicate the sum of the bit values ​​of the bit and the bit before the bit; The processing module is further used to determine whether the sequence to be detected passes the randomness test according to the bit sum value distribution information of the bits in the bit set; The determining whether the sequence to be detected passes the randomness test according to the bit sum value distribution information of the bits in the bit set includes: The processing module is specifically used for: Determining the number of bit sets corresponding to the target value according to the numerical distribution information and the number of bit sets, wherein the value range of the target value is set; the numerical distribution information is a counting result of using a counter to count the number of bits and values ​​corresponding to the target value; Determine a second value corresponding to the target value according to the number of bit sets corresponding to the target value, the number of bit sets and the target value; the second value is used to represent a P value of the distribution of bit sets with different value distributions, and the P value is used to indicate the probability of an event that a statistical summary is the same as or even greater than actual observed data in a probability model; When the second numerical value corresponding to the target value satisfies the randomness condition, it is determined that the sequence to be detected passes the randomness test.

6. The device according to claim 5, characterized in that The bit sum value of the sequence to be detected is determined according to the bit value of the sequence to be detected and the adjustment value corresponding to the bit value, wherein different bit values ​​correspond to different adjustment values, and the same bit value corresponds to the same adjustment value.

7. The device according to claim 5, characterized in that The numerical distribution information corresponding to any bit set is used to indicate the number of bits and values ​​corresponding to the bit set whose values ​​are the target value, and the target value does not include the set value.

8. The device according to claim 5, characterized in that The second numerical value corresponding to the target value satisfies the randomness condition, including: the second numerical value corresponding to any target value is greater than or equal to a threshold.

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

10. A computer-readable storage medium, characterized in that: The device stores program codes, and when the program codes are run on an electronic device, the program codes are used to enable the electronic device to execute the steps of any one of the methods in claims 1 to 4.

Citation Information

Patent Citations

  • Run-length detection method and device and electronic equipment

    CN110798230A

  • Memory system and random number generation device

    US20230091431A1