WO2013091416A1 - 一种在嵌入式系统中生成大素数的方法 - Google Patents

一种在嵌入式系统中生成大素数的方法 Download PDF

Info

Publication number
WO2013091416A1
WO2013091416A1 PCT/CN2012/081901 CN2012081901W WO2013091416A1 WO 2013091416 A1 WO2013091416 A1 WO 2013091416A1 CN 2012081901 W CN2012081901 W CN 2012081901W WO 2013091416 A1 WO2013091416 A1 WO 2013091416A1
Authority
WO
WIPO (PCT)
Prior art keywords
identifier
modulo value
storage area
value
reset
Prior art date
Application number
PCT/CN2012/081901
Other languages
English (en)
French (fr)
Inventor
陆舟
于华章
Original Assignee
飞天诚信科技股份有限公司
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 飞天诚信科技股份有限公司 filed Critical 飞天诚信科技股份有限公司
Priority to US14/237,363 priority Critical patent/US9419793B2/en
Publication of WO2013091416A1 publication Critical patent/WO2013091416A1/zh

Links

Images

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/0816Key establishment, i.e. cryptographic processes or cryptographic protocols whereby a shared secret becomes available to two or more parties, for subsequent use
    • H04L9/0819Key transport or distribution, i.e. key establishment techniques where one party creates or otherwise obtains a secret value, and securely transfers it to the other(s)
    • 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/60Methods or arrangements for performing computations using a digital non-denominational number representation, i.e. number representation without radix; Computing devices using combinations of denominational and non-denominational quantity representations, e.g. using difunction pulse trains, STEELE computers, phase computers
    • G06F7/72Methods or arrangements for performing computations using a digital non-denominational number representation, i.e. number representation without radix; Computing devices using combinations of denominational and non-denominational quantity representations, e.g. using difunction pulse trains, STEELE computers, phase computers using residue arithmetic

