CN116743371A - Method and device for determining random number - Google Patents

Method and device for determining random number Download PDF

Info

Publication number
CN116743371A
CN116743371A CN202310890116.6A CN202310890116A CN116743371A CN 116743371 A CN116743371 A CN 116743371A CN 202310890116 A CN202310890116 A CN 202310890116A CN 116743371 A CN116743371 A CN 116743371A
Authority
CN
China
Prior art keywords
random number
length
output
values
message digest
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.)
Pending
Application number
CN202310890116.6A
Other languages
Chinese (zh)
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 CN202310890116.6A priority Critical patent/CN116743371A/en
Publication of CN116743371A publication Critical patent/CN116743371A/en
Pending legal-status Critical Current

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/08Key distribution or management, e.g. generation, sharing or updating, of cryptographic keys or passwords
    • H04L9/0861Generation of secret information including derivation or calculation of cryptographic keys or passwords
    • H04L9/0869Generation of secret information including derivation or calculation of cryptographic keys or passwords involving random numbers or seeds
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L2209/00Additional information or applications relating to cryptographic mechanisms or cryptographic arrangements for secret or secure communication H04L9/00
    • H04L2209/08Randomization, e.g. dummy operations or using noise
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L2209/00Additional information or applications relating to cryptographic mechanisms or cryptographic arrangements for secret or secure communication H04L9/00
    • H04L2209/20Manipulating the length of blocks of bits, e.g. padding or block truncation

Abstract

The application discloses a method and a device for determining random numbers. The length of the first random number is a second length, the first length is a length supported by a message digest algorithm, and N is a positive integer greater than or equal to 2. And processing the N first numerical values according to a message digest algorithm to obtain N first output digests. The data length of each first output abstract is a first length, the ith first output abstract is obtained by processing the ith first numerical value according to a message abstract algorithm, and i is a positive integer less than or equal to N. And splicing the N first output summaries to obtain the second random number. The length of the second random number and the length of the first random number are both the second length. And outputting the second random number if the second random number meets the randomness requirement. Therefore, the method can improve the randomness of the random number, thereby improving the quality of the random number.

Description

