GM/T 0005-2021 (GM/T0005-2021, GMT 0005-2021, GMT0005-2021) & related versions
Buy with any currencies (Euro, JPY, KRW...): GM/T 0005-2021 Preview this PDF: GM/T 0005-2021
GM/T 0005-2021
CRYPTOGRAPHIC INDUSTRY STANDARD
OF THE PEOPLE’S REPUBLIC OF CHINA
ICS 35.030
CCS L 80
Replacing GM/T 0005-2012
Randomness test specification
ISSUED ON: OCTOBER 18, 2021
IMPLEMENTED ON: MAY 01, 2022
Issued by: State Cryptography Administration
Table of Contents
Foreword ... 3
1 Scope ... 5
2 Normative references ... 5
3 Terms and definitions... 5
4 Symbols ... 6
5 Randomness test method ... 8
5.1 Single-bit frequency test method ... 8
5.2 In-block frequency test method ... 8
5.3 Poker test method ... 9
5.4 Overlapping subsequence test method ... 10
5.5 Test method for total number of runs ... 11
5.6 Test method for run distribution ... 12
5.7 Test method for in-block maximum run ... 13
5.8 Binary derivation test method ... 14
5.9 Autocorrelation test method ... 15
5.10 Matrix rank test method ... 16
5.11 Test method for cumulative sum ... 17
5.12 Approximate entropy test method ... 18
5.13 Linear complexity test method ... 19
5.14 Test method for Maurer general statistics ... 20
5.15 Discrete Fourier test method ... 22
6 Determination of randomness test ... 23
6.1 Overview ... 23
6.2 Determination of sample passing rate ... 23
6.3 Determination of sample distribution uniformity ... 23
6.4 Determination of randomness test results ... 24
Annex A (normative) Sample length and test setting ... 25
Annex B (informative) Principle of randomness test ... 27
Annex C (informative) Examples of randomness test results ... 38
Randomness test specification
1 Scope
This document specifies the randomness test indicators and test methods applicable to
binary sequence.
2 Normative references
There are no normative references in this document.
3 Terms and definitions
For the purposes of this document, the following terms and definitions apply.
3.1 binary sequence
A bit string consisting of "0" and "1".
NOTE: Unless otherwise specified, the sequences referred to in this document are all binary
sequences.
3.2 randomness hypothesis
When testing the randomness of a binary sequence, it is first assumed that the sequence
is random. This hypothesis is called the null hypothesis or the null hypothesis, denoted
as H0. The hypothesis contrary to the null hypothesis, that is, the sequence is not random,
is called the alternative hypothesis, denoted as Hα.
3.3 randomness test
A function or procedure for binary sequence test. It can be used to judge whether to
accept the randomness null hypothesis.
3.4 significance level
The probability of incorrectly judging random sequences as non-random sequences in
randomness test.
3.5 sample
Binary sequences for randomness test.
3.6 sample group
A collection of multiple samples.
3.7 sample length
The number of bits in the sample.
3.8 sample size
The number of samples in the sample group.
3.9 test parameter
Parameters that need to be set for randomness test.
4 Symbols
The following symbols apply to this document.
d: The number of bits for the logical left shift of the sequence in autocorrelation test.
H0: Original hypothesis (null hypothesis).
Hα: Alternative hypothesis.
K: The number of L-bit subsequences of the sequence to be tested in the general
statistical test.
L: General statistical neutron sequence length.
Li: The linear complexity of subsequence in the linear complexity test.
M: The number of rows of the matrix in the matrix rank test.
m: The bit length of the subsequence.
N: The number of m-bit subsequences in an n-bit sequence to be tested.
n: The bit length of the binary sequence to be tested.
Q: The number of columns of the matrix in the matrix rank test, or the number of L-bit
subsequences of the initial sequence in the general statistical test.
V: Statistical value.
Xi: 2εi-1.
α: Significance level for sample passing rate test.
αT: Significance level used for sample distribution uniformity test.
ε: Binary sequence to be tested.
ε': A new sequence generated according to certain rules on the basis of ε.
π: The proportion of 1 in the binary sequence to be tested.
Σ: Summation symbol.
*: Multiplication, sometimes omitted.
ln(x): The natural logarithm of x.
log2(x): The base 2 logarithm of x.
: The largest integer not greater than x.
max: Take the maximum value from several elements.
min: Take the minimum value from several elements.
Φ(x): Cumulative distribution function of standard normal distribution.
P_value: A metric to measure the randomness of a sample, which is used to determine
the passing rate of the sample.
Q_value: A metric to measure the randomness of samples, which is used to determine
the uniformity of sample distribution.
erfc: Complementary Error Function.
igamc: Incomplete Gamma Function.
Vn(obs): The total number of runs in the binary sequence to be tested.
ApEn(m): Approximate entropy of the binary sequence to be tested.
modulus(x): The operation used to calculate the modulus value of the complex
coefficient x.
: The first statistic in overlapping subsequence test.
: The second statistic in overlapping subsequence test.
Step 5: Calculate .
Test settings are as required in Annex A. See B.11 for the test principle.
5.11.3 Result determination
Compare the result of P_value calculated in 5.11.2 with α. If P_value≥α, it is considered
that the sequence to be tested passes the test of the cumulative sum, otherwise it fails to
pass the test of the cumulative sum.
5.12 Approximate entropy test method
5.12.1 Overview
Approximate entropy test evaluates its randomness by comparing the frequency of m-
bit overlapping subsequence modes with the frequency of m+1-bit overlapping
subsequence modes. Calculate the frequency difference between the m-bit overlapping
subsequence mode and the m+1-bit overlapping subsequence mode. A small difference
value indicates that the sequence to be tested has regularity and continuity. A large
difference value indicates that the sequence to be tested has irregularity and
discontinuity. For any m, the approximate entropy of the random sequence shall be
approximately equal to ln2.
5.12.2 Test steps
The approximate entropy test steps are as follows.
Step 1: Construct a new sequence ε' from the sequence ε to be tested. The construction
method is as follows: Add the m-1 bits of data at the beginning of the sequence ε to the
end of the sequence ε to get ε'. The length of the new sequence ε' is n'=n+m-1.
Step 2: Count the frequency of occurrence of the sequence mode of m bits for all 2m in
n. Denote the frequency of occurrence of the m-bit mode i1i2…im as vi1i2…im.
Step 3: For all j (0≤j≤2m-1), calculate , of which j is the decimal value
corresponding to the m-bit mode i1i2…im.
5.15.3 Result determination
Compare the result of P_value calculated in 5.15.2 with α. If P_value≥α, it is considered
that the sequence to be tested passes the discrete Fourier test, otherwise it fails the
discrete Fourier test.
6 Determination of randomness test
6.1 Overview
It shall use the 15 randomness test methods specified in Chapter 5 and the test settings
specified in Annex A to test the randomness of the binary sequence sample group. A
randomness test method corresponds to at least one randomness test item. If a
randomness test method adopts different test parameter settings (see Annex A for details)
or has different test modes (such as the in-block maximum run test method, cumulative
sum test method), or has multiple statistical values (such as overlapping subsections)
sequence test method), it shall be tested as a separate random test item. The passing rate
and distribution uniformity of each test item in the binary sequence sample group shall
be respectively subjected to determination of conformity. For example, the test method
of cumulative sum includes two modes: forward cumulative sum and backward
cumulative sum. The forward cumulative sum and the backward cumulative sum shall
be tested as 2 independent test items. The passing rate and distribution uniformity of
the forward cumulative sum and backward cumulative sum of the binary sequence
sample group are respectively judged for conformity.
This document determines the sample size in the binary sequence sample group to be
1000.
6.2 Determination of sample passing rate
For each randomness test item, count the number of samples whose P _value is greater
than or equal to α in the binary sequence sample group. The significance level
determined by this document for sample passing rate test is α=0.01.
Let the sample size be s. When the number of samples passing a test item is greater than
or equal to , then the sample group shall be considered to pass this
test, otherwise it fails this test. For example, if the sample size is 1000, the number of
samples that pass the test item shall be greater than or equal to 981.
6.3 Determination of sample distribution uniformity
For each randomness test item, the Q_value value of each sample in the binary sequence
Maurer general statistics (referred to as general statistics) test mainly tests whether the
sequence to be tested can be compressed losslessly. If the sequence to be tested can be
significantly compressed, the sequence is considered non-random, because random
sequences cannot be significantly compressed.
General statistics test can be used to test various characteristics of the sequence to be
tested. But this does not mean that general statistics test is an assembly of the previous
tests. General statistics test takes a completely different approach from other tests.
Certain statistical defects of the sequence to be tested can be tested. A sequence can be
tested by general statistics if and only if the sequence is incompressible.
General statistics test requires a large amount of data. It divides the sequence into
subsequences of length L. Then the sequence to be tested is divided into two parts: the
initial sequence and the test sequence. The initial sequence includes Q subsequences. Q
shall be greater than or equal to 10*2L. The test sequence includes K subsequences. K
shall be greater than or equal to 1000*2L. Therefore, the sequence length n shall be
greater than or equal to 10*2L*L +1000*2L*L. The value range of L shall be 1≤L≤16.
The value of L shall not be less than 6. Obviously, when L=6, n is at least 387840. When
the sequence length n is constant, take .
First, traverse the initial sequence (unit is blocks) from the beginning. Find the last
occurrence of each L-bit pattern in the initial sequence (block number). If an L-bit mode
does not appear in the initial sequence, set its position to 0. After that, the test sequence
is traversed from the beginning. Obtain an L-bit subsequence each time. Calculate the
difference between the position of this subsequence and the position of the last
occurrence before it. That is the block number subtraction. Record the subtraction result
as the distance len. Then take the base 2 logarithm of the distance len. Finally, add all
the logarithm results. In this way, the statistical value shall be obtained:
Calculate the expected value:
In fact, the expected value of fn is the expected value of the random variable log2G.
Where, G=GL is the geometric distribution with parameters 1-2-L. The geometric
distribution is defined as: Let the probability of a successful Bernoulli experiment be p,
and take the random variable X as the number of independent Bernoulli experiments
performed before the success, then:
......
GM/T 0005-2012
GM
CRYPTOGRAPHY INDUSTRY STANDARD
OF THE PEOPLE’S REPUBLIC OF CHINA
ICS 35.040
L 80
RECORD NO.. 36832-2012
Randomness test specification
ISSUED ON. MARCH 21, 2012
IMPLEMENTED ON. MARCH 21, 2012
Issued by. State Cryptography Administration
Table of Contents
Foreword ... 3
1 Scope .. 4
2 Terms and conventions ... 4
3 Symbols and abbreviations ... 8
4 Binary sequence test .. 9
5 Test for random number generator ... 17
Annex A (Informative) Principle for randomness test ... 19
Annex B (Informative) Table of randomness test parameters ... 29
Annex C (Informative) Analytical table of randomness test results .. 30
Foreword
This Standard was drafted in accordance with the rules given in GB/T 1.1-2009.
This Standard is a standard for randomness test and provides scientific basis
for randomness assessment.
Attention is drawn to the possibility that some of the elements of this document
may be the subject of patent rights. The issuer of this document shall not be
held responsible for identifying any or all such patent rights.
Annex A, Annex B and Annex C to this Standard are informative.
This Standard was proposed by and shall be under the jurisdiction of the State
Cryptography Administration of the People’s Republic of China.
The drafting organizations of this Standard. State Cryptography Administration
Commercial Cryptography Testing Center, Institute of Software Chinese
Academy of Sciences.
The main drafters of this Standard. Li Dawei, Feng Dengguo, Chen Hua, Zhang
Chao, Zhou Yongbin, Dong Fang, Fan Limin, Xu Nannan.
Randomness test specification
1 Scope
This Standard specifies the randomness test parameters and test methods in
the commercial cryptography application.
This Standard applies to the randomness test for binary sequence which is
generated by random number generator.
2 Terms and conventions
For the purposes of this document, the following terms and definitions apply.
2.1
binary sequence
Bit string which comprises “0” and “1”.
2.2
random number generator
Random number generator refers to a device or program which generates
random sequences.
2.3
randomness hypothesis
For the randomness test of binary sequence, first make a hypothesis that the
sequence is random, which is called original hypothesis or null hypothesis,
denoted as H0. Alternative hypothesis refers to the hypothesis which is contrary
to original hypothesis, i.e. this sequence is not random, denoted as Hα.
2.4
randomness test
A function or process for binary sequence test, through which it is determined
whether the original hypothesis of randomness is acceptable.
2.5
2.13
frequency test within a block
A statistical test item which is used to test whether the number of ones in the
m-bit subsequences (namely “blocks”) of sequence to be tested is close to m/2.
2.14
poker test
A statistical test item which is used to test whether the number of all modes of
the m-bit non-overlap subsequences in sequence to be tested are close.
2.15
serial test
A statistical test item which is used to test whether the numbers of all modes of
the m-bit overlapping subsequences in sequence to be tested are close.
2.16
runs test
A statistical test item which is used to test whether the total number of runs of
sequence to be tested complies with the randomness requirements.
2.17
runs distribution test
A statistical test item which is used to test whether the numbers of equal-length
runs of sequence to be tested are close to identical.
2.18
test for the longest run of ones in a block
A statistical test item which is used to test whether the distribution of the
maximum “1” runs of all equal-length subsequences of subsequences to be
tested comply with the randomness requirements.
2.19
binary derivative test
A statistical test item. Binary derivative sequence is a new sequence which is
generated by an original sequence; and it is the result which is obtained from
the exclusive-OR operation of two adjacent bits of the original sequence in turn.
The object of binary derivative test is to determine whether the numbers of 0
and 1 in the k-th binary derivative sequence are close to identical.
2.20
autocorrelation test
A statistical test item which is used to test the correlation degree between a
sequence to be tested and a new sequence which is obtained after logic shit of
it by d bits.
2.21
binary matrix rank test
A statistical test item which is used to test the linear independence between
given-length subsequences of sequences to be tested.
2.22
cumulative test
A statistical test item which is used to determine whether the maximum
deviation of a sequence to be tested is too large or too small, by comparing the
maximum deviation of all subsequences of sequence to be tested (here, it
refers to the maximum deviation from 0, i.e. the maximum cumulative sum) and
the maximum deviation of a random sequence.
2.23
approximate entropy test
A statistical test item which is used to determine the randomness by comparing
the frequency of the m-th bit overlapping sequence mode and the frequency of
the m + 1-bit overlapping subsequence mode.
2.24
linear complexity test
A statistical test item which is used to determine whether the distribution of
linear complexities of a sequence to be test comply with the randomness
requirements.
2.25
Maurer’s “Universal Test”
b) Calculate the length of the longest run of ones in each subsequence and
include them into a corresponding set {v0, v1, ., v6}.
c) Calculate the statistical value . See Annex A.7 for the
definitions of vi and πi.
d) Calculate .
e) If P-value ≥ α, then the sequence to be tested passes the test for the
longest run of ones in a block.
4.4.9 Binary derivative test
a) For the sequence to be tested ε, conduct exclusive-OR operation of two
adjacent bits in the original sequence to obtain a new sequence ε’, i.e.
b) Repeat operation a) for k times. k = 3,7 in this Specification.
c) Convert the 0 and 1 in the new sequence ε’ respectively into -1 and 1 and
then do cumulative summation to obtain .
d) Calculate the statistical value .
e) Calculate .
f) If P-value ≥ α, then the sequence to be tested passes the binary derivative
test.
4.4.10 Autocorrelation test
a) Calculate . d = 1, 2, 8, 16 in this Specification.
b) Calculate the statistical value .
c) Calculate .
d) If P-value ≥ α, then the sequence to be tested passes the autocorrelation
test.
Annex A
(Informative)
Principle for randomness test
A.1 Monobit frequency test
The monobit frequency test is a most basic test which is used to test whether
the numbers of zeros and ones in a binary sequence are close, i.e. if a binary
sequence of length n is known, it is tested whether the sequence has good
balance of zeros and ones. Let n0 and n1 denote the numbers of zeros and ones
in the sequence. For a random sequence, when its length is sufficiently large,
its statistical value V shall be of standard normal distribution.
A.2 Frequency test within a block
The frequency test within a block is used to test whether the number of ones in
the m-bit subsequences of the sequence to be tested is close to m/2. For a
random sequence, the number of ones in the m-bit subsequences of any length
shall be close to m/2.
In the frequency test within a block, the sequence to be tested is divided into N
subsequences, the length of each subsequence m, n = N * m. Certainly, if n
can’t be divided exactly by m, there will definitely be redundant bits, and then
the abundant bits shall be abandoned. Calculate the proportion of ones in each
subsequence, and set πi = . Let the cumulative sum of the
proportions of ones in all N subsequences as the statistical value, and then.
The statistical value shall follow the x2 distribution with degree of freedom N.
A.3 Poker test
For any positive integer m, there are 2m binary sequences of length m. Divide
the sequence to be tested into non-overlapping subsequences of
length m; and use ni (1 ≤ i ≤ 2m) to represent the number of the i-th subsequence
Annex C
(Informative)
Analytical table of randomness test results
Table C.1
S.N. Test item Principle Parameter requirement Fail analysis
Monobit frequency
test
Test whether the numbers of zeros and ones
in the sequence to be tested are close
n >100
Indicate the number of
zeros or ones is too
small
Frequency test
within a block
whether the number of ones in the m-bit
subsequences is close to m/2
n ≥ 100, m ≥ 20
The proportion of zeros
and ones in the m-bit
subsequences is
unbalanced
3 Poker test
The 2m kinds of subsequences of length m.
Use the length to divide the sequence to be
tested and test whether the numbers of
...
......
Standard ID | GM/T 0005-2021 (GM/T0005-2021) | Description (Translated English) | Randomness test specification | Sector / Industry | Chinese Industry Standard (Recommended) | Classification of Chinese Standard | L80 | Classification of International Standard | 35.040 | Word Count Estimation | 30,380 | Date of Issue | 2021-10-18 | Date of Implementation | 2022-05-01 | Standard ID | GM/T 0005-2012 (GM/T0005-2012) | Description (Translated English) | Randomness test specification | Sector / Industry | Chinese Industry Standard (Recommended) | Classification of Chinese Standard | L80 | Word Count Estimation | 22,269 | Date of Issue | 2012/3/21 | Date of Implementation | 2012/3/21 |
|