Definitions

  • the present invention relates to the field of cryptography, and in particular to a method for generating large prime numbers in an embedded system.
  • the embedded system needs to generate large prime numbers for encryption and other processes.
  • the key parameters in the RSA encryption process need to use the large prime numbers generated by the embedded system.
  • the process of generating a large prime number includes: first generating a random number of sufficient length; then determining whether the random number is a prime number; and when determining that the random number is not a prime number, regenerating a new set of random numbers or The random number is moderately transformed, and then it is judged again whether the new random number is a prime number until a random number that meets the requirement is generated.
  • the present invention provides a method for generating a large prime number in an embedded system, which is applied to a system including a first storage area and a second storage area, wherein the first storage area stores an identifier group of a preset size.
  • the serial number of the identifier in the identifier group is a continuous number of integers including 0, and different identifiers have different serial numbers;
  • the second storage area includes multiple storage units, and different storage units store different
  • the prime number the method includes the following steps:
  • step 2 determining whether there is a set identifier in the identifier group, if yes, executing step 3; if not, returning to step 1;
  • the determining, by the modulo value and the data stored by the storage unit corresponding to the modulo value, the sequence number of the identifier that needs to be reset in the identifier group specifically:
  • the modulo value When the modulo value is 0, the sum of the integer multiples of the data stored in the storage unit corresponding to the modulo value is used as the sequence number of the identifier to be reset;
  • the modulo value is a non-zero even number
  • the quotient obtained by dividing the current modulo value by 2 is obtained, and the difference between the current prime number and the quotient is used as the sequence number of the identifier that needs to be reset;
  • a result obtained by adding 2 times the serial number of the set identifier to the random number is used as the to-be-tested number.
  • the modulo value When the modulo value is 0, the sum of the integer multiples of the data stored in the storage unit corresponding to the modulo value is used as the sequence number of the identifier to be reset;
  • the modulo value is a non-zero even number
  • the quotient obtained by dividing the modulo value by 2 is used as the sequence number of the identifier to be reset;
  • the difference between the random number and the number of the set identifier is twice as the number to be measured.
  • the generating the random number of the predetermined number of digits including:
  • the generating the random number of the predetermined number of digits including:
  • the invention has the beneficial effects of providing a large prime number generation method suitable for an embedded system, which greatly improves the probability of passing the prime detection by screening the data to be detected with a small prime number before the prime detection. In turn, the efficiency of large prime generation is improved.
  • FIG. 1 is a flowchart of a method for generating a large prime number in an embedded system according to Embodiment 1 of the present invention
  • FIG. 2 is a flowchart of a method for generating a large prime number in an embedded system according to Embodiment 2 of the present invention
  • FIG. 3 is a flowchart of a method for generating a large prime number by a CPU according to Embodiment 3 of the present invention.
  • the first embodiment provides a method for generating a large prime number in an embedded system, and the specific steps are as follows:
  • Step S1 setting all the identifiers in the identifier group of a predetermined size
  • the predetermined size is 768
  • the identifier group contains 768 identifiers.
  • other sizes can be used. For the convenience of description, it is sequentially recorded as the 0th mark, the 1st mark, the ..., the 766th mark, and the 767th mark;
  • Step S2 generating a random number of a predetermined number of bits length
  • the predetermined number of bits is 1024.
  • other bit lengths can be used.
  • step S2 further includes:
  • the lowest bit of the generated random number is not 1, it is set to 1; if the highest bit of the generated random number is not 1, it is set to 1; further, if the generated If the next highest bit of the random number is not 1, set it to 1. This is to ensure that the random number is large enough and not even.
  • step S1 and step S2 can be reversed.
  • Step S3 processing the identification group according to the random number and a predetermined small prime number table.
  • the small prime number table includes all small prime numbers between 3-255: 3, 5, 7, 11, «and many more. In addition to this, other prime numbers can be used.
  • Step S3 is specifically as follows:
  • Step S3-1 taking the current small prime number as a modulus, and modulo the random number to obtain a modulo value
  • the modulo value ranges from 0, 1, ..., n-1. Specifically, for example, if the current prime number is 13, the modulo value ranges from 0, 1, . . .
  • the result of the modulo calculation may be within the range by adding or subtracting an integer multiple of the current small prime number.
  • Step S3-2 Calculate the identification number to be reset in each unit according to the modulo value.
  • step S3-2 is specifically:
  • the identifier number to be reset is 0 and an integer multiple of the current prime number; otherwise, if the modulo value is an odd number, the identifier number to be reset is the current prime number and the fetching a difference between the modulus values divided by 2, and a sum of the result and an integer multiple of the current prime number; otherwise, if the modulo value is an even number, the identification number to be reset is the current prime number and the modulo The difference between the value divided by the quotient of 2, and the sum of the difference and the integer multiple of the current prime number;
  • Step S3-3 Reset the corresponding identifier in the identification group.
  • Step S4 Generate a set of to-be-tested numbers according to the random number and the identifier group, and perform prime detection.
  • the identifier group is sequentially checked, and the following operations are performed:
  • Step S4-1 If all the indicators are checked, the process ends; otherwise, it checks whether the current flag is set. If yes, calculate a sum of 2 times the current identification number and the random number, where the sum is the current number to be tested, and perform a prime detection on the current to-be-tested number; otherwise, continue;
  • Step S4-2 The next flag is set as the current flag, and the process returns to step S4-1.
  • Step S3-2 may be replaced with step S3-2'. Accordingly, step S4-1 is replaced with step S4-1', and the specific contents of step S3-2' and step S4-1' are as follows:
  • Step S3-2' Calculate the identification number to be reset in each unit according to the modulo value.
  • the identifier number to be reset is 0 and an integer multiple of the current prime number; otherwise, if the modulo value is an odd number, the identifier number to be reset is the current prime number and the fetching
  • the sum of the modulo values is further divided by the result of 2, and the sum of the result and the integer multiple of the current prime number; otherwise, if the modulo value is even, the identification number to be reset is the modulo value divided by The result after 2, and the sum of the result and the integer multiple of the current prime number;
  • Step S4-1' If all the indicators are checked, the process ends; otherwise, it checks whether the current flag is set. If yes, calculate a difference between the random number and the current identification sequence number twice, the difference is the current to-be-measured number, and perform a prime detection on the current to-be-tested number; otherwise, continue;
  • the second embodiment provides a method for generating a large prime number in the embedded system based on the first embodiment.
  • the specific steps are as follows:
  • Step 101 The computer sets the value of each data unit in the first storage area to a valid value
  • the size of the first storage area is 768 bits, and each bit is one data unit, corresponding to 768 random number identifiers. Specifically, the sequence number of each data unit is sequentially recorded as 0. 1, 1, ..., 766, 767;
  • the effective value is 1.
  • Step 102 The computer generates a random number of a specified number of bits in a third storage area, and sets it to 1 when the value of the lowest bit of the random number is not 1.
  • the values of the highest bit and the next highest bit of the random number may be set to 1; other settings of the random number may also be performed to facilitate the prime number. Generated, no longer repeat them here;
  • the specified number of bits is 64 bits, that is, a random number of 512 bits is generated, and the random number is recorded as p.
  • Step 103 The computer modulates the data in the third storage area by using the current data in the second storage area, and obtains that the current modulo value is stored in the fourth storage area, when the fourth When the data in the storage fetch is 0, step 106 is performed; when it is odd, step 104 is performed; when it is non-zero even, step 105 is performed;
  • the second storage area includes all small prime numbers between 3-255, each small prime number occupies one storage unit, and the storage unit may be several bits or several bytes;
  • the current data is data in the first storage unit of the second storage area.
  • Step 104 The computer calculates a difference between the current data in the second storage area and the data in the fourth storage area, and divides by 2, and replaces the data in the fourth storage area with the result, and performs step 106. ;
  • Step 105 The computer calculates a difference between a current data in the second storage area and a quotient of data in the fourth storage area divided by 2, and replaces data in the fourth storage area with the difference;
  • Step 106 Set a value of a data unit whose value is a valid value in a corresponding data unit of the first storage area to an invalid value
  • step 107 if the value of the corresponding data unit is an invalid value, step 107 is directly executed;
  • the corresponding data unit is specifically: the data unit whose sequence number value is the current modulo value, and the sequence number value is the current modulo value and the current data in the second storage area.
  • An integer multiple of the sum of the data units; the invalid value is zero.
  • Step 107 The computer determines whether there is a next data unit in the second storage area, and then returns the data in the next data unit as current data, and proceeds to step 103, otherwise step 108 is performed;
  • Step 108 The computer determines whether the value of the current data unit of the first storage area is a valid value, if yes, go to step 109, otherwise go to step 112;
  • the current data unit is a data unit with a sequence number value of 0 in the first storage area.
  • Step 109 The computer calculates a sum of 2 times the serial number value of the current data unit and the data in the third storage area, and performs prime detection on the sum;
  • Step 110 The computer determines whether the sum has passed the prime detection, if yes, step 111 is performed, otherwise step 112 is performed;
  • Step 111 The computer outputs the sum as a large prime number, and ends the process;
  • Step 112 Determine whether there is a next data unit in the first storage area, and then return the next data unit as the current data unit to step 108, otherwise return to step 102.
  • step 101 can be performed at any position prior to step 106.
  • the third embodiment provides a method for generating a large prime number by using a CPU.
  • the specific steps are as follows:
  • Step 201 The CPU opens a first data storage area of a preset size in the memory area, sets a value of each data unit in the first data storage area to be valid, and stores the number of the data unit in the Second data storage area;
  • the data unit may be one bit or one byte, or may be multiple bits or multiple bytes, etc.
  • the data unit is a bit.
  • the data unit has a value of 1 and is valid. When it is 0, it is invalid.
  • each data unit is sequentially numbered as 0, 1, 2, .
  • Step 202 The CPU initializes a first variable i in the first variable storage area
  • the CPU initializes the value of the first variable i to 1.
  • Step 203 The CPU uses the ith data in the fourth data storage area as a modulus, and modulates the data in the third data storage area to obtain a current modulo value, and stores the data in the fourth variable storage area.
  • the third data storage area stores a random number of a specified bit length generated by the random number generator.
  • the random number generator generates a random number with a bit length of 512 bits;
  • a set of prime numbers is stored in the fourth data storage area, and the values of the prime numbers are stored in the fifth data storage area.
  • the fourth data storage area stores 3- All small prime numbers between 255.
  • Step 204 The CPU detects data in the fourth variable storage area.
  • Step 205 The CPU initializes the second variable j in the second variable storage area
  • the CPU When the data in the fourth variable storage area is 0, the CPU initializes the value of the second variable j to the data in the fourth storage area;
  • the CPU When the data in the fourth variable storage area is an odd number, the CPU initializes the value of the second variable j to the difference between the data in the third variable storage area and the ith data in the fourth data storage area. Divide by the value after 2;
  • the CPU initializes the value of the second variable j to the ith data in the fourth data storage area minus the data in the third variable storage area Divide by 2 after the quotient.
  • Step 206 The CPU detects whether the value of the jth data unit in the first data storage area is valid, if yes, step 207 is performed; otherwise, step 208 is performed;
  • Step 207 The CPU sets the value of the jth data unit in the first data storage area to be invalid.
  • Step 208 The CPU updates the value of the second variable j in the second variable storage area.
  • the updating the value of the second variable j in the second variable storage area is specifically updating the value of the second variable j to the second variable j and the The sum of the i-th data in the fourth data storage area.
  • Step 209 The CPU determines whether the value of the second variable j in the second variable storage area is greater than the data in the second data storage area, if yes, step 210 is performed; otherwise, step 206 is performed;
  • Step 210 The CPU updates a value of the first variable i in the first variable storage area.
  • the updating the value of the first variable i in the first variable storage area is specifically updating the value of the first variable i to the first variable i plus one Value.
  • Step 211 The CPU determines whether the value of the first variable i in the first variable storage area is greater than the data in the fifth data storage area, if yes, step 212 is performed, otherwise returns to step 203;
  • Step 212 The CPU initializes a third variable k in the third variable storage area
  • the CPU initializes the value of the third variable k to zero.
  • Step 213 The CPU determines whether the value of the kth data unit in the first data storage area is valid. If yes, step 216 is performed; otherwise, step 214 is performed:
  • Step 214 The CPU updates the value of the third variable k in the third variable storage area.
  • the updating the value of the third variable k in the third variable storage area is specifically updating the value of the third variable k to the third variable k plus one. Value.
  • Step 215 The CPU determines whether the value of the third variable k in the third variable storage area is greater than the data in the second data storage area, and updates the data in the third data storage area, and returns to step 202, otherwise Returning to step 213;
  • Step 216 The CPU calculates a sum of two times the data in the third data storage area and the third variable k in the third variable storage area, and stores the sum in the fifth variable storage area.
  • Step 217 The CPU determines whether the data in the fifth variable storage area can pass the prime detection, if yes, go to step 218, otherwise return to step 214;
  • Step 218 The CPU outputs the data in the fifth variable storage area.
  • the steps in the methods described in connection with the embodiments disclosed herein may be implemented directly in hardware, a software module executed by a processor, or a combination of both.
  • the software module can be placed in random access memory (RAM), memory, read only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or technical field. Any other form of storage medium known.

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Mathematics (AREA)
  • Mathematical Analysis (AREA)
  • Mathematical Optimization (AREA)
  • Pure & Applied Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Mathematical Physics (AREA)
  • General Engineering & Computer Science (AREA)
  • Computing Systems (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)
  • Storage Device Security (AREA)
  • Tests Of Electronic Circuits (AREA)
  • Mobile Radio Communication Systems (AREA)