Method and device for determining random number
Technical Field
The present application relates to the field of information security technologies, and in particular, to a method and an apparatus for determining a random number.
Background
Random numbers are widely used in the field of cryptographic applications, such as key generation for symmetric or asymmetric cryptographic algorithms, challenge values in challenge-response schemes, secret information in digital signature schemes, resistance to side channel analysis attacks, etc., and the quality of random numbers plays a decisive role in the field of cryptographic applications. For example, the quality of a key for symmetric or asymmetric cryptographic algorithms depends on the quality of the random number that generated the key. Random numbers are currently typically generated by a random number generator (Random Number Generator, RNG).
However, the quality of the random numbers generated by the current random number generator is not high, and needs to be improved.
Disclosure of Invention
The embodiment of the application provides a method and a device for determining a random number, which are used for improving the quality of the random number.
In a first aspect, an embodiment of the present application provides a method for determining a random number, including: determining N first numerical values with a first length according to a first random number, wherein the length of the first random number is a second length, the first length is a length supported by a message digest algorithm, and N is a positive integer greater than or equal to 2; processing the N first values according to a message digest algorithm to obtain N first output digests, wherein the data length of each first output digest is the first length, the ith first output digest is obtained by processing the ith first value according to the message digest algorithm, and i is a positive integer less than or equal to N; splicing the N first output abstracts to obtain a second random number, wherein the length of the second random number is the second length; and outputting the second random number if the second random number meets the randomness requirement.
By adopting the method, the first random number is split into a plurality of first values, a plurality of first output summaries are obtained according to the plurality of first values, and the plurality of first output summaries are combined into the second random number, so that the randomness of the random number can be improved, and the quality of the random number is improved.
In one possible design, determining M second values with a third length according to a third random number, where the third length is a length supported by a message digest algorithm, and M is a positive integer greater than or equal to 2; processing the M second values according to a message digest algorithm to obtain M second output digests, wherein the data length of each second output digest is a third length, the kth second output digest is obtained by processing the kth second value according to the message digest algorithm, and k is a positive integer less than or equal to M; splicing the M second output abstracts to obtain a fourth random number, wherein the length of the fourth random number and the length of the third random number are both the fourth length; and if the second random number does not meet the randomness requirement and the fourth random number meets the randomness requirement, outputting the fourth random number.
By adopting the design, a plurality of random numbers are generated, the random numbers are detected, and when the random numbers meet the randomness requirement, the random numbers are output, so that the output random numbers are ensured to meet the randomness requirement, and the output random numbers are ensured to meet the randomness requirements of various cryptographic algorithms, cryptographic protocols and cryptographic products on the random numbers.
In one possible design, the N first output digests are spliced to obtain a fifth random number, where the length of the fifth random number is N times the first length; and if the fifth random number and the sixth random number meet the randomness requirement, splicing the fifth random number and the sixth random number to obtain a second random number meeting the randomness requirement.
By adopting the design, the randomness of the fifth random number and the sixth random number is verified, and the output random numbers are ensured to meet the randomness requirement.
In one possible design, the second length is greater than or equal to N times the first length.
In one possible design, the second length is greater than N times the first length and less than n+1 times the first length; determining N first values with a first length and third values with a fifth length according to the first random number, wherein the fifth length is smaller than the first length; processing the third numerical value according to a message digest algorithm to obtain a third output digest of a fifth length; and splicing the N first output summaries with the third output summaries to obtain the second random number.
Based on the embodiment, the random number which cannot be uniformly divided (i.e. the second length cannot be divided by the first length) can be divided by the dividing method, so that the applicability of the application is improved.
In a second aspect, an embodiment of the present application provides a device for determining a random number, including: the processing module is used for determining N first numerical values with a first length according to a first random number, wherein the length of the first random number is a second length, the first length is a length supported by a message digest algorithm, and N is a positive integer greater than or equal to 2; the processing module is further used for processing the N first numerical values according to a message digest algorithm to obtain N first output digests, the data length of each first output digest is the first length, the ith first output digest is obtained by processing the ith first numerical value according to the message digest algorithm, and i is a positive integer smaller than or equal to N; the processing module is also used for splicing the N first output abstracts to obtain a second random number, and the length of the second random number is a second length; and if the second random number meets the randomness requirement, the output module is used for outputting the second random number.
In one possible design, the processing module is further configured to determine M second values with a third length according to a third random number, where the third length is a length supported by the message digest algorithm, and M is a positive integer greater than or equal to 2; the processing module is further used for processing the M second values according to a message digest algorithm to obtain M second output digests, the data length of each second output digest is a third length, the kth second output digest is obtained by processing the kth second value according to the message digest algorithm, and k is a positive integer less than or equal to M; the processing module is further used for splicing the M second output abstracts to obtain a fourth random number, and the length of the fourth random number and the length of the third random number are both the fourth length; if the second random number does not meet the randomness requirement and the fourth random number meets the randomness requirement, the output module is further used for outputting the fourth random number.
In one possible design, the processing module is specifically configured to: splicing the N first output abstracts to obtain a fifth random number, wherein the length of the fifth random number is N times of the first length; and if the fifth random number and the sixth random number meet the randomness requirement, splicing the fifth random number and the sixth random number to obtain a second random number meeting the randomness requirement.
In one possible design, the second length is greater than or equal to N times the first length.
In one possible design, the second length is greater than N times the first length and less than n+1 times the first length, and the processing module is specifically configured to: determining N first values with a first length and third values with a fifth length according to the first random number, wherein the fifth length is smaller than the first length; processing the third numerical value according to a message digest algorithm to obtain a third output digest of a fifth length; and splicing the N first output summaries with the third output summaries to obtain the second random number.
In a third aspect, embodiments of the present application further provide a computer readable storage medium, in which a computer program is stored, which when executed by a processor, implements the method of the first and second aspects and any one of the designs thereof.
In a fourth aspect, embodiments of the present application also 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 methods of the first aspect and the second 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, and it is obvious that the drawings in the following description are only some embodiments of the present application, and other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flow chart of a method for determining a random number according to an embodiment of the present application;
fig. 2 is a schematic structural diagram of a method for determining a random number according to an embodiment of the present application;
FIG. 3 is a schematic diagram of another method for determining a random number according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of a device for determining a random number according to an embodiment of the present application;
fig. 5 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
For the purpose of promoting an understanding of the principles and advantages of the application, reference will now be made in detail to the drawings, in which embodiments of the application are illustrated, some but not all of which are illustrated. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
Next, a method of determining a random number will be described in connection with the related art.
Current prior art schemes for generating random numbers typically generate random numbers from a random number generator. The random number generator may be largely classified into a true random number generator and a pseudo random number generator.
However, the quality of the random numbers generated by the current random number generator is not high, and needs to be improved.
For example, a true random number generator is susceptible to external objective environmental factors, which cause the random number generated by the true random number generator to be unstable, thereby affecting the quality of the random number.
For another example, the pseudorandom number generator generates random numbers according to a deterministic algorithm and a random number sequence, and if the input random number sequence and the deterministic algorithm used remain unchanged, the random numbers generated by the pseudorandom number generator are the same, resulting in low randomness of the random numbers and low quality of the random numbers.
In order to solve the technical defects, the application provides a method and a device for determining a random number, which are used for improving the quality of the random number.
In the application, the method comprises the following steps: the first device may determine N first values having a first length from the first random number. The length of the first random number is a second length, the first length is a length supported by a message digest algorithm, and N is a positive integer greater than or equal to 2. The first device may further process the N first values according to a message digest algorithm to obtain N first output digests. The data length of each first output abstract is a first length, the ith first output abstract is obtained by processing the ith first numerical value by first equipment according to a message abstract algorithm, and i is a positive integer less than or equal to N. The first device may further splice the N first output digests to obtain a second random number. The length of the second random number and the length of the first random number are both the second length. If the second random number meets the randomness requirement, the first device outputs the second random number. Therefore, the method can improve the randomness of the random number, thereby improving the quality of the random number.
In addition, the first device may be a computer system, or may be a device for executing the method shown in the present application in a data device, such as a processor or a processing module, where the present application is not specifically limited.
Fig. 1 is a flow chart of a method for determining a random number according to an embodiment of the present application. Taking the first device as an execution body as an example, the process may include the following steps:
s101, the first device determines N first numerical values with a first length according to the first random number. The length of the first random number is a second length, the first length is a length supported by a message digest algorithm, and N is a positive integer greater than or equal to 2.
Specifically, the first random number may be a random number of a second length generated by the random number generator. The second length is any length, that is, the length of the first random number is not specifically limited in the present application. The random number generator may be a true random number generator or a pseudo random number generator, and the present application is not particularly limited.
The first length is a length supported by a message digest algorithm. It is appreciated that the first length is less than or equal to the length of the message digest algorithm output data. For example, the SM3 algorithm is one of the message digest algorithms. In the SM3 algorithm, the length of the input value of SM3 may be any length, and the length of the output value of SM3 is 256 bits. Thus, if the application employs the SM3 algorithm, the first length is less than or equal to the length of the output value of SM3, i.e. the first length is less than or equal to 256 bits.
In one or more embodiments, the second length may be equal to N times the first length, N being a positive integer greater than or equal to 2. That is, the first random length may be divided by the first length.
Specifically, when the length of the first random number is equal to N times the first length, the first device may divide the first random number into N first values having the first length, where N is a positive integer greater than or equal to 2.
For example, fig. 2 is a schematic structural diagram of a method for determining a random number according to an embodiment of the present application. Wherein, A is a random number with a length of 107616 bits, and the dividing length is 128 bits. The first length may be expressed as 128 bits and the second length may be expressed as 107616 bits, and then the second length may be divided by the first length. It is understood that N is 7872 and the second length is equal to 7872 times the first length. The first random number may be a and the first length may be 128 bits, and the first device may divide a into 7872 values of 128 bits in length.
Based on the embodiment, the first random number can be divided into N first values in a uniform division manner, so that the randomness of the first values is improved.
In one or more embodiments, the second length may be greater than N times the first length, N being a positive integer greater than or equal to 2. That is, the length of the first random number is not divisible by the first length, i.e., the present application also supports dividing the first random number in a non-uniform division manner.
Specifically, when the length of the first random number is greater than N times the first length, the first device may divide the first random number into N first values of the first length and 1 value of the remaining bits. Wherein the length of the value of the remaining bits is smaller than the first length, and N is a positive integer greater than or equal to 2.
For example, fig. 3 is a schematic structural diagram of a method for determining a random number according to an embodiment of the present application. The first random number may be expressed as C the first random number is a random number of length 107716 bits divided into 128 bits, i.e., the first length is 128 bits, the second length is 107716 bits, and the second length is not divisible by the first length, the first device may divide C into 7872 values of length 128 bits, and 1 value of length 100 bits.
Based on the embodiment, the random number which cannot be uniformly divided (namely, the second length cannot be divided by the first length) can be divided by the dividing mode, so that the applicability of the method is improved.
In the present application, the N first values are values of the first length of N obtained from the first random number, but the values of the N values are not limited to be the same. Wherein, the value of each first numerical value can be the same or different.
Based on step S101, the first device divides the first random number of any length into a plurality of first values, which ensures the effectiveness and flexibility of the subsequent processing algorithm.
S102, the first device processes the N first values according to a message digest algorithm to obtain N first output digests.
The data length of each first output abstract is a first length, the ith first output abstract is obtained by processing the ith first numerical value according to a message abstract algorithm, and i is a positive integer less than or equal to N.
Specifically, if the length of the first random number is equal to N times the first length, the first device may divide the first random number into N first values having the first length. The first device may process the ith first value according to a message digest algorithm to obtain an ith output value. The ith output value is an operation result obtained by performing message digest algorithm operation on the ith first value. The first device may further extract a value of the first length from the i-th output value as the i-th first output digest.
Alternatively, the first device may extract successive values from any one of the output values as the corresponding first output digest. For example, the 1 st output value has a length of 256 bits and the first length is 128 bits, the first device may take the first 128 bits of the 1 st output value as the 1 st first output digest. The first device may also extract a discrete value from any of the output values as a corresponding first output digest. For example, the length of the 2 nd output value is 256 bits, and the first length is 128 bits, the first device may splice 128 bits of values randomly extracted from the 2 nd output value, as the 2 nd first output digest.
Illustratively, as shown in FIG. 2, the first random number may be A and the first length may be 128 bits. The first device splits a into 7872 first values having 128 bits. The first device processes the ith 128-bit value according to the SM3 algorithm to obtain an ith 256-bit value. The first device extracts the first 128-bit value from the i-th 256-bit value as the i-th output digest. Wherein i is a positive integer less than or equal to 7872.
Based on step S102, the first device processes the plurality of first values according to the message digest algorithm, so as to obtain a plurality of first output digests, which can improve the randomness of the first output digests.
And S103, the first equipment splices the N first output summaries to obtain a second random number.
Specifically, the first device splices the N first output digests according to the arrangement sequence of the N first values, and obtains a second random number. The position of the ith first numerical value in the first random number is the same as the position of the ith first output digest in the second random number.
Illustratively, as shown in FIG. 2, A is a random number of length 1007616 and B is a random number of length 1007616. Wherein, A can be divided into 7872 128-bit values, and B can be obtained by splicing 7872 output summaries. The 1 st output digest is obtained by processing the 1 st 128-bit value according to the SM3 algorithm. The 1 st output digest is located at the same position in B as the 1 st 128-bit value in a.
Based on step S103, the first device splices the N first output digests according to the arrangement sequence of the N first values, so as to obtain the second random number, which can ensure the randomness and stability of the second random number.
In one or more embodiments, if the second length is greater than N times the first length and less than n+1 times the first length, the first random number may be divided into N first values of the first length and 1 third value of the fifth length. Wherein the fifth length is less than the first length. The first device may process the ith first value according to a message digest algorithm to obtain an ith output value. Wherein i is a positive integer less than or equal to n+1. That is, the first device processes the N first values and the 1 third value according to the message digest algorithm, respectively, to obtain n+1 output values. Wherein the first N output values correspond to the N first values one by one, and the (n+1) th output value corresponds to the third value. The first device may further extract a value of the first length from the jth output value as the jth first output digest, and extract a value of the fifth length from the n+1th output value as the n+1th first output digest. Wherein j is less than or equal to N. And splicing the N first output summaries with the 1 third output summaries to obtain the second random number.
For example, as shown in fig. 3, the first random number may be C, and the second random number may be D, and the first random number may have a length of 107716 bits and a split length of 128 bits. The first device may split the first random number into 7872 first values having 128 bits and 1 remaining 100 bits. The first device processes the ith first value according to the SM3 algorithm to obtain an ith 256-bit output value, and processes the remaining 100-bit values according to the SM3 algorithm to obtain a 7873 th 256-bit output value. The first device extracts the first 128-bit value from the i-th 256-bit output value as the i-th output digest. Wherein i is a positive integer less than or equal to 7872. The first device also extracts the first 100-bit output value from the 7873 th 256 bits as the 7873 th output digest. And splicing the first 7872 output summaries with the 7873 output summaries to obtain a second random number with the length of 107716 bits.
In one or more embodiments, the first device may input the random numbers spliced by the N first output digests into the random number indirect hit buffer according to an arrangement order of the N first values. Wherein the random number indirect hit buffer is used for storing random numbers. It can be appreciated that, because the efficiency of the first device for detecting the randomness of the random number is low, the first device can store the generated random number into the random number indirect hit buffer area, and then detect the randomness of the random number in the random number indirect hit buffer area, thereby avoiding the reduction of the efficiency of generating the random number due to the low randomness detection efficiency.
The first device may also perform randomness detection on the random number in the random number indirect hit buffer. For example, the first device may perform randomness detection on the random number according to GM/T0005 randomness detection Specification, or may perform randomness detection on the random number according to NIST SP 800-22A Statistical Test Suite for the Validation of Random Number Generators and Pseudo Random Number Generators for Cryptographic Application.
If the random number meets the randomness requirement, the first device inputs the random number into a random number direct hit buffer. Wherein, the random number direct hit buffer is used for storing the random number. The random number direct hit buffer and the random number indirect hit buffer may be the same storage device or may be different storage devices.
S104, if the second random number meets the randomness requirement, the first device outputs the second random number.
Specifically, before outputting the second random number, the first device may further perform randomness detection on the second random number, and if the second random number meets the randomness requirement, output the second random number.
For example, the first device may perform a randomness detection of the second random number according to GM/T0005 randomness detection Specification or according to NIST SP 800-22A Statistical Test Suite for the Validation of Random Number Generators and Pseudo Random Number Generators for Cryptographic Application. And outputting the second random number if the second random number meets the randomness detection.
Based on step S104, the first device performs randomness detection on the random number, and outputs the random number when the random number meets randomness requirements, so as to ensure that the output random number meets randomness requirements of various cryptographic algorithms, cryptographic protocols and cryptographic products on the random number.
In one or more embodiments, the first device may further determine M second values having a third length from the third random number. The third length is a length supported by the message digest algorithm, and may be the same as or different from the first length. M is a positive integer greater than or equal to 2, and M and N may be the same or different. The manner in which the first device obtains the second value is the same as the manner in which the first device obtains the first value, and will not be described here again.
The first device may further process the M second values according to a message digest algorithm to obtain M second output digests. The data length of each second output abstract is a third length, the kth second output abstract is obtained by processing the kth second numerical value according to a message abstract algorithm, and k is a positive integer less than or equal to M. The manner in which the first device obtains the second output abstract is the same as the manner in which the first device obtains the first output abstract, and will not be described here again.
The first device may further splice the M second output digests to obtain a fourth random number. The length of the fourth random number and the length of the third random number are both the fourth length. The manner in which the first device obtains the fourth random number is the same as the manner in which the first device obtains the second random number, and will not be described here again.
If the second random number does not meet the randomness requirement and the fourth random number meets the randomness requirement, the first device outputs the fourth random number.
It will be appreciated that if the second random number does not meet the randomness requirement, the first device may regenerate the fourth random number and perform randomness check on the fourth random number, and if the fourth random number meets the randomness requirement, output the fourth random number. The fourth random number may be one of a plurality of random numbers in the random number indirect hit buffer. If the second random number does not meet the randomness requirement, the first device may select a fourth random number from the indirect hit buffer, perform randomness test on the fourth random number, and if the fourth random number meets the randomness requirement, output the fourth random number.
Based on this embodiment, the first device may generate a plurality of random numbers, and perform randomness detection on the plurality of random numbers, and output the random numbers when the random numbers meet the randomness requirement. By adopting the method, the output random numbers can be ensured to meet the randomness requirement, and the output random numbers are ensured to meet the randomness requirement of various cryptographic algorithms, cryptographic protocols and cryptographic products on the random numbers.
The first device may also extract a random number of a specified length from the random number direct hit buffer, and directly output the random number, i.e., the second random number.
Alternatively, the first device may store the spliced random number to the random number indirect hit buffer. The first device may further perform a random line check on the random number in the random number indirect hit buffer, and if the randomness requirement is met, input the random number into the random number direct hit buffer, thereby caching the random number meeting the random number requirement. When the random number is used, the random number can be directly obtained from the random number direct hit buffer, and the random number obtaining efficiency is improved.
As one example, if the first device determines that the second random number meets the randomness requirement, the second random number may be stored to the random number direct hit buffer.
Further, if the length of the random number in the random number direct hit buffer is smaller than the specified length, the first device may further obtain the second random number by:
in one or more embodiments, the first device may splice the N first output digests to obtain a fifth random number. Wherein the length of the fifth random number is N times the first length. And if the fifth random number and the sixth random number meet the randomness requirement, splicing the fifth random number and the sixth random number to obtain a second random number meeting the randomness requirement.
Specifically, the first device concatenates the N first output digests into a fifth random number, and if the fifth random number satisfies randomness, inputs the fifth random number into the random number direct hit buffer. Wherein the length of the fifth random number is N times the first length. If the length of the random number in the random number direct hit buffer is smaller than the designated length, that is, only the fifth random number in the random number direct hit buffer is larger than N times the first length, the first device may further obtain the sixth random number from the random number indirect hit buffer. Wherein the sum of the length of the sixth random number and the length of the fifth random number is equal to the specified length.
Before the fifth random number is spliced with the sixth random number, the first device may further perform randomness test on the sixth random number, and if the sixth random number meets the randomness requirement, splice the fifth random number with the sixth random number to obtain the second random number. If the sixth random number does not meet the randomness requirement, the first device again retrieves the sixth random number from the random number indirect hit buffer. It will be appreciated that if the fifth random number meets the randomness requirement and the sixth random number meets the randomness requirement, then the second random number resulting from concatenating the fifth random number and the sixth random number may be considered to meet the randomness requirement. That is, there is no need to additionally verify whether the second random number satisfies the randomness requirement.
Based on this embodiment, in order to avoid that the random number directly hits the fifth random number of the buffer with a length smaller than the specified length, resulting in that the outputted random number does not meet the use requirement, the first device may further acquire the sixth random number with a missing length from the random number direct hit buffer. If the fifth random number and the sixth random number meet the randomness requirement, the fifth random number and the sixth random number are spliced to obtain the random number meeting the use requirement.
Based on the above and the same conception, the present application provides a random number determining apparatus. As shown in fig. 4, the apparatus includes a processing module 401 and an output module 402.
A processing module 401, configured to determine N first values having a first length according to a first random number, where the first random number has a second length, the first length is a length supported by a message digest algorithm, and N is a positive integer greater than or equal to 2; the processing module 401 is further configured to process the N first values according to a message digest algorithm to obtain N first output digests, where a data length of each first output digest is a first length, and the i-th first output digest is obtained by processing the i-th first value according to the message digest algorithm, where i is a positive integer less than or equal to N; the processing module 401 is further configured to splice the N first output digests to obtain a second random number, where a length of the second random number is a second length; the output module 402 is configured to output the second random number if the second random number meets the randomness requirement.
In one possible design, the processing module 401 is further configured to determine M second values with a third length according to a third random number, where the third length is a length supported by the message digest algorithm, and M is a positive integer greater than or equal to 2; the processing module 401 is further configured to process the M second values according to a message digest algorithm to obtain M second output digests, where a data length of each second output digest is a third length, a kth second output digest is obtained by processing a kth second value according to the message digest algorithm, and k is a positive integer less than or equal to M; the processing module 401 is further configured to splice the M second output digests to obtain a fourth random number, where the length of the fourth random number and the length of the third random number are both the fourth length; the output module 402 is further configured to output the fourth random number if the second random number does not satisfy the randomness requirement and the fourth random number satisfies the randomness requirement.
In one possible design, the processing module 401 is specifically configured to: splicing the N first output abstracts to obtain a fifth random number, wherein the length of the fifth random number is N times of the first length; and if the fifth random number and the sixth random number meet the randomness requirement, splicing the fifth random number and the sixth random number to obtain a second random number meeting the randomness requirement.
In one possible design, the second length is greater than or equal to N times the first length.
In one possible design, the second length is greater than N times the first length and less than n+1 times the first length, and the processing module 401 is specifically configured to: determining N first values with a first length and third values with a fifth length according to the first random number, wherein the fifth length is smaller than the first length; processing the third numerical value according to a message digest algorithm to obtain a third output digest of a fifth length; and splicing the N first output summaries with the third output summaries to obtain the second random number.
Fig. 5 shows a schematic structural diagram of an electronic device according to an embodiment of the present application.
The electronic device in an embodiment of the application may comprise a processor 501. The processor 501 is the control center of the device and may connect the various parts of the device using various interfaces and lines by running or executing instructions stored in the memory 503 and invoking data stored in the memory 503. Alternatively, the processor 501 may include one or more processing units, and the processor 501 may integrate an application processor and a modem processor, wherein the application processor primarily processes an operating system and application programs, etc., and the modem processor primarily processes wireless communications. It will be appreciated that the modem processor described above may not be integrated into the processor 501. In some embodiments, the processor 501 and the memory 503 may be implemented on the same chip, and in some embodiments they may be implemented separately on separate chips.
The processor 501 may be a general purpose processor such as a central processing unit (Central Processing Unit, CPU), digital signal processor, application specific integrated circuit, field programmable gate array or other programmable logic device, discrete gate or transistor logic device, discrete hardware components, and may implement or perform the methods, steps and logic blocks disclosed in embodiments of the present application. The general purpose processor may be a microprocessor or any conventional processor or the like. The steps of the method disclosed in connection with the embodiments of the present application may be performed directly by a hardware processor or by a combination of hardware and software modules in the processor.
In an embodiment of the present application, the memory 503 stores instructions executable by the at least one processor 501, and the at least one processor 501, by executing the instructions stored by the memory 503, may be used to perform the method steps disclosed in the embodiment of the present application.
The memory 503 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules. The Memory 503 may include at least one type of storage medium, and may include, for example, flash Memory, hard disk, multimedia card, card Memory, random access Memory (Random Access Memory, RAM), static random access Memory (Static Random Access Memory, SRAM), programmable Read-Only Memory (Programmable Read Only Memory, PROM), read-Only Memory (ROM), charged erasable programmable Read-Only Memory (Electrically Erasable Programmable Read-Only Memory, EEPROM), magnetic Memory, magnetic disk, optical disk, and the like. Memory 503 is 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 to such. The memory 503 in embodiments of the present application may also be circuitry or any other device capable of performing storage functions for storing program instructions and/or data.
In an embodiment of the present application, the apparatus may further include a communication interface 502, and the electronic device may transmit data through the communication interface 502.
Alternatively, the processing module 401 and/or the output module 402 shown in fig. 2 may be implemented by the processor 501 (or the processor 501 and the communication interface 502) shown in fig. 5, that is, the actions of the processing module 401 and/or the output module 402 may be performed by the processor 501 (or the processor 501 and the communication interface 502).
Based on the same inventive concept, embodiments of the present application also provide a computer-readable storage medium in which instructions may be stored, which when run on a computer, cause the computer to perform the operational steps provided by the above-described method embodiments. The computer readable storage medium may be the memory 503 shown in fig. 5.
It will be appreciated by those skilled in the art that embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to the application. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
It will be apparent to those skilled in the art that various modifications and variations can be made to the present application without departing from the spirit or scope of the application. Thus, it is intended that the present application also include such modifications and alterations insofar as they come within the scope of the appended claims or the equivalents thereof.

