<<

Bulgarian Chemical , Volume 52, Issue A (pp. 220-224) 2020 DOI: 10.34049/bcc.52.A.218

Implementation of cryptographic via multithreading N. Sinyagina1, V. Todorov2, G. Kalpachka1* 1South-West University “Neofit Rilski”, 66 Ivan Mihailov Str., 2700 Blagoevgrad, Bulgaria 2Sofia University “St. Kliment Ohridski”, 15 Tsar Osvoboditel Blvd., 1504 Sofia, Bulgaria Received August 11, 2019; Accepted November 08, 2019 Speed of the encryption and decryption processes is one of the main factors when it comes to implementation of cryptographic algorithms. The use of multithreading can significantly decrease the time required for these processes. The article describes a research on multithreaded execution of the RSA and proposes a conceptual model for implementation, outlining the main points of its . The choice of resources, methods and tools for the application deployment has been made as well as an assessment of the used and . Keywords: Multithreading, Cryptographic Algorithms, Asymmetrical Encryption Algorithm RSA. INTRODUCTION Data encryption is a typical example for an algorithm, usually executed as a serial program. In today’s age the cyber-attacks Serial programs are directly dependent on the become more and more frequent and dangerous. frequency of the used CPU core. Such algorithms The (the biggest unsecured global system do not benefit from multiple cores or threads. for data transmission) carries large amounts of data The aim of this article is to research and analyze that should not be accessible by anyone. the pros and cons of RSA implementation on a is a necessary element for most of multithread architecture. The main focus will lay on the current online applications. evaluating the speed when running the same task on Despite high level of security, the methods for a different number of threads. encryption and decryption of data are expected to also have minimum execution delay. Unfortunately, MAIN STATES OF THE MULTITHREAD security and speed are inversely proportional – ARCHITECTURE AND THE RSA faster algorithms have more vulnerabilities, while CRYPTOGRAPHIC ALGORITHM the secure ones need more computational resources. Multithread architecture – hardware allowing The main goal when selecting a cryptographic using multiple CPU cores or threads in parallel. algorithm is finding the optimal balance between Multithread (or parallel) programming is the execution time and security. method of coding, utilizing hardware running with Fortunately, the are rapidly multiple cores and/or threads [2]. improving. The components are always Cryptographic algorithm – method for data being upgraded for faster handling of data and conversion using standardized encrypting and computational tasks. The cryptographic algorithms decrypting operations, aiming to protect the data also need to improve along with the . from unauthorized access. The RSA algorithm is an In the recent years the parallel programming has example for a cryptographic algorithm and more been established as the best approach for getting specifically an asymmetrical one. higher speed in . Most of the current st In the middle of the first decade of the 21 CPUs use architecture with more than one century the multithreaded architecture started to operational thread [1]. The operating systems are rapidly appear in personal . also adapted to multicore technology. The main strength of the multithread on a multicore hardware architecture is the multitasking. It allows the system requires additional effort. Existing serial algorithms processes and the user applications to be physically need to be adapted to parallel solutions. The separated. The different tasks can be run actually in breaking down of a process to its main components parallel. Additionally, different jobs can be and running them simultaneously is the main assigned with different priorities. A lot of the principle of modern programming. Unfortunately, multithread hardware also provides a separation of not all algorithms are adapted and optimized for the the cache memory between the different cores. multithread architecture. * To whom all correspondence should be sent. E-mail: [email protected]  2020 Bulgarian Academy of Sciences, Union of Chemists in Bulgaria 220 N. Sinyagina et al.: Implementation of cryptographic algorithms via multithreading With the increasing popularity of the mobile on the hardware as on the software optimizations technologies the problem with power consumption [5]. raises its priority. The multithread architecture has Published in 1977, the RSA algorithm remains better energy utilization. If a given core is not used, one of the most widely spread and secure it can be set to idle until it is needed again, which algorithms for data transfers over unsecured drastically reduces its power consumption. channels. On top of that, modern technology has almost The basic implementation of the RSA reached the physical limits of single core clock algorithms does not require complex software speed. The only way to get more computational design but executing it with a high security level power is to use additional processing units. requires significant computation power. Its The pros of a multithread architecture are many relatively slow run speed is the main reason why it and are undoubtedly more than enough to is not more widely spread [6]. overwhelm the single thread systems but the cons The main plus of the RSA algorithm is the fact should also be considered [3]. that it is asymmetric. By definition it does not Using multiple threads definitely expands the require exchange of private information between possibilities for software development but also the parties at any point during the data transfer. raises some complications. New issues appear that This is important because any sharing of private were previously not present on serial programs. information has a risk of directly violating the One of them is the access to shared memory. In security. On top of that, if the public key is big serial programming memory conflicts (a process enough in length, the cypher becomes virtually modifying another process’ memory during its impossible to crack. execution) are rare. In parallel programming it is METHOD OF IMPLEMENTING RSA ON common for two or more processes to share and MULTITHREAD ARCHITECTURE modify the same memory. If the threads are not properly synchronized problems can occur. To Proposal for speeding up the RSA process via avoid them, mutual exclusions and multicore architecture need to be implemented to ensure proper system The RSA algorithm is implemented in 4 steps operation. However, their requires [7]: more complex software solutions, as well as 1. Key generation – the recipient of the additional resources for their implementation [4]. encrypted messages should generate a pair of keys: The order of executing tasks on the different public and private. The public key can be freely threads is also a big problem in multithread distributed while the private key should not be architectures. Often the processes depend on one shared. The public key is used for encryption while another, which requires timeouts and checks for the the private key is used for decryption. completion and integrity of the results of a given 2. Sharing of public keys – after generating job. the key pair, the public key should be delivered to The separation of the processes and the tracking the of the encrypted messages. The sharing of their execution require additional system can occur over unsecured channels because the resources. The use of two cores instead of one does public key by itself does not present any security not mean double performance. The complexity of risks. the job synchronization increases with the number 3. Encryption of the message – anyone having of threads used. There even are cases where the public key can generate encrypted messages dividing a process into multiple ones actually slows using the RSA procedure [8]. down its execution. When developing a 4. Decryption of the message – the encrypted multithreaded software there always are resource message can be decrypted only with the private losses because of the needed for the key, which should only be available for the and management of the sub tasks. recipient. The multithread architectures fit the modern requirements for development of processor Method for multithreaded implementation of the technologies but on the other hand they put more RSA algorithm weight on the software developers. Additionally, to 1. Creating a number of threads – a number (n) optimize any existing serial algorithms, they need of threads is created at the begging of the task. The to be adapted for the new hardware architectures. number n is predefined and corresponds to the The task execution time does not depend as much number of threads to be used. They cannot exceed the number of threads the operating system can 221 N. Sinyagina et al.: Implementation of cryptographic algorithms via multithreading access. All threads should be able to work in based on measuring the executing speed of the parallel with each other. encryption and decryption processes using different 2. Splitting the data for encryption or hardware resources with the same input parameters. decryption into chunks – the input for encryption It is responsible for running and managing all tests should be split in relatively even blocks, the with the requested input parameters. number of which should be the same as the number  RSA process management block – connects of threads. Verifications need to be implemented to the actual RSA algorithm implementation with the make sure all data are collected and false data are test functionalities. The main task of the block is not accidentally added. splitting the data, creation of encryption and 3. Passing the split data blocks for processing – decryption threads, managing, collecting and at the beginning of the execution of every thread arranging the output data from the threads. the position of the processed data needs to be  Results block (time measurement and result marked. This makes it possible to put the data back calculation) – measures the time needed for all in order when merging the output of all threads. tasks, calculation of average result scores 4. Running and managing the threads – all (minimizing errors), output of the final test results. threads are independent from each other. There The final result analysis is made based on the should not be any resource conflicts between them. output of this module. A process is created to check the state of the  Blocks for RSA encryption and decryption separate threads during their execution: not started, – executing of the base RSA encryption and running or finished. This process should be highly decryption functions. optimized and need minimum amount of computing The connections between the blocks are marked resources. on the algorithm flowchart (Fig. 1). 5. Data collection – the parallel executing of the The algorithm starts with setting up the input different tasks does not ensure that the processes parameters. They are used for initial setting of the will finish in the same order they were started. The test environment and do not change during the test data from all treads need to be collected and execution. The input variables are also used for pre- assembled in the same order they were split. After a calculation of other values that will remain constant thread finishes its task, its output is being saved in during all tests. These include: generation of a key its corresponding place according to the input pair with a given length and generation of a random order. Once all threads are done and all data are character string (used for encryption), again with a assembled, the process has successfully finished. predefined length. The key pair, the data for CONCEPTUAL MODEL encryption (the message) and the input parameters create the test environment. After creating it, the The main aim in the current article is a actual test can begin. presentation of the created application for After the Starting block has finished its task it evaluating the speed during encryption and calls the Test block, passing all test environment decryption, using the asymmetrical RSA algorithm variables to it. Based on those parameters the Test on a multicore platform. Such task requires block prepares the tests for execution. For each test implementation of multiple different sub blocks, the block calls the RSA process management block working successively. once to encrypt and once to decrypt the data. Apart The sub blocks are divided as follows: from starting the tasks, the Test block also aims to  Starting block (input data set up) – this minimize the measurement error of the procedure. block sets up the input parameters, which is To accomplish that it replays each test multiple important for fast and easy modification of the times allowing a possibility to even out any errors initial parameters for the different tests. The caused by outside factors. After all tests are done, comparison analysis requires a large number of the Results block is called to give the final test various tests with different input variables. The results. input parameters consist of: size of the encryption The most complicated part of the application is data, number of threads used, size of the encryption the RSA process management block. It prepares the key, number of consecutive tests to run with these input data and passes them in parallel to the settings. This module lays the base for the working threads. The flow of the block can be execution of the actual encryption and decryption summarized in four steps: splitting of the input data procedures. in relatively equal chunks depending on the number  Test block (management of the testing of used threads; creation of the threads; starting and functions)–the comparison analysis of the test is managing of the threads; collection and 222 N. Sinyagina et al.: Implementation of cryptographic algorithms via multithreading arrangement of the output data of each thread. decryption functions. These steps are similar for both encryption and

