# Enhancing Resilience in Digital Twins: ASCON-Based Security Solutions for Industry 4.0
## 3 Proposed Solution
### Ditto Java Base Payload Mapping
\begin{table}
\begin{tabular}{c c c c} \hline \hline  & **No-Encrypption** & **ASCON** & **AES-GCM** \\ \hline Cycle Count & 2009 & 36,811 & 49,956 \\ Byte Processed & 32 & 32 & 32 \\ CPU Freq MHz & 240 & 240 & 240 \\ Cycle per byte & 64.28 & 1094.68 & 31,517.90 \\ Time Elapsed \(\upmu\)s & 8.57 & 145.95 & 202.38 \\ Throughput B/\(\upmu\)s & 3.73 & 0.219 & 0.158 \\ \hline \hline \end{tabular}
\end{table} 
Table 4: Cycle count for 3 cases: No-Encrypption, ASCON, AES-GCM. Figure 9: Static code size of the scheme for three scenarios (No-Encryption, ASCON, AES-GCM). affected by the program's operations, we opted for alternative methods to approximate the dynamic memory usage of each algorithm, described as follows. In our device (ESP32), we discovered that the initially allocated memory for handling heap and stack allocation is 327,680 Bytes. With this information, we track the minimum heap size ever available, utilizing the system call _esp_get_minimum_free_heap_size_. Our program was executed for 1000 iterations calling the encryption function for each implementation, allowing us to obtain a snapshot of the free memory available between the stack and heap 1000 times. By calculating the difference between the total allocated dynamic memory and the minimum heap size recorded, we were able to approximate the memory footprint of each implementation. Furthermore, we employed the baseline implementation, which does not incorporate an encryption/decryption algorithm, as a benchmark to estimate the dynamic memory usage overhead added by ASCON and AES-GCM algorithms(see Figure 9(b)). This comparison with the baseline provided insight into the dynamic memory usage of each algorithm at the running time. Measuring the dynamic RAM usage of each algorithm presents a challenge compared with measuring static memory usage. This difficulty stems from the need to monitor dynamic memory allocations and deallocations on both the heap and stack, occurring during function calls and returns. While an effective technique suggested by NIST involves overwriting memory with known values before program execution and subsequently tracking the memory cells affected by the program's operations, we have chosen alternative methods to approximate the dynamic memory usage of each algorithm, as described below. In the ESP32 device, we found that the initially allocated memory for handling heap and stack allocation is 327,680 bytes. Armed with this information, we monitored the minimum heap size available using the system call _esp_get_minimum_free_heap_size_. The program was executed for 1000 iterations, calling the encryption function for each implementation. This allowed us to capture a snapshot of the free memory available between the stack and heap 1000 times. By calculating the difference between the total allocated dynamic memory and the minimum heap size recorded, we could approximate the memory footprint of each implementation. Additionally, we utilized the baseline implementation, which lacks an encryption/decryption algorithm, as a benchmark to estimate the dynamic memory usage overhead introduced by the ASCON and AES-GCM algorithms (refer to Figure 9(b)). This comparison with the baseline offered valuable insights into the dynamic memory usage of each algorithm during runtime. Figure 10: Dynamic memory usage comparison of our scheme implementation and algorithms. ### Power Consumption Measurement

Power consumption holds paramount importance, especially for resource-constrained Internet of Things (IoT) devices, as it directly impacts their battery life. Several techniques are available for measuring the power consumption of IoT devices, such as USB power meters and oscilloscopes. USB power meters offer a cost-effective and user-friendly option; however, they may lack accuracy by not considering the power consumption of individual device components. On the other hand, while oscilloscopes offer high precision, they might lack the granularity needed to measure very low-power states accurately.