Claims (10)

1. A method of determining a random number, the method comprising:
determining N first numerical values with a first length according to a first random number, wherein the length of the first random number is a second length, the first length is a length supported by a message digest algorithm, and N is a positive integer greater than or equal to 2;
processing the N first values according to the message digest algorithm to obtain N first output digests, wherein the data length of each first output digest is the first length, the ith first output digest is obtained by processing the ith first value according to the message digest algorithm, and i is a positive integer less than or equal to N;
splicing the N first output abstracts to obtain a second random number, wherein the length of the second random number is the second length;
and outputting the second random number if the second random number meets the randomness requirement.
2. The method of claim 1, wherein the method further comprises:
determining M second numerical values with a third length according to a third random number, wherein the third length is the length supported by the message digest algorithm, and M is a positive integer greater than or equal to 2;
processing the M second values according to the message digest algorithm to obtain M second output digests, wherein the data length of each second output digest is the third length, the kth second output digest is obtained by processing the kth second value according to the message digest algorithm, and k is a positive integer less than or equal to M;
splicing the M second output abstracts to obtain a fourth random number, wherein the length of the fourth random number and the length of the third random number are both the fourth length;
and outputting the fourth random number if the second random number does not meet the randomness requirement and the fourth random number meets the randomness requirement.
3. The method of claim 1, wherein the concatenating the N first output digests to obtain a second random number comprises:
splicing the N first output abstracts to obtain a fifth random number, wherein the length of the fifth random number is N times of the first length;
and if the fifth random number and the sixth random number meet the randomness requirement, splicing the fifth random number and the sixth random number to obtain the second random number meeting the randomness requirement.
4. A method according to any one of claims 1 to 3, wherein the second length is greater than or equal to N times the first length.
5. The method of claim 4, wherein the second length is greater than N times the first length and less than n+1 times the first length;
the determining N first values having a first length according to the first random number includes:
determining N first values with a first length and third values with a fifth length according to the first random number, wherein the fifth length is smaller than the first length;
the method further comprises the steps of:
processing the third numerical value according to the message digest algorithm to obtain a third output digest of the fifth length;
the splicing the N first output abstracts to obtain a second random number includes:
and splicing the N first output summaries with the third output summaries to obtain the second random number.
6. A device for determining a random number, the device comprising:
the processing module is used for determining N first numerical values with a first length according to a first random number, wherein the length of the first random number is a second length, the first length is a length supported by a message digest algorithm, and N is a positive integer greater than or equal to 2;
the processing module is further configured to process the N first values according to the message digest algorithm to obtain N first output digests, where a data length of each first output digest is the first length, and an ith first output digest is obtained by processing the ith first value according to the message digest algorithm, where i is a positive integer less than or equal to N;
the processing module is further configured to splice the N first output summaries to obtain a second random number, where the length of the second random number is the second length;
and if the second random number meets the randomness requirement, the output module is used for outputting the second random number.
7. The apparatus of claim 6, wherein the processing module is further configured to determine M second values having a third length based on a third random number, the third length being a length supported by the message digest algorithm, M being a positive integer greater than or equal to 2;
the processing module is further configured to process the M second values according to the message digest algorithm to obtain M second output digests, where a data length of each second output digest is the third length, and a kth second output digest is obtained by processing the kth second value according to the message digest algorithm, where k is a positive integer less than or equal to M;
the processing module is further configured to splice the M second output summaries to obtain a fourth random number, where the length of the fourth random number and the length of the third random number are both the fourth length;
and if the second random number does not meet the randomness requirement and the fourth random number meets the randomness requirement, the output module is further used for outputting the fourth random number.
8. The apparatus of claim 6, wherein the processing module is specifically configured to:
splicing the N first output abstracts to obtain a fifth random number, wherein the length of the fifth random number is N times of the first length;
and if the fifth random number and the sixth random number meet the randomness requirement, splicing the fifth random number and the sixth random number to obtain the second random number meeting the randomness requirement.
9. An electronic device comprising a processor for implementing the steps of the method according to any of claims 1-5 when executing a computer program stored in a memory.
10. A computer-readable storage medium, characterized in that it stores a computer program which, when executed by a processor, implements the steps of the method according to any of claims 1-5.
CN202310890116.6A 2023-07-19 2023-07-19 Method and device for determining random number Pending CN116743371A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310890116.6A CN116743371A (en) 2023-07-19 2023-07-19 Method and device for determining random number

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310890116.6A CN116743371A (en) 2023-07-19 2023-07-19 Method and device for determining random number