Abstract

一种在嵌入式系统中生成大素数的方法,包括:①将第一存储区中标识组的全部标识置位;生成预定位长的随机数存于第三存储区,以第二存储区存储单元中存储的数据为模数,对所述第三存储区中的数据取模,根据取模值以及所述取模值对应的存储单元中的数据确定所述标识组中需被复位标识的序号,将所述序号对应的标识复位;②判断所述标识组中是否有置位的标识,是则执行③;否则返回①;③根据所述随机数和所述标识组中置位的标识的序号确定待测数,对所述待测数进行素性检测,若所述待测数通过素性检测则输出所述待测数;若所述标识组中所有置位的标识对应的待测数均未通过素性检测,则返回①,该方法效率高,适用于嵌入式系统。

Description

一种在嵌入式系统中生成大素数的方法 技术领域
本发明涉及密码学领域,特别涉及一种在嵌入式系统中生成大素数的方法。
背景技术
在密码实现过程中,特别是公开密钥密码的实现过程中,需要嵌入式系统生成大素数供加密等过程使用,例如,RSA加密过程中的密钥参数需要使用嵌入式系统生成的大素数。
现有技术中,大素数的生成过程包括:首先生成长度足够的随机数;然后判断该随机数是否为素数;当确定该随机数不为素数时,则重新生成一组新随机数或对当前随机数进行适度变换,然后再次判断新随机数是否为素数,直到生成一个符合要求的随机数。
在上述生成大素数的过程中,发明人发现现有技术中至少存在如下问题:在大素数产生的过程中,需要对很多随机数进行素性检测以判断该随机数是否为素数,由于素性检测需要用到很消耗时间的模幂运算,且素性检测通过的概率并不高,大多数情况下需要寻找数百甚至上千次随机数后才能找到大素数,不适于运用在嵌入式系统中。
发明内容
本发明的目的是提供一种在嵌入式系统中生成大素数的方法,其大大提高素性检测通过的概率,进而提高大素数生成的效率。
为此,本发明提供了一种在嵌入式系统中生成大素数的方法,应用于包括第一存储区和第二存储区的系统中,所述第一存储区存储有预设大小的标识组,所述标识组中的标识的序号为包括0在内的数值连续的整数,且不同的标识具有不同的序号;所述第二存储区包括多个存储单元,不同的存储单元中存储有不同的素数,所述方法包括以下步骤:
①将所述第一存储区中存储的标识组中的全部标识置位;生成预定位数长度的随机数,将所述随机数存储到第三存储区,以所述第二存储区中的存储单元存储的数据为模数,对所述第三存储区存储的数据取模,得到取模值;根据所述取模值以及所述取模值对应的存储单元存储的数据,确定所述标识组中需要被复位的标识的序号,并对所述序号对应的标识进行复位;
②判断所述标识组中是否存在置位的标识,如果存在,则执行步骤③;如果不存在,则返回步骤①;
③根据所述随机数和所述标识组中置位的标识的序号确定待测数,对所述待测数进行素性检测,如果所述待测数通过素性检测,则将所述待测数作为大素数输出;如果所述标识组中所有置位的标识对应的待测数均未通过素性检测,则返回步骤①。
其中,所述根据所述取模值以及所述取模值对应的存储单元存储的数据,确定所述标识组中需要被复位的标识的序号,具体为:
当所述取模值为0时,将所述取模值与所述取模值对应的存储单元存储的数据的整数倍的和,作为所述需要被复位的标识的序号;
当所述取模值为奇数时,获取所述取模值对应的存储单元存储的数据与所述取模值之间的差,将所述差除以2得到的结果作为所述需要被复位的标识的序号;
当所述取模值为非零偶数时,获取所述当前取模值除以2得到的商,将所述当前素数与所述商的差作为所述需要被复位的标识的序号;
所述根据所述随机数和所述标识组中置位的标识的序号确定待测数,具体为:
将所述置位的标识的序号的2倍与所述随机数相加得到的结果,作为所述待测数。
或者,所述根据所述取模值以及所述取模值对应的存储单元存储的数据,确定所述标识组中需要被复位的标识的序号,具体为:
当所述取模值为0时,将所述取模值与所述取模值对应的存储单元存储的数据的整数倍的和,作为所述需要被复位的标识的序号;
当所述取模值为奇数时,获取所述取模值对应的存储单元存储的数据与所述取模值的和,将所述和除以2得到的商作为所述需要被复位的标识的序号;
当所述取模值为非零偶数时,将所述取模值除以2得到的商作为所述需要被复位的标识的序号;
所述根据所述随机数和所述标识组中置位的标识的序号确定待测数,具体为:
将所述随机数与所述置位的标识的序号的2倍的差,作为所述待测数。
其中,所述生成预定位数长度的随机数,包括:
生成预定位数长度的二进制数;
判断所述二进制数的最低位是否为1,如果所述最低位为1,则将所述二进制数作为所述随机数;如果所述最低位不为1,则将所述最低位置为1,并将所述二进制数作为所述随机数。
其中,所述生成预定位数长度的随机数,包括:
生成预定位数长度的二进制数;
判断所述二进制数的最高位是否为1,如果所述最高位为1,则将所述二进制数作为所述随机数;如果所述最高位不为1,则将所述最高位置为1,并将所述二进制数作为所述随机数。
本发明的有益效果在于:提供了一种适用于嵌入式系统的大素数生成方法,所述方法通过在素性检测前用小素数对需要检测的数据进行筛选,大大提高了素性检测通过的概率,进而提高大素数生成的效率。
附图说明
图1为本发明实施例一中提供的一种在嵌入式系统中生成大素数的方法的流程图;
图2为本发明实施例二中提供的一种在嵌入式系统中生成大素数的方法的流程图;
图3为本发明实施例三提供的一种通过CPU生成大素数的方法的流程图。
具体实施方式
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域的技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。
实施例一
参见图1,为了提高素性检测通过的概率,从而提高大素数生成的效率,本实施例一提供了一种在嵌入式系统中生成大素数的方法,具体步骤如下:
步骤S1:将预定大小的标识组中的全部标识置位;
具体地,在本实施例中,所述预定大小为768,所述标识组含有768个标识。除此之外,也可以使用其他大小。为便于描述,依序将其记为第0标识、第1标识、…、第766标识和第767标识;
步骤S2:生成预定位数长度的随机数;
具体地,在本实施例中,所述预定位数长度为1024。除此之外,也可以使用其他位数长度。
优选地,在本实施例中,步骤S2还包括:
如果生成的所述随机数的最低位不为1,则将其置为1;如果生成的所述随机数的最高位不为1,则将其置为1;进一步地,如果生成的所述随机数的次高位不为1,则将其置为1。这是为了保证随机数足够大且不为偶数。
步骤S1和步骤S2的顺序可以颠倒。
步骤S3:根据所述随机数和预定的小素数表对所述标识组进行处理。
具体地,在本实施例中,所述小素数表中包含3-255之间的所有小素数:3, 5, 7, 11, ……等等。除此之外,也可使用其他的素数表。
步骤S3具体为:
对所述小素数表中的每个素数,进行如下步骤:
步骤S3-1:以当前小素数为模数,对所述随机数取模,得到取模值;
若当前小素数为n,则取模值的范围为0,1,……n-1。具体地,例如,当前素数为13,则取模值的范围为0,1,……12。
如果取模计算的结果不在所述范围内,可通过加上或减去当前小素数的整数倍,使结果在所述范围之内。
步骤S3-2:根据所述取模值计算各单元中将要复位的标识编号。
具体地,步骤S3-2具体为:
① 将所述标识组根据当前素数分为多个单元,将单元中的标识依序编号为0、1、…,如果所述取模值为0,所述将要复位的标识编号为0;否则,如果所述取模值为奇数,所述将要复位的标识编号为当前素数与所述取模值之差再除以2;否则,所述取模值为偶数,所述将要复位的标识编号为当前素数减去所述取模值除以2后的结果;
例如,设当前素数为13,则将所述标识组分为(768与13相除,取整加1)60个单元。其中59个单元各有13个标识,最后一个单元有1个标识,如果所述取模值为5,则所述将要复位的标识编号为(13-5)/2 = 4;如果所述取模值为6,则所述将要复位的标识编号为13-(6/2) = 10。
或者为:
② 如果所述取模值为0,所述将要复位的标识编号为0以及当前素数的整数倍;否则,如果所述取模值为奇数,所述将要复位的标识编号为当前素数与所述取模值之差再除以2的结果,以及所述结果与当前素数的整数倍的和;否则,如果所述取模值为偶数,所述将要复位的标识编号为当前素数与所述取模值除以2的商的差,以及所述差与当前素数的整数倍的和;
例如,设当前素数为13,如果所述取模值为5,则所述将要复位的标识编号为(13-5)/2 = 4,以及4与当前素数13的整数倍的和;如果所述取模值为6,则所述将要复位的标识编号为13-(6/2) = 10,以及4与当前素数13的整数倍的和。
步骤S3-3:将标识组中相应标识复位。
如果标识组中没有对应所述编号的标识,则跳过本步骤。
步骤S4:根据所述随机数和所述标识组生成一组待测数,进行素性检测。
具体地,依序检查所述标识组,进行如下操作:
步骤S4-1:如果所有标识都检查完毕,结束;否则,检查当前标识是否置位。如果是,计算当前标识序号的2倍与所述随机数的和,所述和为当前待测数,对当前待测数进行素性检测;否则,继续;
步骤S4-2:将下一个标识设为当前标识,返回步骤S4-1。
步骤S3-2可替换为步骤S3-2',相应地,步骤S4-1替换为步骤S4-1',所述步骤S3-2'和步骤S4-1'的具体内容如下:
步骤S3-2':根据所述取模值计算各单元中将要复位的标识编号。
① 将所述标识组根据当前素数分为多个单元,将单元中的标识依序编号为0、1、…,如果所述取模值为0,所述将要复位的标识编号为0;否则,如果所述取模值为奇数,所述将要复位的标识编号为当前素数与所述取模值之和再除以2;否则,所述取模值为偶数,所述将要复位的标识编号为所述取模值除以2后的结果。
例如,设当前素数为13,则将所述标识组分为(768与13相除,取整加1)60个单元。其中59个单元各有13个标识,最后一个单元有1个标识,如果所述取模值为5,则所述将要复位的标识编号为(13+5)/2 = 9;如果所述取模值为6,则所述将要复位的标识编号为6/2 = 3;
② 如果所述取模值为0,所述将要复位的标识编号为0以及当前素数的整数倍;否则,如果所述取模值为奇数,所述将要复位的标识编号为当前素数与所述取模值之和再除以2的结果,以及所述结果与当前素数的整数倍的和;否则,如果所述取模值为偶数,所述将要复位的标识编号为所述取模值除以2后的结果,以及所述结果与当前素数的整数倍的和;
例如,设当前素数为13,如果所述取模值为5,则所述将要复位的标识编号为(13+5)/2 = 9,以及9与当前素数13的整数倍的和;如果所述取模值为6,则所述将要复位的标识编号为6/2 = 3,以及3与当前素数13的整数倍的和。
步骤S4-1':如果所有标识都检查完毕,结束;否则,检查当前标识是否置位。如果是,计算所述随机数与当前标识序号的2倍的差,所述差为当前待测数,对当前待测数进行素性检测;否则,继续;
实施例二
参见图2,为了提高素性检测通过的概率,从而提高大素数生成的效率,本实施例二在实施例一的基础上提供了一种在嵌入式系统中生成大素数的方法,具体步骤如下:
步骤101:计算机将第一存储区中每一数据单元的值均置为有效值;
优选地,在本实施例中,所述第一存储区的大小为768比特,每1比特为一个数据单元,对应768个随机数标识,具体地,依序记各数据单元的序号值为0、1、…、766、767;
优选地,在本实施例中,所述有效值为1。
步骤102:所述计算机生成指定位数长度的随机数存于第三存储区中,并在所述随机数最低比特位的值不为1时将其置为1;
在本实施例中,为了确保生成的随机数足够大,可以将所述随机数的最高比特位和次高比特位的值均置为1;还可以对随机数进行其他设置,以便于素数的生成,在此不再一一赘述;
优选地,在本实施例中,所述指定位数长度为64位,即生成长度为512比特的随机数,所述随机数记为p,相应地,所述步骤101中,各数据单元分别为随机数p+2*m(m=0,1,2,…,766,767)的标识,所述m为所述存储空间中数据单元的序号值。
步骤103:所述计算机以第二存储区中的当前数据为模数,对所述第三存储区中的数据取模,得到当前取模值存于第四存储区中,当所述第四存储取中的数据为0时,执行步骤106;为奇数时,执行步骤104;为非0偶数时,执行步骤105;
优选地,在本实施例中,所述第二存储区中包含3-255之间的所有小素数,每个小素数占用一个存储单元,所述存储单元可以为若干比特或若干字节;
具体地,在本实施例中,第一次执行所述步骤103时,所述当前数据为所述第二存储区的第一存储单元中的数据。
步骤104:所述计算机计算所述第二存储区中的当前数据和所述第四存储区中的数据的差再除以2,用结果替换所述第四存储区中的数据,执行步骤106;
步骤105:所述计算机计算所述第二存储区中的当前数据与所述第四存储区中的数据除以2的商的差,用所述差替换所述第四存储区中的数据;
步骤106:将所述第一存储区的相应数据单元中值为有效值的数据单元的值置为无效值;
具体地,在本实施例中,若所述相应数据单元的值均为无效值,则直接执行步骤107;
优选地,在本实施例中,所述相应数据单元具体为:序号值为所述当前取模值的数据单元、序号值为所述当前取模值与所述第二存储区中当前数据的整数倍的和的数据单元;所述无效值为0。
步骤107:所述计算机判断所述第二存储区中是否存在下一个数据单元,是则将所述下一个数据单元中的数据作为当前数据,返回执行步骤103,否则执行步骤108;
步骤108:所述计算机判断所述第一存储区的当前数据单元的值是否为有效值,是则执行步骤109,否则执行步骤112;
具体地,在本实施例中,第一次执行所述步骤108时,所述当前数据单元为所述第一存储区中序号值为0的数据单元。
步骤109:所述计算机计算所述当前数据单元的序号值的2倍与所述第三存储区中的数据的和,并对所述和进行素性检测;
步骤110:所述计算机判断所述和是否通过了素性检测,是则执行步骤111,否则执行步骤112;
步骤111:所述计算机将所述和作为大素数输出,结束进程;
步骤112:判断所述第一存储区中是否存在下一个数据单元,是则将所述下一个数据单元作为当前数据单元,返回执行步骤108,否则返回执行步骤102。
在本实施例中,所述步骤101可以在步骤106之前的任意位置执行。
实施例三
参见图3,本实施例三提供了一种通过CPU生成大素数的方法,具体步骤如下:
步骤201:CPU在内存区域中开辟预设大小的第一数据存储区,将所述第一数据存储区中每一数据单元的值均置为有效,并将所述数据单元的个数存于第二数据存储区;
其中,所述数据单元可以为一个比特位或一个字节,也可以为多个比特位或多个字节等,优选地,在本实施例中,所述数据单元为一个比特位,当所述数据单元的值为1时有效,为0时无效;
为便于描述,在本实施例中,将各个数据单元依序编号为0, 1, 2…。
步骤202:CPU初始化第一变量存储区中的第一变量i;
具体地,在本实施例中,CPU将所述第一变量i的值初始化为1。
步骤203:CPU以第四数据存储区中的第i个数据作为模数,对第三数据存储区中的数据取模,得到当前取模值,存于第四变量存储区中;
其中,所述第三数据存储区中存储了随机数发生器生成的指定位长的随机数,优选地,在本实施例中,随机数发生器生成位长为512比特的随机数;
所述第四数据存储区中存储了一组素数,且所述素数的个数值存于第五数据存储区,优选地,在本实施例中,所述第四数据存储区中存储了3-255之间的所有小素数。
步骤204:CPU检测所述第四变量存储区中的数据;
步骤205:CPU初始化第二变量存储区中的第二变量j;
具体地,在本实施例中:
当所述第四变量存储区中的数据为0时,CPU将所述第二变量j的值初始化为所述第四存储区中的数据;
当所述第四变量存储区中的数据为奇数时,CPU将所述第二变量j的值初始化为所述第三变量存储区中的数据与第四数据存储区中的第i数据的差再除以2后的值;
当所述第四变量存储区中的数据为非0偶数时,CPU将所述第二变量j的值初始化为第四数据存储区中的第i数据减去所述第三变量存储区中数据除以2后的商。
步骤206:CPU检测所述第一数据存储区中第j数据单元的值是否有效,是则执行步骤207,否则执行步骤208;
步骤207:CPU将所述第一数据存储区中第j数据单元的值置为无效;
步骤208:CPU更新所述第二变量存储区中所述第二变量j的值;
具体地,在本实施例中,所述更新所述第二变量存储区中所述第二变量j的值具体为将所述第二变量j的值更新为所述第二变量j与所述第四数据存储区中第i数据的和。
步骤209:CPU判断所述第二变量存储区中所述第二变量j的值是否大于所述第二数据存储区中的数据,是则执行步骤210,否则返回执行步骤206;
步骤210:CPU更新所述第一变量存储区中所述第一变量i的值;
具体地,在本实施例中,所述更新所述第一变量存储区中所述第一变量i的值具体为将所述第一变量i的值更新为所述第一变量i加1后的值。
步骤211:CPU判断所述第一变量存储区中所述第一变量i的值是否大于所述第五数据存储区中的数据,是则执行步骤212,否则返回执行步骤203;
步骤212:CPU初始化第三变量存储区中的第三变量k;
具体地,在本实施例中,所述CPU将所述第三变量k的值初始化为0。
步骤213:CPU判断所述第一数据存储区中的第k数据单元的值是否有效,是则执行步骤216,否则执行步骤214:
步骤214:CPU更新所述第三变量存储区中所述第三变量k的值;
具体地,在本实施例中,所述更新所述第三变量存储区中所述第三变量k的值具体为将所述第三变量k的值更新为所述第三变量k加1后的值。
步骤215:CPU判断所述第三变量存储区中第三变量k的值是否大于所述第二数据存储区中的数据,是则更新第三数据存储区中的数据,返回执行步骤202,否则返回执行步骤213;
步骤216:CPU计算所述第三数据存储区中的数据与所述第三变量存储区中第三变量k的2倍的和,存于第五变量存储区;
步骤217:CPU判断所述第五变量存储区中的数据可否通过素性检测,是则执行步骤218,否则返回执行步骤214;
步骤218:CPU输出所述第五变量存储区中的数据。
结合本文中所公开的实施例描述的方法中的步骤可以直接用硬件、处理器执行的软件模块,或者二者的结合来实施。软件模块可以置于随机存储器(RAM)、内存、只读存储器(ROM)、电可编程ROM、电可擦除可编程ROM、寄存器、硬盘、可移动磁盘、CD-ROM、或技术领域内所公知的任意其它形式的存储介质中。
以上仅为本发明的具体实施方式,本发明的保护范围并不局限于此,本领域的技术人员在本发明揭露的技术范围内,可轻易想到的变化或替换都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应以权利要求书限定的保护范围为准。

