Disclosure of Invention
The key negotiation method and the device provided by the invention can safely complete key negotiation, are not easy to be broken and have forward security.
In a first aspect, the present invention provides a key agreement method, including:
acquiring a first random number, and generating a first public and private key pair according to the first random number;
sending a first public key in the public-private key pair to a negotiation object; to cause the negotiation object to calculate a first shared key;
receiving a second public key sent by a negotiation object, and generating a second shared key according to the second public key;
determining a first verification identifier according to the shared secret, the second public key and the second shared key;
receiving an identifier to be verified sent by a negotiation object; the identification to be verified is a first identification to be verified determined according to the second public key, the first shared secret key and the shared secret;
and verifying the current shared key negotiation result according to the first verification identifier and the first to-be-verified identifier.
Optionally, determining the first authentication identity according to the shared secret, the second public key and the second shared key comprises:
splicing the shared secret, the second public key and the second shared key with the first fixed data to obtain spliced data;
performing hash operation on the spliced data to obtain a hash value of the spliced data;
and taking the hash value as the first verification identifier.
Optionally, the method further comprises:
determining a second identifier to be verified according to the shared secret, the first public key and the second shared key;
and sending the second identifier to be verified to a negotiation object so that the negotiation object verifies the negotiation result of the shared secret key.
Optionally, sending the second identifier to be verified to the negotiation object includes:
encrypting the second identifier to be verified by adopting a second public key;
and sending the encrypted second identifier to be verified to the negotiation object.
Optionally, determining the second identifier to be verified according to the shared secret, the first public key, and the second shared key includes:
splicing the shared secret, the first public key and the second shared key with second fixed data to obtain spliced data;
performing hash operation on the spliced data to obtain a hash value of the spliced data;
and taking the hash value as the second identifier to be verified.
Optionally, the shared secret includes at least a root key of the processor.
Optionally, the obtaining a first random number and generating a first public-private key pair according to the first random number includes:
acquiring a first random number, and taking the first random number as a first private key;
acquiring an elliptic curve base point;
and determining a first public key according to the private key and the elliptic curve base point.
Optionally, verifying the current shared key negotiation result according to the first verification identifier and the first identifier to be verified includes:
when the first verification identifier is the same as the first to-be-verified identifier, determining that the current shared key negotiation result is successful in verification;
and when the first verification identifier is different from the first identifier to be verified, determining that the current shared key negotiation result is verification failure.
Optionally, the determining process of the first public key, the first shared key, the second public key, and the second shared key is calculated in a manner conforming to an exchange law.
Optionally, determining the first authentication identity according to the shared secret, the second public key and the second shared key comprises:
encrypting the second public key and the second shared key with a shared secret;
and determining a first verification identifier according to the shared secret and the encrypted second public key and the encrypted second shared key.
In a second aspect, the present invention provides a key agreement apparatus, including:
the key pair acquisition module is used for acquiring a first random number and generating a first public and private key pair according to the first random number;
the public key sending module is used for sending the first public key in the public-private key pair to a negotiation object; to cause the negotiation object to calculate a first shared key;
the public key receiving module is used for receiving a second public key sent by the negotiation object and generating a second shared secret key according to the second public key;
the verification identifier generation module is used for determining a first verification identifier according to the shared secret, the second public key and the second shared key;
the identification receiving module to be verified is used for receiving the identification to be verified sent by the negotiation object; the identification to be verified is a first identification to be verified determined according to the second public key, the first shared secret key and the shared secret;
and the verification module is used for verifying the current shared key negotiation result according to the first verification identifier and the first identifier to be verified.
Optionally, the verification identifier generation module includes:
the data splicing unit is used for splicing the shared secret, the second public key and the second shared key with the first fixed data to obtain spliced data;
the hash operation unit is used for carrying out hash operation on the spliced data to obtain a hash value of the spliced data;
and the verification identifier generating unit is used for taking the hash value as the first verification identifier.
In the technical scheme provided by the invention, the processor carries out the calculation of the shared key through the public key information sent by the opposite side, and the shared key cannot be directly transmitted or calculated through the information exchanged between CPUs, thereby ensuring the confidentiality of the shared key. And, the shared key participates in the calculation of the identification information. If the message in the negotiation stage is tampered, the shared key generated by the two parties is different, and the identity identifications calculated based on the shared key are also different, so that the first verification information is different from the first information to be verified, which also results in the failure of the negotiation of the shared key. Although the shared secret is fixed, the two do not participate in the calculation of the shared key; the public-private key pair is randomly generated in each key agreement process, so even if the secret is shared, the data encrypted by using the old shared key is still safe.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
An embodiment of the present invention provides a key agreement method, as shown in fig. 1, including:
step 100, acquiring a first random number, and generating a first public and private key pair according to the first random number;
in some embodiments, the first random number is generated by a random number generation module, and the generation of the first public-private key pair is based on the first random number, for example, the first random number is used as the first private key, and the first public key is generated with the first random number and an elliptic curve base point. For example, the first random number is a, the first random number a is used as a private key, and a first public key PA ═ a ] G is formed according to the first random number.
Step 200, sending a first public key in the public-private key pair to a negotiation object; to cause the negotiation object to calculate a first shared key;
in some embodiments, the first public key is sent to the negotiation object, the negotiation object generates the first shared key according to the second random number and the first public key obtained by the negotiation object, and the first shared key is the shared key successfully negotiated under the condition that negotiation is successful. For example, the first shared key may be obtained by the following calculation: KB ═ b ] PA; wherein b is a second random number obtained by the negotiation object.
Step 300, receiving a second public key sent by a negotiation object, and generating a second shared secret key according to the second public key;
in some embodiments, the second public key is a second public key in a second public-private key pair formed by the negotiation object, the second shared key is a shared key generated according to the first random number and the second public key, and the second shared key is the same as the first shared key in case of successful negotiation. For example, the second shared key may be calculated as follows: KA ═ a ] PB; the PB is a second public key formed by the negotiation object according to the second random number, and preferably, the second public key may be calculated in the following manner: PB ═ b ] G.
Step 400, determining a first verification identifier according to the shared secret, the second public key and the second shared key;
in some embodiments, the shared secret is secret information known to both communication parties, and the first authentication identifier is identification information used to authenticate whether the two parties negotiate success. For example, taking the shared key negotiation process of the dual-path processor as an example, the shared secret information may be a root key of the processor. For the first authentication identity, for example, the following calculation may be performed: MID2 ═ Hash (data2+ shared secret + PB + KA); data2 can be any information.
Step 500, receiving an identifier to be verified sent by a negotiation object; the identification to be verified is a first identification to be verified determined according to the second public key, the first shared secret key and the shared secret;
in some embodiments, the first to-be-verified identifier is information that is used by the negotiation object to indicate an identity of the negotiation object, and the identity of the communication peer may be determined by verifying the first to-be-verified identifier with the first verification identifier. The first identifier to be verified may be calculated as follows: SID2 ═ Hash (data2+ shared secret + PB + KB); wherein data2 is the same information as data2 in step 400. In the step, the first to-be-verified mark is verified through the verification mark, and in the verification process, only the first to-be-verified mark needs to be transmitted, and the first shared key or the second shared key does not need to be transmitted, so that information cannot be leaked even if hijacked by a third party. Meanwhile, the first to-be-verified identifier and the first verification identifier are formed based on the first shared key and the second shared key, so that the negotiation result of the shared key can be verified by comparing the first to-be-verified identifier and the second to-be-verified identifier.
Step 600, verifying a current shared key negotiation result according to the first verification identifier and the first identifier to be verified.
In some embodiments, through comparison between the first authentication identifier and the second identifier to be authenticated, when the first authentication identifier and the second identifier to be authenticated are the same, it may be determined that the first shared key and the second shared key are the same, that is, the key agreement is successful, and when the first authentication identifier and the second identifier are different, it may be determined that the first shared key and the second shared key are different, that is, the key agreement is failed.
In the technical scheme provided by this embodiment, the processor performs shared key calculation through public key information sent by the other party, and the shared key is not directly transmitted or cannot be calculated through messages exchanged between CPUs, so that confidentiality of the shared key can be ensured. And, the shared key participates in the calculation of the identification information. If the message in the negotiation stage is tampered, the shared key generated by the two parties is different, and the identity identifications calculated based on the shared key are also different, so that the first verification information is different from the first information to be verified, which also results in the failure of the negotiation of the shared key. Although the shared secret is fixed, the two do not participate in the calculation of the shared key; the public-private key pair is randomly generated in each key agreement process, so even if the secret is shared, the data encrypted by using the old shared key is still safe.
On the basis of the above-mentioned embodiment shown in fig. 1, as an alternative implementation, as shown in fig. 2, step 400 includes:
step 410, splicing the shared secret, the second public key and the second shared key with the first fixed data to obtain spliced data;
in some embodiments, the shared secret and the first fixed data of the two communication parties are fixed, and the second public key and the second shared key are respectively generated randomly, and by splicing the shared secret, the second public key and the second shared key with the first fixed data, in a subsequent verification process, if one of the information changes, the verification will fail, so that the integrity of the verified information can be ensured.
Step 420, performing hash operation on the spliced data to obtain a hash value of the spliced data;
in some embodiments, the hash operation is different for each different piece of information, and the hash values of the two pieces of information can be made the same only if the pieces of information are identical. Therefore, it can be ensured that the authenticated information in the key agreement process is identical.
Step 430, using the hash value as the first verification identifier.
In some embodiments, as described in step 420, the hash value is used as the first authentication identifier, and the first to-be-authenticated identifier sent by the negotiation object is also used as the hash value, and the two are the same, that is, it can be confirmed that the information of the two is identical.
In the embodiment, a plurality of information splicing modes are adopted for verification, so that the information which is verified successfully is complete and reliable, and meanwhile, the hash algorithm is used for accurately and quickly verifying the consistency of the information because the obtained value is unique.
On the basis of the embodiment shown in fig. 1, as shown in fig. 3, the method further includes:
step 010, determining a second to-be-verified identifier according to the shared secret, the first public key and the second shared key;
in some embodiments, in the verification process of whether the negotiation is successful or not, a mode that both communication parties respectively perform verification is adopted, and therefore, in this embodiment, a second to-be-verified identifier is also generated.
Step 020, sending the second identifier to be verified to a negotiation object, so that the negotiation object verifies the negotiation result of the shared key.
In some embodiments, the second identifier to be verified is sent to the negotiation object for verification, and in some preferred embodiments, the verification process of the second identifier to be verified may be performed in the same manner as the verification method of the first identifier to be verified.
In this embodiment, the second shared key generated by the negotiation object of the local terminal is verified by generating the second identifier to be verified. Therefore, the security of the key agreement method can be further improved.
On the basis of the embodiment shown in fig. 3, as shown in fig. 4, step 020 includes:
step 021, encrypting the second identifier to be verified by adopting a second public key;
in some embodiments, in order to ensure the transmission security of the second identifier to be verified, the second public key is used for encryption and then transmitted to the negotiation object. Since the second public key is a public key corresponding to the private key held by the negotiation object, the negotiation object may decrypt the information using the private key and then process the decrypted information.
And 022, sending the encrypted second identifier to be verified to a negotiation object.
In some embodiments, the encrypted second identifier to be verified is sent to the negotiation object, and the negotiation object performs comparison and verification after being decrypted by using a private key held by the negotiation object. The verification method can be performed in the same way as the comparison and verification process of the first identifier to be verified.
In this embodiment, the second public key is used for encryption and then sent to the negotiation object, the negotiation object possesses the private key corresponding to the second public key, the ciphertext encrypted by the second public key can be decrypted, and the third party without the private key cannot decrypt the ciphertext, so that the security of the negotiation verification process can be enhanced.
On the basis of the embodiment shown in fig. 3, as shown in fig. 5, step 010 includes:
step 011, splicing the shared secret, the first public key and the second shared key with the second fixed data to obtain spliced data;
in some embodiments, the step uses the data obtained by splicing the shared secret, the first public key, the second shared secret key, and the second fixed data as a basis for subsequently forming the second identifier to be verified. Those skilled in the art will understand that the negotiation object should generate the second verification identifier according to the shared secret, the first public key and the first shared key, so as to verify the second to-be-verified identifier.
Step 012, performing a hash operation on the concatenated data to obtain a hash value of the concatenated data;
in some embodiments, since the hash operation has a unique operation result for any information, subsequent verification of the hash value obtained by the hash operation can ensure the consistency of the information, and meanwhile, all data can be verified by comparing one hash value, and the comparison method is simple and quick.
And 013, taking the hash value as the second identifier to be verified.
In some embodiments, the hash value is used as the second identifier to be verified, and the consistency of all data participating in the hash operation can be determined through comparison of one hash value, so that the operation amount in the comparison process can be reduced.
In the embodiment, the data needing to be operated are subjected to hash comparison, so that the integrity and consistency of the data can be ensured, meanwhile, the operation amount can be reduced, and the operation efficiency is improved.
As an alternative embodiment, the shared secret includes at least a root key of the processor. The shared secret should be information that both parties of the negotiation know and that the third party cannot know, so that since the shared secret participates in the subsequent verification, the security can be further improved by using information that the third party does not know.
On the basis of the embodiment shown in fig. 1, as shown in fig. 6, step 100 includes:
step 110, acquiring a first random number, and using the first random number as a first private key;
in some embodiments, the random number is used as the private key to perform the subsequent negotiation process before each communication, so that the probability of being known by a third party can be reduced, and the security of the negotiation process is improved.
Step 120, acquiring an elliptic curve base point;
in some embodiments, the base point of the elliptic curve is an important ring for generating the public key by adopting an elliptic curve encryption algorithm, and the base point of the elliptic curve obtained in the step provides a basis for the subsequent generation of the first public key.
Step 130, determining a first public key according to the private key and the elliptic curve base point.
In some embodiments, the elliptic curve algorithm is adopted to generate the public key due to the characteristic that the elliptic curve is difficult to reversely calculate the private key, so that the protection of the private key after the public key is issued is facilitated.
In the embodiment, the public key is generated by adopting an elliptic curve algorithm, and due to the characteristic that the elliptic curve is difficult to calculate reversely, the safety of the private key can be ensured even if the public key is hijacked, so that the hijacked condition is judged in the subsequent authentication process.
On the basis of the embodiment shown in fig. 1, step 600 includes:
when the first verification identifier is the same as the first to-be-verified identifier, determining that the current shared key negotiation result is successful in verification;
and when the first verification identifier is different from the first identifier to be verified, determining that the current shared key negotiation result is verification failure.
In this embodiment, on the basis of calculating the shared key and not transmitting the shared key, the security is further enhanced by using an authentication method, so as to ensure the identities of both parties in negotiation.
As an optional implementation manner, the determination process of the first public key, the first shared key, the second public key, and the second shared key is calculated in a manner conforming to the commutative law. By adopting a calculation mode conforming to the exchange law, the two parties in negotiation can be ensured to obtain the same verification identifier and the identifier to be verified through the exchange of the exchange law after adopting different calculation data for calculation.
Based on the embodiment shown in fig. 1, as shown in fig. 7, the step 400 includes:
step 440, encrypting the second public key and the second shared key with a shared secret;
in some embodiments, in the authentication process, the second public key and the second shared key may be encrypted by using a shared secret, and since the shared secret is information that cannot be known by the third party, only the two parties can encrypt data by using the shared secret, so as to obtain the same information, thereby being capable of ensuring security in the authentication process.
Step 450, determining a first authentication identifier according to the shared secret and the encrypted second public key and the encrypted second shared key.
In some embodiments, the encrypted data is used as the first authentication identifier, and since only two parties in negotiation can know the shared secret, the third party cannot encrypt the data in the same way, which makes it difficult to hijack and replace the first authentication identifier.
In this embodiment, the first authentication identifier can be prevented from being hijacked and replaced by encrypting and authenticating only the information that both parties can know, and thus, the security of the negotiation process can be further improved.
As shown in fig. 8, taking the key negotiation process of the dual-path processor as an example, a specific negotiation process for negotiating both parties is provided, which includes:
g is the base point of the recommended parameters of the elliptic curve, and both parties of the key agreement know
The CPU A acquires a random number a from the random number module as a first private key;
the CPU B acquires a random number B from the random number module as a second private key;
the CPU A calculates PA ═ a ] G to obtain a first public key PA;
CPU B calculates PB ═ B ] G to obtain a second public key PB;
the CPU A sends the PA to the CPU B;
the CPU B sends the PB to the CPU A;
the CPU a receives PB, calculates [ a ] PB, and obtains a second shared key KA ([ a ] PB ═ a ] [ b ] G);
after receiving PA, CPU B calculates [ B ] PA to obtain first shared key KB
([b]PA=[b][a]G=[a][b]G);
The CPU A respectively calculates the following information by using a hash function to obtain two identity identifications:
determining a second identifier MID1 to be verified according to the shared secret + KA + PA + fixed data 1
Determining a first authentication identifier MID2 from the shared secret + KA + PB + fixed data2
Fixed data 1 and fixed data2 may be any data, but it is necessary to ensure that they must be different, while CPU A and CPU B must remain the same.
The CPU B uses a hash function to respectively calculate the following information to obtain two identity identifications:
determining a second authentication identity SID1 from "shared secret + KB + PA + fixed data 1";
determining a first to-be-verified identity SID2 from "shared secret + KB + PB + anchor data 2";
fixed data 1 and fixed data2 may be any data, but it is necessary to ensure that they must be different, while CPU A and CPU B must remain the same.
The CPU A sends the identity MID1 to the CPU B;
the CPU B sends the identification SID2 to the CPU A;
the CPU A judges whether the received CPU B identity SID2 is equal to the MID2, if so, the key agreement is successful, otherwise, the key agreement is failed;
and the CPU B judges whether the received CPU A identity MID1 is equal to SID1, if so, the key agreement is successful, otherwise, the key agreement is failed.
An embodiment of the present invention further provides a key negotiation apparatus, as shown in fig. 9, including
A key pair obtaining module 1010, configured to obtain a first random number, and generate a first public-private key pair according to the first random number;
in some embodiments, the first random number is generated by a random number generation module, and the generation of the first public-private key pair is based on the first random number, for example, the first random number is used as the first private key, and the first public key is generated with the first random number and an elliptic curve base point. For example, the first random number is a, the first random number a is used as a private key, and a first public key PA ═ a ] G is formed according to the first random number.
A public key sending module 1020, configured to send the first public key in the public-private key pair to the negotiation object; to cause the negotiation object to calculate a first shared key;
in some embodiments, the first public key is sent to the negotiation object, the negotiation object generates the first shared key according to the second random number and the first public key obtained by the negotiation object, and the first shared key is the shared key successfully negotiated under the condition that negotiation is successful. For example, the first shared key may be obtained by the following calculation: KB ═ b ] PA; wherein b is a second random number obtained by the negotiation object.
A public key receiving module 1030, configured to receive a second public key sent by the negotiation object, and generate a second shared secret key according to the second public key;
in some embodiments, the second public key is a second public key in a second public-private key pair formed by the negotiation object, the second shared key is a shared key generated according to the first random number and the second public key, and the second shared key is the same as the first shared key in case of successful negotiation. For example, the second shared key may be calculated as follows: KA ═ a ] PB; the PB is a second public key formed by the negotiation object according to the second random number, and preferably, the second public key may be calculated in the following manner: PB ═ b ] G.
The verification identifier generating module 1040 is configured to determine the first verification identifier according to the shared secret, the second public key, and the second shared key;
in some embodiments, the shared secret is secret information known to both communication parties, and the first authentication identifier is identification information used to authenticate whether the two parties negotiate success. For example, taking the shared key negotiation process of the dual-path processor as an example, the shared secret information may be a root key of the processor. For the first authentication identity, for example, the following calculation may be performed: MID2 ═ Hash (data2+ shared secret + PB + KA); data2 can be any information.
A to-be-verified identifier receiving module 1050, configured to receive a to-be-verified identifier sent by a negotiation object; the identification to be verified is a first identification to be verified determined according to the second public key, the first shared secret key and the shared secret;
in some embodiments, the first to-be-verified identifier is information that is used by the negotiation object to indicate an identity of the negotiation object, and the identity of the communication peer may be determined by verifying the first to-be-verified identifier with the first verification identifier. The first identifier to be verified may be calculated as follows: SID2 ═ Hash (data2+ shared secret + PB + KB); wherein data2 is the same information as data2 in step 400. In the step, the first to-be-verified mark is verified through the verification mark, and in the verification process, only the first to-be-verified mark needs to be transmitted, and the first shared key or the second shared key does not need to be transmitted, so that information cannot be leaked even if hijacked by a third party. Meanwhile, the first to-be-verified identifier and the first verification identifier are formed based on the first shared key and the second shared key, so that the negotiation result of the shared key can be verified by comparing the first to-be-verified identifier and the second to-be-verified identifier.
The verification module 1060 is configured to verify a current shared key negotiation result according to the first verification identifier and the first identifier to be verified.
In some embodiments, through comparison between the first authentication identifier and the second identifier to be authenticated, when the first authentication identifier and the second identifier to be authenticated are the same, it may be determined that the first shared key and the second shared key are the same, that is, the key agreement is successful, and when the first authentication identifier and the second identifier are different, it may be determined that the first shared key and the second shared key are different, that is, the key agreement is failed.
In the technical scheme provided by this embodiment, the processor performs shared key calculation through public key information sent by the other party, and the shared key is not directly transmitted or cannot be calculated through messages exchanged between CPUs, so that confidentiality of the shared key can be ensured. And, the shared key participates in the calculation of the identification information. If the message in the negotiation stage is tampered, the shared key generated by the two parties is different, and the identity identifications calculated based on the shared key are also different, so that the first verification information is different from the first information to be verified, which also results in the failure of the negotiation of the shared key. Although the shared secret is fixed, the two do not participate in the calculation of the shared key; the public-private key pair is randomly generated in each key agreement process, so even if the secret is shared, the data encrypted by using the old shared key is still safe.
On the basis of the above-mentioned embodiment shown in fig. 9, as an alternative implementation, as shown in fig. 10, the verified identity generating module 1040 includes:
a data splicing unit 1041, configured to splice the shared secret, the second public key, and the second shared key with the first fixed data to obtain spliced data;
in some embodiments, the shared secret and the first fixed data of the two communication parties are fixed, and the second public key and the second shared key are respectively generated randomly, and by splicing the shared secret, the second public key and the second shared key with the first fixed data, in a subsequent verification process, if one of the information changes, the verification will fail, so that the integrity of the verified information can be ensured.
A hash operation unit 1042, configured to perform a hash operation on the spliced data to obtain a hash value of the spliced data;
in some embodiments, the hash operation is different for each different piece of information, and the hash values of the two pieces of information can be made the same only if the pieces of information are identical. Therefore, it can be ensured that the authenticated information in the key agreement process is identical.
A verification identifier generating unit 1043, configured to use the hash value as the first verification identifier.
In some embodiments, as described in step 420, the hash value is used as the first authentication identifier, and the first to-be-authenticated identifier sent by the negotiation object is also used as the hash value, and the two are the same, that is, it can be confirmed that the information of the two is identical.
In the embodiment, a plurality of information splicing modes are adopted for verification, so that the information which is verified successfully is complete and reliable, and meanwhile, the hash algorithm is used for accurately and quickly verifying the consistency of the information because the obtained value is unique.
It will be understood by those skilled in the art that all or part of the processes of the embodiments of the methods described above may be implemented by a computer program, which may be stored in a computer-readable storage medium, and when executed, may include the processes of the embodiments of the methods described above. The storage medium may be a magnetic disk, an optical disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), or the like.
The above description is only for the specific embodiment of the present invention, but the scope of the present invention is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present invention are included in the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.