Fig. 1. Algorithm flowchart. Additionally, the RSA process management threads for data encryption and decryption leads to block also has to communicate with the Results significant speed improvement of the algorithm. block. The time needed for each step has to be The time for encryption and decryption is measured and saved. Since the steps are created reduced almost twice when executing the task on inside the RSA modules, time measuring functions two threads instead of just one. At eight threads, the from the test blocks need to be implemented in the speed is more than three times faster than at one. RSA modules. The blocks for encryption and Even though the needed time does not decrease decryption contain the main computing linearly with the number of threads used, the results functionalities of the RSA processes. The show quite an improvement. possibility to use multiple processes for encoding The only downside of the implementation is the and decoding at the same time is a requirement for lack of improvement when working with small in the current implementation. The parallel processes size messages. In that case the resources lost for should not have any conflicts between them. The thread management actually slow down the actual encryption and decryption modules do not call out execution of the task. other blocks after their completion. Instead, they Even with the proposed speed improvements, just notify their management block when their task the RSA algorithm still remains on the slow end of is completed. cryptographic algorithms, especially compared to The last part of the test application is the Results the symmetrical ones. The reached level of block. It gathers the time information during the optimization might not make it a preferred choice execution of the program and outputs its final over its rivals but it will definitely make it a better version at the end of all tests. All results need to be option for the cases where a high level of security is recorded, averaged and presented in an easy to read required. form. REFERENCES The output information consists of: a number of threads for completing the task, time for 1. J. Stokes, Introduction to Multithreading, encryption/decryption and preparation of the test Superthreading and Hyperthreading, 2002, environment. The end results can be used for https://arstechnica.com/features/2002/10/hyperthrea ding/. additional calculations and studies. 2. D. Marr, F. Binns, D Hill, G. Hinton, D. Koufaty, J. CONCLUSIONS Miller, M. Upton, Intel Technology Journal, 6(1), 4 (2002). The implementation of the asymmetric 3. S. Casey, How to Determine the Effectiveness of cryptographic RSA algorithm on multithread Hyper-Threading Technology with an Application, architecture proves that using multiple parallel 2011, https://software.intel.com/en-us/articles/how- 223 N. Sinyagina et al.: Implementation of cryptographic algorithms via multithreading to-determine-the-effectiveness-of-hyper-threading- 7. J. Jonsson, B. Kaliski, Public-Key Cryptography technology-with-an-application. Standards (PKCS) #1: RSA Cryptography 4. J. Hruska, Maximized Performance: Comparing the Specifications Version 2.1, 2003, Effects of Hyper-Threading, Software Updates, https://www.ietf.org/rfc/rfc3447.txt. 2012. 8. B. Aleksandrov, Hybrid Cryptographic Methods 5. Hyper-Threading Technology – Operating Systems And Tools For Information Protection in the That Include Optimizations for Hyper-Threading Computer Networks and Systems, in: Technology, Intel, 2011. UNITECH’2012 (Proc. Int. Sci. Conf.), Technical 6. H. Fadhil, M. Younis, International Journal of University of Gabrovo, part I, p. 382, 2012. Computer Applications, 87(6), 15 (2014).

224