Claims (5)

  1. 一种在嵌入式系统中生成大素数的方法,用于包括第一存储区和第二存储区的系统中,其特征在于,所述第一存储区存储有预设大小的标识组,所述标识组中的标识的序号为包括0在内的数值连续的整数,且不同的标识具有不同的序号;所述第二存储区包括多个存储单元,不同的存储单元中存储有不同的素数,所述方法包括以下步骤:
    ①将所述第一存储区中存储的标识组中的全部标识置位;生成预定位数长度的随机数,将所述随机数存储到第三存储区,以所述第二存储区中的存储单元存储的数据为模数,对所述第三存储区存储的数据取模,得到取模值;根据所述取模值以及所述取模值对应的存储单元存储的数据,确定所述标识组中需要被复位的标识的序号,并对所述序号对应的标识进行复位;
    ②判断所述标识组中是否存在置位的标识,如果存在,则执行步骤③;如果不存在,则返回步骤①;
    ③根据所述随机数和所述标识组中置位的标识的序号确定待测数,对所述待测数进行素性检测,如果所述待测数通过素性检测,则将所述待测数作为大素数输出;如果所述标识组中所有置位的标识对应的待测数均未通过素性检测,则返回步骤①。
  2. 如权利要求1所述的方法,其特征在于,所述根据所述取模值以及所述取模值对应的存储单元存储的数据,确定所述标识组中需要被复位的标识的序号,具体为:
    当所述取模值为0时,将所述取模值与所述取模值对应的存储单元存储的数据的整数倍的和,作为所述需要被复位的标识的序号;
    当所述取模值为奇数时,获取所述取模值对应的存储单元存储的数据与所述取模值之间的差,将所述差除以2得到的结果作为所述需要被复位的标识的序号;
    当所述取模值为非零偶数时,获取所述当前取模值除以2得到的商,将所述当前素数与所述商的差作为所述需要被复位的标识的序号;
    所述根据所述随机数和所述标识组中置位的标识的序号确定待测数,具体为:
    将所述置位的标识的序号的2倍与所述随机数相加得到的结果,作为所述待测数。
  3. 如权利要求1所述的方法,其特征在于,所述根据所述取模值以及所述取模值对应的存储单元存储的数据,确定所述标识组中需要被复位的标识的序号,具体为:
    当所述取模值为0时,将所述取模值与所述取模值对应的存储单元存储的数据的整数倍的和,作为所述需要被复位的标识的序号;
    当所述取模值为奇数时,获取所述取模值对应的存储单元存储的数据与所述取模值的和,将所述和除以2得到的商作为所述需要被复位的标识的序号;
    当所述取模值为非零偶数时,将所述取模值除以2得到的商作为所述需要被复位的标识的序号;
    所述根据所述随机数和所述标识组中置位的标识的序号确定待测数,具体为:
    将所述随机数与所述置位的标识的序号的2倍的差,作为所述待测数。
  4. 如权利要求1所述的方法,其特征在于,所述生成预定位数长度的随机数,包括:
    生成预定位数长度的二进制数;
    判断所述二进制数的最低位是否为1,如果所述最低位为1,则将所述二进制数作为所述随机数;如果所述最低位不为1,则将所述最低位置为1,并将所述二进制数作为所述随机数。
  5. 如权利要求1所述的方法,其特征在于,所述生成预定位数长度的随机数,包括:
    生成预定位数长度的二进制数;
    判断所述二进制数的最高位是否为1,如果所述最高位为1,则将所述二进制数作为所述随机数;如果所述最高位不为1,则将所述最高位置为1,并将所述二进制数作为所述随机数。
