[go: up one dir, main page]

CN104753684B - A kind of method for realizing digital signature and sign test - Google Patents

A kind of method for realizing digital signature and sign test Download PDF

Info

Publication number
CN104753684B
CN104753684B CN201510177842.9A CN201510177842A CN104753684B CN 104753684 B CN104753684 B CN 104753684B CN 201510177842 A CN201510177842 A CN 201510177842A CN 104753684 B CN104753684 B CN 104753684B
Authority
CN
China
Prior art keywords
data
register
result
preset
memory
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.)
Expired - Fee Related
Application number
CN201510177842.9A
Other languages
Chinese (zh)
Other versions
CN104753684A (en
Inventor
陆舟
于华章
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Feitian Technologies Co Ltd
Original Assignee
Feitian Technologies 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 Feitian Technologies Co Ltd filed Critical Feitian Technologies Co Ltd
Priority to CN201510177842.9A priority Critical patent/CN104753684B/en
Publication of CN104753684A publication Critical patent/CN104753684A/en
Application granted granted Critical
Publication of CN104753684B publication Critical patent/CN104753684B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Storage Device Security (AREA)

Abstract

本发明公开了一种实现数字签名和验签的方法,属于信息安全领域,所述方法包括:CPU将哈希结果与第一预设存储器中的数据进行模运算,结果保存至第三寄存器中;对第一随机数存储器、第四、第五寄存器、第一预设存储器中的数据进行运算,结果保存至第七寄存器中;对读取的签名私钥、第七寄存器、第三寄存器和第一随机存储器中的数据进行处理,结果保存至第八寄存器中;将第七、第八寄存器中的数据作为签名结果输出。采用本发明的技术方案,能够实现身份认证,保证数据的完整性和不可抵赖性,而且对模运算参数和椭圆曲线参数进行初始化,提高了运算效率,除此之外,验签的过程中有对公钥的验证,更加提高了签名的安全性。

The invention discloses a method for realizing digital signature and signature verification, which belongs to the field of information security. The method includes: the CPU performs modulo calculation on the hash result and the data in the first preset memory, and saves the result in the third register ;Operate the data in the first random number memory, the fourth and fifth registers, and the first preset memory, and store the result in the seventh register; read the signature private key, the seventh register, the third register and The data in the first random access memory is processed, and the result is stored in the eighth register; the data in the seventh and eighth registers are output as the signature result. Adopting the technical scheme of the present invention can realize identity authentication, ensure the integrity and non-repudiation of data, and initialize the modulus operation parameters and elliptic curve parameters, which improves the operation efficiency. The verification of the public key further improves the security of the signature.

Description

一种实现数字签名和验签的方法A Method for Realizing Digital Signature and Signature Verification

技术领域technical field

本发明涉及信息安全领域,尤其涉及一种实现数字签名和验签的方法。The invention relates to the field of information security, in particular to a method for realizing digital signature and signature verification.

背景技术Background technique

数字签名是附加在数据单元上的一些数据或者是对数据单元所作的密码变化,这种数据或变化只允许数据单元的接收者用以确认数据单元的来源和数据单元的完整性,保护数据防止被他人伪造。数字签名是基于公钥密码体制和私钥密码体制实现的。A digital signature is some data attached to a data unit or a cryptographic change made to a data unit. This data or change only allows the receiver of the data unit to confirm the source of the data unit and the integrity of the data unit, protecting the data from forged by others. Digital signature is realized based on public key cryptosystem and private key cryptosystem.

发明内容Contents of the invention

本发明提供了一种实现数字签名和验签的方法,采用的技术方案是:一种实现数字签名的方法,包括:The present invention provides a method for realizing digital signature and signature verification. The adopted technical solution is: a method for realizing digital signature, comprising:

步骤S1:CPU读取哈希结果,并读取第一预设存储器中的数据,将所述哈希结果与所述第一预设存储器中的数据进行模运算,将结果保存至第二寄存器中;Step S1: The CPU reads the hash result, reads the data in the first preset memory, performs a modulo operation on the hash result and the data in the first preset memory, and saves the result to the second register middle;

步骤S2:CPU读取第一随机数存储器、第二预设存储器和第三预设存储器中的数据,将所述第一随机数存储器中的数据与所述第二预设存储器和所述第三预设存储器中的数据进行点乘运算,将运算结果保存至第三寄存器中;Step S2: CPU reads the data in the first random number memory, the second preset memory and the third preset memory, and combines the data in the first random number memory with the second preset memory and the third preset memory Dot multiplication operation is performed on the data in the three preset memories, and the operation result is saved in the third register;

步骤S3:CPU将所述第三寄存器中的数据与所述第一预设存储器中的数据进行模运算,将结果保存至第四寄存器中;Step S3: The CPU performs a modulo operation on the data in the third register and the data in the first preset memory, and saves the result in the fourth register;

步骤S4:CPU读取签名私钥,对所述签名私钥、所述第二寄存器中的数据、所述第四寄存器中的数据和所述第一随机数存储器中的数据进行预设运算,将结果保存至第五寄存器中;Step S4: The CPU reads the signature private key, and performs preset operations on the signature private key, the data in the second register, the data in the fourth register, and the data in the first random number memory, Save the result to the fifth register;

步骤S5:CPU将所述第四寄存器中的数据和所述第五寄存器中的数据作为签名结果输出。Step S5: The CPU outputs the data in the fourth register and the data in the fifth register as a signature result.

所述步骤S1之前还包括:CPU接收外部传入的待签名数据,对所述待签名数据进行预设哈希运算,将运算得到的哈希结果保存。Before the step S1, the method further includes: the CPU receives the data to be signed from outside, performs a preset hash operation on the data to be signed, and saves the hash result obtained from the operation.

所述步骤S1之前还包括:CPU将模运算参数设置为第一预设值,并保存至所述第一预设存储器中,将椭圆曲线参数设置为第二预设值和第三预设值,将第二预设值保存至所述第二预设存储器中,将第三预设值保存至所述第三预设存储器中。Before the step S1, it also includes: the CPU sets the modulo operation parameter as the first preset value and saves it in the first preset memory, and sets the elliptic curve parameter as the second preset value and the third preset value , saving the second preset value into the second preset memory, and saving the third preset value into the third preset memory.

所述步骤S1与所述步骤S2之间还包括:CPU判断所述第二寄存器中的数据是否为第四预设值,如果是,则将所述第二寄存器中的数据设置为第五预设值,执行步骤S2,否则直接执行步骤S2。Between the step S1 and the step S2, it also includes: the CPU judges whether the data in the second register is the fourth preset value, and if yes, sets the data in the second register to the fifth preset value. Set the value, execute step S2, otherwise directly execute step S2.

所述步骤S2之前还包括:Also include before the step S2:

步骤a:CPU生成随机数,判断所述随机数是否大于第四预设值且小于第一预设值,如果是,则将所述随机数保存至所述第一随机数存储器中,执行步骤S2,否则继续执行步骤a。Step a: the CPU generates a random number, judges whether the random number is greater than the fourth preset value and smaller than the first preset value, if yes, saves the random number into the first random number memory, and executes the step S2, otherwise proceed to step a.

所述步骤S3与所述步骤S4之间,还包括:判断所述第四寄存器中的数据是否为第四预设值,如果是,则执行步骤S4,否则返回步骤a。Between the step S3 and the step S4, it further includes: judging whether the data in the fourth register is the fourth preset value, and if so, executing step S4, otherwise returning to step a.

所述步骤S4中,所述对所述签名私钥、所述第二寄存器中的数据、所述第四寄存器中的数据和所述第一随机数存储器中的数据进行预设运算,将结果保存至第五寄存器中,具体为:In the step S4, the preset operation is performed on the signature private key, the data in the second register, the data in the fourth register and the data in the first random number memory, and the result Save to the fifth register, specifically:

步骤a1:CPU将所述第四寄存器中的数据与所述签名私钥做乘法,将结果保存至第一中间值存储器中,将所述第一随机数存储器中的数据与所述第二寄存器中的数据做乘法,将结果保存至第二中间值存储器中;Step a1: The CPU multiplies the data in the fourth register by the signature private key, saves the result in the first intermediate value memory, and multiplies the data in the first random number memory by the second register The data in is multiplied, and the result is stored in the second intermediate value memory;

步骤a2:CPU将所述第一中间值存储器中的数据与所述第二中间值存储器中的数据相加,将结果保存至第三中间值存储器中;Step a2: The CPU adds the data in the first intermediate value memory to the data in the second intermediate value memory, and saves the result in the third intermediate value memory;

步骤a3:CPU将所述第三中间值存储器中的数据与所述第一预设存储器中的数据做模运算,将结果保存至所述第五寄存器中。Step a3: The CPU performs a modulo operation on the data in the third intermediate value memory and the data in the first preset memory, and saves the result in the fifth register.

所述步骤S4和所述步骤S5之间,还包括:CPU判断所述第五寄存器中的数据是否为第四预设值,如果是,则返回执行步骤a,否则执行步骤S5。Between the step S4 and the step S5, it further includes: the CPU judges whether the data in the fifth register is the fourth preset value, and if yes, returns to step a, otherwise executes step S5.

所述步骤S5,具体为:CPU将所述第四寄存器中的数据和所述第五寄存器中的数据进行组合,并输出。The step S5 specifically includes: the CPU combines the data in the fourth register and the data in the fifth register, and outputs the combined data.

所述将所述第四寄存器中的数据和所述第五寄存器中的数据进行组合,得到签名结果,具体为:将所述第四寄存器中的数据与所述第五寄存器中的数据进行拼接,得到签名结果。The combination of the data in the fourth register and the data in the fifth register to obtain a signature result is specifically: splicing the data in the fourth register and the data in the fifth register , get the signature result.

一种实现数字验签的方法,包括:A method for realizing digital signature verification, comprising:

步骤T1:CPU读取签名结果,对所述签名结果进行处理,将得到的两个结果分别保存至第八寄存器和第九寄存器中,读取待签名数据,对所述待签名数据进行哈希计算,将结果保存至第十寄存器中;Step T1: The CPU reads the signature result, processes the signature result, saves the obtained two results into the eighth register and the ninth register respectively, reads the data to be signed, and hashes the data to be signed Calculate and save the result to the tenth register;

步骤T2:CPU读取第一预设存储器中的数据,将所述第十寄存器中的数据与第一预设存储器中的数据进行模运算,将结果保存至第十一寄存器中;Step T2: the CPU reads the data in the first preset memory, performs a modulo operation on the data in the tenth register and the data in the first preset memory, and saves the result in the eleventh register;

步骤T3:CPU计算所述第十一寄存器中的数据与所述第一预设存储器中的数据取模的逆元,将结果保存至第十二寄存器中;Step T3: The CPU calculates the inverse of the modulo between the data in the eleventh register and the data in the first preset memory, and saves the result in the twelfth register;

步骤T4:CPU对所述第九寄存器中的数据、所述第十二寄存器中的数据和所述第一预设存储器中的数据进行处理,将结果保存至第十三寄存器中,对所述第八寄存器中的数据、所述第十二寄存器中的数据和所述第一预设存储器中的数据进行处理,将结果保存至第十四寄存器中;Step T4: The CPU processes the data in the ninth register, the data in the twelfth register, and the data in the first preset memory, saves the result to the thirteenth register, and performs processing on the Processing the data in the eighth register, the data in the twelfth register and the data in the first preset memory, and storing the result in the fourteenth register;

步骤T5:CPU读取签名公钥,对所述第十三寄存器中的数据、所述第十四寄存器中的数据和所述签名公钥进行预设运算,将结果保存至第十五寄存器中;Step T5: The CPU reads the signature public key, performs preset operations on the data in the thirteenth register, the data in the fourteenth register, and the signature public key, and saves the result in the fifteenth register ;

步骤T6:CPU将所述第十五寄存器中的数据与所述第一预设存储器中的数据进行模运算,将结果保存至第十六寄存器中;Step T6: The CPU performs a modulo operation on the data in the fifteenth register and the data in the first preset memory, and saves the result in the sixteenth register;

步骤T7:CPU判断所述第十六寄存器中的数据与所述第八寄存器中的数据是否相等,如果是,则输出验签成功信息,否则输出验签失败信息。Step T7: The CPU judges whether the data in the sixteenth register is equal to the data in the eighth register, and if so, outputs signature verification success information, otherwise outputs signature verification failure information.

所述步骤T2之前还包括:CPU将模运算参数设置为第一预设值,并保存至所述第一预设存储器中;CPU将椭圆曲线参数设置为第二预设值和第三预设值,将所述第二预设值保存至所述第二预设存储器中,将所述第三预设值保存至所述第三预设存储器中。Before the step T2, it also includes: the CPU sets the modulo operation parameter to the first preset value and saves it in the first preset memory; the CPU sets the elliptic curve parameter to the second preset value and the third preset value, saving the second preset value into the second preset memory, and saving the third preset value into the third preset memory.

所述步骤T1与所述步骤T2之间,还包括:CPU判断所述第八寄存器中的数据与所述第九寄存器中的数据是否均大于第四预设值且小于第一预设值,如果是,则执行步骤T2,否则报错,结束。Between the step T1 and the step T2, further comprising: CPU judging whether the data in the eighth register and the data in the ninth register are both larger than the fourth preset value and smaller than the first preset value, If yes, execute step T2, otherwise report an error and end.

所述步骤T2与所述步骤T3之间,还包括:CPU判断所述第十一寄存器中的数据是否为第四预设值,如果是,则将所述第十一寄存器中的数据设置为第五预设值,执行步骤T3,否则直接执行步骤T3。Between the step T2 and the step T3, it also includes: the CPU judges whether the data in the eleventh register is the fourth preset value, and if yes, sets the data in the eleventh register to The fifth preset value, execute step T3, otherwise directly execute step T3.

所述步骤T4中,所述对所述第九寄存器中的数据、所述第十二寄存器中的数据和所述第一预设存储器中的数据进行处理,将结果保存至第十三寄存器中,具体为:CPU计算所述第九寄存器中的数据与所述第十二寄存器中的数据的乘积,将乘积结果与所述第一预设存储器中的数据进行模运算,将模运算结果保存至所述第十三寄存器中。In the step T4, the data in the ninth register, the data in the twelfth register and the data in the first preset memory are processed, and the result is saved in the thirteenth register , specifically: the CPU calculates the product of the data in the ninth register and the data in the twelfth register, performs a modulo operation on the product result and the data in the first preset memory, and saves the result of the modulo operation to the thirteenth register.

所述步骤T4中,所述对所述第八寄存器中的数据、所述第十二寄存器中的数据和所述第一预设存储器中的数据进行处理,将结果保存至第十四寄存器中,具体为:CPU计算所述第八寄存器中的数据与所述第十二寄存器中的数据的乘积,将乘积结果与所述第一预设存储器中的数据进行模运算,将模运算结果保存至所述第十四寄存器中。In the step T4, the data in the eighth register, the data in the twelfth register and the data in the first preset memory are processed, and the result is saved in the fourteenth register , specifically: the CPU calculates the product of the data in the eighth register and the data in the twelfth register, performs a modulo operation on the product result and the data in the first preset memory, and saves the result of the modulo operation to the fourteenth register.

所述步骤T5,具体包括:The step T5 specifically includes:

步骤b1:CPU读取第二预设存储器和第三预设存储器中的数据,并读取签名公钥;Step b1: CPU reads the data in the second preset memory and the third preset memory, and reads the signature public key;

步骤b2:CPU将所述第十三寄存器中的数据与所述第二预设存储器中的数据和所述第三预设存储器中的数据进行点乘运算,将运算得到的两个结果分别保存至第四中间值存储器和第五中间值存储器中;Step b2: The CPU performs a dot multiplication operation on the data in the thirteenth register, the data in the second preset memory and the data in the third preset memory, and saves the two results obtained by the operation respectively to the fourth intermediate value memory and the fifth intermediate value memory;

步骤b3:CPU将所述第十四寄存器中的数据与所述签名公钥做乘法,将运算得到的两个结果分别保存至第六中间值存储器和第七中间值存储器中;Step b3: The CPU multiplies the data in the fourteenth register by the signature public key, and saves the two results obtained by the operation into the sixth intermediate value memory and the seventh intermediate value memory;

步骤b4:CPU对所述第四中间值存储器、所述第五中间值存储器、所述第六中间值存储器和所述第七中间值存储器中的数据进行计算,将计算结果保存至所述第十五寄存器中。Step b4: The CPU calculates the data in the fourth intermediate value memory, the fifth intermediate value memory, the sixth intermediate value memory and the seventh intermediate value memory, and saves the calculation result in the first Fifteen registers.

本发明取得的有益效果是:采用本发明的技术方案,能够实现身份认证,保证数据的完整性和不可抵赖性,而且对模运算参数和椭圆曲线参数进行初始化,提高了运算效率,验签的过程中对公钥的验证,更加提高了签名的安全性。The beneficial effects obtained by the present invention are: adopting the technical scheme of the present invention, identity authentication can be realized, data integrity and non-repudiation can be guaranteed, and the modulo operation parameters and elliptic curve parameters can be initialized to improve the operation efficiency, and the signature verification The verification of the public key in the process further improves the security of the signature.

附图说明Description of drawings

为了更清楚的说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单的介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings that need to be used in the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are only These are some embodiments of the present invention. Those skilled in the art can also obtain other drawings based on these drawings without creative work.

图1是本发明实施例1提供的一种实现数字签名的方法流程图;FIG. 1 is a flow chart of a method for realizing a digital signature provided by Embodiment 1 of the present invention;

图2是本发明实施例2提供的一种实现数字签名的方法流程图;FIG. 2 is a flow chart of a method for implementing a digital signature provided by Embodiment 2 of the present invention;

图3是本发明实施例3提供的一种实现数字验签的方法流程图Figure 3 is a flow chart of a method for realizing digital signature verification provided by Embodiment 3 of the present invention

图4是本发明实施例4提供的一种实现数字验签的方法流程图。Fig. 4 is a flow chart of a method for implementing digital signature verification provided by Embodiment 4 of the present invention.

具体实施方式detailed description

下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only some, not all, embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by persons of ordinary skill in the art without making creative efforts belong to the protection scope of the present invention.

实施例1Example 1

本发明实施例1提供了一种实现数字签名的方法,如图1所示,包括:Embodiment 1 of the present invention provides a method for realizing a digital signature, as shown in Figure 1, including:

步骤S1:CPU读取哈希结果,并读取第一预设存储器中的数据,将哈希结果与第一预设存储器中的数据进行模运算,将结果保存至第二寄存器中;Step S1: The CPU reads the hash result, and reads the data in the first preset memory, performs a modulo operation on the hash result and the data in the first preset memory, and saves the result in the second register;

步骤S2:CPU读取第一随机数存储器、第二预设存储器和第三预设存储器中的数据,将第一随机数存储器中的数据与第二预设存储器和第三预设存储器中的数据进行点乘运算,将运算结果保存至第三寄存器中;Step S2: CPU reads the data in the first random number memory, the second preset memory and the third preset memory, and compares the data in the first random number memory with the data in the second preset memory and the third preset memory The data is multiplied by dot, and the operation result is saved in the third register;

步骤S3:CPU将第三寄存器中的数据与第一预设存储器中的数据进行模运算,将结果保存至第四寄存器中;Step S3: The CPU performs a modulo operation on the data in the third register and the data in the first preset memory, and saves the result in the fourth register;

步骤S4:CPU读取签名私钥,对签名私钥、第四寄存器中的数据、第二寄存器中的数据和第一随机数存储器中的数据进行预设运算,将结果保存至第五寄存器中;Step S4: The CPU reads the signature private key, performs preset operations on the signature private key, the data in the fourth register, the data in the second register and the data in the first random number memory, and saves the result in the fifth register ;

步骤S5:CPU将第四寄存器中的数据和第五寄存器中的数据作为签名结果输出。Step S5: The CPU outputs the data in the fourth register and the data in the fifth register as a signature result.

实施例2Example 2

本发明实施例2提供了一种实现数字签名的方法,如图2所示,包括:Embodiment 2 of the present invention provides a method for implementing a digital signature, as shown in Figure 2, including:

步骤101:CPU读取第一寄存器中的哈希结果;Step 101: the CPU reads the hash result in the first register;

本实施例中,CPU对外部传入的待签名数据进行预设哈希运算,得到哈希结果,保存至第一寄存器中;In this embodiment, the CPU performs a preset hash operation on the data to be signed externally, obtains the hash result, and saves it in the first register;

例如,待签名数据为0x499602D2;For example, the data to be signed is 0x499602D2;

经过预设哈希运算后得到的第一寄存器中的第一哈希数据为:The first hash data in the first register obtained after the preset hash operation is:

0x1785EC310767F81A8D9FD076D39074261C13EA788B9311DEE3CAFF2ECF00670D;0x1785EC310767F81A8D9FD076D39074261C13EA788B9311DEE3CAFF2ECF00670D;

步骤102:CPU初始化模运算参数,将模运算参数设置为第一预设值,并保存至第一预设存储器中,将椭圆曲线参数设置为第二预设值和第三预设值,将第二预设值保存至第二预设存储器中,将第三预设值保存至第三预设存储器中;Step 102: CPU initializes the modulo operation parameters, sets the modulo operation parameters as the first preset value, and saves them in the first preset memory, sets the elliptic curve parameters as the second preset value and the third preset value, and sets saving the second preset value into the second preset memory, and saving the third preset value into the third preset memory;

本实施例中,优选的,第一预设值为:In this embodiment, preferably, the first preset value is:

0x8000000000000000000000000000000150FE8A1892976154C59CFC193ACCF5B3;0x8000000000000000000000000000000150FE8A1892976154C59CFC193ACCF5B3;

步骤103:CPU读取第一预设存储器中的数据,将第一寄存器中的哈希结果与第一预设存储器中的第一预设值进行模运算,将模运算结果保存至第二寄存器中;Step 103: The CPU reads the data in the first preset memory, performs a modulo operation on the hash result in the first register and the first preset value in the first preset memory, and saves the result of the modulo operation in the second register middle;

例如,CPU将第一寄存器中的哈希数据0x1785EC310767F81A8D9FD076D39074261C13EA788B9311DEE3CAFF2ECF00670D与第一预设值0x8000000000000000000000000000000150FE8A1892976154C59CFC193ACCF5B3进行模运算,得到的结果为:For example, the CPU calculates the hash data 0x1785EC310767F81A8D9FD076D39074261C13EA788B9311DEE3CAFF2ECF00670D in the first register and the first preset value 0x8000000000000000000000000000000150CFB to obtain ACFC53C modulo 8A1892976154C3C.

0x2DFBC1B372D89A1188C09C52E0EEC61FCE52032AB1022E8E67ECE6672B043EE5,将该数据存储至第二寄存器中;0x2DFBC1B372D89A1188C09C52E0EEC61FCE52032AB1022E8E67ECE6672B043EE5, store the data in the second register;

步骤104:CPU判断第二寄存器中的数据是否为第四预设值,如果是,则将第二寄存器中的数据设置为第五预设值,执行步骤105,否则直接执行步骤105;Step 104: CPU judges whether the data in the second register is the fourth preset value, if yes, then sets the data in the second register to the fifth preset value, and executes step 105, otherwise directly executes step 105;

优选的,第四预设值为0,第五预设值为1;Preferably, the fourth preset value is 0, and the fifth preset value is 1;

步骤105:CPU生成随机数并保存至第一随机数存储器中,判断第一随机数存储器中的随机数是否大于第四预设值且小于第一预设值,如果是,则执行步骤106,否则继续执行步骤105;Step 105: The CPU generates a random number and saves it in the first random number memory, and judges whether the random number in the first random number memory is greater than the fourth preset value and smaller than the first preset value, and if so, executes step 106, Otherwise, proceed to step 105;

例如,CPU生成的随机数,即第一随机数存储器中的数据为:For example, the random number generated by the CPU, that is, the data in the first random number memory is:

0x77105C9B20BCD3122823C8CF6FCC7B956DE33814E95B7FE64FED924594DCEAB3;满足大于第四预设值小于第一预设值,执行步骤106;0x77105C9B20BCD3122823C8CF6FCC7B956DE33814E95B7FE64FED924594DCEAB3; if it is greater than the fourth preset value and less than the first preset value, go to step 106;

步骤106:CPU读取第一随机数存储器、第二预设存储器和第三预设存储器中的数据,将第一随机数存储器中的数据与第二预设存储器和第三预设存储器中的数据进行点乘运算,将运算结果保存至第三寄存器中;Step 106: CPU reads the data in the first random number memory, the second preset memory and the third preset memory, and compares the data in the first random number memory with the data in the second preset memory and the third preset memory The data is multiplied by dot, and the operation result is saved in the third register;

优选的,第二预设存储器中的数据为:0x2Preferably, the data in the second preset memory is: 0x2

第三预设存储器中的数据为:The data in the third preset memory is:

0x8E2A8A0E65147D4BD6316030E16D19C85C97F0A9CA267122B96ABBCEA7E8FC8;0x8E2A8A0E65147D4BD6316030E16D19C85C97F0A9CA267122B96ABBCEA7E8FC8;

第一随机数存储器中的数据为:The data in the first random number memory is:

0x77105C9B20BCD3122823C8CF6FCC7B956DE33814E95B7FE64FED924594DCEAB3;0x77105C9B20BCD3122823C8CF6FCC7B956DE33814E95B7FE64FED924594DCEAB3;

CPU将第一随机数存储器中的数据与第二预设存储器和第三预设存储器中的数据进行点乘运算,得到的运算结果为:The CPU performs a dot multiplication operation on the data in the first random number memory and the data in the second preset memory and the third preset memory, and the obtained operation result is:

0x41AA28D2F1AB148280CD9ED56FEDA41974053554A42767B83AD043FD39DC0493,将该数据保存至第三寄存器中。0x41AA28D2F1AB148280CD9ED56FEDA41974053554A42767B83AD043FD39DC0493, save this data to the third register.

步骤107:CPU将第三寄存器中的数据与第一预设存储器中的数据进行模运算,将结果保存至第四寄存器中;Step 107: The CPU performs a modulo operation on the data in the third register and the data in the first preset memory, and saves the result in the fourth register;

例如,第三寄存器中的数据为:For example, the data in the third register is:

0x41AA28D2F1AB148280CD9ED56FEDA41974053554A42767B83AD043FD39DC0493;0x41AA28D2F1AB148280CD9ED56FEDA41974053554A42767B83AD043FD39DC0493;

CPU将第三寄存器中的数据与第一预设存储器中的数据进行模运算,计算得到的数据为:The CPU performs a modulo operation on the data in the third register and the data in the first preset memory, and the calculated data is:

0x41AA28D2F1AB148280CD9ED56FEDA41974053554A42767B83AD043FD39DC0493,将该数据保存至第四寄存器中;0x41AA28D2F1AB148280CD9ED56FEDA41974053554A42767B83AD043FD39DC0493, save this data to the fourth register;

步骤108:CPU判断第四寄存器中的数据是否为第四预设值,如果是,则返回执行步骤105,否则执行步骤109;Step 108: the CPU judges whether the data in the fourth register is the fourth preset value, if yes, returns to step 105, otherwise executes step 109;

优选的,第四预设值为0;Preferably, the fourth preset value is 0;

步骤109:CPU读取签名私钥,将第四寄存器中的数据与签名私钥做乘法,将结果保存至第一中间值存储器中,将第一随机数存储器中的数据与第二寄存器中的数据做乘法,将结果保存至第二中间值存储器;Step 109: The CPU reads the signature private key, multiplies the data in the fourth register with the signature private key, saves the result in the first intermediate value memory, and multiplies the data in the first random number memory with the data in the second register The data is multiplied, and the result is stored in the second intermediate value memory;

例如,读取到的签名私钥为:For example, the read signature private key is:

0x7A929ADE789BB9BE10ED359DD39A72C11B60961F49397EEE1D19CE9891EC3B28;0x7A929ADE789BB9BE10ED359DD39A72C11B60961F49397EEE1D19CE9891EC3B28;

CPU将第四寄存器中的数据与签名私钥做乘法计算得到的第一中间值存储器中的数据为:The CPU multiplies the data in the fourth register and the signature private key to obtain the data in the first intermediate value memory as follows:

0x1F70B2393C875C74B1A479D9F7971E8DA54B116F1A1D872B5E15035BC1DE2B9EF18B59F89A2CE73B4E87980453EEB0084809CEE08C64296CCB18F29A39F297F8;0x1F70B2393C875C74B1A479D9F7971E8DA54B116F1A1D872B5E15035BC1DE2B9EF18B59F89A2CE73B4E87980453EEB0084809CEE08C64296CCB18F29A39F297F8;

CPU将第一随机数存储器中的随机数0x77105C9B20BCD3122823C8CF6FCC7B956DE33814E95B7FE64FED924594DCEAB3与第二寄存器中的数据0x2DFBC1B372D89A1188C09C52E0EEC61FCE52032AB1022E8E67ECE6672B043EE5做乘法,计算得到的第二中间值存储器中的数据为:CPU将第一随机数存储器中的随机数0x77105C9B20BCD3122823C8CF6FCC7B956DE33814E95B7FE64FED924594DCEAB3与第二寄存器中的数据0x2DFBC1B372D89A1188C09C52E0EEC61FCE52032AB1022E8E67ECE6672B043EE5做乘法,计算得到的第二中间值存储器中的数据为:

0x1562F768DC86051699E15ED2B82E87498C7035EE2FAA123ED4B2D512D4E848270A434EC3C8B6DBC95A088D4F9ADE41B1E36C0B2EE5002CC6C3CB613066414C1F;0x1562F768DC86051699E15ED2B82E87498C7035EE2FAA123ED4B2D512D4E848270A434EC3C8B6DBC95A088D4F9ADE41B1E36C0B2EE5002CC6C3CB613066414C1F;

步骤110:CPU将第一中间值存储器中的数据与第二中间值存储器中的数据相加,将结果保存至第三中间值存储器中,将第三中间值存储器中的数据与第一预设存储器中的数据做模运算,将结果保存在第五寄存器中;Step 110: The CPU adds the data in the first intermediate value memory to the data in the second intermediate value memory, saves the result in the third intermediate value memory, and combines the data in the third intermediate value memory with the first preset The data in the memory is subjected to a modulo operation, and the result is stored in the fifth register;

例如,CPU将第一中间值存储器中的数据与第二中间值存储器中的数据相加得到的第三中间值存储器中的数据为:For example, the data in the third intermediate value memory obtained by adding the data in the first intermediate value memory and the data in the second intermediate value memory by the CPU is:

0x34D3A9A2190D618B4B85D8ACAFC5A5D731BB475D49C7996A32C7D86E96C673C5FBCEA8BC62E3C304A8902553EECCF1BA2B75DA0F716456338EE453CAA033E417;0x34D3A9A2190D618B4B85D8ACAFC5A5D731BB475D49C7996A32C7D86E96C673C5FBCEA8BC62E3C304A8902553EECCF1BA2B75DA0F716456338EE453CAA033E417;

CPU将第三中间值存储器中的数据与第一预设存储器中的数据做模运算得到的第五寄存器中的数据为:The data in the fifth register obtained by the CPU performing modulo operation on the data in the third intermediate value memory and the data in the first preset memory is:

0x1456C64BA4642A1653C235A98A60249BCD6D3F746B631DF928014F6C5BF9C40;0x1456C64BA4642A1653C235A98A60249BCD6D3F746B631DF928014F6C5BF9C40;

步骤111:CPU判断第五寄存器中的数据是否为第四预设值,如果是,则返回执行步骤105,否则执行步骤112;Step 111: the CPU judges whether the data in the fifth register is the fourth preset value, if yes, returns to step 105, otherwise executes step 112;

步骤112:CPU将第四寄存器中的数据和第五寄存器中的数据作为签名结果输出;Step 112: The CPU outputs the data in the fourth register and the data in the fifth register as a signature result;

本实施例中,优选的,将第四寄存器中的数据和第五寄存器中的数据进行拼接,得到签名结果;In this embodiment, preferably, the data in the fourth register and the data in the fifth register are spliced to obtain a signature result;

例如,CPU将第四寄存器中的数据0x41AA28D2F1AB148280CD9ED56FEDA41974053554A42767B83AD043FD39DC0493和第五寄存器中的数据0x1456C64BA4642A1653C235A98A60249BCD6D3F746B631D F928014F6C5BF9C40进行拼接,得到的签名结果为:For example, the CPU concatenates the data 0x41AA28D2F1AB148280CD9ED56FEDA41974053554A42767B83AD043FD39DC0493 in the fourth register and the data 0x1456C64BA4642A1653C235A98A60249BCD6D3F746B631D F928019F in the fifth register.

0x41AA28D2F1AB148280CD9ED56FEDA41974053554A42767B83AD043FD39DC04931456C64BA4642A1653C235A98A60249BCD6D3F746B631DF928014F6C5BF9C40。0x41AA28D2F1AB148280CD9ED56FEDA41974053554A42767B83AD043FD39DC04931456C64BA4642A1653C235A98A60249BCD6D3F746B631DF928014F6C5BF9C40.

实施例3Example 3

本发明实施例3提供了一种实现数字验签的方法,如图3所示,包括:Embodiment 3 of the present invention provides a method for realizing digital signature verification, as shown in Figure 3, including:

步骤T1:CPU读取签名结果,对签名结果进行处理,将结果保存至第八寄存器和第九寄存器中,读取待签名数据,对待签名数据进行哈希计算,将结果保存至第十寄存器中;Step T1: The CPU reads the signature result, processes the signature result, saves the result to the eighth register and the ninth register, reads the data to be signed, performs hash calculation on the data to be signed, and saves the result to the tenth register ;

步骤T2:CPU读取第一预设存储器中的数据,将第十寄存器中的数据与第一预设存储器中的数据进行模运算,将结果保存至第十一寄存器中;Step T2: The CPU reads the data in the first preset memory, performs a modulo operation on the data in the tenth register and the data in the first preset memory, and saves the result in the eleventh register;

步骤T3:CPU计算第十一寄存器中的数据与第一预设存储器中的数据取模的逆元,将结果保存至第十二寄存器中;Step T3: The CPU calculates the inverse of the modulo between the data in the eleventh register and the data in the first preset memory, and saves the result in the twelfth register;

步骤T4:CPU对第九寄存器中的数据、第十二寄存器中的数据和第一预设存储器中的数据进行处理,将结果保存至第十三寄存器中,对第八寄存器中的数据、第十二寄存器中的数据和第一预设存储器中的数据进行处理,将结果保存至第十四寄存器中;Step T4: The CPU processes the data in the ninth register, the data in the twelfth register and the data in the first preset memory, saves the result in the thirteenth register, and processes the data in the eighth register, the data in the first preset memory The data in the twelve registers and the data in the first preset memory are processed, and the result is stored in the fourteenth register;

步骤T5:CPU读取签名公钥,对第十三寄存器中的数据、第十四寄存器中的数据和签名公钥进行预设运算,将结果保存至第十五寄存器中;Step T5: The CPU reads the signature public key, performs preset operations on the data in the thirteenth register, the data in the fourteenth register, and the signature public key, and saves the result in the fifteenth register;

步骤T6:CPU将第十五寄存器中的数据与第一预设存储器中的数据进行模运算,将结果保存至第十六寄存器中;Step T6: The CPU performs a modulo operation on the data in the fifteenth register and the data in the first preset memory, and saves the result in the sixteenth register;

步骤T7:CPU判断第十六寄存器中的数据与第八寄存器中的数据是否相等,如果是,则输出验签成功信息,否则输出验签失败信息。Step T7: The CPU judges whether the data in the sixteenth register is equal to the data in the eighth register, and if so, outputs a signature verification success message, otherwise outputs a signature verification failure message.

实施例4Example 4

本发明实施例4提供了一种实现数字验签的方法,如图4所示,当接收到需要验签的签名结果和待签名数据时,将签名结果保存至第六寄存器中,将待签名数据保存至第七寄存器中,CPU执行以下操作:Embodiment 4 of the present invention provides a method for realizing digital signature verification. As shown in FIG. 4, when receiving the signature result and the data to be signed that need to be The data is saved to the seventh register, and the CPU performs the following operations:

步骤201:CPU初始化椭圆曲线参数,将模运算参数设置为第一预设值,并保存至第一预设存储器中,将椭圆曲线参数设置为第二预设值和第三预设值,将第二预设值保存至第二预设存储器中,将第三预设值保存至第三预设存储器中;Step 201: The CPU initializes the elliptic curve parameters, sets the modulo calculation parameters as the first preset value, and saves them in the first preset memory, sets the elliptic curve parameters as the second preset value and the third preset value, and sets saving the second preset value into the second preset memory, and saving the third preset value into the third preset memory;

本实施例中,第一预设存储器中的第一预设值为:In this embodiment, the first preset value in the first preset memory is:

0x8000000000000000000000000000000150FE8A1892976154C59CFC193ACCF5B3;0x8000000000000000000000000000000150FE8A1892976154C59CFC193ACCF5B3;

第二预设存储器中的第二预设值为:The second preset value in the second preset memory is:

0x41AA28D2F1AB148280CD9ED56FEDA41974053554A42767B83AD043FD39DC0493;0x41AA28D2F1AB148280CD9ED56FEDA41974053554A42767B83AD043FD39DC0493;

第三预设存储器中的第三预设值为:The third preset value in the third preset memory is:

0x489C375A9941A3049E33B34361DD204172AD98C3E5916DE27695D22A61FAE46E;0x489C375A9941A3049E33B34361DD204172AD98C3E5916DE27695D22A61FAE46E;

步骤202:CPU从第六寄存器中获取第二数据和第三数据,将第二数据保存至第八寄存器中,将第三数据保存至第九寄存器中;Step 202: the CPU acquires the second data and the third data from the sixth register, saves the second data into the eighth register, and saves the third data into the ninth register;

例如,CPU从签名结果中获取到的第二数据,即保存至第八寄存器中的数据为:For example, the second data obtained by the CPU from the signature result, that is, the data stored in the eighth register is:

0x41AA28D2F1AB148280CD9ED56FEDA41974053554A42767B83AD043FD39DC0493;0x41AA28D2F1AB148280CD9ED56FEDA41974053554A42767B83AD043FD39DC0493;

CPU从签名结果中获取到的第三数据,即保存至第九寄存器中的数据为:The third data obtained by the CPU from the signature result, that is, the data stored in the ninth register is:

0x1456C64BA4642A1653C235A98A60249BCD6D3F746B631DF928014F6C5BF9C40;0x1456C64BA4642A1653C235A98A60249BCD6D3F746B631DF928014F6C5BF9C40;

步骤203:CPU判断第八寄存器中的数据和第九寄存器中的数据是否均大于第四预设值小于第一预设值,如果是,则执行步骤204,否则报错,结束;Step 203: The CPU judges whether the data in the eighth register and the data in the ninth register are both greater than the fourth preset value and smaller than the first preset value, if yes, execute step 204, otherwise report an error and end;

优选的,第四预设值为0;Preferably, the fourth preset value is 0;

步骤204:CPU读取第七寄存器中的待签名数据,对第七寄存器中的待签名数据进行哈希计算,得到哈希结果,将哈希结果保存至第十寄存器中;Step 204: The CPU reads the data to be signed in the seventh register, performs hash calculation on the data to be signed in the seventh register, obtains the hash result, and saves the hash result in the tenth register;

本实施例中,CPU对接收到的待签名数据进行预设哈希运算,得到哈希结果;In this embodiment, the CPU performs a preset hash operation on the received data to be signed to obtain a hash result;

例如,CPU接收到的待签名数据为0x499602D2,对该待签名数据进行哈希计算后得到的哈希结果为:For example, the data to be signed received by the CPU is 0x499602D2, and the hash result obtained after performing hash calculation on the data to be signed is:

0x2DFBC1B372D89A1188C09C52E0EEC61FCE52032AB1022E8E67ECE6672B043EE5;0x2DFBC1B372D89A1188C09C52E0EEC61FCE52032AB1022E8E67ECE6672B043EE5;

步骤205:CPU读取第一预设存储器中的数据,将第十寄存器中的哈希结果与第一预设存储器中的第一预设值进行模运算,将结果保存至第十一寄存器;Step 205: The CPU reads the data in the first preset memory, performs a modulo operation on the hash result in the tenth register and the first preset value in the first preset memory, and saves the result in the eleventh register;

例如,CPU将哈希结果与第一预设值进行模运算,计算得到的第十一寄存器中的数据为:For example, the CPU performs a modulo operation on the hash result and the first preset value, and the calculated data in the eleventh register is:

0x2DFBC1B372D89A1188C09C52E0EEC61FCE52032AB1022E8E67ECE6672B043EE5;0x2DFBC1B372D89A1188C09C52E0EEC61FCE52032AB1022E8E67ECE6672B043EE5;

步骤206:CPU判断第十一寄存器中的数据是否为第四预设值,如果是,则将第十一寄存器中的数据设置为第五预设值,执行步骤207,否则直接执行步骤207;Step 206: the CPU judges whether the data in the eleventh register is the fourth preset value, if yes, sets the data in the eleventh register to the fifth preset value, and executes step 207, otherwise directly executes step 207;

优选的,第四预设值为0,第五预设值为1;Preferably, the fourth preset value is 0, and the fifth preset value is 1;

步骤207:CPU计算第十一寄存器中的数据与第一预设存储器中的第一预设值取模的逆元,将结果保存至第十二寄存器;Step 207: The CPU calculates the inverse of the modulus between the data in the eleventh register and the first preset value in the first preset memory, and saves the result to the twelfth register;

例如,CPU计算得到的第十二寄存器中的数据为:For example, the data in the twelfth register calculated by the CPU is:

0x271A4EE429F84EBC423E388964555BB29D3BA53C7BF945E5FAC8F381706354C2;0x271A4EE429F84EBC423E388964555BB29D3BA53C7BF945E5FAC8F381706354C2;

步骤208:CPU计算第九寄存器中的数据与第十二寄存器中的数据的乘积,将结果与第一预设存储器中的第一预设值进行模运算,得到的结果保存至第十三寄存器中;Step 208: The CPU calculates the product of the data in the ninth register and the data in the twelfth register, performs a modulo operation on the result and the first preset value in the first preset memory, and saves the result to the thirteenth register middle;

本实施例中,CPU计算得到的第十三寄存器中的数据为:In this embodiment, the data in the thirteenth register calculated by the CPU is:

0x5358F8FFB38F7C09ABC782A2DF2A3927DA4077D07205F763682F3A76C9019B4F;0x5358F8FFB38F7C09ABC782A2DF2A3927DA4077D07205F763682F3A76C9019B4F;

步骤209:CPU计算第八寄存器中的数据与第十二寄存器中的数据的乘积,将结果与第一预设存储器中的第一预设值进行模运算,将结果保存至第十四寄存器中;Step 209: The CPU calculates the product of the data in the eighth register and the data in the twelfth register, performs a modulo operation on the result and the first preset value in the first preset memory, and saves the result in the fourteenth register ;

本实施例中,CPU计算得到的第十四寄存器中的数据为:In this embodiment, the data in the fourteenth register calculated by the CPU is:

0x3221B4FBBF6D101074EC14AFAC2D4F7EFAC4CF9FEC1ED11BAE336D27D527665;0x3221B4FBBF6D101074EC14AFAC2D4F7EFAC4CF9FEC1ED11BAE336D27D527665;

本实施例中,步骤208与步骤209无先后顺序,可同时执行;In this embodiment, step 208 and step 209 have no sequence and can be executed at the same time;

步骤210:CPU读取第二预设存储器和第三预设存储器中的数据,将第十三寄存器中的数据与第二预设存储器中的第二预设值和第三预设存储器中的第三预设值进行点乘运算,将得到的两个结果分别保存至第四中间值存储器和第五中间值存储器中;Step 210: The CPU reads the data in the second preset memory and the third preset memory, and compares the data in the thirteenth register with the second preset value in the second preset memory and the data in the third preset memory Dot multiplication is performed on the third preset value, and the two obtained results are respectively stored in the fourth intermediate value memory and the fifth intermediate value memory;

例如,CPU进行点乘运算,得到的第四中间值存储器中的数据为:For example, the CPU performs dot multiplication, and the obtained data in the fourth intermediate value memory is:

0xCA4036F2B1EC00E1D9E4F789EE594C83F22987A2D9FD7844572ECB443F676E67;0xCA4036F2B1EC00E1D9E4F789EE594C83F22987A2D9FD7844572ECB443F676E67;

同时,CPU得到的第五中间值存储器中的数据为:At the same time, the data in the fifth intermediate value memory obtained by the CPU is:

0x55E6DD8D570DD7CE2E1C8E2DE340E2F9785E94E257E3530C074510E46CE50464;0x55E6DD8D570DD7CE2E1C8E2DE340E2F9785E94E257E3530C074510E46CE50464;

步骤211:CPU读取签名公钥,将第十四寄存器中的数据与签名公钥做乘法,将运算得到的两个结果分别保存至第六中间值存储器和第七中间值存储器中;Step 211: The CPU reads the signature public key, multiplies the data in the fourteenth register by the signature public key, and saves the two results obtained from the operation into the sixth intermediate value memory and the seventh intermediate value memory;

例如,CPU获取到的签名公钥为:For example, the signature public key obtained by the CPU is:

(0x7F2B49E270DB6D90D8595BEC458B50C58585BA1D4E9B788F6689DBD8E56FD80B,0x26F1B489D6701DD185C8413A977B3CBBAF64D1C593D26627DFFB101A87FF77DA);(0x7F2B49E270DB6D90D8595BEC458B50C58585BA1D4E9B788F6689DBD8E56FD80B, 0x26F1B489D6701DD185C8413A977B3CBBAF64D1C593D26627DFFB101A87FF77DA);

CPU将第十四寄存器中的数据与签名公钥做乘法得到的第六中间值存储器中的数据为:The data in the sixth intermediate value memory obtained by the CPU multiplying the data in the fourteenth register and the signature public key is:

0x64A4B968FFEE6A93EC23445E47129E087F1517FA6152DD5DABC2ADBA527191DC;0x64A4B968FFEE6A93EC23445E47129E087F1517FA6152DD5DABC2ADBA527191DC;

同时,CPU得到的第七中间值存储器中的数据为:At the same time, the data in the seventh intermediate value memory obtained by the CPU is:

0x1CA5EE5FC1BFC27EFC8B4E260F8FD17593A5E4E42821045B546A3DC2E2B8A290;0x1CA5EE5FC1BFC27EFC8B4E260F8FD17593A5E4E42821045B546A3DC2E2B8A290;

本实施例中,步骤210与步骤211无先后顺序,可同时执行;In this embodiment, step 210 and step 211 have no sequence and can be executed at the same time;

步骤212:CPU对第四中间值存储器、第五中间值存储器、第六中间值存储器和第七中间值存储器中的数据进行计算,将计算结果保存至第十五寄存器中;Step 212: CPU calculates the data in the fourth intermediate value memory, the fifth intermediate value memory, the sixth intermediate value memory and the seventh intermediate value memory, and saves the calculation result in the fifteenth register;

例如,CPU计算得到的第十五寄存器中的数据为:For example, the data in the fifteenth register calculated by the CPU is:

0x41AA28D2F1AB148280CD9ED56FEDA41974053554A42767B83AD043FD39DC0493;0x41AA28D2F1AB148280CD9ED56FEDA41974053554A42767B83AD043FD39DC0493;

步骤213:CPU将第十五寄存器中的数据与第一预设存储器中的第一预设值进行模运算,将结果保存至第十六寄存器中;Step 213: The CPU performs a modulo operation on the data in the fifteenth register and the first preset value in the first preset memory, and saves the result in the sixteenth register;

例如,CPU计算得到的第十六寄存器中的数据为:For example, the data in the sixteenth register calculated by the CPU is:

0x41AA28D2F1AB148280CD9ED56FEDA41974053554A42767B83AD043FD39DC0493;0x41AA28D2F1AB148280CD9ED56FEDA41974053554A42767B83AD043FD39DC0493;

步骤214:CPU判断第十六寄存器中的数据与第八寄存器中的数据是否相等,如果是,则输出验签成功信息,否则输出验签失败信息;Step 214: the CPU judges whether the data in the sixteenth register is equal to the data in the eighth register, and if yes, then outputs signature verification success information, otherwise outputs signature verification failure information;

本实施例中,CPU从接收到的签名结果中获取到的第八寄存器中的数据与第十六寄存器中的数据相同,验签成功。In this embodiment, the data in the eighth register obtained by the CPU from the received signature result is the same as the data in the sixteenth register, and the signature verification is successful.

以上所述,仅为本发明较佳的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明公开的技术范围内,可轻易想到的变化或替换,都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应该以权利要求的保护范围为准。The above is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto, any changes or variations that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention Replacement should be covered within the protection scope of the present invention. Therefore, the protection scope of the present invention should be determined by the protection scope of the claims.

Claims (10)

  1. A kind of 1. method for realizing digital signature, it is characterised in that including:
    Step S1:CPU read Hash result, and read the first preset memory in data, by the Hash result with it is described Data in first preset memory carry out modular arithmetic, and result is preserved into the second register;
    Step S2:CPU reads the data in the first random number memories, the second preset memory and the 3rd preset memory, will Data in first random number memories and the data in second preset memory and the 3rd preset memory Point multiplication operation is carried out, operation result is preserved into the 3rd register;
    Step S3:Data in data in 3rd register and first preset memory are carried out modular arithmetic by CPU, Result is preserved into the 4th register;
    Step S4:CPU reads signature private key, to the data in the signature private key, second register, the 4th deposit The data in data and first random number memories in device carry out default computing, and result is preserved to the 5th register In;
    Step S5:CPU is defeated as signature result using the data in the data and the 5th register in the 4th register Go out;
    Also include before the step S1:CPU receives outside incoming data to be signed, and the data to be signed are preset Hash operation, the Hash result that computing is obtained preserve;
    In the step S4, in the data in the signature private key, second register, the 4th register Data in data and first random number memories carry out default computing, result are preserved into the 5th register, specifically For:
    Step a1:Data in 4th register and the signature private key are done multiplication by CPU, and result is preserved into first Between be worth in memory, the data in the data in first random number memories and second register are done into multiplication, will As a result preserve into the second median memory;
    Step a2:CPU is by the data in the first median memory and the data phase in the second median memory Add, result is preserved into the 3rd median memory;
    Step a3:Data in data in the 3rd median memory and first preset memory are done mould by CPU Computing, result is preserved into the 5th register;
    The step S5, it is specially:CPU carries out the data in the data in the 4th register and the 5th register Splicing, obtain result of signing.
  2. 2. according to the method for claim 1, it is characterised in that also include before the step S1:CPU is by modular arithmetic parameter The first preset value is arranged to, and is preserved into first preset memory, elliptic curve parameter is arranged to the second preset value With the 3rd preset value, the second preset value is preserved into second preset memory, the 3rd preset value is preserved to described In three preset memories.
  3. 3. according to the method for claim 1, it is characterised in that also include between the step S1 and the step S2:CPU Judge whether the data in second register are the 4th preset value, if it is, by the data in second register The 5th preset value is arranged to, performs step S2, otherwise directly performs step S2.
  4. 4. according to the method for claim 1, it is characterised in that also include before the step S2:
    Step a:CPU generates random number, judges whether the random number is more than the 4th preset value and is less than the first preset value, if It is then to preserve the random number into first random number memories, performs step S2, otherwise continue executing with step a.
  5. 5. according to the method for claim 4, it is characterised in that between the step S3 and the step S4, in addition to:Sentence Whether the data broken in the 4th register are the 4th preset value, if it is, performing step S4, otherwise return to step a.
  6. 6. according to the method for claim 4, it is characterised in that between the step S4 and the step S5, in addition to: CPU judges whether the data in the 5th register are the 4th preset value, performs step a if it is, returning, otherwise performs Step S5.
  7. A kind of 7. method for realizing digital sign test, it is characterised in that including:
    Step T1:CPU read signature result, to it is described signature result handle, by obtain two results preserve respectively to In 8th register and the 9th register, data to be signed are read, Hash calculation is carried out to the data to be signed, result is protected Deposit into the tenth register;
    Step T2:CPU reads the data in the first preset memory, and the data in the tenth register are preset with first and deposited Data in reservoir carry out modular arithmetic, and result is preserved into the 11st register;
    Step T3:CPU calculates the data in the 11st register and the data modulus in first preset memory Inverse element, result is preserved into the 12nd register;
    Step T4:CPU is preset to the data in the 9th register, the data in the 12nd register and described first Data in memory are handled, and result is preserved into the 13rd register, to the data in the 8th register, institute The data stated in the data in the 12nd register and first preset memory are handled, and result is preserved to the 14th In register;
    Step T5:CPU reads public signature key, to the data in the 13rd register, the number in the 14th register Default computing is carried out according to the public signature key, result is preserved into the 15th register;
    Step T6:Data in data in 15th register and first preset memory are carried out mould fortune by CPU Calculate, result is preserved into the 16th register;
    Step T7:CPU judges whether the data in the 16th register and the data in the 8th register are equal, such as Fruit is then to export sign test successful information, otherwise exports sign test failure information;
    In the step T4, the data in the 9th register, data in the 12nd register and described Data in first preset memory are handled, and result is preserved into the 13rd register, are specially:Described in CPU is calculated The product of data and the data in the 12nd register in 9th register, result of product is preset with described first and deposited Data in reservoir carry out modular arithmetic, and modular arithmetic result is preserved into the 13rd register;
    In the step T4, the data in the 8th register, data in the 12nd register and described Data in first preset memory are handled, and result is preserved into the 14th register, are specially:Described in CPU is calculated The product of data and the data in the 12nd register in 8th register, result of product is preset with described first and deposited Data in reservoir carry out modular arithmetic, and modular arithmetic result is preserved into the 14th register;
    The step T5, is specifically included:
    Step b1:CPU reads the data in the second preset memory and the 3rd preset memory, and reads public signature key;
    Step b2:CPU is by the data in the data in the 13rd register and second preset memory and described the Data in three preset memories carry out point multiplication operation, and two results that computing is obtained are preserved to the 4th median and stored respectively In device and the 5th median memory;
    Step b3:Data in 14th register and the public signature key are done multiplication by CPU, two that computing is obtained As a result preserve respectively into the 6th median memory and the 7th median memory;
    Step b4:CPU stores to the 4th median memory, the 5th median memory, the 6th median Data in device and the 7th median memory are calculated, and result of calculation is preserved into the 15th register.
  8. 8. according to the method for claim 7, it is characterised in that also include before the step T2:CPU is by modular arithmetic parameter The first preset value is arranged to, and is preserved into first preset memory;Elliptic curve parameter is arranged to second and preset by CPU Value and the 3rd preset value, second preset value is preserved into second preset memory, and the 3rd preset value is protected Deposit into the 3rd preset memory.
  9. 9. according to the method for claim 7, it is characterised in that between the step T1 and the step T2, in addition to: CPU judges whether data in the 8th register and the data in the 9th register are all higher than the 4th preset value and small In the first preset value, if it is, performing step T2, otherwise report an error, terminate.
  10. 10. according to the method for claim 7, it is characterised in that between the step T2 and the step T3, in addition to: CPU judges whether the data in the 11st register are the 4th preset value, if it is, by the 11st register Data be arranged to the 5th preset value, perform step T3, otherwise directly execution step T3.
CN201510177842.9A 2015-04-15 2015-04-15 A kind of method for realizing digital signature and sign test Expired - Fee Related CN104753684B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510177842.9A CN104753684B (en) 2015-04-15 2015-04-15 A kind of method for realizing digital signature and sign test

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510177842.9A CN104753684B (en) 2015-04-15 2015-04-15 A kind of method for realizing digital signature and sign test

Publications (2)

Publication Number Publication Date
CN104753684A CN104753684A (en) 2015-07-01
CN104753684B true CN104753684B (en) 2018-01-05

Family

ID=53592843

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510177842.9A Expired - Fee Related CN104753684B (en) 2015-04-15 2015-04-15 A kind of method for realizing digital signature and sign test

Country Status (1)

Country Link
CN (1) CN104753684B (en)

Families Citing this family (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108259184B (en) * 2018-01-16 2021-06-08 飞天诚信科技股份有限公司 A kind of digital signature based on user identification, signature verification method and device
CN109064170B (en) * 2018-07-23 2021-10-22 西安电子科技大学 Group signature method without trusted center
CN111143893B (en) * 2019-12-17 2023-04-07 北京宏思电子技术有限责任公司 Secure implementation method and device for Hash grouping calculation
CN112100644B (en) * 2020-11-19 2021-03-16 飞天诚信科技股份有限公司 Method and device for generating data signature
CN113704740B (en) * 2021-09-01 2025-12-30 上海兆芯集成电路股份有限公司 Processors with Elliptic Curve Cryptography Algorithms and Their Processing Methods
CN113704741B (en) 2021-09-01 2025-11-28 上海兆芯集成电路股份有限公司 Processor with elliptic curve cryptography algorithm and processing method thereof
CN113722700B (en) 2021-09-01 2026-02-03 上海兆芯集成电路股份有限公司 Processor with elliptic curve cryptography algorithm and processing method thereof
CN113961947A (en) 2021-09-01 2022-01-21 上海兆芯集成电路有限公司 Processor with Hash cipher algorithm and processing method thereof
CN113676335B (en) * 2021-10-21 2021-12-28 飞天诚信科技股份有限公司 Method and device for realizing signature in security chip
CN114844650B (en) * 2022-05-24 2023-12-01 北京宏思电子技术有限责任公司 Equipment signature method and system

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103049688A (en) * 2013-01-25 2013-04-17 北京天诚盛业科技有限公司 Identity authentication device as well as authentication handling method and handling device thereof
CN103401681A (en) * 2013-07-02 2013-11-20 北京华大信安科技有限公司 Modulus taking method, modulus taking device and chip

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP3503638B1 (en) * 2002-09-26 2004-03-08 日本電気株式会社 Cryptographic device and cryptographic program

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103049688A (en) * 2013-01-25 2013-04-17 北京天诚盛业科技有限公司 Identity authentication device as well as authentication handling method and handling device thereof
CN103401681A (en) * 2013-07-02 2013-11-20 北京华大信安科技有限公司 Modulus taking method, modulus taking device and chip

Also Published As

Publication number Publication date
CN104753684A (en) 2015-07-01

Similar Documents

Publication Publication Date Title
CN104753684B (en) A kind of method for realizing digital signature and sign test
US10333718B2 (en) Method for the generation of a digital signature of a message, corresponding generation unit, electronic apparatus and computer program product
CN111064583B (en) Threshold SM2 digital signature method and device, electronic equipment and storage medium
JP7206324B2 (en) System and method for one-time Chinese Remainder Theorem exponentiation for cryptographic algorithms
CN103024006A (en) Security outsourcing method for bilinear pairings under cloud computing environment
CN104917608B (en) A kind of method of the anti-power consumption attack of key
CN108259506B (en) SM2 white box password implementation method
US20200344056A1 (en) Device and method for protecting execution of a cryptographic operation
US11902432B2 (en) System and method to optimize generation of coprime numbers in cryptographic applications
CN108259179B (en) Encryption and decryption coprocessor based on SM9 identification cryptographic algorithm and operation method thereof
CN109274504B (en) A cloud platform-based multi-user big data storage and sharing method and system
CN108039947B (en) An SM2 Signature Method Using Coprocessor to Resist Attacks
TW200411593A (en) Method and apparatus for protecting public key schemes from timing, power and fault attacks
CN102227759B (en) Scalar multiplier and scalar multiplication method
CN109933304B (en) Rapid Montgomery modular multiplier operation optimization method suitable for national secret sm2p256v1 algorithm
CN101969374B (en) Method for realizing confusing layer in block cipher algorithm
CN103580869B (en) A kind of CRT-RSA signature method and device
US7454625B2 (en) Method and apparatus for protecting a calculation in a cryptographic algorithm
CN110224829B (en) Matrix-based post-quantum encryption method and device
US20120039462A1 (en) Rsa signature method and apparatus
CN105373366B (en) A kind of method and device generating Big prime
CN104579651B (en) The method and apparatus of elliptic curve cipher point multiplication operation
CN107248973A (en) A kind of safely outsourced method that two Bilinear maps are directed to based on dual stage Cloud Server
CN110266481A (en) Matrix-based post-quantum encryption and decryption method and decryption device
US9313027B2 (en) Protection of a calculation performed by an integrated circuit

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20180105

CF01 Termination of patent right due to non-payment of annual fee