# Enhancing Resilience in Digital Twins: ASCON-Based Security Solutions for Industry 4.0
## 3 Proposed Solution
### Payload Encryption Algorithms
We implemented the main IoT device application in C++, and chose ASCON ([[https://github.com/ascon/ascon-c/tree/29](https://github.com/ascon/ascon-c/tree/29) ef7a20a7372 bd47e7f4c92861e58e49 cdce94/crypto_aead/ascon128 av12/esp32]([https://github.com/ascon/ascon-c/tree/29](https://github.com/ascon/ascon-c/tree/29) ef7a20a7372 bd47e7f4c92861e58e49 cdce94/crypto_aead/ascon128 av12/esp32) (accessed on 24 May 2023))) and AES-GCM ([[https://github.com/usnistgov/Lightweight-Crypto-graphy-Benchmarking/tree/main/implementations/reference_/crypto_aead/aes-gc](https://github.com/usnistgov/Lightweight-Crypto-graphy-Benchmarking/tree/main/implementations/reference_/crypto_aead/aes-gc)]([https://github.com/usnistgov/Lightweight-Crypto-graphy-Benchmarking/tree/main/implementations/reference_/crypto_aead/aes-gc](https://github.com/usnistgov/Lightweight-Crypto-graphy-Benchmarking/tree/main/implementations/reference_/crypto_aead/aes-gc)) m/mbedts (accessed on 24 May 2023)) algorithms implemented in C. We then integrated these AEAD algorithms into our C++ main application using the \"extern\" macro. In the Ditto, only ASCON implementation in Java ([[https://github.com/ascon/javaason/tree/cc](https://github.com/ascon/javaason/tree/cc)]([https://github.com/ascon/javaason/tree/cc](https://github.com/ascon/javaason/tree/cc)) d7622190791 fba05 dc61a9f7b5d286a0a9 cb8/src/iaik (accessed on 24 May 2023)) was used to verify that the connection and encryption/decryption between Ditto and ESP32 works as intended. Since our focus was on measuring performance on the resource-constrained devices, it was not necessary to implement both encryption/decryption algorithms on the Ditto side. Ditto's connectivity module is extendable with Java modules, so we chose the Java implementation of ASCON for decrypting the payloads of the IoT device messages. Importantly, we used the ESP32 device-optimized reference implementation of ASCON. We did not alter the algorithms' implementations or introduce any further optimizations. However, to enhance security, we incorporated a nonce generation function, vital for countering security attacks like replay attacks involving the repeated use of encrypted information on the hardware IoT device was carried out using C and C++ programming languages within Arduino for the ESP-IDF embedded development framework. We opted for C and C++ because those two choices are more suitable for low-level programming, such as embedded resource constraint devices. The main application for the IoT device was developed in C++, while the algorithm for ASCON and AES-GCM was implemented in C and incorporated through the use of the \"extern\" macro in the C++ main application. The counterpart of the algorithms in the Digital Twin were implemented in Java. This is because the connectivity microservice of Ditto is implemented in Java. This allowed us to extend the connectivity module using Java to incorporate an extension for encryption and decryption of the payload that comes from IoT devices. We did not introduce optimizations in the design of these algorithms. Still, for ASCON we selected the optimized reference C implementation ([[https://github.com/ascon/ascon-c/tree/29](https://github.com/ascon/ascon-c/tree/29) ef7a20a7372 bd47 fe7f4c9]([https://github.com/ascon/ascon-c/tree/29](https://github.com/ascon/ascon-c/tree/29) ef7a20a7372 bd47 fe7f4c9) 2861e58e49 cdce94/crypto_aead/ascon128 av12/esp32 (accessed on 24 May 2023)). We also implemented a nonce generation function to provide nonces as inputs for ASCON, which is crucial in addressing security attacks, such as replay attacks, which involve the repeated use of encrypted information.