Terminal program verification method and system and readable storage medium
By adding configuration files to the terminal program and calculating a unified hash value, the problem of increasing difficulty in terminal software version control is solved, and the efficiency and accuracy of terminal program verification is achieved.
Patent Information
- Application Number
- CN202510391992.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-31
- Publication Date
- 2025-04-29
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
With the increase in terminal functions and complexity, the number of APPs in the terminal and the operating system, drivers, parameter configuration and other files have increased, resulting in the increase in the difficulty of terminal software version control. It is difficult for the existing technology to efficiently verify whether the versions of all programs and parameter files in the terminal are correct.
By adding configuration files to the program, all files and paths that need to be compared and checked are added to the configuration file. The terminal calculates a unified hash value based on the configuration file. When the detection software reads the terminal hash value, the terminal directly returns the final hash value to the detection software. The detection software compares the final hash value to determine whether the versions of all programs and parameter files in the current terminal are correct.
It improves the accuracy and efficiency of terminal program verification, can effectively detect the integrity and consistency of files in the terminal, and reduces the complexity in the verification process.
Smart Images

Figure CN119902961A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of program verification technology, and in particular to a terminal program verification method, system and readable storage medium. Background Art
[0002] Terminal program verification is mainly used in the field of data communication to ensure that no errors occur during data transmission or storage. This method can effectively detect errors in data and improve the reliability and security of data transmission.
[0003] As the functions and complexity of terminals increase, the number of apps in the terminal and the number of operating system, driver, parameter configuration and other files increase, and the difficulty of terminal software version control also increases. Before the terminal leaves the factory and during operation, in order to check whether the operating system, driver, software, configuration parameters and other files are correct, it is necessary to check and judge the check value of each file. At the same time, if the terminal files are added or deleted, the detection software needs to be modified synchronously. Summary of the invention
[0004] The purpose of the present application is to provide a terminal program verification method, system and readable storage medium. By adding a configuration file to the program, all files and paths that need to be compared and verified are added to the configuration file. The terminal calculates a unified hash value based on the configuration file. When the detection software reads the terminal hash value, the terminal directly returns the final hash value to the detection software. The detection software determines whether the versions of all programs and parameter files in the current terminal are correct by comparing the final hash value, so as to improve the accuracy and efficiency of terminal program verification.
[0005] The first aspect of the present application provides a terminal program verification method, the method comprising: Read program configuration files; Parse the program configuration file to obtain the total number of programs that need to be calculated; Obtain a random number Rn through the terminal encryption chip; According to the program path and size and the random number Rn of the program file, the hash value of each program is calculated in turn, and the hash value of the program file and the program name are written into a temporary file; Perform SM3 verification on temporary files in the software program, return the random number Rn and the final hash value of the program file, generate a terminal program hash reference value, and save it in the terminal program; Receive the terminal program verification instruction to be verified, call the terminal program hash value reference value according to the program path, verify whether all program configurations in the terminal to be verified are correct according to the terminal program hash value reference value, and output the verification result.
[0006] Optionally, after reading the program configuration file, the method further comprises the following steps: Check whether the program configuration file is correct; If yes, the program configuration file is parsed to obtain the total number of programs that need to be calculated; Obtain a random number Rn through the terminal encryption chip; If not, the hash value of the program is cleared and the terminal program verification is exited.
[0007] Optionally, the step of calculating the hash value of each program in sequence according to the program path and size and the random number Rn of the program file specifically includes: Read the program file according to the program path, and concatenate the program file with the random number to obtain the concatenated program file; Determine the security level of the spliced program files. If the security level is high, use the SM3 algorithm to calculate the hash value of each program in turn; if the security level is low, use the MD5 algorithm to calculate the hash value.
[0008] Optionally, the program file and the random number are concatenated as follows: CombinedData=Filebytes⊕Rnbytes Among them, CombinedData is the concatenated program file, Filebytes is the byte data of the program file, and Rnbytes is the random number byte data of the program file.
[0009] Optionally, the hash value is calculated using the MD5 algorithm, specifically: Get the size of the program through the program file; Add padding to the program; Divide the file after adding the padding bit into blocks; obtain the program file data block; Initialize MD buffer; Expand the variables of the program file data block; According to the initialization result of the MD buffer, nonlinear function operation and bit operation are performed on the expanded program file data block to obtain the current hash value of the program file data block; Traverse all program file data blocks and add the nonlinear function and bit operation results of all program file data blocks to the current hash value; Combine the current hash values to get the MD5 hash value of the program file.
[0010] Optionally, adding padding bits to the program includes: Determine the size of the program file and whether the data length of the program file is a multiple of 512 bits; If so, the program file is divided into blocks; If not, fill the data bits of the program file as follows: First add a 1, then add a sufficient number of 0s, and finally add a 64-bit padding length to make the data length of the program file a multiple of 512 bits.
[0011] Optionally, the nonlinear function operation includes: F function: F(X,Y,Z)=(X&Y)∣((~X)&Z) Among them, X, Y, and Z represent input variables; "~" is the negation operator, and "&" is the sum operator; in the F function, if X and Y are the same, the result is X, otherwise it is Z; G function: G(X,Y,Z)=(X&Z)∣(Y&(~Z)) In the G function, if X and Z are the same, the result is X, otherwise it is Y; H function: H(X,Y,Z)=X⊕Y⊕Z Among them, ⊕ is the exclusive OR operator, and the H function represents the exclusive OR of X, Y and Z; I function: I(X,Y,Z)=Y⊕(X∣(~Z)) In the I function, if Z is 0, the result is the exclusive OR of Y and X, otherwise it is Y.
[0012] Optionally, the bit operation includes circular left shift and addition; The circular left shift operation shifts a 32-bit number to the left by the specified number of bits, and the overflowed bits will loop back to the right of the number; The addition operation modulo 2^32 ensures that the result is still a 32-bit number.
[0013] Optionally, verifying whether all program configurations in the terminal to be verified are correct based on the terminal program hash reference value includes: Retrieve the terminal program hash reference value, and compare the hash value of the terminal program to be verified with the terminal program hash reference value; if the two are exactly the same, it means that the terminal program to be verified is complete; if they are different, it means that the terminal program to be verified is incomplete.
[0014] A second aspect of the present invention provides a terminal program verification system, comprising a memory and a processor, wherein the memory comprises a terminal program verification method program, and when the terminal program verification method program is executed by the processor, the steps of the terminal program verification method are implemented.
[0015] A third aspect of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium includes a terminal program verification method program, and when the terminal program verification method program is executed by a processor, the steps of the terminal program verification method are implemented.
[0016] As can be seen from the above, the present application provides a terminal program verification method, system and readable storage medium. The present application adds a configuration file to the program, adds all the files and paths that need to be compared and verified to the configuration file, and the terminal calculates a unified hash value based on the configuration file. When the detection software reads the terminal hash value, the terminal directly returns the final hash value to the detection software, and the detection software determines whether the versions of all programs and parameter files in the current terminal are correct by comparing the final hash value. The method described in the present application can effectively improve the accuracy of terminal program verification by adding a configuration file to the program, and verifying based on the configuration file hash value during verification, and can also improve the efficiency of terminal program verification.
[0017] Other features and advantages of the present application will be described in the following description, and partly become apparent from the description, or be understood by practicing the embodiments of the present application. The purpose and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0019] Figure 1 A flow chart of a terminal program verification method provided in an embodiment of the present application.
[0020] Figure 2 This is the flowchart for obtaining the hash value for this application.
[0021] Figure 3 A block diagram of a terminal program verification system provided in an embodiment of the present application. DETAILED DESCRIPTION
[0022] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.
[0023] It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. At the same time, in the description of this application, the terms "first", "second", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance.
[0024] Please refer to Figure 1 , is a terminal program verification method in some embodiments of the present application, the method comprising: S102: Reading a program configuration file; S104: Parse the program configuration file to obtain the total number of programs that need to be calculated; obtain a random number Rn through the terminal encryption chip; S106: Calculate the hash value of each program in turn according to the program path and size and the random number Rn of the program file, and write the hash value of the program file and the program name into a temporary file; S108: Perform SM3 verification on the temporary file in the software program, and return the random number Rn and the final hash value of the program file, generate a terminal program hash reference value, and save it in the terminal program; S110: receiving a terminal program verification instruction to be verified, retrieving a terminal program hash value reference value according to the program path, verifying whether all program configurations in the terminal to be verified are correct according to the terminal program hash value reference value, and outputting a verification result.
[0025] According to an embodiment of the present invention, the program configuration file adopts the JSON format, including three fields: file name, path, size, and security_level.
[0026] It should be noted that this application adds the files that need to be compared to the version configuration file according to the functional requirements of the terminal. The version configuration file includes the file name, path, and security level that need to be calculated. The configuration file is bound to the program. For files with higher security levels such as kernel, uboot, and APP, the SM3 algorithm is used to ensure the reliability of verification. For files with lower security levels such as configuration scripts and dynamic libraries, the MD5 algorithm is used to increase the calculation speed.
[0027] JSON (JavaScript Object Notation) is a lightweight data exchange format that uses a text format that is completely independent of programming languages to store and represent data. It is based on a subset of ECMAScript (JavaScript specification developed by the European Computer Association). Its concise and clear hierarchical structure makes JSON an ideal data exchange language. JSON is easy for people to read and write, and it is also easy for machines to parse and generate, which effectively improves network transmission efficiency.
[0028] In the present application, the file name of the program configuration file is used to achieve program matching, the path path is used to facilitate the storage and retrieval of the program, and the security_level is used to identify the security level of the file. According to an embodiment of the present invention, the method further includes the following steps after reading the program file: Check whether the program configuration file is correct; If yes, the program configuration file is parsed to obtain the total number of programs that need to be calculated; Obtain a random number Rn through the terminal encryption chip; If not, the hash value of the program is cleared and the terminal program verification is exited.
[0029] It should be noted that the present application first judges the program before calculating the hash value of the program to determine whether the program is correct, executes the next step for the correctly configured file, and clears the hash value of the incorrectly configured program, and then exits the terminal verification program to reduce the complexity of the program terminal verification, thereby improving the efficiency of the terminal program verification.
[0030] According to an embodiment of the present invention, the step of calculating the hash value of each program in turn according to the program path and size and the random number Rn of the program file specifically includes: Read the program file according to the program path, and concatenate the program file with the random number to obtain the concatenated program file; Determine the security level of the spliced program files. If the security level is high, use the SM3 algorithm to calculate the hash value of each program in turn; if the security level is low, use the MD5 algorithm to calculate the hash value.
[0031] It should be noted that MD5 (Message-Digest Algorithm 5) is a widely used hash function that can convert input data of any length into a fixed-length (128-bit) hash value. The MD5 algorithm was designed by Ron Rivest in 1991 and was originally used for digital signatures and data integrity verification. It can also be used to verify the integrity of files.
[0032] According to an embodiment of the present invention, the concatenation of the program file and the random number is specifically as follows: CombinedData=Filebytes⊕Rnbytes Among them, CombinedData is the concatenated program file, Filebytes is the byte data of the program file, and Rnbytes is the random number byte data of the program file.
[0033] According to an embodiment of the present invention, the hash value is calculated using the SM3 algorithm or the MD5 algorithm, specifically: H=SM3(CombinedData) H=MD5(CombinedData) It should be noted that in this application, the random number Rn is first obtained from the encryption chip, the program configuration file is read to obtain the check number N, and the flag pos=1 is initialized; then the posth file is read and spliced (connected) with Rn; the security level of the spliced program file is determined according to the security level of the file, and the hash value of each program is calculated in turn according to the security level of the file. If the security level is high, the SM3 algorithm is used to calculate the hash value of each program in turn; if the security level is low, the MD5 algorithm is used to calculate the hash value. Then the hash value of the program file and the program name are written into a temporary file; then pos=pos+1, and then determine whether pos≤N is true. If so, the file corresponding to pos is spliced with Rn and the next cycle is performed until pos≤N is not true; finally, the temporary file in the software program is SM3 checked, and the random number Rn and the final hash value of the program file are returned. See the above process. Figure 2 .
[0034] It should be noted that in this application, the security level of the file is defined artificially.
[0035] According to an embodiment of the present invention, calculating the hash value using the MD5 algorithm specifically includes: Get the size of the program; Add padding to the program; Divide the file after adding the padding bit into blocks; obtain the program file data block; Initialize MD buffer; Expand the variables of the program file data block; According to the initialization result of the MD buffer, nonlinear function operation and bit operation are performed on the expanded program file data block to obtain the current hash value of the program file data block; Traverse all program file data blocks and add the nonlinear function and bit operation results of all program file data blocks to the current hash value; Combine the current hash values to get the MD5 hash value of the program file.
[0036] It should be noted that the calculation method of the MD5 value involves a complex mathematical algorithm that converts the input (such as a file) into a fixed-length hash value. The following are the basic steps for calculating the MD5 value: Step 1: Input preparation: First, prepare the input data (which can be a file or a string). If the input is a file, you need to read the file content.
[0037] Step 2: Padding: The MD5 algorithm requires that the length of the input data is a multiple of 512 bits. If the length of the input data is not a multiple of 512 bits, padding bits need to be added until this requirement is met. The padding bits are added in the following way: first add a 1, then add a sufficient number of 0s, and finally add a 64-bit padding length (this length is the binary representation of the input data length).
[0038] Step 3: Chunking: Divide the padded data into 512-bit blocks.
[0039] Step 4: Initialize MD buffer: Assuming A, B, C, and D are variables for MD value calculation, initialize four 32-bit variables A, B, C, and D, which will be used for intermediate results in the calculation process.
[0040] Step 5: Main loop: For each 512-bit block of data, perform the following steps: Expand the value of the data block into 16 32-bit variables (X[0] to X
[15] ).
[0041] Copy the initial values of A, B, C, and D to four other variables (AA, BB, CC, DD).
[0042] For four rounds (16 operations per round), a series of nonlinear functions and bit operations are performed involving the variables of the data block and the current hash value (A, B, C, D).
[0043] Add the result of each round to the current hash value.
[0044] Step 6: Final Hash Value: After all the data blocks have been processed, the final hash values (A, B, C, D) are combined into a 128-bit value, which is the MD5 hash value.
[0045] Step 7: Output: Convert the 128-bit hash value into a 32-bit hexadecimal string, which is the final MD5 value.
[0046] According to an embodiment of the present invention, adding padding bits to a program includes: Determine the size of the program file and whether the data length of the program file is a multiple of 512 bits; If so, the program file is divided into blocks; If not, fill the data bits of the program file as follows: First add a 1, then add a sufficient number of 0s, and finally add a 64-bit padding length to make the data length of the program file a multiple of 512 bits.
[0047] It should be noted that since the MD5 algorithm requires the length of the input data to be a multiple of 512 bits, data that meets the requirement can be used directly; data that does not meet the requirement needs to be padded first, and then the next step can be performed after it is padded to a multiple of 512 bits.
[0048] According to an embodiment of the present invention, the nonlinear function operation includes: F function: F(X,Y,Z)=(X&Y)∣((~X)&Z) Among them, X, Y, and Z represent input variables; "~" is the negation operator, and "&" is the sum operator; in the F function, if X and Y are the same, the result is X, otherwise it is Z; G function: G(X,Y,Z)=(X&Z)∣(Y&(~Z)) In the G function, if X and Z are the same, the result is X, otherwise it is Y; H function: H((X,Y,Z)=X⊕Y⊕Z Among them, ⊕ is the exclusive OR operator, and the H function represents the exclusive OR of X, Y and Z; I function: I((X,Y,Z)=Y⊕(X∣(~Z)) In the I function, if Z is 0, the result is the exclusive OR of Y and X, otherwise it is Y.
[0049] It should be noted that in the MD5 algorithm, nonlinear functions and bit operations are the core components, which ensure the security and complexity of the algorithm. The MD5 algorithm uses four main nonlinear functions: F function, G function, H function, and I function. The purpose of these functions is that if the corresponding bits of input X, Y, and Z are independent and uniform, then each bit of the result should also be independent and uniform.
[0050] According to an embodiment of the present invention, the bit operation includes rotate left and addition (mod 2^32); The circular left shift operation shifts a 32-bit number to the left by the specified number of bits, and the overflowed bits will loop back to the right of the number; The addition operation modulo 2^32 ensures that the result is still a 32-bit number.
[0051] It should be noted that in the main loop of MD5, these nonlinear functions and bit operations are used to update the values of four variables A, B, C, and D. Each round uses different functions and operations, as well as different constants and message subgroups. The specific steps of these operations are as follows: For each operation in each round, a nonlinear function (F, G, H, or I) is first selected.
[0052] Add the result of the function to the current message subgroup and a constant.
[0053] Circularly shift the result left.
[0054] Add the result of the left shift to another variable.
[0055] This process is repeated 16 times in each round, using a different nonlinear function and a different amount of displacement in each round. In this way, the MD5 algorithm is able to produce a seemingly random, fixed-length output, where even a small change in the input will result in a huge change in the output, which is the so-called avalanche effect.
[0056] According to an embodiment of the present invention, verifying whether all program configurations in the terminal to be verified are correct based on the terminal program hash reference value includes: Retrieve the terminal program hash reference value and compare the hash value of the terminal program to be verified with the terminal program hash reference value; if the two are exactly the same, it means that the terminal program to be verified is complete and has not been tampered with; if they are different, it means that the terminal program to be verified is incomplete and the terminal program may have been modified or damaged during transmission.
[0057] It should be noted that MD5 value verification is a method to verify the integrity of the terminal program to ensure that the file has not been tampered with or damaged during transmission or storage. By comparing the MD5 value of the terminal program to be verified with the stored MD5 reference value of the terminal program, if the two are exactly the same, it means that the terminal program to be verified is complete and has not been tampered with; if they are different, it means that the terminal program to be verified is incomplete and the terminal program may have been modified or damaged during transmission.
[0058] Please refer to Figure 3 , is a block diagram of a terminal program verification system of the present application, the terminal program verification system 3 includes a memory 31 and a processor 32, the memory 31 includes a terminal program verification method program, and when the terminal program verification method program is executed by the processor 32, the following steps are implemented: Read program configuration files; Parse the program configuration file to obtain the total number of programs that need to be calculated and the random number Rn of the program file; According to the program path and size and the random number Rn of the program file, the hash value of each program is calculated in turn, and the hash value of the program file and the program name are written into a temporary file; Perform SM3 verification on temporary files in the software program, return the random number Rn and the final hash value of the program file, generate a terminal program hash reference value, and save it in the terminal program; Receive the terminal program verification instruction to be verified, call the terminal program hash value reference value according to the program path, verify whether all program configurations in the terminal to be verified are correct according to the terminal program hash value reference value, and output the verification result.
[0059] The method further comprises the following steps after reading the program configuration file: Check whether the program configuration file is correct; If yes, the program configuration file is parsed to obtain the total number of programs to be calculated and the random number Rn of the program files; If not, the hash value of the program is cleared and the terminal program verification is exited.
[0060] The process of calculating the hash value of each program in turn according to the program path and size and the random number Rn of the program file includes: Read the program file according to the program path, and concatenate the program file with the random number to obtain the concatenated program file; Determine the security level of the spliced program files. If the security level is high, use the SM3 algorithm to calculate the hash value of each program in turn; if the security level is low, use the MD5 algorithm to calculate the hash value.
[0061] The program file and the random number are concatenated as follows: CombinedData=Filebytes⊕Rnbytes Among them, CombinedData is the concatenated program file, Filebytes is the byte data of the program file, and Rnbytes is the random number byte data of the program file.
[0062] The MD5 algorithm is used to calculate the hash value, specifically: Get the size of the program through the program file; Add padding to the program; Divide the file after adding the padding bit into blocks; obtain the program file data block; Initialize MD buffer; Expand the variables of the program file data block; According to the initialization result of the MD buffer, nonlinear function operation and bit operation are performed on the expanded program file data block to obtain the current hash value of the program file data block; Traverse all program file data blocks and add the nonlinear function and bit operation results of all program file data blocks to the current hash value; Combine the current hash values to get the MD5 hash value of the program file.
[0063] The adding of padding bits to the program comprises: Determine the size of the program file and whether the data length of the program file is a multiple of 512 bits; If so, the program file is divided into blocks; If not, fill the data bits of the program file as follows: First add a 1, then add a sufficient number of 0s, and finally add a 64-bit padding length to make the data length of the program file a multiple of 512 bits.
[0064] The nonlinear function operation includes: F function: F(X,Y,Z)=(X&Y)∣((~X)&Z) Among them, X, Y, and Z represent input variables; "~" is the negation operator, and "&" is the sum operator; in the F function, if X and Y are the same, the result is X, otherwise it is Z; G function: G(X,Y,Z)=(X&Z)∣(Y&(~Z)) In the G function, if X and Z are the same, the result is X, otherwise it is Y; H function: H((X,Y,Z)=X⊕Y⊕Z Among them, ⊕ is the exclusive OR operator, and the H function represents the exclusive OR of X, Y and Z; I function: I((X,Y,Z)=Y⊕(X∣(~Z)) In the I function, if Z is 0, the result is the exclusive OR of Y and X, otherwise it is Y.
[0065] The bit operations include circular left shift and addition; The circular left shift operation shifts a 32-bit number to the left by the specified number of bits, and the overflowed bits will loop back to the right of the number; The addition operation modulo 2^32 ensures that the result is still a 32-bit number.
[0066] The step of verifying whether all program configurations in the terminal to be verified are correct based on the terminal program hash reference value includes: Retrieve the terminal program hash reference value, and compare the hash value of the terminal program to be verified with the terminal program hash reference value; if the two are exactly the same, it means that the terminal program to be verified is complete; if they are different, it means that the terminal program to be verified is incomplete.
[0067] A third aspect of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium includes a terminal program verification method program, and when the terminal program verification method program is executed by a processor, the steps of the terminal program verification method are implemented.
[0068] As can be seen from the above, the present application provides a terminal program verification method, system and readable storage medium. The present application adds a configuration file to the program, adds all the files and paths that need to be compared and verified to the configuration file, and the terminal calculates a unified hash value based on the configuration file. When the detection software reads the terminal hash value, the terminal directly returns the final hash value to the detection software, and the detection software determines whether the versions of all programs and parameter files in the current terminal are correct by comparing the final hash value. The method described in the present application can effectively improve the accuracy of terminal program verification by adding a configuration file to the program, and verifying based on the configuration file hash value during verification, and can also improve the efficiency of terminal program verification.
[0069] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0070] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units; they may be located in one place or distributed on multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0071] In addition, all functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may be separately used as a unit, or two or more units may be integrated into one unit; the above-mentioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0072] Those skilled in the art can understand that: all or part of the steps of implementing the above method embodiments can be completed by hardware related to program instructions, the aforementioned program can be stored in a readable storage medium, and when the program is executed, it executes the steps of the above method embodiments; and the aforementioned storage medium includes: mobile storage devices, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), disks or optical disks, and other media that can store program codes.
[0073] Alternatively, if the above-mentioned integrated unit of the present invention is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiment of the present invention can be essentially or partly reflected in the form of a software product that contributes to the prior art. The software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROM, RAM, magnetic disks or optical disks.
Claims
1. A terminal program verification method, characterized in that: The method comprises: Read program configuration files; Parse the program configuration file to obtain the total number of programs that need to be calculated; Obtain a random number Rn through the terminal encryption chip; According to the program path and size and the random number Rn of the program file, the hash value of each program is calculated in turn, and the hash value of the program file and the program name are written into a temporary file; Perform SM3 verification on temporary files in the software program, return the random number Rn and the final hash value of the program file, generate a terminal program hash reference value, and save it in the terminal program; Receive the terminal program verification instruction to be verified, call the terminal program hash value reference value according to the program path, verify whether all program configurations in the terminal to be verified are correct according to the terminal program hash value reference value, and output the verification result.
2. A terminal program verification method according to claim 1, characterized in that: The method further comprises the following steps after reading the program configuration file: Check whether the program configuration file is correct; If yes, the program configuration file is parsed to obtain the total number of programs that need to be calculated; Obtain a random number Rn through the terminal encryption chip; If not, the hash value of the program is cleared and the terminal program verification is exited.
3. A terminal program verification method according to claim 2, characterized in that: The process of calculating the hash value of each program in turn according to the program path and size and the random number Rn of the program file includes: Read the program file according to the program path, and concatenate the program file with the random number to obtain the concatenated program file; Determine the security level of the spliced program files. If the security level is high, use the SM3 algorithm to calculate the hash value of each program in turn; if the security level is low, use the MD5 algorithm to calculate the hash value.
4. A terminal program verification method according to claim 3, characterized in that: The MD5 algorithm is used to calculate the hash value, specifically: Get the size of the program through the program file; Add padding to the program; Divide the file after adding the padding bit into blocks to obtain the program file data block; Initialize MD buffer Expand the variables of the program file data block; According to the initialization result of the MD buffer, nonlinear function operation and bit operation are performed on the expanded program file data block to obtain the current hash value of the program file data block; Traverse all program file data blocks and add the nonlinear function and bit operation results of all program file data blocks to the current hash value; Combine the current hash values to get the MD5 hash value of the program file.
5. A terminal program verification method according to claim 4, characterized in that: The adding of padding bits to the program comprises: Determine the size of the program file and whether the data length of the program file is a multiple of 512 bits; If so, the program file is divided into blocks; If not, fill the data bits of the program file as follows: First add a 1, then add a sufficient number of 0s, and finally add a 64-bit padding length to make the data length of the program file a multiple of 512 bits.
6. A terminal program verification method according to claim 5, characterized in that: The nonlinear function operation includes: F function: F(X,Y,Z)=(X&Y)∣((~X)&Z) Among them, X, Y, and Z represent input variables; "~" is the negation operator, and "&" is the sum operator; in the F function, if X and Y are the same, the result is X, otherwise it is Z; G function: G(X,Y,Z)=(X&Z)∣(Y&(~Z)) In the G function, if X and Z are the same, the result is X, otherwise it is Y; H function: H(X,Y,Z)=X⊕Y⊕Z Among them, ⊕ is the exclusive OR operator, and the H function represents the exclusive OR of X, Y and Z; I function: I(X,Y,Z)=Y⊕(X∣(~Z)) In the I function, if Z is 0, the result is the exclusive OR of Y and X, otherwise it is Y.
7. A terminal program verification method according to claim 6, characterized in that: The bit operations include circular left shift and addition; The circular left shift operation shifts a 32-bit number to the left by the specified number of bits, and the overflowed bits will loop back to the right of the number; The addition operation modulo 2^32 ensures that the result is still a 32-bit number.
8. A terminal program verification method according to claim 7, characterized in that: The step of verifying whether all program configurations in the terminal to be verified are correct based on the terminal program hash reference value includes: Retrieve the terminal program hash reference value, and compare the hash value of the terminal program to be verified with the terminal program hash reference value; if the two are exactly the same, it means that the terminal program to be verified is complete; if they are different, it means that the terminal program to be verified is incomplete.
9. A terminal program verification system, characterized in that: The method comprises a memory and a processor, wherein the memory comprises a terminal program verification method program, and when the terminal program verification method program is executed by the processor, the steps of a terminal program verification method according to any one of claims 1 to 8 are implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a terminal program verification method program, and when the terminal program verification method program is executed by a processor, the steps of a terminal program verification method according to any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
Data verification method and device based on hash algorithm, equipment and storage medium
CN110503434A
Terminal authentication information extraction and verification method and system based on national cryptographic algorithm
CN111709010A
Device and method for verifying application program and related product
CN114064462A
System legality verification method and device and electronic equipment
CN116776317A
Cited By
System call verification method and system based on verification table
CN121009067A