CN116821925B - Random number checking method and device, electronic equipment and storage medium - Google Patents

Random number checking method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN116821925B
CN116821925B CN202310521937.2A CN202310521937A CN116821925B CN 116821925 B CN116821925 B CN 116821925B CN 202310521937 A CN202310521937 A CN 202310521937A CN 116821925 B CN116821925 B CN 116821925B
Authority
CN
China
Prior art keywords
random number
randomness
data length
hamming weight
determining
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202310521937.2A
Other languages
Chinese (zh)
Other versions
CN116821925A (en
Inventor
罗影
张红杰
傅勇
胡伯良
安晓江
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Chengdu Haitai Fangyuan Technology Co ltd
Original Assignee
Chengdu Haitai Fangyuan Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Chengdu Haitai Fangyuan Technology Co ltd filed Critical Chengdu Haitai Fangyuan Technology Co ltd
Priority to CN202310521937.2A priority Critical patent/CN116821925B/en
Publication of CN116821925A publication Critical patent/CN116821925A/en
Application granted granted Critical
Publication of CN116821925B publication Critical patent/CN116821925B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/60Protecting data
    • G06F21/604Tools and structures for managing or administering access control systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/60Protecting data
    • G06F21/602Providing cryptographic facilities or services
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F7/00Methods or arrangements for processing data by operating upon the order or content of the data handled
    • G06F7/58Random or pseudo-random number generators
    • G06F7/588Random number generators, i.e. based on natural stochastic processes

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Health & Medical Sciences (AREA)
  • Computer Security & Cryptography (AREA)
  • Software Systems (AREA)
  • Computer Hardware Design (AREA)
  • Bioethics (AREA)
  • Health & Medical Sciences (AREA)
  • Automation & Control Theory (AREA)
  • Computational Mathematics (AREA)
  • Mathematical Analysis (AREA)
  • Mathematical Optimization (AREA)
  • Pure & Applied Mathematics (AREA)
  • Storage Device Security (AREA)

Abstract

The application discloses a random number checking method, a random number checking device, electronic equipment and a storage medium, wherein the random number checking method comprises the following steps: acquiring a first random number; judging whether the randomness of the first random number passes the randomness test or not according to the hamming weight of the first random number and the data length of the first random number, wherein the hamming weight is determined according to the number of bits one of the first random number; outputting the first random number when the randomness of the first random number passes the randomness check. The method can improve the quality of the random number output by the random number generator.

Description

Random number checking method and device, electronic equipment and storage medium
Technical Field
The embodiment of the application relates to the field of information security, in particular to a random number checking method, a random number checking device, electronic equipment and a storage medium.
Background
Currently, in the field of information security, random numbers are generally generated by a random number generator. The random number generator may be largely classified as a true random number generator (true random number generator, TRNG) or a pseudo random number generator (pseudo random number generator, PRNG).
The quality of the generated random number is not checked when the chip of the partial random number generator is designed, so that the quality of the random number generated by the random number generator is difficult to meet the requirements of the national password industry standard (GM/T) 0005-2021 of the people's republic of China (random detection Specification). Therefore, the current random number generator lacks of checking the quality of the random number, so that the quality of the random number output by the random number generator is poor, and the random number generator needs to be improved.
Disclosure of Invention
The embodiment of the application provides a random number checking method, a device, electronic equipment and a storage medium, which are used for improving the quality of a random number output by a random number generator.
In a first aspect, an embodiment of the present application provides a method for checking a random number, including:
acquiring a first random number; judging whether the randomness of the first random number passes the randomness test or not according to the hamming weight of the first random number and the data length of the first random number, wherein the hamming weight is determined according to the number of bits one of the first random number; outputting the first random number when the randomness of the first random number passes the randomness check.
According to the method, the randomness of the first random number can be checked according to the Hamming weight and the data length of the first random number, the random number detected by the randomness is output, and the quality of the first random number output by the random number generator is improved.
In one possible design, the obtaining the first random number includes: acquiring a second random number; determining a first key and an initialization vector according to a sequence cipher algorithm; and processing the second random number through a sequence cipher algorithm according to the first key and the initialization vector to obtain the first random number.
According to this design, a first key is determined from the sequence cipher algorithm, the first key being used to encrypt the second random number. The randomness of the second random number is improved through the encryption process of the second random number, and the quality of the first random number is further improved.
In one possible design, the sequence cipher algorithm includes a ancestral sequence cipher algorithm.
According to the design, the key is determined according to the sequence cipher algorithm of the ancestral punch or other sequence cipher algorithms, the second random number is encrypted according to the key, the encryption result is used for obtaining the random number to be checked, and the encryption efficiency of the second random number is improved.
In one possible design, the determining whether the randomness of the first random number passes the randomness test according to the hamming weight of the first random number and the data length of the first random number includes: determining a randomness value of the first random number according to the hamming weight of the first random number and the data length of the first random number; determining a randomness threshold according to the data length of the first random number; if the randomness value of the first random number is smaller than the randomness threshold, determining that the randomness of the first random number passes the randomness test; and if the randomness value of the first random number is not smaller than the randomness threshold, determining that the randomness of the first random number does not pass the randomness test.
According to the design, the randomness of the first random number can be obtained according to the Hamming weight and the data length of the first random number, the randomness of the first random number is checked, the efficiency of the first equipment for acquiring the randomness value of the first random number can be improved, and therefore the randomness checking accuracy is improved.
In one possible design, the randomness value of the first random number satisfies:
d=|c-s/2|;
wherein d represents a randomness value of the first random number, s represents a data length of the first random number, and c represents a hamming weight of the first random number.
According to the design, the randomness of the first random number is calculated according to the first random Hamming weight and the data length of the first random number through a formula, so that the accuracy of the first random number can be further improved.
In one possible design, the randomness threshold satisfies:
wherein T is 0 Representing the randomness threshold, t=max { x|erfc (x) > N }, N being a constant, erfc (x) representing a residual error function, x representing an argument of the residual error function, s representing a data length of the first random number.
According to the design, the randomness threshold value of the first random number is calculated according to the data length of the first random number through a formula, so that the checking efficiency of the first random number can be further improved.
In a second aspect, embodiments of the present application provide a random number checking device, including:
the acquisition module is used for acquiring the first random number; the processing module is used for judging whether the randomness of the first random number passes the randomness test according to the hamming weight of the first random number and the data length of the first random number, wherein the hamming weight is determined according to the number of bits one of the first random number; the processing module is further configured to output the first random number when randomness of the first random number passes a randomness check.
In one possible design, the acquisition module is specifically configured to: acquiring a second random number; determining a first key and an initialization vector according to a sequence cipher algorithm; and processing the second random number through a sequence cipher algorithm according to the first key and the initialization vector to obtain the first random number.
In one possible design, the sequence cipher algorithm includes a ancestral sequence cipher algorithm.
In one possible design, the processing module is specifically configured to: determining a randomness value of the first random number according to the hamming weight of the first random number and the data length of the first random number; determining a randomness threshold according to the data length of the first random number; if the randomness value of the first random number is smaller than the randomness threshold, determining that the randomness of the first random number passes the randomness test; and if the randomness value of the first random number is not smaller than the randomness threshold, determining that the randomness of the first random number does not pass the randomness test.
In one possible design, the randomness value of the first random number satisfies:
d=|c-s/2|;
wherein d represents a randomness value of the first random number, s represents a data length of the first random number, and c represents a hamming weight of the first random number.
In one possible design, the randomness threshold satisfies:
wherein T is 0 Representing the randomness threshold, t=max { x|erfc (x) > N }, N being a constant, erfc (x) representing a residual error function, x representing an argument of the residual error function, s representing a data length of the first random number.
In a third aspect, embodiments of the present application further provide a computer readable storage medium, where a computer program is stored, the computer program implementing the method of the first aspect and any one of the designs thereof when executed by a processor.
In a fourth aspect, embodiments of the present application further provide an electronic device, including a memory and a processor, where the memory stores a computer program executable on the processor, and when the computer program is executed by the processor, causes the processor to implement the method of the first aspect and any one of the designs thereof.
The technical effects of the second aspect to the fourth aspect and any one of the designs thereof may be referred to as the technical effects of the corresponding designs in the first aspect, and will not be described herein.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the description of the embodiments will be briefly described below, it being obvious that the drawings in the following description are only some embodiments of the present application, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
Fig. 1 is a schematic flow chart of a random number checking method according to an embodiment of the present application;
fig. 2 is a schematic structural diagram of a device according to an embodiment of the present application;
fig. 3 is a schematic structural diagram of another device according to an embodiment of the present application.
Detailed Description
For the purposes of clarity, technical solutions and advantages of the present application, the following optional detailed description of the present application will be made with reference to the accompanying drawings, it being apparent that the described embodiments are only some, but not all, embodiments of the present application. All other embodiments, which can be made by one of ordinary skill in the art without undue burden from the present disclosure, are within the scope of the present disclosure. It should be appreciated that the specific methods of operation described in the method embodiments described below may also be applied in device embodiments or system embodiments.
The terms first and second in the description and claims of the present application and in the above-described figures are used for distinguishing between different objects and not for describing a particular sequential order. Furthermore, the term "include" and any variations thereof is intended to cover non-exclusive protection. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not limited to only those listed steps or elements but may include other steps or elements not listed or inherent to such process, method, article, or apparatus. The term "plurality" in the present application may mean at least two, for example, two, three or more, and embodiments of the present application are not limited.
Currently, in the field of information security, random numbers are generally generated by a random number generator. The quality of the random number needs to meet the requirements of GM/T0005-2021 randomness detection Specification. The quality of the random number may be represented by the randomness of the random number.
Wherein the randomness of the random numbers generated by the random number generator chip is not checked when the partial random number generator chip is designed, so that the random numbers generated by the random number generator are uneven in quality. For example, the random number generator may be largely classified into a true random number generator TRNG or a pseudo random number generator PRNG. The pseudo random number generator can generate random numbers of any length, but the randomness of the generated random numbers is insufficient, thereby affecting the quality of the random numbers.
The current random number generator lacks in checking the generated random number, so that the quality of the random number generated by the random number generator is poor and needs to be improved.
In order to solve the above problems, the present application provides a random number checking method for improving the quality of the random number output from the random number generator.
In the example of the application, a first random number is obtained; judging whether the randomness of the first random number passes the randomness test or not according to the hamming weight of the first random number and the data length of the first random number, wherein the hamming weight is determined according to the number of bits one of the first random number; outputting the first random number when the randomness of the first random number passes the randomness check. The method can test the random number generated by the random number generator and output the random number passing the randomness test, so that the randomness of the output random number can be improved.
Fig. 1 schematically shows a flow chart of a random number checking method. For example, the execution subject of the method may be a first device. The first device may be a random number generator or a device comprising a random number generator or receive a random number generated by other means that may be used to generate a random number. The random number generator may be implemented by a processor or chip or logic circuit, etc. Illustratively, the random number generator shown in the present application may be a true random number generator or a pseudo-random number generator, and will be described hereinafter by taking the first device as an execution body as an example.
Referring to the flow shown in fig. 1, the specific steps of the method provided in the embodiment of the present application include:
step 101, a first random number is acquired.
In one possible embodiment, the first device may obtain the second random number, encrypt the second random number to obtain the first random number, check the randomness of the first random number, output the first random number that passes the check, and discard the first random number that fails the check, thereby improving the randomness of the random number output by the random number generator. The first device checks the first random number according to the data length of the first random number and the hamming weight of the first random number, and outputs the checked first random number, and the checked first random number can meet the requirements of GM/T0005-2021 randomness detection Specification. The checksum output of the first random number is shown in step 102 and step 103, which are not described in detail herein.
First, the process of acquiring the second random number will be described.
In one possible embodiment, the first device may include a random number generation module. The random number generation module of the first device may generate random numbers of arbitrary data length. Alternatively, the random number generation module may be a true random number generator chip, a software random number generator, or a quantum random number generation module. It will be appreciated that the first device may receive the second random number generated by other devices or means, such as a random number generator.
The process of obtaining the first random number from the second random number is described below.
In one possible embodiment, the first device obtains a sequence cipher algorithm. The sequence cipher algorithm is an algorithm for encrypting or decrypting a random number by performing a bitwise exclusive or calculation on the random number. The first device may determine a data length of a single output of the sequence cipher algorithm according to a type of the sequence cipher algorithm. The first device may obtain a first key, where the data length of the first key is k, and the value of k is a natural number. The first key may be used to encrypt or decrypt the second random number to obtain the first random number.
The process of obtaining the first random number will be described below by taking an encryption process as an example.
In one possible embodiment, the data length of a single output of the sequence cipher algorithm may be denoted as n. The first device may obtain the second random number according to the random number outputted by the sequence cipher algorithm multiple times. The data length of the second random number may be n, or may be an integer multiple of n, where n is a natural number.
In one possible embodiment, the first device may determine the values of n and k described above based on the type of sequence cipher algorithm obtained. For example, the sequence cipher algorithm may be a prime sequence cipher algorithm or a prime 256 sequence cipher algorithm, and the data length n of the single encryption output of both cipher algorithms is 32 bits. When the first device obtains the sequence cipher algorithm of the ancestor worship, the first device may obtain a value of n of 32 and a value of k of 128. As another example, the sequence cipher algorithm may be a hardware type sequence cipher algorithm, such as Trivium algorithm. When the first device uses a hardware-based sequence cipher algorithm, the first device may obtain a value of n of 32 and a value of k of 80.
In one possible embodiment, the first device may complete encryption of the second random number based on a bit-wise exclusive-or operation of the first key and the second random number. For example, taking the example of the Summit sequence cipher algorithm, the Summit sequence cipher algorithm may output a 32-bit encryption result. The first device may obtain a total of 32 bits of random numbers. The first device may use the 32-bit random number as the second random number "111000 … …". The first device may obtain a 320-bit random number, and obtain a first key of "101111 … …" with k being 128 bits from the 320-bit random number. The first device performs a bit-wise exclusive-or operation on "111000 … …" and "101111 … …" to obtain "010111 … …" of 32 bits.
It will be appreciated that the sequence cipher algorithm may also be other sequence cipher algorithms, such as a stream cipher (stream cipher) algorithm, and is not limited to the sequence cipher algorithm described above. Also, the values of n and k are determined according to a sequence cipher algorithm, and are not limited to the values in the above example.
In one possible embodiment, the first device may include a plurality of buffers, one of which is selected as the first buffer, and the first device may store the obtained random number to the first buffer based on the physical characteristics of the hardware component. The length of the first buffer area is equal to n, the length of the second buffer area is equal to s, and the first buffer area and the second buffer area are random numbers for acquiring fixed data length. The values of n and s may be determined based on the type of sequence cipher algorithm. For example, when the data of the first buffer is full, the data length of the first buffer is 32 bits. The first device may extract a second random number of 32 bits, and the first device may obtain a random number of 32 bits in length from the first buffer as the second random number.
In one possible embodiment, the first device may further select one from the plurality of buffers as the second buffer, and acquire the random number from the random number in the second buffer as the first random number.
Alternatively, the first device may initialize the buffer, i.e., empty the buffer of data, before the first device stores the random number in the first buffer. For example, the first device determines the data length of the buffer and the buffer, and sets the data length of the buffer to 0.
In one possible embodiment, the first device may initialize a sequence cipher algorithm before encrypting the second random number. The first device may determine an update threshold y of the sequence cipher algorithm, y being a natural number, the value of y being likewise determinable according to the type of sequence cipher algorithm. When the first device determines that the data length of the random number in the first buffer is not less than y bits, the first device may determine the data length v bits of the initialization vector according to the type of the sequence cipher algorithm, acquire the random number of v bits from the first buffer as the initialization vector, and v is a natural number. The first device may input the initialization vector into a sequential cryptographic algorithm to obtain the encrypted data. For example, the first device determines that the sequence cipher algorithm is the sequence cipher algorithm of the ancestor worry, then determines that y is equal to 2 10 Bits. When the data length of the random number in the first buffer is not less than 2 10 When the bits are received, the first device acquires 128-bit random numbers from the first buffer as initialization vectors.
Step 102, judging whether the randomness of the first random number passes the randomness test according to the hamming weight of the first random number and the data length of the first random number.
First, the hamming weight of the first random number is introduced. Hamming weight refers to the number of bits one in a random number. For example, if there are 4 1's in the random number "101011", the bit one number is 4, and the hamming weight of the random number is 4, or the hamming weight may be a value determined according to the bit one number, which may be an integer greater than 4 in this example. Thus, the first device may determine the hamming weight of the first random number with the data length s according to the number of bits one of the first random number acquired in step 101. The first device may determine a randomness value of the first random number based on the hamming weight of the first random number and the data length of the first random number, and may determine a randomness threshold of the first random number based on the data length of the first random number. Based on the randomness value and the randomness threshold, the first device may determine whether the randomness of the first random number passes the randomness check.
In one possible embodiment, the first device determines a hamming weight for the first random number with a data length s, which may be noted as c. The randomness value of the first random number satisfies the following formula:
d=|c-s/2|,
wherein d represents a randomness value of the first random number, s represents a data length of the first random number, and c represents a hamming weight of the first random number.
For example, the first device selects a second buffer from the plurality of buffers, and when the second buffer is full, the data length of the second buffer is s bits, and s is preferably 256. The first device may extract a random number having a data length of s bits from the second buffer as the first random number. Taking "010111 … …" as an example, if the number of bits one of the first random number is 120, the hamming weight c of the first random number is 120. The first device substitutes s and c into the formula d= |c-s/2|, determining d is equal to 8.
In one possible embodiment, the randomness threshold of the first random number satisfies the following formula:
wherein T is 0 Representing the randomness threshold, t=max { x|erfc (x) > N }, N being a constant, erfc (x) representing a residual error function, x representing an argument of the residual error function, s representing a data length of the first random number. max { a, b } represents the maximum value taken between a and b.
For example, still taking s as 256 (unit: bit) as an example, the first device may determine that N is 0.01 according to the user's requirement, and determine that according to the relationship of erfc (x) > 0.01 and the residual error functionT is 1.821 (three decimal places are reserved), and T is determined 0 20.6 (one decimal place reserved).
In one possible embodiment, if the randomness value of the first random number is less than the randomness threshold, determining that the randomness of the first random number passes the randomness test, and if the randomness value of the first random number is not less than the randomness threshold, determining that the randomness of the first random number does not pass the randomness test.
For example, the first device determines that the randomness value d is equal to 8, the randomness threshold T 0 Equal to 20.6, i.e. d < T 0 The first device determines that the randomness of the first random number passes the randomness check. If d is greater than or equal to T 0 The first random number fails the randomness check; further, the first device may not output, stop outputting, or discard the first random number that has been acquired. Alternatively, the first device may re-perform step 101 to obtain the random number, or alternatively, may re-generate the random number of the randomness to be checked by using the first random number as the second random number related to S101.
Alternatively, the first device may store the random number passing the randomness check in the third buffer.
Step 103, outputting the first random number when the randomness of the first random number passes the randomness test.
In one possible embodiment, the first device may output a first random number that passes the randomness check. The first device may determine the third buffer from the plurality of buffers. The first device may store a plurality of first random numbers that pass the inspection and wait for output in the third buffer. When the data length of the data to be output stored in the third buffer area satisfies the data length of the third buffer area, the first device may output the first random number in the third buffer area. When the data length of the data to be output in the third buffer area is smaller than that of the third buffer area, the first device can feed back error information such as insufficient data length and the like, and prompts the user to try to extract the random number later.
The data length of the third buffer may be determined according to the user's needs.
In one possible embodiment, the random number output by the first device that passes the randomness check may meet the requirements of GM/T0005-2021 randomness detection Specification. For example, alternatively, two types of data are collected as comparison objects, namely, 10 sets of data in total, each set of data containing 1000 samples, each sample being 125000 bytes. The first type of data is a random number directly collected from a random number generator chip; the second type of data is data obtained after the random number test in the embodiment of the application. The two sets of data were each randomly characterized according to GM/T0005-2021. The obtained random quality identification result is as follows: only 5 sets of data of the first type are identified by the random quality of GM/T0005-2021, and 9 sets of data of the second type are identified by the random quality of GM/T0005-2021. Therefore, the random number quality output by the random number generator in the embodiment of the application is improved.
In one possible embodiment, the first device may further de-initialize the sequence cipher algorithm after outputting the first number of data. For example, the first device may clear the security sensitive data such as the first key, further improving the security of obtaining the first random number.
Based on the same technical idea, the present application exemplarily provides a random number checking device, as shown in fig. 2, which includes:
an acquisition module 201, configured to acquire a first random number;
a processing module 202, configured to determine whether randomness of the first random number passes a randomness test according to a hamming weight of the first random number and a data length of the first random number, where the hamming weight is determined according to a number of bits one of the first random number;
the processing module 202 is further configured to output the first random number when the randomness of the first random number passes the randomness check.
Optionally, the obtaining module 201 is specifically configured to: acquiring a second random number; determining a first key and an initialization vector according to a sequence cipher algorithm; and processing the second random number through a sequence cipher algorithm according to the first key and the initialization vector to obtain the first random number.
Optionally, the sequence cipher algorithm comprises a ancestral sequence cipher algorithm.
Optionally, the processing module 202 is specifically configured to: determining a randomness value of the first random number according to the hamming weight of the first random number and the data length of the first random number; determining a randomness threshold according to the data length of the first random number; if the randomness value of the first random number is smaller than the randomness threshold, determining that the randomness of the first random number passes the randomness test; and if the randomness value of the first random number is not smaller than the randomness threshold, determining that the randomness of the first random number does not pass the randomness test.
Optionally, the randomness value of the first random number satisfies:
d=|c-s/2|;
wherein d represents a randomness value of the first random number, s represents a data length of the first random number, and c represents a hamming weight of the first random number.
Optionally, the randomness threshold satisfies:
wherein T is 0 Representing the randomness threshold, t=max { x|erfc (x) > N }, N being a constant, erfc (x) representing a residual error function, x representing an argument of the residual error function, s representing a data length of the first random number.
The embodiment of the application also provides electronic equipment based on the same inventive concept as the embodiment of the method. The electronic device may be configured to perform the actions described in the method embodiments above. In this embodiment, the structure of the electronic device may include a memory 301 and one or more processors 302 as shown in FIG. 3.
A memory 301 for storing a computer program for execution by the processor 302. The memory 301 may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, a program required for running an instant communication function, and the like; the storage data area can store various instant messaging information, operation instruction sets and the like.
The memory 301 may be a volatile memory (RAM), such as a random-access memory (RAM); the memory 301 may also be a non-volatile memory (non-volatile memory), such as a read-only memory, a flash memory (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 desired program code in the form of instructions or data structures and that can be accessed by a computer, but is not limited thereto. The memory 301 may be a combination of the above.
The processor 302 may include one or more central processing units (central processing unit, CPU) or digital processing units, etc. The processor 302 is configured to implement the above method when invoking a computer program stored in the memory 301.
The specific connection medium between the memory 301 and the processor 302 is not limited in the embodiments of the present application. As an example, in the embodiment of the present application, the memory 301 and the processor 302 are connected by the bus 303 in fig. 3, the bus 303 is shown by a thick line in fig. 3, and the connection manner between other components is merely schematically illustrated, which is not limited thereto. The bus 303 may be classified as an address bus, a data bus, a control bus, or the like. For ease of illustration, only one thick line is shown in fig. 3, but not only one bus or one type of bus.
Optionally, the processor 302 may be configured to perform the actions performed by any one or more of the acquisition module 201, the processing module 202, and the like.
According to one aspect of the present application, there is provided a computer program product or computer program comprising computer instructions stored in a computer readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device performs the method in the above-described embodiment.
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 can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples (a non-exhaustive list) of the readable storage medium would include the following: an electrical connection having one or more wires, a portable disk, a hard disk, random Access Memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
The foregoing is merely specific embodiments of the present application, but the scope of the present application is not limited thereto, and any person skilled in the art can easily think about changes or substitutions within the technical scope of the present application, and the changes and substitutions are intended to be covered by the scope of the present application.

Claims (8)

1. A method of random number verification comprising:
acquiring a first random number;
judging whether the randomness of the first random number passes the randomness test or not according to the hamming weight of the first random number and the data length of the first random number, wherein the hamming weight is determined according to the number of bits one of the first random number;
outputting the first random number when the randomness of the first random number passes the randomness test;
the step of judging whether the randomness of the first random number passes the randomness test according to the hamming weight of the first random number and the data length of the first random number, comprising the following steps:
determining a randomness value of the first random number according to the hamming weight of the first random number and the data length of the first random number;
determining a randomness threshold according to the data length of the first random number;
if the randomness value of the first random number is smaller than the randomness threshold, determining that the randomness of the first random number passes the randomness test;
if the randomness value of the first random number is not smaller than the randomness threshold, determining that the randomness of the first random number does not pass the randomness test;
wherein the randomness value of the first random number satisfies:
d=|c-s/2|;
d represents a randomness value of the first random number, s represents a data length of the first random number, and c represents a hamming weight of the first random number;
wherein the randomness threshold satisfies:
T 0 representing the randomness threshold, t=max { x|erfc (x) > N }, N being a constant, erfc (x) representing a residual error function, x representing an argument of the residual error function, s representing a data length of the first random number.
2. The method of claim 1, wherein the obtaining the first random number comprises:
acquiring a second random number;
determining a first key and an initialization vector according to a sequence cipher algorithm;
and processing the second random number through a sequence cipher algorithm according to the first key and the initialization vector to obtain the first random number.
3. The method of claim 2, wherein the sequence cipher algorithm comprises a ancestral sequence cipher algorithm.
4. A random number checking device, comprising:
the acquisition module is used for acquiring the first random number;
the processing module is used for judging whether the randomness of the first random number passes the randomness test according to the hamming weight of the first random number and the data length of the first random number, wherein the hamming weight is determined according to the number of bits one of the first random number;
the processing module is further used for outputting the first random number when the randomness of the first random number passes the randomness test;
the processing module is specifically configured to:
determining a randomness value of the first random number according to the hamming weight of the first random number and the data length of the first random number;
determining a randomness threshold according to the data length of the first random number;
if the randomness value of the first random number is smaller than the randomness threshold, determining that the randomness of the first random number passes the randomness test;
if the randomness value of the first random number is not smaller than the randomness threshold, determining that the randomness of the first random number does not pass the randomness test;
wherein the randomness value of the first random number satisfies:
d=|c-s/2|;
d represents a randomness value of the first random number, s represents a data length of the first random number, and c represents a hamming weight of the first random number;
wherein the randomness threshold satisfies:
T 0 representing the randomness threshold, T = max { x|erfc (x) > N }, N being a constant, erfc (x) representing a residual error function,x represents an argument of a residual error function, and s represents a data length of the first random number.
5. The apparatus of claim 4, wherein the acquisition module is specifically configured to:
acquiring a second random number;
determining a first key and an initialization vector according to a sequence cipher algorithm;
and processing the second random number through a sequence cipher algorithm according to the first key and the initialization vector to obtain the first random number.
6. The apparatus of claim 5, wherein the sequence cipher algorithm comprises a ancestral sequence cipher algorithm.
7. An electronic device comprising a processor and a memory, wherein the memory stores program code that, when executed by the processor, causes the processor to perform the steps of the method of any of claims 1-3.
8. A computer readable storage medium, characterized in that it stores a program code for causing an electronic device to perform the steps of the method of any of claims 1-3 when said program code is run on said electronic device.
CN202310521937.2A 2023-05-10 2023-05-10 Random number checking method and device, electronic equipment and storage medium Active CN116821925B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310521937.2A CN116821925B (en) 2023-05-10 2023-05-10 Random number checking method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310521937.2A CN116821925B (en) 2023-05-10 2023-05-10 Random number checking method and device, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN116821925A CN116821925A (en) 2023-09-29
CN116821925B true CN116821925B (en) 2024-03-15

Family

ID=88115608

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310521937.2A Active CN116821925B (en) 2023-05-10 2023-05-10 Random number checking method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN116821925B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110851113A (en) * 2020-01-16 2020-02-28 江苏芯盛智能科技有限公司 Method and device for detecting randomness of byte sequence, storage medium and electronic equipment
CN114489570A (en) * 2022-02-14 2022-05-13 深圳市速腾聚创科技有限公司 Circuit and method for detecting random number abnormality, circuit for generating random number, and radar
CN115756390A (en) * 2022-11-17 2023-03-07 江苏亨通问天量子信息研究院有限公司 Method and system for testing randomness of quantum random number
KR20230053343A (en) * 2021-10-14 2023-04-21 충북대학교 산학협력단 Performance improving method of true random number generator

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20210247963A1 (en) * 2020-02-10 2021-08-12 Jpmorgan Chase Bank, N.A. Method and system for verification of random numbers

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110851113A (en) * 2020-01-16 2020-02-28 江苏芯盛智能科技有限公司 Method and device for detecting randomness of byte sequence, storage medium and electronic equipment
KR20230053343A (en) * 2021-10-14 2023-04-21 충북대학교 산학협력단 Performance improving method of true random number generator
CN114489570A (en) * 2022-02-14 2022-05-13 深圳市速腾聚创科技有限公司 Circuit and method for detecting random number abnormality, circuit for generating random number, and radar
CN115756390A (en) * 2022-11-17 2023-03-07 江苏亨通问天量子信息研究院有限公司 Method and system for testing randomness of quantum random number

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
随机性测试的研究与实现;师国栋;康绯;顾海文;;计算机工程(第20期);全文 *

Also Published As

Publication number Publication date
CN116821925A (en) 2023-09-29

Similar Documents

Publication Publication Date Title
KR101324825B1 (en) Message authentication code pre-computation with applications to secure memory
JP6058245B2 (en) Random number expansion apparatus, random number expansion method and random number expansion program
US10678707B2 (en) Data processing device and method for cryptographic processing of data
US7412468B2 (en) Generation of cryptographically strong random numbers using MISRS
US11151290B2 (en) Tamper-resistant component networks
US8200727B2 (en) Method and apparatus for verifying and diversifying randomness
US11232718B2 (en) Methods and devices for protecting data
CN109388954A (en) Method and apparatus and storage medium for inspection result
US11368319B2 (en) Integrated circuit performing authentication using challenge-response protocol and method of using the integrated circuit
CN112469036A (en) Message encryption and decryption method and device, mobile terminal and storage medium
JPWO2009075353A1 (en) Distributed information generation apparatus, restoration apparatus, verification apparatus, and secret information distribution system
CN108431819B (en) Method and system for protecting client access to service of DRM agent of video player
JP2012080152A (en) Encryption system, encryption apparatus, decryption apparatus, encryption system program and encryption method
US7788479B2 (en) Apparatus, system and method of ensuring that only randomly-generated numbers that have passed a test are used for cryptographic purposes
US9887835B2 (en) Symmetric stream cipher
CN111859424B (en) Data encryption method, system, terminal and storage medium of physical management platform
CN116821925B (en) Random number checking method and device, electronic equipment and storage medium
CN113434876A (en) Data encryption method and device, memory controller, chip and electronic equipment
JP3277139B2 (en) Input bit string encryption apparatus and method
KR101754532B1 (en) Method and apparatus for detecting error of program using CNG(cryptography API(application programming interface) next generation) library
KR20210071394A (en) Sensor network system based on blockchain and method for generating dynamic link key in the sensor network system
JP2005080279A (en) Device and method of applying parity bit to encrypt data for protection
KR20190052605A (en) Random number generator generating random number by using at least two algorithms and security device comprising the same
JP2015082077A (en) Encryption device, control method, and program
US20050050341A1 (en) Device of applying protection bit codes to encrypt a program for protection

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant