Disclosure of Invention
Therefore, the invention provides a code downloading and starting safety protection method and device based on a safety chip, and aims to solve the problem that in the prior art, the safety chip lacks the processing of code downloading and starting, and the safety of a product is influenced due to the fact that a tampered illegal code is operated.
In order to achieve the above purpose, the invention provides the following technical scheme: the code downloading starting safety protection method based on the safety chip comprises the following steps:
configuring downloading authority: judging whether the security chip downloads the public key, and if the security chip downloads the public key, finishing configuration; if the public key is not downloaded by the security chip, configuring random number information, downloading the public key to an SRAM of the security chip, signing the random number by adopting a private key, and copying the public key to a storage area of the security chip according to a signature verification result of the random number;
acquiring downloading authority: acquiring the random number from the security chip, signing the random number by adopting a private key, issuing signature data to the security chip, verifying the signature data by the security chip according to the public key, and judging whether the security chip has a downloading right or not according to a verification result;
configuring a starting authority: after obtaining the download authority, downloading the code to the security chip; performing summary operation on the code to obtain a summary value, and encrypting the summary value by adopting a private key to obtain code encryption data; configuring the code encryption data into configuration information, and downloading the configuration information to the security chip;
acquiring a starting authority: when the code is started, verifying the configuration information; when the configuration information is verified successfully, performing abstract operation on codes in a code storage area of the security chip to obtain code abstract data; and decrypting the code encrypted data by adopting a public key, comparing the decrypted data with the code abstract data, and judging whether the code encrypted data has the starting authority or not according to a comparison result.
As a preferred scheme of a code downloading starting security protection method based on a security chip, in the process of configuring downloading authority, a private key is adopted to sign the random number, a signature value is issued to the security chip, the security chip adopts a public key in an SRAM to verify the signature value, and the public key is copied to a storage area of the security chip after verification is successful.
As a preferred scheme of a code downloading starting security protection method based on a security chip, in the process of configuring downloading permission, an OTP storage mode is adopted for one-time configuration:
storing a public key and a public key mark in an OTP storage area of the security chip subjected to downloading permission configuration, judging whether the public key is valid through the public key mark, and finishing downloading permission configuration if the public key mark is valid; and if the public key mark is invalid, carrying out downloading authority configuration on the security chip.
As a preferred scheme of a code downloading starting safety protection method based on a safety chip, in the process of obtaining downloading authority, the safety chip verifies signature data according to a public key, the signature verification is successful, the code downloading is allowed, the signature verification fails, and the code downloading is prevented.
As a preferred scheme of a code downloading starting security protection method based on a security chip, in the process of configuring the starting authority, the configuration information configured by the code encryption data is subjected to digest operation again, and a digest value obtained by performing digest operation again is added to the configuration information.
As a preferred scheme of a code downloading starting safety protection method based on a safety chip, in the process of obtaining starting authority, after summary data in configuration information is removed, summary operation is carried out on the configuration information with the summary data removed, the calculated summary value is compared with the removed summary value, if the comparison result is consistent, the configuration information is correct, the starting downloading is allowed, otherwise, the starting downloading is failed;
when the configuration information is verified to be correct, performing abstract operation on the codes downloaded in the security chip to obtain abstract values of the downloaded codes; and decrypting the code encrypted data in the configuration information by adopting a public key, comparing the decrypted abstract value with the abstract value of the downloaded code, if the comparison result is consistent, the code is correct, and allowing the security chip to be normally started, otherwise, the starting and downloading are failed.
The invention also provides a code downloading starting safety protection device based on the safety chip, which comprises:
the download authority configuration unit is used for judging whether the security chip downloads the public key or not, and finishing configuration if the security chip downloads the public key; if the public key is not downloaded by the security chip, configuring random number information, downloading the public key to an SRAM of the security chip, signing the random number by adopting a private key, and copying the public key to a storage area of the security chip according to a signature verification result of the random number;
the download authority acquisition unit is used for acquiring the random number from the security chip, signing the random number by adopting a private key, issuing signature data to the security chip, verifying the signature data by the security chip according to a public key and judging whether the download authority exists or not according to a verification result;
the starting authority configuration unit is used for downloading the code to the security chip after acquiring the downloading authority; performing summary operation on the code to obtain a summary value, and encrypting the summary value by adopting a private key to obtain code encrypted data; configuring the code encryption data into configuration information, and downloading the configuration information to the security chip;
the starting authority acquiring unit is used for verifying the configuration information when the code is started; after the configuration information is verified successfully, performing abstract operation on the codes of the code storage area of the security chip to obtain code abstract data; and decrypting the code encrypted data by adopting a public key, comparing the decrypted data with the code abstract data, and judging whether the starting authority is available or not according to a comparison result.
As a preferred scheme for starting a security protection device by downloading a code based on a security chip, in the downloading permission configuration unit, a private key is adopted to sign the random number, a signature value is issued to the security chip, the security chip adopts a public key in an SRAM to verify the signature value, and the public key is copied to a storage area of the security chip after the verification is successful;
in the download authority configuration unit, an OTP storage mode is adopted for one-time configuration:
storing a public key and a public key mark in an OTP (one time programmable) storage area of the security chip subjected to downloading permission configuration, judging whether the public key is valid through the public key mark, and finishing downloading permission configuration if the public key mark is valid; and if the public key mark is invalid, carrying out downloading authority configuration on the security chip.
As a preferred scheme for starting the security protection device by downloading the code based on the security chip, in the download permission acquisition unit, the security chip verifies the signature data according to the public key, the signature verification is successful, the code download is allowed, the signature verification fails, and the code download is prevented.
As a preferred scheme for starting the security protection device by downloading the code based on the security chip, the start authority configuration unit performs digest operation on the configuration information configured by the code encryption data again, and adds a digest value obtained by performing digest operation again to the configuration information.
As a preferred scheme for starting the security protection device by code downloading based on the security chip, in the starting authority acquiring unit, after removing the abstract data in the configuration information, performing abstract operation on the configuration information without the abstract data, comparing the operated abstract value with the removed abstract value, if the comparison result is consistent, the configuration information is correct, and the downloading is allowed to be started, otherwise, the downloading is failed to be started;
when the configuration information is verified to be correct, performing abstract operation on the codes downloaded in the security chip to obtain abstract values of the downloaded codes; and decrypting the code encrypted data in the configuration information by adopting a public key, comparing the decrypted abstract value with the abstract value of the downloaded code, if the comparison result is consistent, the code is correct, and allowing the security chip to be normally started, otherwise, the starting and downloading are failed.
The invention has the following advantages: judging whether the security chip downloads the public key, and finishing the configuration if the security chip downloads the public key; if the public key is not downloaded by the security chip, random number information is configured, the public key is downloaded to an SRAM of the security chip, the private key is adopted to sign the random number, and the public key is copied to a storage area of the security chip according to a signature verification result of the random number; acquiring a random number from a security chip, signing the random number by adopting a private key, sending signature data to the security chip, verifying the signature data by the security chip according to a public key, and judging whether the security chip has a downloading right or not according to a verification result; after obtaining the downloading authority, downloading the code to the security chip; performing summary operation on the code to obtain a summary value, and encrypting the summary value by adopting a private key to obtain code encrypted data; configuring the code encryption data into configuration information, and downloading the configuration information to a security chip; when the code is started, verifying the configuration information; when the configuration information is verified successfully, performing abstract operation on codes in a code storage area of the security chip to obtain code abstract data; and decrypting the code encrypted data by adopting the public key, comparing the decrypted data with the code abstract data, and judging whether the starting authority is available or not according to a comparison result. The invention can ensure the safety of the chip code, prevent illegal code downloading, ensure the starting safety of the safety chip and prevent code tampering; the invention adopts double authentication, the download authority needs configuration information authentication (otherwise, the configuration is unsuccessful) and download authentication (otherwise, the download cannot be carried out); the starting authority needs configuration information authentication (preventing configuration information from being tampered) and starting authentication (preventing code from being tampered), product safety is ensured, and economic loss of developers is avoided.
Detailed Description
The present invention is described in terms of particular embodiments, other advantages and features of the invention will become apparent to those skilled in the art from the following disclosure, and it is to be understood that the described embodiments are merely exemplary of the invention and that it is not intended to limit the invention to the particular embodiments disclosed. All other embodiments, which can be obtained by a person skilled in the art without making any creative effort based on the embodiments in the present invention, belong to the protection scope of the present invention.
Example 1
Referring to fig. 1, embodiment 1 of the present invention provides a method for starting security protection of code download based on a security chip, including:
configuring downloading authority: judging whether the security chip downloads the public key or not, and finishing configuration if the security chip downloads the public key; if the public key is not downloaded by the security chip, configuring random number information, downloading the public key to an SRAM of the security chip, signing the random number by adopting a private key, and copying the public key to a storage area of the security chip according to a signature verification result of the random number;
acquiring downloading authority: acquiring the random number from the security chip, signing the random number by adopting a private key, issuing signature data to the security chip, verifying the signature data by the security chip according to the public key, and judging whether the security chip has a downloading right or not according to a verification result;
configuring a starting authority: after obtaining the downloading authority, downloading a code to the security chip; performing summary operation on the code to obtain a summary value, and encrypting the summary value by adopting a private key to obtain code encryption data; configuring the code encryption data into configuration information, and downloading the configuration information to the security chip;
acquiring a starting authority: when the code is started, verifying the configuration information; when the configuration information is verified successfully, performing abstract operation on codes in a code storage area of the security chip to obtain code abstract data; and decrypting the code encrypted data by adopting a public key, comparing the decrypted data with the code abstract data, and judging whether the starting authority is available or not according to a comparison result.
In the process of configuring the download permission, the present embodiment signs the random number with a private key, issues a signature value to the security chip, verifies the signature value with a public key in the SRAM, and copies the public key to a storage area of the security chip after the verification is successful.
Referring to fig. 2, the security chip may be configured to generate a random number and may verify a signature with a public key. Before downloading the code to the security chip, firstly, confirming whether the security chip downloads the public key, if the public key is not downloaded, downloading the public key to the storage area of the security chip, and if the public key is downloaded, directly running the next step. When the public key is downloaded to the storage area of the security chip, the public key is downloaded to an SRAM of the security chip, the random number is obtained from the security chip, the private key is used for signing the random number, the signature value is issued to the security chip, the security chip uses the public key in the SRAM to check the signature value, and after the signature is successfully checked, the security chip copies the public key to the storage area.
In this embodiment, in the process of configuring the download permission, an OTP storage mode is used for one-time configuration:
storing a public key and a public key mark in an OTP (one time programmable) storage area of the security chip subjected to downloading permission configuration, judging whether the public key is valid through the public key mark, and finishing downloading permission configuration if the public key mark is valid; and if the public key mark is invalid, carrying out downloading authority configuration on the security chip.
Specifically, before the secure chip is securely downloaded, it is first determined whether the secure chip has configured the download permission, and for the sake of security, the OTP memory mode is used for one-time configuration when configuring the download permission, that is, each secure chip can only perform one-time download permission configuration. The security chip which performs downloading authority configuration stores a public key and a public key mark in the OTP storage area, whether the public key is valid can be judged through the public key mark, if the public key is valid, the security chip performs downloading authority configuration, and the security chip finishes the downloading authority configuration. And if the public key mark is invalid, carrying out downloading authority configuration on the security chip.
Specifically, when the download authority configuration is performed on the security chip, it is further determined whether the chip is a security chip. The security chip has the functions of generating random numbers and verifying signatures of signatures, a section of random numbers are obtained from the chip after the random number initialization and other configurations are carried out on the chip through a downloading tool, the random numbers are signed at the downloading tool after the random numbers are obtained, and signature information and public key information are downloaded into the chip for verification after being prepared. Because the chip public key information is stored in the OTP storage area, in order to prevent the problem that the OTP area information cannot be recovered due to verification failure, the public key information is firstly downloaded into the chip SRAM, then the signature data is downloaded into the chip verification area, and finally the chip verifies the signature of the signature information. If the signature verification is successful, the public key information is stored in the OTP storage area, if the signature verification is failed, the downloading permission configuration is ended, and the public key information is automatically cleared after the chip is powered off.
In the embodiment, in the process of acquiring the downloading permission, the security chip verifies the signature data according to the public key, the signature verification is successful, the code downloading is allowed, the signature verification fails, and the code downloading is prevented.
Referring to fig. 3, specifically, the public key is itself public and can be obtained by anyone at will, but only the user who owns the private key corresponding to the public key in the security chip can obtain the download authority and download the code. The method comprises the steps that a random number is obtained from a security chip through a downloading tool, the random number is signed at the downloading tool, the downloading tool issues signature information to the security chip, the security chip uses a public key configured before to verify the signature of the signature information, if the signature verification is successful, codes can be downloaded, and if the signature verification fails, the codes cannot be downloaded.
In this embodiment, in the process of configuring the start permission, the digest operation is performed again on the configuration information configured by the code encrypted data, and the digest value obtained by performing the digest operation again is added to the configuration information.
Referring to fig. 4, specifically, the configuration of the start authority is to download configuration information into the storage area of the security chip, and the process and the code downloading process are performed synchronously. The configuration information comprises private key encryption data and digest values of the configuration information, the configuration information is generated in a downloading tool, the downloading tool firstly obtains downloading codes, the size of the downloading code data is possibly large, the downloading codes are operated through a hash algorithm to obtain a group of digest values, and the digest values are unique if the codes are unique. And encrypting the digest value by using a private key at the downloading tool end, wherein the code encrypted data can be decrypted only by using a corresponding public key. The length of the configuration information is equal to the length of the code encrypted data plus the length of the digest value of the configuration information, in order to ensure the integrity of the configuration information, the digest operation is carried out on the configuration information (the positions of the digest values are all zero), and then the digest values are added into the configuration information to form the complete configuration information. And finally, downloading the configuration information to the security chip when downloading the code.
Specifically, the protection of the configuration information adopts a method of changing the configuration information by hashing the configuration information per se to ensure the safety of the configuration information, and the specific method is that the length of the configuration information is fixed, 32 bytes (determined according to the hashing) are reserved as 0 to be used as a position for storing an abstract value, the configuration information is abstracted and then the abstract value is put at the position of the abstract value, and the data of the position of the abstract value is cleared and then hashed when being verified later.
In the embodiment, in the process of acquiring the starting authority, after the abstract data in the configuration information is removed, the configuration information with the abstract data removed is subjected to abstract operation, the operated abstract value is compared with the removed abstract value, if the comparison result is consistent, the configuration information is correct, the starting of downloading is allowed, otherwise, the starting of downloading fails;
after the configuration information is verified to be correct, carrying out abstract operation on the codes downloaded in the security chip to obtain abstract values of the downloaded codes; and decrypting the code encrypted data in the configuration information by adopting a public key, comparing the decrypted abstract value with the abstract value of the downloaded code, if the comparison result is consistent, the code is correct, and allowing the security chip to be normally started, otherwise, the starting and downloading are failed.
Referring to fig. 5, specifically, the obtaining of the start permission is automatically completed inside the security chip, and the security chip may automatically complete verification and start under the condition that the code security download and the security start configuration are correct.
When the safety chip is started, if the safety starting configuration information is detected in the safety chip, the safety chip automatically acquires the configuration information, after the abstract data in the configuration information is removed, the configuration information without the abstract information is subjected to abstract operation, the abstract value of the operation is compared with the removed abstract value, if the result is consistent, the configuration information is correct, and if not, the starting is failed. And after the configuration information is verified to be correct, verifying the code correctness. And performing summary operation on the code downloaded from the security chip to obtain a summary value of the downloaded code, decrypting the encrypted data in the configuration information by using a public key, comparing the decrypted summary value with the summary value of the downloaded code, and if the results are consistent, judging that the code is correct, and normally starting the security chip, otherwise, judging that the starting fails, and ensuring the legality of the code.
By combining the technical scheme of the invention, the code downloading of the chip can support common downloading and safe downloading, and the code is downloaded through a downloading tool. The common downloading is the same as the common MCU chip, the code can be directly downloaded to the storage area of the chip, and then the code can be directly operated; the safe downloading needs to configure the downloading authority of the chip at first, the chip with the configured downloading authority can download the code only after acquiring the downloading authority from the chip. The safe downloading comprises configuring the downloading authority and obtaining the downloading authority, and the legality of the user is guaranteed.
By combining the technical scheme of the invention, the chip code starting supports common starting and safe starting. The common start is the same as the general MCU chip, and the code stored in the chip can be directly started to run; the safe starting needs to be firstly carried out on the chip, the chip with the starting permission is configured, the operation can be started only after the code is verified by obtaining the starting permission, the safe starting comprises the steps of configuring the starting permission and obtaining the starting permission, and the legality of the code is guaranteed. After the chip is configured with the downloading authority and the starting authority, only the starting authority needs to be obtained and started every time the chip is started, and if the code is upgraded, the starting authority needs to be reconfigured.
In summary, the present invention determines whether the security chip downloads the public key, and if the security chip has downloaded the public key, the configuration is ended; if the public key is not downloaded by the security chip, configuring random number information, downloading the public key to an SRAM of the security chip, signing the random number by adopting a private key, and copying the public key to a storage area of the security chip according to a signature verification result of the random number; acquiring a random number from a security chip, signing the random number by adopting a private key, issuing signature data to the security chip, verifying the signature data by the security chip according to the public key, and judging whether the security chip has a downloading right or not according to a verification result; after obtaining the downloading authority, downloading the code to the security chip; performing summary operation on the code to obtain a summary value, and encrypting the summary value by adopting a private key to obtain code encrypted data; configuring the code encryption data into configuration information, and downloading the configuration information to a security chip; when the code is started, verifying the configuration information; when the configuration information is verified successfully, performing abstract operation on codes in a code storage area of the security chip to obtain code abstract data; and decrypting the code encrypted data by adopting the public key, comparing the decrypted data with the code abstract data, and judging whether the starting authority is available or not according to a comparison result. The invention can ensure the safety of the chip code, prevent illegal code downloading, ensure the starting safety of the safety chip and prevent code tampering; the invention adopts double authentication, the download authority needs configuration information authentication (otherwise, the configuration is unsuccessful) and download authentication (otherwise, the download cannot be carried out); the starting authority needs configuration information authentication (preventing configuration information from being tampered) and starting authentication (preventing code from being tampered), product safety is ensured, and economic loss of developers is avoided.
Example 2
Referring to fig. 6, embodiment 2 of the present invention provides a security chip-based code download start security protection apparatus, including:
the download authority configuration unit 1 is used for judging whether the security chip downloads the public key or not, and finishing configuration if the security chip downloads the public key; if the public key is not downloaded by the security chip, configuring random number information, downloading the public key to an SRAM of the security chip, signing the random number by adopting a private key, and copying the public key to a storage area of the security chip according to a signature verification result of the random number;
the download authority acquiring unit 2 is used for acquiring the random number from the security chip, signing the random number by adopting a private key, issuing the signature data to the security chip, verifying the signature data by the security chip according to the public key, and judging whether the download authority exists according to a verification result;
the starting authority configuration unit 3 is used for downloading codes to the security chip after acquiring downloading authority; performing summary operation on the code to obtain a summary value, and encrypting the summary value by adopting a private key to obtain code encryption data; configuring the code encryption data into configuration information, and downloading the configuration information to the security chip;
the starting authority acquiring unit 4 is used for verifying the configuration information when the code is started; after the configuration information is verified successfully, performing abstract operation on the codes of the code storage area of the security chip to obtain code abstract data; and decrypting the code encrypted data by adopting a public key, comparing the decrypted data with the code abstract data, and judging whether the code encrypted data has the starting authority or not according to a comparison result.
In this embodiment, in the download permission configuration unit 1, a private key is used to sign the random number, a signature value is issued to the security chip, the security chip verifies the signature value by using a public key in an SRAM, and the public key is copied to a storage area of the security chip after the verification is successful;
in the download authority configuration unit 1, an OTP storage mode is adopted for one-time configuration:
storing a public key and a public key mark in an OTP storage area of the security chip subjected to downloading permission configuration, judging whether the public key is valid through the public key mark, and finishing downloading permission configuration if the public key mark is valid; and if the public key mark is invalid, carrying out downloading authority configuration on the security chip.
In this embodiment, in the download permission obtaining unit 2, the security chip verifies the signature data according to the public key, and if the signature verification is successful, the code download is allowed, and if the signature verification fails, the code download is prevented.
In this embodiment, in the start authority configuration unit 3, the digest operation is performed again on the configuration information configured by the code encrypted data, and the digest value obtained by performing the digest operation again is added to the configuration information.
In this embodiment, in the starting permission obtaining unit 4, after the summary data in the configuration information is removed, the configuration information with the summary data removed is subjected to summary operation, the calculated summary value is compared with the removed summary value, if the comparison result is consistent, the configuration information is correct, the starting of downloading is allowed, otherwise, the starting of downloading fails;
after the configuration information is verified to be correct, carrying out abstract operation on the codes downloaded in the security chip to obtain abstract values of the downloaded codes; and decrypting the code encrypted data in the configuration information by adopting a public key, comparing the decrypted abstract value with the abstract value of the downloaded code, if the comparison result is consistent, the code is correct, and the security chip is allowed to be normally started, otherwise, the starting and downloading are failed.
It should be noted that, because the contents of information interaction, execution process, and the like between the modules/units of the apparatus are based on the same concept as the method embodiment in embodiment 1 of the present application, the technical effect brought by the contents is the same as the method embodiment of the present application, and specific contents may refer to the description in the foregoing method embodiment of the present application, and are not described herein again.
Example 3
Embodiment 3 of the present invention provides a non-transitory computer-readable storage medium, where a program code for downloading and starting a security protection method based on a code of a security chip is stored in the computer-readable storage medium, where the program code includes an instruction for executing the security chip-based code downloading and starting the security protection method according to embodiment 1 or any possible implementation manner of the embodiment.
Computer-readable storage media can be any available media that can be accessed by a computer or a data storage device, such as a server, data center, etc., that includes one or more available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid State Disk (SSD)), among others.
Example 4
An embodiment 4 of the present invention provides an electronic device, including: a memory and a processor;
the processor and the memory are communicated with each other through a bus; the memory stores program instructions executable by the processor, and the processor calls the program instructions to execute the secure chip-based code download initiation security protection method of embodiment 1 or any possible implementation manner thereof.
Specifically, the processor may be implemented by hardware or software, and when implemented by hardware, the processor may be a logic circuit, an integrated circuit, or the like; when implemented in software, the processor may be a general-purpose processor implemented by reading software code stored in a memory, which may be integrated with the processor, located external to the processor, or stand-alone.
In the above embodiments, all or part of the implementation may be realized by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, cause the processes or functions described in accordance with the embodiments of the invention to be performed in whole or in part. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another computer readable storage medium, for example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means.
It will be apparent to those skilled in the art that the modules or steps of the present invention described above may be implemented by a general purpose computing device, they may be centralized in a single computing device or distributed across a network of multiple computing devices, and alternatively, they may be implemented by program code executable by a computing device, such that they may be stored in a memory device and executed by a computing device, and in some cases, the steps shown or described may be executed out of order, or separately as individual integrated circuit modules, or multiple modules or steps thereof may be implemented as a single integrated circuit module. Thus, the present invention is not limited to any specific combination of hardware and software.
Although the invention has been described in detail above with reference to a general description and specific examples, it will be apparent to one skilled in the art that modifications or improvements may be made thereto based on the invention. Accordingly, such modifications and improvements are intended to be within the scope of the invention as claimed.