# Security in Wireless Sensor Networks: A Cryptography Performance Analysis at MAC Layer
## 5 Performance Evaluation
### Performance Evaluation: Impersonation Attack
#### 5.5.1 Impersonation Attack with BMAC  
Considering AES and ECC, for each sensor, an energy supply of 1 J and a slot duration of 0.025 shave been used. Instead, for RSA, an energy supply of 2 J and a slot duration of 0.060 shave been set for each node. These choices are due to RSA using keys with higher size in order to guarantee a correct system behavior and to prevent sensors' energy drain. The experimental results are shown in Figure 13.  
As we can see from the Figure 13, considering the attacker sensor node inside the network and applying no mitigation, the total number of received packets is 155, and the energy consumed is 0.431655 J with packet of 10 bytes. The total lost packets, instead, is equal to 343. Introducing the use of cryptography, to mitigate the attack, network performance will show notable variations with respect to this initial setup.  
Figure 11: Simulation with drain attack towards sensor1.  
Figure 12: Average energy consumed, total number of received and loss packets for BMAC with and without energy drain attack.  
In particular, observing Figure 13 it is possible to make the following consideration for each cryptographic method:  
Using AES  
* The total received packet number is equal to 121 and there are 34 packets less than the initial setup described earlier.
* The energy consumption is equal to 0.46844 J and it is greater than the initial setup.  
The total number of received packets is low since, considering the applied mitigation, the server is able to recognize tampered packets and then it discards them. Also, the packet size is greater (16 bytes) than the initial setup (10 bytes) due to the key length used for AES. Therefore, the energy consumption is strictly related to the size of the packet, and thus it is greater than the previous scenario.  
Using RSA  
* The total number of received packets in this case is equal to 32, so 123 packets less than the initial setup and 89 packets with respect to the scenario with AES. This is due to two factors: firstly, the ability of the server to discard the tampered and forged packets and, secondly, the low number of packets sent by sensor nodes since the packets with RSA have a greater length (128 bytes).
* The energy consumption is equal to 1.21514 J and it is greater than the initial setup, AES and even ECC. Since sensor nodes are equipped with limited power and computing resources, they are not able to handle packets which are characterized by a high size, and thus the network will experiment a bottleneck. As a consequence, a large number of packets gets lost.  
Using ECC  
* The total number of received packets is equal to 105, so 50 packets less than the initial setup, 16 less than AES and 73 less than RSA.
* The energy consumption is equal to 0.567043 J and it is greater than all other scenarios.  
This data is due to the greater size of the packets, that in the case of ECC is equal to 256 bytes, according to key size used in ECC. This is with respect to the initial setup and with the AES scenario. Considering RSA, instead, the reason is due to the number of received packets being significantly higher, with 73 packets more added to the total number.  
Figure 13: Average energy consumed, total number of received and loss packets for BMAC.