Energy side channel analysis method based on hybrid lightweight Transform model
Through the hybrid lightweight Transformer model, the energy-side channel is analyzed, and the problem of low key accuracy is solved, and the key prediction accuracy and computing efficiency is achieved. The complete key is predicted through feature extraction and probability accumulation.
Patent Information
- Application Number
- CN202411124160.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-16
- Publication Date
- 2024-11-12
AI Technical Summary
The key accuracy in the existing energy-side channel analysis methods is low, and the network structure of the deep learning model is single, so the energy leakage characteristics cannot be fully extracted, resulting in low accuracy of prediction keys.
Using the energy-side channel analysis method based on the hybrid lightweight Transformer model, the power-consumption leakage trajectory is initially extracted and compressed through the pre-processing module, and then the energy-side channel leakage feature extracted by the Transformer module, combining multiple power-consumption leakage trajectories. The result probability accumulates the complete key to predict the model structure to improve training speed and computational efficiency.
It improves the accuracy and reliability of key prediction, and acquires leaked features more refined and comprehensively than a single deep learning model, simplifies the model structure, and improves training speed and computing efficiency.
Smart Images

Figure CN118944854A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of information security, and in particular to an energy side channel analysis method based on a hybrid lightweight Transformer model. Background Art
[0002] As a non-traditional cryptanalysis method, side-channel attack (SCA) has attracted widespread attention from researchers. Side-channel attackers infer key information by analyzing the physical leakage information (such as energy consumption, electromagnetic radiation, sound, etc.) of cryptographic devices when performing encryption operations, posing a threat to cryptographic systems. In side-channel attacks, power side-channel leakage is a common leakage method. Since cryptographic devices will generate energy leakage when performing encryption operations, energy side-channel attackers can obtain specific information about confidential values by inputting incentive information to different hardware functional modules and recording the physical leakage signals at the algorithm implementation level caused by the incentive conditions. The key information used in the calculation process can be obtained by indirectly analyzing the energy trajectory data.
[0003] Among the non-descriptive side channel analysis methods, the Correlation Power Analysis (CPA) method is a side channel analysis method that infers encryption keys or sensitive data by analyzing the energy consumption of encryption devices when performing encryption operations. The CPA method is highly dependent on accurate assumptions about the power consumption model of the target device. If there is a large difference between the assumed model and the actual situation, the results of the CPA analysis may be seriously affected, and even wrong conclusions may be drawn, reducing the accuracy of the key.
[0004] Template attack is an effective attack method in descriptive side channel analysis methods. It relies on pre-building energy trajectory templates of devices under different operations, and infers keys or sensitive data by comparing the similarity between the energy trajectory in actual operation and the template. Template attack requires the attacker to build energy trajectory templates of devices under different operations in advance, which usually requires a large amount of experimental data and sophisticated analysis, and the attack complexity is high.
[0005] In addition, there are some methods that perform energy side channel analysis by building deep learning models, such as building convolutional neural network models for side channel analysis. However, the network structure built by existing deep learning models is relatively simple, and it is impossible to extract energy leakage features at a deeper level and give full play to the model performance, resulting in low accuracy of predicted keys. Summary of the invention
[0006] The main purpose of this application is to provide an energy side channel analysis method based on a hybrid lightweight Transformer model, aiming to solve the problem of low key accuracy obtained by existing energy side channel analysis methods.
[0007] To achieve the above-mentioned purpose, the present application provides an energy side channel analysis method based on a hybrid lightweight Transformer model, comprising the following steps: inputting several power consumption leakage trajectories of the bytes to be attacked into a pre-trained hybrid lightweight Transformer model in sequence to obtain probability values of multiple intermediate quantities corresponding to each power consumption leakage trajectory; accumulating the probability values of multiple intermediate quantities corresponding to all power consumption leakage trajectories to obtain accumulated probability values of multiple intermediate quantities; taking the intermediate quantity corresponding to the maximum accumulated probability value as the predicted intermediate quantity, and performing an inverse transformation on it to obtain a key value; wherein the pre-trained hybrid lightweight Transformer model includes: a preprocessing module, which is used to perform preliminary feature extraction on the power consumption leakage trajectory to obtain initial features; a Transformer module, which is used to perform energy side channel leakage feature extraction on the initial features to obtain probability values of multiple intermediate quantities corresponding to each power consumption leakage trajectory.
[0008] Optionally, several power consumption leakage trajectories of the bytes to be attacked are sequentially input into a pre-trained hybrid lightweight Transformer model to obtain probability values of multiple intermediate quantities corresponding to each power consumption leakage trajectory, including: performing a first convolution, a first compression, a second convolution, a second compression, and a normalization process on the power consumption leakage trajectory to obtain an initial feature; converting the initial feature into a fixed-dimensional vector to capture the dependency between the converted initial features, and preventing overfitting and standardizing them to obtain a first standardized output, adding the first standardized output to the converted initial features to obtain a first connection feature, performing a nonlinear transformation on the first connection feature, preventing overfitting and standardizing the features after the nonlinear transformation to obtain a second standardized output, adding the second standardized output to the first connection feature to obtain a second connection feature, and sequentially performing linear changes and operations on the second connection features to obtain probability values of multiple intermediate quantities corresponding to each power consumption leakage trajectory.
[0009] Optionally, the intermediate quantity corresponding to the maximum cumulative probability value is used as the predicted intermediate quantity, and an inverse conversion is performed on it, including: taking the intermediate quantity corresponding to the maximum cumulative probability value as the predicted intermediate quantity, if the byte to be attacked is a plaintext key XOR attack point, the predicted intermediate quantity is XORed with the corresponding plaintext; if the byte to be attacked is an S-box replacement attack point, the predicted intermediate quantity is reversely replaced with a control S-box, and the predicted intermediate quantity after the reverse replacement is XORed with the corresponding plaintext.
[0010] Optionally, the preprocessing module includes a first convolutional layer, a first normalization layer, a first activation function layer, a second convolutional layer, a first maximum pooling layer, a recurrent network, a second maximum pooling layer, and a first normalization and activation function layer connected in sequence; wherein the recurrent network includes three convolutional networks connected in sequence, the convolutional network includes a second normalization and activation function layer, and a third convolutional layer, and the number of convolution kernels of the three third convolutional layers decreases in sequence.
[0011] Optionally, the Transformer module includes an encoder and an output unit; wherein the encoder includes: multiple encoder layers, including an embedding layer, a multi-head self-attention sublayer, a first normalization and residual connection layer connected in sequence, and the normalization and connection layer is also connected to the embedding layer; a feedforward fully connected sublayer, including a feedforward network layer and a second normalization and residual connection layer connected in sequence, the feedforward network layer includes a fourth convolutional layer and a fifth convolutional layer connected in sequence, and the second normalization and residual connection layer is also connected to the first normalization and residual connection layer.
[0012] Optionally, the output unit includes a linear layer and a softmax layer.
[0013] Optionally, the training process of a pre-trained hybrid lightweight Transformer model includes: Construct a sample data set, which includes multiple power leakage trajectories and corresponding real intermediate quantities; input the sample data set into the preset model to obtain the probability values of multiple intermediate quantities corresponding to each power leakage trajectory, and use the intermediate quantity corresponding to the maximum probability value as the predicted intermediate quantity; use the loss function to calculate the loss value by combining the predicted intermediate quantity and the real intermediate quantity, and update the parameters of the preset model according to the loss value until the preset model converges to obtain the pre-trained hybrid lightweight Transformer model.
[0014] In addition, the present application also provides an energy side channel analysis device based on a hybrid lightweight Transformer model, including: a prediction module, which is used to input a preset number of power consumption leakage trajectories of bytes to be attacked into a pre-trained hybrid lightweight Transformer model in sequence to obtain probability values of multiple intermediate quantities corresponding to each power consumption leakage trajectory; an accumulation module, which is used to accumulate the probability values of multiple intermediate quantities corresponding to all power consumption leakage trajectories to obtain accumulated probability values of multiple intermediate quantities; a conversion module, which takes the intermediate quantity corresponding to the maximum accumulated probability value as the predicted intermediate quantity, and inversely converts it to obtain a key value.
[0015] The present application discloses an energy side channel analysis method based on a hybrid lightweight Transformer model. The preprocessing module performs initial feature extraction and compression on the input power leakage trajectory, and then the Transformer module performs energy side channel leakage feature extraction. Compared with a deep learning model with a single structure, the leakage features can be obtained more precisely and comprehensively, and the accuracy of analysis and prediction can be further improved. Compared with the traditional Transformer model, the hybrid lightweight Transformer model discards the decoder part, simplifies the model structure, reduces the number of parameters, and can improve the training speed and computing efficiency. The complete key is predicted by probabilistically accumulating the results of multiple power leakage trajectories, thereby improving the reliability of key prediction. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 A flowchart of an energy side channel analysis method based on a hybrid lightweight Transformer model in this application; Figure 2 This is a structural schematic diagram of a hybrid lightweight Transformer model in an energy side channel analysis method based on a hybrid lightweight Transformer model in this application; Figure 3 A loss value variation diagram obtained by an embodiment of an energy side channel analysis method based on a hybrid lightweight Transformer model of the present application; Figure 4 This is a graph of accuracy changes obtained by an embodiment of an energy side channel analysis method based on a hybrid lightweight Transformer model of the present application; Figure 5 This is a graph showing changes in probability values of intermediate quantities obtained in an embodiment of an energy side channel analysis method based on a hybrid lightweight Transformer model of the present application.
[0017] Figure 6 The present application provides a structural schematic diagram of an energy side channel analysis device based on a hybrid lightweight Transformer model.
[0018] In the figure, 100. preprocessing module, 101. first convolution layer, 102. first normalization layer, 103. first activation function layer, 104. second convolution layer, 105. first maximum pooling layer, 106. recurrent network, 1061. convolution network, 10611. second normalization and activation function layer, 10612. third convolution layer, 107. second maximum pooling layer, 108. first normalization and activation function layer; 200. Transformer module, 201. Encoder, 2011. Feedforward fully connected sublayer, 2012. Encoder layer, 20121. Embedding layer, 20122. Multi-head self-attention sublayer, 20123. First normalization and residual connection layer, 20111. Feedforward network layer, 20112. Second normalization and residual connection layer, 202. Output unit, 2021. Linear layer, 2022. Softmax layer; 10. Prediction module, 20. Accumulation module, 30. Conversion module.
[0019] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0020] In order to make the purpose, technical solutions and advantages of this application clearer, the technical solutions in this application will be clearly and completely described below in conjunction with the drawings in this application. Obviously, the described embodiments are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0021] The energy side channel analysis method based on the hybrid lightweight Transformer model of the present invention is suitable for the analysis of multiple encryption methods. Each encryption method includes a different number of bytes. The energy side channel analysis method of the present invention analyzes each byte to obtain the key corresponding to the byte, and finally outputs the completed key. For example, it can be an AES-128 encryption method. The AES-128 encryption method contains 16 bytes. Then the energy side channel analysis method of the present invention is used to analyze each byte separately, and finally outputs a string of 16 bytes of complete keys. In addition, there are two energy leakage processes (hereinafter referred to as attack points) in the encryption process of the AES-128 encryption method. One is the energy leakage generated when the plaintext and the initial key are XORed, and the other is the energy leakage generated when the result after XOR is replaced by bytes through the SBOX box (hereinafter referred to as S box). Therefore, the energy side channel analysis method of the present invention can attack any of the above two attack points. For other encryption methods, their attack points are also attacked, and the specific method is as follows.
[0022] Example 1 An energy side channel analysis method based on a hybrid lightweight Transformer model, such as Figure 1 As shown, the following steps are included: Step S10, inputting several power consumption leakage traces of the bytes to be attacked into the pre-trained hybrid lightweight Transformer model in sequence, and obtaining probability values of multiple intermediate quantities corresponding to each power consumption leakage trace; It is worth noting that the power consumption leakage trace in this embodiment contains byte information to be attacked, such as a key, and the intermediate quantity is the intermediate quantity of the predicted key.
[0023] Specifically, step S10 includes: Step S11, performing a first convolution, a first compression, a second convolution, a second compression, and a normalization process on the power leakage trace in sequence to obtain an initial feature; Step S12, converting the initial features into fixed-dimensional vectors, capturing the dependencies between the converted initial features, preventing overfitting and standardizing them to obtain a first standardized output, adding the first standardized output to the converted initial features to obtain a first connection feature, performing a nonlinear transformation on the first connection feature, preventing overfitting and standardizing the features after the nonlinear transformation to obtain a second standardized output, adding the second standardized output to the first connection feature to obtain a second connection feature, performing linear changes and operations on the second connection feature in sequence, and obtaining probability values of multiple intermediate quantities corresponding to each power consumption leakage trajectory.
[0024] Among them, Figure 2 As shown, the pre-trained hybrid lightweight Transformer model includes a preprocessing module 100 and a Transformer module 200. The preprocessing module 100 is used to perform preliminary feature extraction and size compression on the power consumption leakage trajectory to obtain the initial features; the Transformer module 200 is used to extract energy side channel leakage features on the initial features to obtain the probability value of the intermediate quantity of each byte.
[0025] Specifically, the preprocessing module 100 includes a first convolutional layer 101, a first normalization layer 102, a first activation function layer 103, a second convolutional layer 104, a first maximum pooling layer 105, a recurrent network 106, a second maximum pooling layer 107, and a first normalization and activation function layer 108 connected in sequence; wherein, the recurrent network 106 includes three convolutional networks 1061 connected in sequence, the convolutional network 1061 includes a second normalization and activation function layer 10611, and a third convolutional layer 10612, and the number of convolution kernels of the three third convolutional layers 10612 decreases in sequence.
[0026] The Transformer module 200 includes an encoder 201 and an output unit 202; wherein the encoder 201 includes a feedforward fully connected sublayer 2011 and multiple encoder layers 2012, the encoder layer 2012 includes an embedding layer 20121, a multi-head self-attention sublayer 20122, a first normalization and residual connection layer 20123 connected in sequence, and the first normalization and residual connection layer 20123 is also connected to the embedding layer 20121; the feedforward fully connected sublayer 2011 includes a feedforward network layer 20111 and a second normalization and residual connection layer 20112 connected in sequence, the feedforward network layer 20111 includes a fourth convolutional layer and a fifth convolutional layer connected in sequence, and the second normalization and residual connection layer 20112 is also connected to the first normalization and residual connection layer 20123. The output unit 202 includes a linear layer 2021 and a softmax layer 2022.
[0027] As a preferred embodiment, adding a first dropout layer and a second dropout layer after the multi-head self-attention sublayer 20122 and the fourth convolutional layer respectively can prevent overfitting and improve the generalization ability of the model.
[0028] The processing procedures of the preprocessing module 100 and the Transformer module 200 are described in detail below.
[0029] The power leakage trajectory is input into the preprocessing module 100, and is sequentially subjected to the first convolutional layer 101, the first normalization layer 102, the first activation function layer 103, and the second convolutional layer 104 for feature extraction, and then the input power leakage trajectory data is compressed through the first maximum pooling layer 105, and then input into the three convolutional networks 1061 in the recurrent network 106 for feature extraction again, and after multiple cycles, it is input into the second maximum pooling layer 107 to compress the input data again; finally, it is subjected to the first normalization and activation function layer 108 to obtain the initial features; the initial features are input into the embedding layer 20121 to convert the initial feature data into a fixed-dimensional vector, and then the dependency between the converted initial features is captured through the multi-head self-attention sublayer 20122, and then the first discard layer, the first normalization layer 1061 and the activation function layer 108 are used to obtain the initial features; The residual connection layer 20123 is used to prevent overfitting and standardize the output, and the standardized output is added to the output of the embedding layer 20121 as the input of the feedforward fully connected sublayer 2011; the input of the feedforward fully connected sublayer 2011 enters the fourth convolutional layer for nonlinear transformation processing and then enters the second drop layer, and then passes through the fifth convolutional layer to convert the output dimension back to the same dimension as the original input, so that the output data can still match the input dimension of the next encoder 201, and then passes through the second normalization and residual connection layer 20112 to prevent overfitting and standardize the output, and the standardized output is added to the input of the feedforward fully connected sublayer 2011 as the input of the output unit 202; the input of the output unit 202 is linearly changed through the linear layer 2021, and then outputs the probability values of various intermediate quantities through the softmax layer 2022.
[0030] Step S20, accumulating the probability values of various intermediate quantities corresponding to all power consumption leakage traces to obtain accumulated probability values of the various intermediate quantities; In this embodiment, the accumulation method may be logarithmic accumulation.
[0031] Step S30, taking the intermediate quantity corresponding to the maximum cumulative probability value as the predicted intermediate quantity, and performing an inverse transformation on it to obtain a key value; Specifically, in step S30, the intermediate quantity corresponding to the maximum cumulative probability value is used as the predicted intermediate quantity, and the inverse conversion is performed on it, including: The intermediate quantity corresponding to the maximum cumulative probability value is used as the predicted intermediate quantity. If the byte to be attacked is the plaintext key XOR attack point, the predicted intermediate quantity is XORed with the corresponding plaintext. If the byte to be attacked is an S-box replacement attack point (specifically, an S-box post-replacement attack point), the predicted intermediate quantity is subjected to an S-box inverse replacement, and an XOR operation is performed between the predicted intermediate quantity after the inverse replacement and the corresponding plaintext.
[0032] Through the above methods, the energy side channel analysis method based on the hybrid lightweight Transformer model of the present invention performs initial feature extraction and compression on the input power consumption leakage trajectory through the preprocessing module 100, and then extracts the energy side channel leakage feature through the Transformer module 200. Compared with the deep learning model with a single structure, it can obtain leakage features more accurately and comprehensively, and further improve the accuracy of prediction; compared with the traditional Transformer model, the hybrid lightweight Transformer model discards the decoder part, simplifies the model structure, reduces the number of parameters, and can improve the training speed and computing efficiency; the complete key is predicted by probabilistically accumulating the results of multiple power consumption leakage trajectories, thereby improving the reliability of key prediction.
[0033] Example 2 Step S100, construct a sample data set, the sample data set includes multiple power consumption leakage trajectories and corresponding real intermediate quantities; input the sample data set into a preset model to obtain probability values of multiple intermediate quantities corresponding to each power consumption leakage trajectory, and use the intermediate quantity corresponding to the maximum probability value as the predicted intermediate quantity; use the loss function to calculate the loss value by combining the predicted intermediate quantity and the real intermediate quantity, and update the parameters of the preset model according to the loss value until the preset model converges to obtain a pre-trained hybrid lightweight Transformer model.
[0034] Specifically, before constructing the sample data set, it is necessary to configure the training hyperparameters, determine the optimizer, and the loss function. The following is a detailed introduction to step S1.
[0035] Step S110, initializing a preset model; Step S120, configuring the training hyperparameters of the preset model, determining the optimizer and the loss function; the training hyperparameters may include a learning rate, an epoch, and a batch size; This embodiment uses a random grid parameter adjustment algorithm to configure the training hyperparameters of the preset model. The random grid parameter adjustment algorithm reduces the number of hyperparameter combinations that need to be searched through random sampling, thereby speeding up the search process. Unlike traditional grid search, which traverses all possible hyperparameter combinations and incurs a high computational cost, the random grid parameter adjustment algorithm only randomly selects a portion of the combinations for search, thereby improving computational efficiency. The specific steps are as follows: a. Define the parameter space, that is, define a reasonable search range for each hyperparameter of the preset model; for example, the learning rate setting range is (0.001, 0.01, 0.1), the number of iterations range is 0~100, and the batch size range is (16, 32, 64). b. Use RandomizedSearchCV to perform random search. In this process, the number of search iterations can be controlled by adjusting the n_iter parameter to indirectly control the search density. c. Call the fit method to start the search. The scikit-learn library will automatically handle the training and verification of the model. d. Get the best training hyperparameters. Based on the evaluation results, select the parameter combination with the best performance as the final model parameters. If you need to adjust the parameters more finely, you can perform more intensive sampling near the optimal parameters by repeating steps (3) and (4).
[0036] The loss function selects the cross-entropy loss function. The cross-entropy loss function is mainly used to compare the differences between probability values. The formula is expressed as:
[0037] In the formula, is the probability value of the true intermediate quantity (i.e., a one-hot encoded vector of 256 byte values), is the probability value of the predicted intermediate quantity, The function is The logarithmic function with base .
[0038] The optimizer is Adam. Adam (Adaptive Moment Estimation) is a widely used optimization algorithm for training deep learning models. The Adam optimizer combines the advantages of Adagrad in handling sparse gradients and RMSprop in handling non-stationary targets. The first-order moment estimation and second-order moment estimation of the gradient are used to dynamically adjust the learning rate of each parameter.
[0039] The evaluation indicator can be accuracy, which indicates the proportion of samples that are correctly classified.
[0040] Step S130, constructing a sample data set; the sample data set includes a training data set, a verification data set and a test data set; Step S140, configuring a callback function; The callback function can perform custom operations at different stages of training, such as saving the optimal model, recording training logs, etc. ModelCheckpoint is a commonly used callback function that is used to save the best weights of the model at the end of each epoch (based on the performance on the validation dataset). In the ModelCheckpoint callback function, only save the best weights (save_best_only=True). After each evaluation, if the performance on the validation dataset improves (for example, the accuracy improves), the weights of the current model are saved. These weights are saved in the specified file path, and the file name contains training information (such as byte number, attack point type, etc.) for subsequent loading and use.
[0041] In step S150, the training data set and the verification data set are input into the preset model, and the fit function is used to perform iterative training according to the training hyperparameters configured in step 3; after each iteration, the preset model outputs the probability values of various intermediate quantities corresponding to each power consumption leakage trajectory, and the intermediate quantity corresponding to the maximum probability value is used as the predicted intermediate quantity; using the loss function, the loss value is calculated by combining the predicted intermediate quantity and the true intermediate quantity corresponding to the training data set, and the parameters of the preset model in the callback function are updated according to the loss value; after the update is completed, the evaluation index is used to combine the predicted intermediate quantity and the true intermediate quantity corresponding to the verification data set, and the evaluation value is calculated to evaluate the preset model, and the weight of the round with the highest evaluation value is saved as the optimal weight parameter of the model, which is used as the final model.
[0042] In this embodiment, the evaluation value may be an accuracy rate, where the accuracy rate is the ratio of the number of correctly predicted power consumption leakage traces to the total number of input power consumption leakage traces.
[0043] After the training is completed, the test data set is input into the optimal preset model for testing, and finally a pre-trained hybrid lightweight Transformer model is obtained.
[0044] Step S200, inputting several power consumption leakage traces of the bytes to be attacked into the pre-trained hybrid lightweight Transformer model in sequence, and obtaining probability values of multiple intermediate quantities corresponding to each power consumption leakage trace; Step S300, accumulating probability values of various intermediate quantities corresponding to all power consumption leakage traces to obtain accumulated probability values of the various intermediate quantities; Step S400, taking the intermediate quantity corresponding to the maximum cumulative probability value as the predicted intermediate quantity, if the byte to be attacked is a plaintext key XOR attack point, performing an XOR operation on the predicted intermediate quantity and the corresponding plaintext; if the byte to be attacked is an S-box replacement attack point, performing an S-box inverse replacement on the predicted intermediate quantity, and performing an XOR operation on the predicted intermediate quantity after the inverse replacement and the corresponding plaintext to obtain the key value.
[0045] It is worth noting that the number of power consumption leakage traces input in step S6 is obtained in advance through testing, and the specific acquisition method is as follows.
[0046] Part of the data in the test data set can be selected, and a power leakage trajectory can be first input into the pre-trained hybrid lightweight Transformer model to obtain the probability values of various intermediate quantities corresponding to the power leakage trajectory, and the maximum probability value can be judged. If the probability value does not reach the preset value, the next power leakage trajectory is input, and the probability values of various intermediate quantities corresponding to the power leakage trajectory and the probability values of various intermediate quantities corresponding to the previously input power leakage trajectory are logarithmically accumulated, and so on, until the accumulated probability value reaches the preset value.
[0047] Example 3 Taking the seventh byte S-box output attack point in the AES-128 encryption process as a test example, the hardware environment used for implementation is: Intel(R) Xeon(R) Silver 4214R CPU @ 2.40GHz, 30GB memory, RTX 3080 Ti(12GB) * 1; the running software environment is: Ubuntu 20.04 operating system, TensorFlow 2.9.0, Python 3.8, Cuda 11.2.
[0048] Step S1, initializing a preset model, the preset model includes a preprocessing module 100 and a Transformer module 200; The preprocessing module 100 includes a first convolutional layer 101, a first normalization layer 102, a first activation function layer 103, a second convolutional layer 104, a first maximum pooling layer 105, a recurrent network 106, a second maximum pooling layer 107, and a first normalization and activation function layer 108, which are connected in sequence; the number of filters in the first convolutional layer 101 is 512, the number of convolution kernels is 3, and the step size is 1; the number of filters in the second convolutional layer 104 is 256, the number of convolution kernels is 3, and the step size is 1; the size of the first maximum pooling layer 105 is 4, which can compress the size of the input data The size of the second maximum pooling layer 107 is 2, which can compress the size of the input data to (32, 625, 256). The recurrent network 106 includes three convolutional networks 1061 connected in sequence. The convolutional network 1061 includes a second normalization and activation function layer 10611 and a third convolutional layer 10612. The number of convolution kernels of the three third convolutional layers 10612 is 4*filters, 2*filters, and filters, respectively. Filters=128, and the number of cycles is 2.
[0049] The Transformer module 200 includes an encoder 201 and an output unit 202; wherein the encoder 201 includes a feed-forward fully connected sublayer 2011 and multiple encoder layers 2012, the encoder layer 2012 includes an embedding layer 20121, a multi-head self-attention sublayer (including initialization, segmentation, attention calculation, and concatenation operations), a first drop layer, a first normalization and residual connection layer 20123 connected in sequence, and the normalization and connection layer is also connected to the embedding layer 20121; the feed-forward fully connected sublayer 2011 includes a feed-forward network layer 20111 and a second normalization and residual connection layer 20112 connected in sequence, the feed-forward network layer 20111 includes a fourth convolutional layer, a second drop layer, and a fifth convolutional layer connected in sequence, and the second normalization and residual connection layer 20112 is also connected to the first normalization and residual connection layer 20123. The output unit 202 includes a linear layer 2021 and a softmax layer 2022. The number of filters of the fourth convolutional layer is ff_dim (256 in this example), the convolution kernel size is 1, and the ReLU activation function is applied. The number of filters of the fifth convolutional layer is 256 and the convolution kernel size is 1. In this embodiment, the number of cycles of the encoder 201 is 6 times, the multi-head self-attention sublayer is 4 heads, the dimension of each head is set to 32, and the drop rate is set to 0.1. The output unit 202 includes a linear layer 2021 and a softmax layer 2022, and the linear layer 2021 is connected to the second normalization and residual connection layer 20112 and the softmax layer 2022 respectively.
[0050] Outputs 256 softmax probability values of bytes.
[0051] Step S2, use the KerasClassifier of the scikit-learn library to package the preset model into a scikit-learn compatible estimator. The optimal parameter combination is obtained through the random grid parameter adjustment algorithm as follows: In Keras, use the model.compile() method to configure the model training process. Specify the loss function as categorical cross entropy, the optimizer as Adam, set the learning rate to 0.001, and the evaluation metric as "acc", i.e., accuracy. During the training process, Keras will calculate and print the value of the accuracy metric. The number of iterations (epoch) is set to 30. The batch size (batchsize) is set to 32.
[0052] Step S3, load the sample data set. The training data set includes 65536 power consumption trajectory data and the actual intermediate quantity corresponding to each trajectory. The verification data set is taken from the 4096 trajectories in the test data set and the actual intermediate quantity corresponding to each trajectory. During the training process, both the training data set and the test data set are divided into 256 slices, each of which corresponds to a specific key, including a plaintext array, a key array, a plaintext key XOR value array, an array of XOR values replaced by S boxes, and a power consumption trajectory array. In addition, since the process related to the required key is mainly the first round of AES encryption, the corresponding power consumption trajectory is included in the first 5000 points of the trajectory, so in order to load data containing more features into the preset model, the first 5000 points of each trajectory are selected as input data.
[0053] Step S5, calling a get_model_stub function to generate a unique file name (stub) containing information about the attack point, attack bytes, and configuration information. Step S6, input the training data sets (x_train) and (y_train), and the validation data set (x_test, y_test) into the preset model, and use the fit function to perform iterative training according to the batch size (batch size=32) and number of iterations (epoch=30) configured in step 2; after each iteration, the preset model outputs the probability values of various intermediate quantities corresponding to each power leakage trajectory, and takes the intermediate quantity corresponding to the maximum probability value as the predicted intermediate quantity; using the loss function, the loss value is calculated by combining the predicted intermediate quantity and the actual intermediate quantity corresponding to the training data set. The change of the loss value with the number of power leakage trajectories is shown in the figure below: Figure 3 As shown, the parameters of the preset model in the callback function are updated according to the loss value; after the update is completed, the evaluation index is used to combine the predicted intermediate quantity and the real intermediate quantity corresponding to the verification data set to calculate the accuracy to evaluate the preset model. The change of accuracy with the number of power leakage traces is shown in Figure 4 shown.
[0054] Step S6, input several power leakage traces of the bytes to be attacked into the pre-trained hybrid lightweight Transformer model in sequence to obtain the probability values of 256 intermediate quantities of each power leakage trace; in this process, a list vals is established, and the 256 possible softmax values of the key are recorded in the list from large to small. When each trace is added, the probability values of the same intermediate quantity are logarithmically accumulated, the list ranking is updated, and the intermediate quantity with the largest probability value is used as the predicted intermediate quantity, and finally the result of the predicted probability value changing with the number of traces is obtained, such as Figure 5When the accumulated probability value reaches 100%, the corresponding intermediate quantity is taken as the prediction result, the S-box inverse replacement is performed on the intermediate quantity, and the predicted intermediate quantity after inverse replacement is XORed with the corresponding plaintext to obtain the key value.
[0055] from Figure 5 It can be seen that under the condition that the prediction probability value of a trajectory prediction is 74%, the hybrid lightweight Transformer model of the present invention only needs 3 trajectories to completely and correctly restore the byte value of the first byte S-box output attack point. The prediction probability value determines the probability of the model successfully predicting the key through a single trajectory. When the prediction probability value is higher, when the logarithmic accumulation of the byte softmax output is performed, the accumulated value of the most likely byte output is larger, and it is easier to predict the true key value through fewer trajectories.
[0056] Example 4 An energy side channel analysis device based on a hybrid lightweight Transformer model includes a prediction module 10, an accumulation module 20 and a conversion module 30. The prediction module 10 is used to input a preset number of power consumption leakage trajectories of bytes to be attacked into a pre-trained hybrid lightweight Transformer model in sequence to obtain probability values of multiple intermediate quantities corresponding to each power consumption leakage trajectory; the accumulation module 20 is used to accumulate the probability values of multiple intermediate quantities corresponding to all power consumption leakage trajectories to obtain accumulated probability values of multiple intermediate quantities; the conversion module 30 is used to use the intermediate quantity corresponding to the maximum accumulated probability value as the predicted intermediate quantity, and perform inverse conversion on it to obtain a key value.
[0057] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. An energy side channel analysis method based on a hybrid lightweight Transformer model, It is characterized in that The following steps are involved: Inputting several power consumption leakage traces of the bytes to be attacked into the pre-trained hybrid lightweight Transformer model in sequence, and obtaining probability values of multiple intermediate quantities corresponding to each of the power consumption leakage traces; Accumulating probability values of various intermediate quantities corresponding to all the power consumption leakage traces to obtain accumulated probability values of various intermediate quantities; The intermediate quantity corresponding to the maximum cumulative probability value is used as the predicted intermediate quantity, and the inverse transformation is performed on it to obtain the key value; The pre-trained hybrid lightweight Transformer model includes: A preprocessing module, used for performing preliminary feature extraction on the power leakage trace to obtain initial features; The Transformer module is used to extract energy side channel leakage features from the initial features to obtain probability values of multiple intermediate quantities corresponding to each of the power consumption leakage trajectories.
2. According to claim 1, the energy side channel analysis method based on the hybrid lightweight Transformer model, It is characterized in that The plurality of power consumption leakage traces of the bytes to be attacked are sequentially input into the pre-trained hybrid lightweight Transformer model to obtain probability values of multiple intermediate quantities corresponding to each of the power consumption leakage traces, including: The power consumption leakage trace is sequentially subjected to a first convolution, a first compression, a second convolution, a second compression, and a normalization process to obtain an initial feature; The initial features are converted into fixed-dimensional vectors, the dependencies between the converted initial features are captured, and they are prevented from overfitting and standardized to obtain a first standardized output, the first standardized output is added to the converted initial features to obtain a first connection feature, the first connection feature is nonlinearly transformed, the features after the nonlinear transformation are prevented from overfitting and standardized to obtain a second standardized output, the second standardized output is added to the first connection feature to obtain a second connection feature, and the second connection feature is linearly changed and operated in sequence to obtain probability values of multiple intermediate quantities corresponding to each of the power consumption leakage trajectories.
3. According to claim 1, the energy side channel analysis method based on the hybrid lightweight Transformer model, It is characterized in that The taking the intermediate quantity corresponding to the maximum accumulated probability value as the predicted intermediate quantity and performing an inverse conversion on it includes: The intermediate quantity corresponding to the maximum cumulative probability value is used as the predicted intermediate quantity, and if the byte to be attacked is a plaintext key XOR attack point, the predicted intermediate quantity is XOR-ed with the corresponding plaintext; If the byte to be attacked is an S-box replacement attack point, the predicted intermediate amount is subjected to an S-box reverse replacement, and an XOR operation is performed between the predicted intermediate amount after the reverse replacement and the corresponding plaintext.
4. The energy side channel analysis method based on the hybrid lightweight Transformer model according to claim 1, It is characterized in that The preprocessing module includes a first convolutional layer, a first normalization layer, a first activation function layer, a second convolutional layer, a first maximum pooling layer, a recurrent network, a second maximum pooling layer, a first normalization and activation function layer connected in sequence; The recurrent network includes three convolutional networks connected in sequence, the convolutional network includes a second normalization and activation function layer, a third convolutional layer, and the number of convolution kernels of the three third convolutional layers decreases in sequence.
5. The energy side channel analysis method based on the hybrid lightweight Transformer model according to claim 1, It is characterized in that The Transformer module includes an encoder and an output unit; Wherein, the encoder comprises: A plurality of encoder layers, including an embedding layer, a multi-head self-attention sublayer, and a first normalization and residual connection layer connected in sequence, wherein the normalization and connection layer is also connected to the embedding layer; The feedforward fully connected sublayer includes a feedforward network layer and a second normalization and residual connection layer connected in sequence, the feedforward network layer includes a fourth convolutional layer and a fifth convolutional layer connected in sequence, and the second normalization and residual connection layer is also connected to the first normalization and residual connection layer.
6. The energy side channel analysis method based on the hybrid lightweight Transformer model according to claim 5, It is characterized in that The output unit includes a linear layer and a softmax layer; the linear layer is connected to the second normalization and residual connection layer and the softmax layer respectively.
7. The energy side channel analysis method based on the hybrid lightweight Transformer model according to claim 1, It is characterized in that The training process of the pre-trained hybrid lightweight Transformer model includes: Constructing a sample data set, wherein the sample data set includes a plurality of power consumption leakage traces and corresponding real intermediate quantities; The sample data set is input into the preset model to obtain probability values of multiple intermediate quantities corresponding to each of the power consumption leakage trajectories, and the intermediate quantity corresponding to the maximum probability value is used as the predicted intermediate quantity; the loss value is calculated by combining the predicted intermediate quantity and the true intermediate quantity using the loss function, and the parameters of the preset model are updated according to the loss value until the preset model converges to obtain the pre-trained hybrid lightweight Transformer model.
8. An energy side channel analysis device based on a hybrid lightweight Transformer model, It is characterized in that include: A prediction module, used to sequentially input a preset number of power consumption leakage traces of bytes to be attacked into a pre-trained hybrid lightweight Transformer model to obtain probability values of multiple intermediate quantities corresponding to each of the power consumption leakage traces; An accumulation module, used for accumulating the probability values of various intermediate quantities corresponding to all the power consumption leakage traces to obtain accumulated probability values of the various intermediate quantities; The conversion module takes the intermediate quantity corresponding to the maximum cumulative probability value as the predicted intermediate quantity, and performs a reverse conversion on it to obtain the key value.
