Machine learning Trojan detection method based on structural feature screening and payload expansion
Through the machine learning method of structural feature screening and load expansion, the problem of data imbalance and function-specific identification in hardware Trojan detection is solved, the detection accuracy and identification ability are improved, and the effective identification of Trojan payload circuits with different functions is achieved.
Patent Information
- Application Number
- CN202110848193.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-27
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2041-07-27
AI Technical Summary
Existing hardware Trojan detection methods have deficiencies in data imbalance and identification of function-specific Trojan payload circuits, resulting in low detection accuracy.
Through machine learning methods based on structural feature screening and load expansion, the trigger structure and similar nodes of Trojan circuits are screened out, a balanced data set is constructed, and backward expansion is used to identify Trojan load circuits with different functions, and a double threshold limit search level is set number to improve detection accuracy.
It effectively improves the accuracy and identification ability of hardware Trojan detection, makes up for the shortcomings of traditional methods in data imbalance and function-specific identification, and improves the detection ability of Trojan payload circuits.
Smart Images

Figure CN113626812B
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of hardware security technology, and in particular relates to a machine learning Trojan detection method based on structural feature screening and load expansion. Background Art
[0002] At present, hardware Trojans are additional circuits that some attackers deliberately insert into normal circuits during chip manufacturing, which are used to secretly leak information, increase circuit power consumption, and interfere with or destroy the normal function of the circuit. In addition, the concealment of Trojan circuits is extremely high and is only triggered under rare conditions, which makes hardware Trojan detection difficult. Existing Trojan detection mostly uses machine learning methods for analysis and has good performance. However, its defects are also obvious: first, compared with normal circuits, the number of Trojan nodes is very small, so the problem of data imbalance during training is particularly serious; second, most of the existing methods are to find the trigger circuit from the rarity analysis of Trojan circuits, but they are helpless against Trojan load circuits with specific functions and structures that are almost the same as normal circuits. These have a great impact on the accuracy of hardware Trojan detection. Therefore, a new hardware Trojan detection and optimization method is urgently needed to make up for the defects of the existing technology.
[0003] Through the above analysis, the problems and defects of the prior art are as follows:
[0004] (1) Existing Trojan detection methods mostly use machine learning methods for analysis, but compared with normal circuits, the number of Trojan nodes is very small, so the problem of data imbalance during training is particularly serious.
[0005] (2) Most existing methods are to analyze the rarity of Trojan circuits to find their trigger circuits, but they are helpless against Trojan payload circuits that are functionally specific and have structures that are similar to normal circuits.
[0006] (3) The defects of existing Trojan detection methods have a significant impact on the accuracy of hardware Trojan detection.
[0007] The difficulty of solving the above problems and defects is:
[0008] (1) The number of Trojan nodes is usually much smaller than the number of normal nodes. Directly using all nodes for training will lead to serious data imbalance. To solve this problem, the commonly used methods are oversampling or undersampling. The former repeatedly samples the positive data, that is, simply repeatedly samples the Trojan nodes multiple times, but over-emphasizing the existing positive examples can easily lead to the noise or errors in the positive examples being amplified exponentially; the latter discards most of the negative data, that is, deletes a large number of non-Trojan nodes, but improper selection of the discarded data will cause a large deviation in the generated model, and it is difficult to choose the nodes to discard.
[0009] (2) Trojan circuits can be divided into trigger circuits and load circuits. The characteristics of trigger circuits are relatively clear, and general Trojan detection methods can detect trigger circuits. However, the functions of load circuits vary. Currently, there are information leakage types, power consumption increase types, function destruction types, etc., and their circuit structures are also very different, which is a great challenge for Trojan detection.
[0010] The significance of solving the above problems and defects is:
[0011] (1) In terms of the balance of the data set, the present invention screens the data set in combination with the structural features of the Trojan circuit, retaining the Trojan circuit (especially the Trojan trigger structure) and normal nodes with similar structures and close distances as the final data set. In this way, most of the irrelevant normal nodes are screened out, and those nodes with special structures and easy to be misjudged are also retained for training the model, which is more reasonable than simply repeating the oversampling of Trojan nodes or randomly deleting the undersampling of normal nodes.
[0012] (2) In terms of load circuit identification, the present invention proposes a backward expansion method based on the low fan-out characteristics of Trojan loads, which effectively improves the Trojan detection algorithm's ability to identify Trojan loads. In order to prevent excessive expansion from causing a decrease in detection accuracy, the present invention proposes to limit the search level with a double threshold to accurately search for Trojan load circuits, which effectively improves the Trojan detection algorithm's ability to identify Trojans. Summary of the invention
[0013] In view of the problems existing in the prior art, the present invention provides a machine learning Trojan detection method based on structural feature screening and load expansion, and more particularly relates to a hardware Trojan detection framework and optimization method based on the netlist level.
[0014] The present invention is implemented in this way: a machine learning Trojan detection method based on structural feature screening and load expansion, the machine learning Trojan detection method based on structural feature screening and load expansion includes:
[0015] First, the circuit netlist is converted into a quantifiable mathematical model, and features are extracted through mathematical methods based on this model; then, combined with the characteristics of the hardware Trojan trigger structure, the nodes are screened to obtain a more balanced data set, and then the machine learning classification method is used for Trojan detection; finally, according to the characteristics of the hardware Trojan payload structure, the Trojan nodes are backward expanded to obtain a complete hardware Trojan circuit.
[0016] Furthermore, the machine learning Trojan detection method based on structural feature screening and load expansion includes the following steps:
[0017] Step 1: Analyze the circuit structure and the operation logic of the Trojan circuit, combine the circuit features of traditional machine learning, propose the features required for Trojan detection, and obtain the features of each node from the preprocessed netlist;
[0018] Step 2: Establish n-level subgraphs starting from each node in the circuit, count the low-probability cascade structures in each subgraph, and screen out low-risk subgraphs and normal subgraphs;
[0019] Step 3: Use the features of low-risk subgraph nodes as a data set for training to obtain a training model; use test data for testing to obtain high-risk nodes;
[0020] Step 4: Expand high-risk nodes to obtain the complete Trojan structure; calculate accuracy parameters based on the test results and evaluate the test results.
[0021] Furthermore, the positive role played by each step in this scheme is:
[0022] Step one is the basis of Trojan detection, which is to convert the circuit netlist into a mathematical model; convert each device in the circuit into a mathematical node, and then combine the circuit characteristics to convert the structural properties of each node into a quantifiable feature vector for subsequent operations.
[0023] The second step is to optimize the machine learning data set, filter out most of the irrelevant normal nodes, retain the Trojan nodes and normal nodes with similar structures and close distances, balance the data set, optimize the training model, and improve the accuracy of machine learning.
[0024] Step three is a specific way to implement Trojan detection, which is to train the existing data set through machine learning to obtain a reliable model for subsequent detection. The present invention mainly optimizes the Trojan detection framework and does not require the specific machine learning algorithm used.
[0025] Step 4 is to optimize the test results. The present invention performs backward expansion under the premise of setting a threshold, thereby obtaining a complete Trojan structure and improving the Trojan recognition capability of the Trojan detection algorithm.
[0026] Furthermore, in step 2, the counting of low-probability cascade structures in each subgraph includes:
[0027] (1) The triggering conditions of the Trojan circuit are very harsh, that is, the probability of gate flipping is very low from the circuit perspective. Therefore, from the perspective of circuit structure and gate device function, a two-level cascade structure of gate devices in which the probability of outputting 0 or 1 is very low is proposed;
[0028] (2) Expanding the two-stage cascade structure in step (1), a low-probability cascade structure is proposed that adds a NOT gate or a flip-flop as an intermediate stage;
[0029] (3) Count the parts of the subgraph to be evaluated that have the same structure as those proposed in step (1) and step (2). If the number of identical structures is greater than a threshold value t0, the subgraph to be evaluated is considered to be a low-risk subgraph; otherwise, it is a normal subgraph.
[0030] (4) Extract all nodes of the low-risk subgraph obtained in step (3), remove duplicates, and use the feature values of the extracted nodes as a data set for subsequent training.
[0031] Further, in step 2, the low probability cascade structure includes:
[0032] Two-level low 0 probability cascade structure: ① OR gate connected to OR gate; ② NAND gate connected to NAND gate; ③ OR gate connected to NAND gate; ④ NAND gate connected to OR gate;
[0033] Two-level low 1 probability cascade structure: ① AND gate connected to AND gate; ② NOR gate connected to NOR gate; ③ AND gate connected to NOR gate; ④ NOR gate connected to AND gate;
[0034] On the basis of the above 8 secondary structures, a multi-level low-probability cascade structure with NOT gates and triggers is added, which is divided into two types:
[0035] Insert an odd number of NOT gates into the original structure: ① Connect an odd number of NOT gates with the NAND gate, and then connect them with the AND gate; ② Connect an odd number of NOT gates with the NAND gate, and then connect them with the NOR gate; ③ Connect an odd number of NOT gates with the NOR gate, and then connect them with the OR gate; ④ Connect an odd number of NOT gates with the NOR gate, and then connect them with the NAND gate.
[0036] Insert an even number of NOT gates or several triggers into the original structure: including all structures in the two-level low-probability cascade structure; among which, all cascade structures must use the gates in the AND gate, OR gate, NAND gate, and NOR gate as the starting node and the ending node.
[0037] Furthermore, in step three, when machine learning is used for training and testing, both the training set and the test set are low-risk nodes that have been screened, and there is no requirement for the specific machine learning method used; the test results obtained by machine learning are identified as high-risk Trojan nodes for subsequent expansion and completion of the Trojan structure.
[0038] Furthermore, in step 4, the expansion of high-risk nodes includes:
[0039] From the functional perspective of the Trojan circuit, the impact of the Trojan node on the circuit is hidden, that is, the fan-out of the Trojan node is very small and will only affect a very small number of nodes; when the high-risk nodes are subsequently expanded, the subsequent nodes of each high-risk node are queried, and the subsequent nodes with fan-out values less than the threshold t1 are added to the Trojan node, and these nodes are continued to be expanded backward; if the fan-out value of the queried subsequent node is greater than or equal to the threshold t1, it is determined to be a normal node and no longer expanded; when all the backward nodes of the high-risk node are expanded to normal nodes, the expansion is terminated.
[0040] According to the circuit structure, each high-risk node screened out after machine learning is backward expanded; the total expansion threshold t2 is set, and for each expansion, the number of expanded nodes is limited according to the fan-out threshold t2 of a single backward node and the total fan-out threshold t3 of all backward nodes; in the expansion of a high-risk node, each time a new backward Trojan node is found, the fan-out of the backward Trojan is accumulated, and when the accumulated value is greater than or equal to the total expansion threshold t2, the expansion is terminated.
[0041] Furthermore, the machine learning Trojan detection method based on structural feature screening and load expansion also includes:
[0042] (1) Preprocess the gate-level netlist to be tested, merge the Verilog code modules in the netlist and integrate them into a unified module; further divide the code into nodes, and quantify the relationship between the nodes into a graph;
[0043] (2) performing feature extraction on the nodes extracted in step (1), extracting the signal features and internal structure features of each node, and quantizing them into vector form;
[0044] (3) Generate a subgraph for the nodes extracted in step (1), starting from each node and searching forward n levels to generate a subgraph;
[0045] (4) Determine the danger of the subgraph generated in step (3), count the number of low-probability cascade structures, and identify it as a low-risk subgraph if the number exceeds the threshold t1, otherwise it is identified as a normal subgraph; extract all nodes of the low-risk subgraph and remove duplicates, and identify these nodes as low-risk nodes;
[0046] (5) Based on the low-risk nodes in step (4), the feature vectors corresponding to these nodes in step (2) are obtained as a feature set; the feature set is used as a data set and sent to the classifier for training; the model is optimized according to the training results to obtain the best training model;
[0047] (6) using a cross-validation method to divide multiple test data sets into training sets and test sets; inputting the test data into the trained model for detection, and obtaining high-risk Trojan nodes in each netlist based on the detection results;
[0048] (7) Based on the graph converted from the netlist in step (1), the high-risk Trojan nodes obtained in step (6) are backward expanded to obtain the complete Trojan circuit; based on the detection results, TPR and TNR indicators are calculated to evaluate the detection capability.
[0049] In step (1), when the gate-level netlist to be tested is preprocessed, a script is used to traverse all gates and triggers in the netlist and regard them as nodes, and basic information of each node is obtained, and a graph is established based on this; wherein the basic information includes node name, node type, node function, input and output line network and forward and backward nodes.
[0050] In step (2), when performing feature analysis on the extracted nodes, traditional Trojan features are used; wherein the traditional Trojan features include the fan-in number of logic gates, multiplexers, triggers, input-output distances, and ring structures.
[0051] Another object of the present invention is to provide a hardware Trojan detection and optimization system using the machine learning Trojan detection method based on structural feature screening and load expansion, the hardware Trojan detection and optimization system comprising:
[0052] The pre-processing module is used to standardize the gate-level netlist structure to be tested and convert it into a graph form;
[0053] A feature extraction module is used to extract the required features of each node from the overall graph;
[0054] The subgraph extraction module extracts n-level subgraphs from the overall graph, starting from each node in the netlist;
[0055] The subgraph screening module is used to count the number of low-probability cascade structures in each subgraph, determine whether the subgraph is a low-risk subgraph, extract all nodes of the low-risk subgraph and remove duplicates;
[0056] The machine learning module uses the low-risk nodes that have been screened as data sets for training and testing. The Trojan nodes in the test results are identified as high-risk nodes, and the specific machine learning method used is not limited;
[0057] The load expansion module is used to expand the backward nodes of high-risk nodes according to the set rules, so as to identify Trojan load circuit nodes with different functions that are difficult to be discovered by traditional hardware Trojan detection methods, and calculate the TPR and TNR indicators based on the expanded results to evaluate the detection results.
[0058] Another object of the present invention is to provide a computer device, the computer device comprising a memory and a processor, the memory storing a computer program, and when the computer program is executed by the processor, the processor performs the following steps:
[0059] First, the circuit netlist is converted into a quantifiable mathematical model, and features are extracted through mathematical methods based on this model; then, combined with the characteristics of the hardware Trojan trigger structure, the nodes are screened to obtain a more balanced data set, and then the machine learning classification method is used for Trojan detection; finally, according to the characteristics of the hardware Trojan payload structure, the Trojan nodes are backward expanded to obtain a complete hardware Trojan circuit.
[0060] Another object of the present invention is to provide an information data processing terminal, which is used to implement the hardware Trojan detection and optimization system.
[0061] Combined with all the above technical solutions, the advantages and positive effects of the present invention are as follows: the machine learning Trojan detection method based on structural feature screening and load expansion provided by the present invention proposes the features required for Trojan detection by analyzing the circuit structure and the operation logic of the Trojan circuit; the netlist is divided into several subgraphs, and the subgraphs are judged for the degree of danger, and low-risk Trojan nodes are screened in combination with the characteristics of the low trigger probability of the Trojan circuit and the special cascade structure in the circuit; the feature vectors corresponding to the nodes after screening are used as data sets for training to obtain a training model; test data is used for testing to obtain high-risk Trojan nodes; combined with the structural characteristics of the Trojan load, the high-risk Trojan nodes are backward expanded to obtain the overall Trojan structure; according to the test results, the parameters such as accuracy are calculated to evaluate the detection effect. The present invention performs an additional screening and an expansion on the basis of the traditional machine learning method for detecting netlist Trojans. The screening helps to balance the data set during training, optimize the model and reduce the training time; the expansion is used to detect Trojan load circuits that are difficult to find in traditional detection methods, further improving the accuracy of detection. The present invention does not limit the specific method of machine learning adopted, and the performance of various detection methods is improved to a certain extent.
[0062] The present invention creatively combines the structural characteristics of the low trigger probability of Trojans with the static characteristics of circuits used in machine learning, performs preliminary screening of the data set for machine learning, and balances the data set used for training, effectively improving the efficiency and accuracy of machine learning, and providing new ideas for subsequent related research. The present invention is not limited to a specific Trojan detection method, and has a certain improvement in the detection effect of most hardware Trojan detection methods, and has strong applicability.
[0063] The present invention provides a method for completing a Trojan circuit and detecting a Trojan load. According to the low fan-out characteristics of a Trojan node, the method can detect a Trojan load circuit that is difficult to detect using conventional methods, and can complete the trigger circuit detected by machine learning to a certain extent, thereby effectively improving the recognition of the Trojan circuit and providing a new direction for subsequent related research in the field of hardware security. BRIEF DESCRIPTION OF THE DRAWINGS
[0064] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments of the present invention. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0065] Figure 1 It is a flow chart of a machine learning Trojan detection method based on structural feature screening and load expansion provided by an embodiment of the present invention.
[0066] Figure 2 It is a schematic diagram of a machine learning Trojan detection method based on structural feature screening and load expansion provided in an embodiment of the present invention.
[0067] Figure 3 It is a structural block diagram of a hardware Trojan detection and optimization system provided by an embodiment of the present invention;
[0068] In the figure: 1. Preprocessing module; 2. Feature extraction module; 3. Subgraph extraction module; 4. Subgraph screening module; 5. Machine learning module; 6. Load expansion module.
[0069] Figure 4 It is a schematic diagram of dangerousness detection for normal sub-graphs and Trojan sub-graphs provided by an embodiment of the present invention.
[0070] Figure 4 (a) is a schematic diagram of a normal circuit provided by an embodiment of the present invention.
[0071] Figure 4 (b) is a schematic diagram of a low probability cascade structure number of 1 provided by an embodiment of the present invention.
[0072] Figure 4 (c) is a schematic diagram of a Trojan horse circuit provided by an embodiment of the present invention.
[0073] Figure 4 (d) is a schematic diagram of a low probability cascade structure number of 6 provided by an embodiment of the present invention.
[0074] Figure 5 It is a schematic diagram of a Trojan circuit of the test circuit s38417-T300 provided in an embodiment of the present invention.
[0075] Figure 6 It is a schematic diagram of backward expansion of a Trojan node provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0076] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0077] In view of the problems existing in the prior art, the present invention provides a machine learning Trojan detection method based on structural feature screening and load expansion. The present invention is described in detail below in conjunction with the accompanying drawings.
[0078] like Figure 1 As shown, the machine learning Trojan detection method based on structural feature screening and load expansion provided by the embodiment of the present invention includes the following steps:
[0079] S101, analyze the circuit structure and the operation logic of the Trojan circuit, combine the circuit features of traditional machine learning, propose the features required for Trojan detection, and obtain the features of each node from the preprocessed netlist;
[0080] S102, establishing n-level subgraphs with each node in the circuit as the starting point, counting low-probability cascade structures in each subgraph, and screening out low-risk subgraphs and normal subgraphs;
[0081] S103, using the features of the low-risk subgraph nodes as a data set for training to obtain a training model; using the test data for testing to obtain high-risk nodes;
[0082] S104, expand the high-risk nodes to obtain the complete Trojan structure; calculate the accuracy parameter according to the test results and evaluate the test results.
[0083] The principle diagram of the method for detecting Trojans based on machine learning based on structural feature screening and load expansion provided by the embodiment of the present invention is as follows: Figure 2 shown.
[0084] like Figure 3 As shown, the hardware Trojan detection and optimization system provided by the embodiment of the present invention includes:
[0085] Preprocessing module 1, used to standardize the gate-level netlist structure to be tested and convert it into a graph form;
[0086] Feature extraction module 2, used to extract the required features of each node from the overall graph;
[0087] The subgraph extraction module 3 extracts n-level subgraphs from the overall graph, taking each node in the netlist as a starting point;
[0088] Subgraph screening module 4 is used to count the number of low-probability cascade structures of each subgraph, determine whether the subgraph is a low-risk subgraph, extract all nodes of the low-risk subgraph and remove duplicates;
[0089] Machine learning module 5 uses the low-risk nodes after screening as data sets for training and testing. The Trojan nodes in the test results are identified as high-risk nodes, and the specific machine learning method used is not limited;
[0090] The load expansion module 6 is used to expand the backward nodes of high-risk nodes according to the set rules, so as to identify Trojan load circuit nodes with different functions that are difficult to be discovered by traditional hardware Trojan detection methods, and calculate the TPR and TNR indicators based on the expanded results to evaluate the detection results.
[0091] The technical solution of the present invention is further described below in conjunction with embodiments.
[0092] Example 1
[0093] The present invention provides a framework and optimization method for hardware Trojan detection based on netlist level. The implementation idea of the present invention is as follows: first, the netlist of the circuit is converted into a quantifiable mathematical model, and feature extraction is performed based on this model by mathematical methods. Then, combined with the characteristics of the hardware Trojan trigger structure, the nodes are screened to obtain a more balanced data set, and then the machine learning classification method is combined to perform Trojan detection. Finally, according to the characteristics of the hardware Trojan payload structure, the Trojan node is backward expanded to obtain a complete hardware Trojan circuit.
[0094] The implementation of the present invention adopts the following technical solutions:
[0095] A framework and optimization method based on netlist-level hardware Trojan detection includes the following steps:
[0096] Step S1: Preprocess the gate-level netlist to be tested, merge the Verilog code modules in the netlist and integrate them into a unified module. Further divide the code into nodes, and quantify the relationship between each node into a graph for subsequent analysis;
[0097] Step S2: extracting features from the nodes extracted in step S1, extracting the signal features and internal structure features of each node, and quantizing them into vector form;
[0098] Step S3: Generate a subgraph for the nodes extracted in step S1, starting from each node, searching forward n levels to generate a subgraph;
[0099] Step S4: Determine the danger of the subgraph generated in step S3, count the number of its low-probability cascade structures, and identify it as a low-risk subgraph if the number exceeds the threshold t1, otherwise it is identified as a normal subgraph; extract all nodes of the low-risk subgraph and remove duplicates, and identify these nodes as low-risk nodes;
[0100] Step S5: Based on the low-risk nodes in step S4, the feature vectors corresponding to these nodes in step S2 are obtained as a feature set; the feature set is used as a data set and sent to the classifier for training; the model is optimized according to the training results to obtain the best training model;
[0101] Step S6: using a cross-validation method to divide multiple test data sets into a training set and a test set; inputting the test data into the trained model for detection, and obtaining the high-risk Trojan node of each netlist according to the detection results;
[0102] Step S7: According to the graph converted from the netlist in step S1, the high-risk Trojan nodes obtained in step S6 are backward expanded to obtain a complete Trojan circuit; TPR and TNR indicators are calculated according to the detection results to evaluate the detection capability.
[0103] Furthermore, when the netlist is preprocessed in step S1, a script is used to traverse all gates and triggers in the netlist and regard them as nodes, and obtain the basic information of each node, such as node name, node type, node function, input and output line network, forward and backward nodes, etc., and a graph is established based on this for subsequent analysis.
[0104] Furthermore, when performing feature analysis on the extracted nodes in step S2, the present invention uses traditional Trojan features, which are the fan-in number of logic gates, multiplexers, triggers, input-output distances, and ring structures. The features selected in this step are not specifically limited, and the features can also be increased or decreased according to the effects of actual use.
[0105] Furthermore, when generating a subgraph for a node in step S3, in order to unify the standard for generating a subgraph, the present invention starts from the selected node and queries all forward nodes within the nth level of the node; if the node or one of its forward nodes is the total input node of the netlist, the query of the branch is stopped. In addition, the value of n is related to the size of the Trojan trigger circuit.
[0106] Furthermore, when performing low-probability cascade structure statistics on the subgraphs in step S4, the selected low-probability cascade structures include:
[0107] Two-level low 0 probability cascade structure: ① OR gate connected to OR gate; ② NAND gate connected to NAND gate; ③ OR gate connected to NAND gate; ④ NAND gate connected to OR gate;
[0108] Two-level low 1 probability cascade structure: ① AND gate connected to AND gate; ② NOR gate connected to NOR gate; ③ AND gate connected to NOR gate; ④ NOR gate connected to AND gate;
[0109] In order to prevent the NOT gate and the trigger from cutting off the low probability cascade structure and making it undetectable, the present invention proposes a multi-level low probability cascade structure with the addition of the NOT gate and the trigger based on the above 8 secondary structures, which is specifically divided into two types:
[0110] Insert an odd number of NOT gates into the original structure: ① Connect an odd number of NOT gates with the NAND gate, and then connect them with the AND gate; ② Connect an odd number of NOT gates with the NAND gate, and then connect them with the NOR gate; ③ Connect an odd number of NOT gates with the NOR gate, and then connect them with the OR gate; ④ Connect an odd number of NOT gates with the NOR gate, and then connect them with the NAND gate.
[0111] Insert an even number of NOT gates or several flip-flops into the original structure: including all structures in the two-level low-probability cascade structure, which will not be repeated here.
[0112] To prevent repeated counting during statistics, all cascade structures must use the gates in the AND gate, OR gate, NAND gate, and NOR gate as the starting node and the ending node.
[0113] Furthermore, in step S6, when extracting high-risk Trojan nodes according to the test results, it is necessary to limit the number of extracted nodes to prevent a large number of correct nodes from being misjudged and interfering with subsequent steps.
[0114] Further, in step S7, when the high-risk node is subsequently expanded, since the number of subsequent nodes affected by the Trojan node is limited, that is, the fan-out of the Trojan node is small, the subsequent nodes of each high-risk node are queried, and the subsequent nodes with fan-out values less than the threshold t1 are added to the Trojan node, and these nodes are further expanded backward; if the fan-out value of the queried subsequent node is greater than or equal to the threshold t1, it is determined to be a normal node and no longer expanded; when all the backward nodes of the high-risk node are expanded to normal nodes, the expansion is terminated. In addition, in order to prevent the expansion level from being too long or falling into an infinite loop due to a loop, the present invention sets a total expansion threshold t2; in the expansion of a high-risk node, each time a new backward Trojan node is found, the fan-out of the backward Trojan is accumulated, and when the accumulated value is greater than or equal to the total expansion threshold t2, the expansion is terminated.
[0115] Example 2
[0116] like Figure 2 As shown, the machine learning Trojan detection method based on netlist-level structural feature screening and load expansion provided by the embodiment of the present invention includes the following steps:
[0117] Step S1: preprocess the gate-level netlist to be tested. The specific operations are as follows:
[0118] S11: For a given gate-level netlist, first integrate all modules in the netlist into a main module and retain their wiring relationships; to prevent duplication of signal names and device names in different modules, add the sub-module name as a prefix to the signal name and device name in the sub-module.
[0119] S12: traverse the entire gate-level circuit, extract the device names of all devices in the netlist, take each device as an independent node, obtain the type of each node (INV, NOR, AND, OR, NAND, AOI, OAI, DFF, others), obtain the input-output relationship of each node (which signals are inputs and which signals are outputs), obtain the fan-in and fan-out relationship of each node (which forward devices are there and which backward devices are there), and convert the gate-level circuit into a graph according to the connection relationship between the external input, external output, and internal devices of the circuit.
[0120] Step S2: Extract features from the nodes extracted in step S1. The specific operations are as follows:
[0121] S21: Select appropriate Trojan circuit features. In this example, the following 15 groups of Trojan features are used, including:
[0122] (1) The logical level of the primary output closest to the node;
[0123] (2) The logical level of the primary input closest to the node;
[0124] (3) The logical level of the flip-flop closest to the node output;
[0125] (4) The logical level of the multiplexer closest to the node output;
[0126] (5) The number of basic logic gates 5 levels away from the node output;
[0127] (6) The number of flip-flops that are 5 levels away from the output of the node;
[0128] (7) The number of multiplexers 5 levels away from the node output;
[0129] (8) The number of flip-flops that are 5 levels away from the node input;
[0130] (9) The logical level of the flip-flop closest to the node input;
[0131] (10) The number of 4-level loops at the node output;
[0132] (11) The number of 5-level loops at the node input;
[0133] (12) The number of logic gates of the same type 5 levels away from the node input;
[0134] (13) The number of multiplexers 5 levels away from the node input;
[0135] (14) The logic level of the inverter closest to the node output;
[0136] (15) The number of basic logic gates that are 5 levels away from the node input.
[0137] S22: traverse all nodes of the generated graph, calculate the above eigenvalue of each node, and obtain the eigenvector of each node.
[0138] Step S3: Generate a subgraph for the nodes extracted in step S1. The specific operations are as follows:
[0139] S31: Set the level n of the subgraph. Start from a node and set it as the first-level node; obtain the second-level node according to the forward node information extracted in step S1; then traverse all nodes of the second level to query their forward nodes and set them as the third-level nodes; repeat the above steps until the query reaches the nth level.
[0140] The value of n determines the size of the subgraph. If n is too small, the threshold t0 set for judging the danger of the subgraph will be too small, interfering with normal judgment; if n is too large, the amount of data judged will be too large, increasing the processing time.
[0141] S32: traverse all nodes, perform the operation of S301, and obtain the subgraphs of all nodes.
[0142] Step S4: Perform risk assessment on the sub-graph generated in step S3. The specific operations are as follows:
[0143] S41: setting a low trigger cascade structure, starting from the second-level low trigger cascade structure. In this example, 8 low trigger cascade structures are set, as shown in Table 1.
[0144] Table 1 Secondary low trigger cascade structure
[0145] Low 0 probability cascade structure Low 1 probability cascade structure OR--OR NOR--NOR NAND--NAND AND--AND OR--NAND NOR--AND NAND--OR AND--NOR
[0146] S42: In order to prevent the NOT gate and the trigger from cutting off the low probability cascade structure and making it undetectable, based on the above 8 secondary structures, this example proposes a multi-level low probability cascade structure with the addition of the NOT gate and the trigger, as shown in Table 2.
[0147] Table 2 Multi-level low trigger cascade structure
[0148] Original cascade structure Cascade structure with odd number of NOT gates Add a cascade structure of flip-flops or even-numbered NOT gates OR--OR NAND--INV--AND OR--FF / INV--OR NAND--NAND NAND--INV--NOR NAND--FF / INV--NAND OR--NAND NOR--INV--OR OR--FF / INV--NAND NAND--OR NOR--INV--NAND NAND--FF / INV--OR NOR--NOR NOR--FF / INV--NOR AND--AND AND--FF / INV--AND NOR--AND NOR--FF / INV--AND AND--NOR AND--FFINV--NOR
[0149] S43: For the acquired sub-graphs, the number of sub-graphs that conform to the above structure is counted. If the number is greater than a set threshold t0, it is determined to have low risk, otherwise it is determined to be a normal sub-graph. Figure 4 This is a schematic diagram of dangerousness detection for normal subgraphs and Trojan subgraphs. The dotted line part is the defined low-probability cascade structure. Obviously, Trojan subgraphs are more likely to have this structure.
[0150] S44: Traverse all subgraphs and perform the operation of S43 to obtain all low-risk subgraphs, extract the nodes of these subgraphs, and identify them as low-risk nodes after deduplication. The circuit used in this example is the gate-level netlist on Trusthub, the subgraph level n is 5, the threshold t0 is set to 6, and the number of nodes in the original netlist and the number of nodes after screening are shown in Table 3.
[0151] Table 3 Comparison of nodes before and after test circuit screening
[0152] Circuit Name Total number of nodes Number of Trojan nodes Total number of nodes after filtering Number of Trojan nodes after screening RS232-T1000 215 13 108 13 RS232-T1100 216 12 100 12 RS232-T1200 216 14 105 14 RS232-T1300 213 9 101 9 RS232-T1400 215 13 110 13 RS232-T1500 216 14 109 14 RS232-T1600 214 12 94 10 s15850-T100 2182 26 1200 24 s35932-T100 5441 14 45 12 s35932-T200 5436 12 64 12 s35932-T300 5462 36 54 18 s38417-T100 5341 12 1687 12 s38417-T200 5344 15 1661 15 s38417-T300 5373 44 1678 14 s38584-T100 6482 9 1679 9
[0153] As shown in Table 3, after screening, the average total number of nodes is reduced to 20.6% of the number before screening. Even for those netlists with poor screening effects, there is about 50% screening effect. The average number of Trojan nodes is 77.6% of the number before screening, but for most of the above netlists, the retention rate of Trojan nodes is more than 90%.
[0154] Due to the different functional structures of loads, step S4 has limited detection capabilities for very long annular loads. Figure 5 The Trojan structure diagram of the netlist s38417-T300 shows that due to the special structure of its payload, the retention rate of the Trojan after screening is low. However, in the subsequent step S7, the Trojan node will be expanded to obtain the entire Trojan structure.
[0155] Step S5: Based on the low-risk nodes in step S4, obtain the feature vectors corresponding to these nodes in step S2 as a feature set; use the feature set as a data set and send it to the classifier for training; optimize the model based on the training results to obtain the best training model. The machine learning method used in this example is based on a deep neural network.
[0156] Step S6: Use cross-validation to divide multiple test data sets into training sets and test sets; input the test data into the trained model for detection, and obtain the high-risk Trojan nodes of each netlist according to the detection results. In this example, a cross-validation method is used. Assuming that there are N circuits to be tested, one circuit to be tested is taken as the test set each time, and the remaining N-1 circuits to be tested are taken as the training set. This process is repeated N times to ensure that all circuits to be tested have been trained and tested, and the data set is used to the maximum extent so that the model can learn all the information of the data. In this example, the results of machine learning are shown in Table 4.
[0157] Table 4 Machine learning test results
[0158] Name TPR TNR Name TPR TNR RS232-T1000 0.92 0.93 s15850-T100 0.81 0.96 RS232-T1100 1 0.93 s35932-T100 1 0.99 RS232-T1200 0.93 0.92 s35932-T200 0.92 0.99 RS232-T1300 1 0.93 s35932-T300 0.44 0.99 RS232-T1400 1 0.92 s38417-T100 0.67 0.98 RS232-T1500 1 0.92 s38417-T200 1 0.97 RS232-T1600 0.83 0.93 s38417-T300 0.21 0.98 s38584-T100 0.78 0.85
[0159] Step S7: Backward expansion of high-risk Trojan nodes, and calculation of TPR and TNR indicators to evaluate detection capabilities. The specific operations are as follows:
[0160] S71: Select a high-risk Trojan node, calculate its fan-out based on the backward node information extracted in step S1, and stop expanding if it is greater than the set threshold t1; otherwise, set the fan-out value of the node to the current total fan-out, and identify all directly connected backward nodes as Trojan nodes.
[0161] S72: Determine all newly added Trojan nodes in S71, find their fan-out values in turn, and if they are greater than the set threshold t1, stop expanding; otherwise, add the fan-out value of the node to the current total fan-out, and identify all directly connected backward nodes as Trojan nodes. Repeat this operation until all backward nodes of the high-risk Trojan node cannot be expanded further, or the current total fan-out value is greater than the set threshold t2, then stop expanding the node.
[0162] S73: Traverse all high-risk nodes, repeat the operations of S71 and S72, obtain all Trojan nodes, and obtain a complete Trojan structure. Figure 6 As shown, the dotted line part is the expanded Trojan load circuit, whose circuit structure is a ring and whose function is to increase the circuit power consumption.
[0163] S74: According to the final test results, the TPR and TNR of each netlist recognition result are calculated to evaluate the detection capability of the method. For the gate-level netlist used in this example, the test results are shown in Table 5.
[0164] Table 5 Test results after Trojan expansion
[0165] Name TPR TNR Name TPR TNR RS232-T1000 1 0.92 s15850-T100 0.92 0.91 RS232-T1100 1 0.92 s35932-T100 1 0.98 RS232-T1200 0.93 0.91 s35932-T200 0.92 0.98 RS232-T1300 1 0.92 s35932-T300 0.97 0.98 RS232-T1400 1 0.90 s38417-T100 0.67 0.95 RS232-T1500 1 0.92 s38417-T200 1 0.92 RS232-T1600 0.92 0.92 s38417-T300 0.86 0.94 s38584-T100 0.78 0.80
[0166] By comparison, it can be seen that step S7 effectively improves the TPR of the test result at the expense of a small amount of TNR, that is, the ability to identify the Trojan circuit is stronger. When the load part of the Trojan circuit is long, the improvement of its TPR is particularly obvious.
[0167] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When the use is 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 the computer program instructions are loaded or executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, 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 site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL) or wireless (e.g., infrared, wireless, microwave, etc.) mode) to another website site, computer, server or data center. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk SolidState Disk (SSD)), etc.
[0168] The above description is only a specific implementation mode of the present invention, but the protection scope of the present invention is not limited thereto. Any modifications, equivalent substitutions and improvements made by any technician familiar with the technical field within the technical scope disclosed by the present invention and within the spirit and principle of the present invention should be covered by the protection scope of the present invention.
Claims
1. A machine learning Trojan detection method based on structural feature screening and load expansion, characterized in that: The machine learning Trojan detection method based on structural feature screening and load expansion includes the following steps: Step 1: Analyze the circuit structure and the operation logic of the Trojan circuit, combine the circuit features of traditional machine learning, propose the features required for Trojan detection, and obtain the features of each node from the preprocessed netlist; Step 2: Establish n-level subgraphs starting from each node in the circuit, count the low-probability cascade structures in each subgraph, and screen out low-risk subgraphs and normal subgraphs; Step 3: Use the features of low-risk subgraph nodes as a data set for training to obtain a training model; use test data for testing to obtain high-risk nodes; Step 4: Expand high-risk nodes to obtain the complete Trojan structure; calculate accuracy parameters based on the test results and evaluate the test results; In step 2, the counting of low-probability cascade structures in each subgraph includes: (1) The triggering conditions of the Trojan circuit are very harsh. From the circuit point of view, the probability of gate flipping is very low. Therefore, from the perspective of circuit structure and gate device function, a two-level cascade structure of gate devices in which the probability of outputting 0 or 1 is very low is proposed; (2) Expanding the two-stage cascade structure in step (1), a low-probability cascade structure with a NOT gate or a trigger as the intermediate stage is proposed; (3) Count the parts of the subgraph to be evaluated that have the same structure as those proposed in step (1) and step (2). If the number of identical structures is greater than the threshold t0, the subgraph to be evaluated is considered to be a low-risk subgraph; otherwise, it is a normal subgraph. (4) Extract all nodes of the low-risk subgraph obtained in step (3), remove duplicates, and use the feature values of the extracted nodes as a data set for subsequent training; In step 4, the expansion of high-risk nodes includes: From the perspective of the function of the Trojan circuit, the impact of the Trojan node on the circuit is hidden, that is, the fan-out of the Trojan node is very small and will only affect a very small number of nodes; when the high-risk nodes are subsequently expanded, the subsequent nodes of each high-risk node are queried, and the subsequent nodes with fan-out values less than the threshold t1 are added to the Trojan node, and these nodes are further expanded backward; if the fan-out value of the queried subsequent node is greater than or equal to the threshold t1, it is considered a normal node and no longer expanded; when all the backward nodes of the high-risk node are expanded to normal nodes, the expansion ends; According to the circuit structure, each high-risk node screened out after machine learning is backward expanded; the total expansion threshold t2 is set, and for each expansion, the number of expanded nodes is limited according to the fan-out threshold t2 of a single backward node and the total fan-out threshold t3 of all backward nodes; in the expansion of a high-risk node, each time a new backward Trojan node is found, the fan-out of the backward Trojan is accumulated, and when the accumulated value is greater than or equal to the total expansion threshold t2, the expansion is terminated.
2. The method for detecting Trojans by machine learning based on structural feature screening and load expansion as claimed in claim 1, characterized in that: In step 2, the low probability cascade structure includes: Two-level low 0 probability cascade structure: ① OR gate connected to OR gate; ② NAND gate connected to NAND gate; ③ OR gate connected to NAND gate; ④ NAND gate connected to OR gate; Two-level low 1 probability cascade structure: ① AND gate connected to AND gate; ② NOR gate connected to NOR gate; ③ AND gate connected to NOR gate; ④ NOR gate connected to AND gate; On the basis of the above 8 secondary structures, a multi-level low-probability cascade structure with NOT gates and triggers is added, which is divided into two types: Insert an odd number of NOT gates into the original structure: ① Connect an odd number of NOT gates to a NAND gate, and then connect to an AND gate; ② Connect an odd number of NOT gates to a NAND gate, and then connect to a NOR gate; ③ Connect an odd number of NOT gates to a NOR gate, and then connect to an OR gate; ④ Connect an odd number of NOT gates to a NOR gate, and then connect to a NAND gate; Insert an even number of NOT gates or several triggers into the original structure: including all structures in the two-level low-probability cascade structure; among which, all cascade structures must use the gates in the AND gate, OR gate, NAND gate, and NOR gate as the starting node and the ending node.
3. The method for detecting Trojans by machine learning based on structural feature screening and load expansion as claimed in claim 1, characterized in that: In step three, when using machine learning for training and testing, both the training set and the test set are low-risk nodes that have been screened, and there are no requirements for the specific machine learning methods used; the test results obtained by machine learning are identified as high-risk Trojan nodes for subsequent expansion and completion of the Trojan structure.
4. The method for detecting Trojans by machine learning based on structural feature screening and load expansion as claimed in claim 1, characterized in that: The machine learning Trojan detection method based on structural feature screening and load expansion also includes: (1) Preprocess the gate-level netlist to be tested, merge the Verilog code modules in the netlist and integrate them into a unified module; further divide the code into nodes, and quantify the relationship between the nodes into a graph; (2) Perform feature extraction on the nodes extracted in step (1), extract the signal features and internal structure features of each node, and quantize them into vector form; (3) Generate a subgraph for the nodes extracted in step (1), starting from each node and searching forward n levels to generate a subgraph; (4) Determine the danger of the subgraph generated in step (3), count the number of low-probability cascade structures, and identify it as a low-risk subgraph if the number exceeds the threshold t1, otherwise it is identified as a normal subgraph; extract all nodes of the low-risk subgraph and remove duplicates, and identify these nodes as low-risk nodes; (5) Based on the low-risk nodes in step (4), the feature vectors corresponding to these nodes in step (2) are obtained as a feature set; the feature set is used as a data set and sent to the classifier for training; the model is optimized based on the training results to obtain the best training model; (6) Using cross-validation, multiple data sets to be tested are divided into training sets and test sets; the test data is input into the trained model for detection, and the high-risk Trojan nodes of each netlist are obtained based on the detection results; (7) Based on the graph converted from the netlist in step (1), the high-risk Trojan nodes obtained in step (6) are backward expanded to obtain the complete Trojan circuit; TPR and TNR indicators are calculated based on the detection results to evaluate the detection capability; In step (1), when the gate-level netlist to be tested is preprocessed, a script is used to traverse all gates and triggers in the netlist and regard them as nodes, and basic information of each node is obtained, and a graph is established based on this; wherein the basic information includes node name, node type, node function, input and output line network and forward and backward nodes; In step (2), when performing feature analysis on the extracted nodes, traditional Trojan features are used; wherein the traditional Trojan features include the fan-in number of logic gates, multiplexers, triggers, input-output distances, and ring structures.
5. A hardware Trojan detection and optimization system implementing the machine learning Trojan detection method based on structural feature screening and load expansion as described in any one of claims 1 to 4, characterized in that: The hardware Trojan detection and optimization system includes: The pre-processing module is used to standardize the gate-level netlist structure to be tested and convert it into a graph form; A feature extraction module is used to extract the required features of each node from the overall graph; The subgraph extraction module extracts n-level subgraphs from the overall graph, starting from each node in the netlist; The subgraph screening module is used to count the number of low-probability cascade structures in each subgraph, determine whether the subgraph is a low-risk subgraph, extract all nodes of the low-risk subgraph and remove duplicates; The machine learning module uses the low-risk nodes that have been screened as data sets for training and testing. The Trojan nodes in the test results are identified as high-risk nodes, and the specific machine learning method used is not limited; The load expansion module is used to expand the backward nodes of high-risk nodes according to the set rules, so as to identify Trojan load circuit nodes with different functions that are difficult to be discovered by traditional hardware Trojan detection methods, and calculate the TPR and TNR indicators based on the expanded results to evaluate the detection results.
6. A computer device, characterized in that: The computer device includes a memory and a processor, the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the machine learning Trojan detection method based on structural feature screening and load expansion as described in any one of claims 1 to 4.
7. An information data processing terminal, characterized in that: The information data processing terminal is used to implement the hardware Trojan detection and optimization system as described in claim 5.