Publications (1)

Publication Number Publication Date
CN116743371A true CN116743371A (en) 2023-09-12

Family

ID=87916983

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310890116.6A Pending CN116743371A (en) 2023-07-19 2023-07-19 Method and device for determining random number

Country Status (1)

Country Link
CN (1) CN116743371A (en)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107943450A (en) * 2017-11-17 2018-04-20 上海众人网络安全技术有限公司 Random digit generation method, device, computer equipment and computer-readable medium
CN108388421A (en) * 2017-12-29 2018-08-10 北京欧链科技有限公司 The generation method and device of random number
CN112306457A (en) * 2020-08-07 2021-02-02 神州融安科技(北京)有限公司 Random number generation method and device

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107943450A (en) * 2017-11-17 2018-04-20 上海众人网络安全技术有限公司 Random digit generation method, device, computer equipment and computer-readable medium
CN108388421A (en) * 2017-12-29 2018-08-10 北京欧链科技有限公司 The generation method and device of random number
CN112306457A (en) * 2020-08-07 2021-02-02 神州融安科技(北京)有限公司 Random number generation method and device

Similar Documents

Publication Publication Date Title
EP3208788B1 (en) Method of protecting a circuit against a side-channel analysis
CN100576174C (en) The possible prime number that the check password is used
US8472621B2 (en) Protection of a prime number generation for an RSA algorithm
JP6366595B2 (en) Method and system for anti-glitch cryptographic discrete log-based signature
Medwed et al. Template attacks on ECDSA
US9298947B2 (en) Method for protecting the integrity of a fixed-length data structure
US20100262840A1 (en) Method and devices for protecting a microcircuit from attacks for obtaining secret data
US10678707B2 (en) Data processing device and method for cryptographic processing of data
JP2011103686A (en) Method for making secure electronic entity with encrypted access
US20130305361A1 (en) Protection of a prime number generation against side-channel attacks
US11646867B2 (en) Systems and methods implementing countermeasures to phase tracking attacks on ring oscillator based entropy sources
US20110274271A1 (en) Countermeasure method and devices for asymmetric encryption
US20130218937A1 (en) Arithmetic apparatus, elliptic scalar multiplication method of arithmetic apparatus, elliptic scalar multiplication program, residue operation method of arithmetic apparatus, and residue operation program
EP3447509A1 (en) Method of testing the resistance of a circuit to a side channel analysis
CN111262686A (en) Security verification method for RSSP-I secure communication
US20180343119A1 (en) System, method, and apparatus for obfuscating device operations
US8707037B2 (en) Cryptographic authentication apparatus, systems and methods
JP2016514315A (en) Method and device for prime number generation
CN116743371A (en) Method and device for determining random number
CN113721986B (en) Data compression method and device, electronic equipment and storage medium
US7797574B2 (en) Control of the execution of an algorithm by an integrated circuit
CN107003903B (en) Method for performing sensitive calculations using multiple distinct and independent branches
US20230198752A1 (en) Masking of key generation operations with random matrices in cryptographic applications
US20230216677A1 (en) Cipher accelerator and differential fault analysis method for encryption/decryption operation
Shoufan A fault attack on a hardware-based implementation of the secure hash algorithm SHA-512

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