PCT/CN2012/081901 2011-12-23 2012-09-25 一种在嵌入式系统中生成大素数的方法 WO2013091416A1 (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
US14/237,363 US9419793B2 (en) 2011-12-23 2012-09-25 Method for generating large prime number in embedded system

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201110439890.2A CN102591618B (zh) 2011-12-23 2011-12-23 一种在嵌入式系统中生成大素数的方法
CN201110439890.2 2011-12-23

Publications (1)

Publication Number Publication Date
WO2013091416A1 true WO2013091416A1 (zh) 2013-06-27

Family

ID=46480354

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2012/081901 WO2013091416A1 (zh) 2011-12-23 2012-09-25 一种在嵌入式系统中生成大素数的方法

Country Status (3)

Country Link
US (1) US9419793B2 (zh)
CN (1) CN102591618B (zh)
WO (1) WO2013091416A1 (zh)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102591618B (zh) * 2011-12-23 2014-12-10 飞天诚信科技股份有限公司 一种在嵌入式系统中生成大素数的方法
CN105071928A (zh) * 2015-07-08 2015-11-18 路博超 一种基于fpga的大素数暨大素数族的快速生成方法

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP1465366A1 (en) * 2001-04-17 2004-10-06 Matsushita Electric Industrial Co., Ltd. Information security device, prime number generation device, and prime number generation method
CN1688973A (zh) * 2002-06-21 2005-10-26 爱特梅尔股份有限公司 检验密码应用的可能素数
CN102279840A (zh) * 2011-08-31 2011-12-14 刘诗章 一种适用于信息加密技术应用的素数族快速生成方法
CN102591618A (zh) * 2011-12-23 2012-07-18 飞天诚信科技股份有限公司 一种在嵌入式系统中生成大素数的方法

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP3518672B2 (ja) * 1998-11-27 2004-04-12 村田機械株式会社 素数生成装置及び暗号システム
US7120248B2 (en) * 2001-03-26 2006-10-10 Hewlett-Packard Development Company, L.P. Multiple prime number generation using a parallel prime number search algorithm
CN1898898A (zh) * 2003-12-26 2007-01-17 松下电器产业株式会社 素数计算装置和方法以及密钥发行系统
JP5848106B2 (ja) * 2011-11-28 2016-01-27 ルネサスエレクトロニクス株式会社 半導体装置及びicカード

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP1465366A1 (en) * 2001-04-17 2004-10-06 Matsushita Electric Industrial Co., Ltd. Information security device, prime number generation device, and prime number generation method
CN1688973A (zh) * 2002-06-21 2005-10-26 爱特梅尔股份有限公司 检验密码应用的可能素数
CN102279840A (zh) * 2011-08-31 2011-12-14 刘诗章 一种适用于信息加密技术应用的素数族快速生成方法
CN102591618A (zh) * 2011-12-23 2012-07-18 飞天诚信科技股份有限公司 一种在嵌入式系统中生成大素数的方法

Also Published As

Publication number Publication date
CN102591618B (zh) 2014-12-10
US9419793B2 (en) 2016-08-16
US20140185799A1 (en) 2014-07-03
CN102591618A (zh) 2012-07-18

Similar Documents

Publication Publication Date Title
WO2015102253A1 (ko) 디지털 값 처리 장치 및 방법
JP2005531031A5 (zh)
CN1989726A (zh) 用于执行加密计算的方法和装置
WO2013091416A1 (zh) 一种在嵌入式系统中生成大素数的方法
JP2010210940A (ja) 演算装置及びプログラム
CN110969207A (zh) 电子证据处理方法、装置、设备以及存储介质
WO2018090759A1 (zh) 一种系统启动文件的校验及编译方法
WO2020105797A1 (ko) 다항식 연산 최적화 처리 장치, 다항식 연산 최적화 처리 방법 및 기록매체
McGrew et al. RFC 8554: Leighton-Micali hash-based signatures
Leiserson et al. Using de Bruijn sequences to index a 1 in a computer word
Barenghi et al. A novel fault attack against ECDSA
CN112737778B (zh) 数字签名生成、验证方法及装置、电子设备及存储介质
WO2014119834A1 (ko) 리셋 신호 경로상의 버퍼를 이용한 광학 오류 주입 탐지 회로
CN105678083A (zh) 一种具有单比特频数检测和块内频数检测的快速检测方法
WO2018199444A1 (en) Apparatus and method for performing operation being secure against side channel attack
AU2018101695A4 (en) An apparatus and method based on sliding window with One’s complementary subtraction recoding in scalar multiplication of ECC to avoid simple power analysis attacks on IoT devices.
Zhang et al. The algebraic normal form, linear complexity and k-error linear complexity of single-cycle T-function
WO2013115429A1 (en) Apparatus and method for generating interleaver index
WO2021161304A1 (en) Methods and ip cores for reducing vulnerability to hardware attacks and/or improving processor performance
Xu et al. A digital copyright protection scheme for soft-IP core based on FSMs
WO2014133241A1 (ko) 분산 네트워크 시스템의 통신 에러 노드 검출 방법
WO2016099069A1 (ko) 고분자의 동일성 평가 방법 및 이를 이용한 시스템
WO2017052125A1 (ko) 비트 수를 증가시킨 sram 기반 tcam의 동작 방법 및 시스템
RU2800039C1 (ru) Устройство для детектирования групп единичных бит и максимальной группы в блоках данных
Cho et al. Block-interleaving based parallel CRC computation for multi-processor systems

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 12860727

Country of ref document: EP

Kind code of ref document: A1

WWE Wipo information: entry into national phase

Ref document number: 14237363

Country of ref document: US

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 12860727

Country of ref document: EP

Kind code of ref document: A1