Encryption Klepsydra

Encryption

Why is Klepsydra SDK interesting for algorithm encryption? 

Klepsydra SDK is beneficial in two different scenarios.  

  • Large volumes of data to be processed, for example, for high resolution images, Lidar data or IMU data. When sensors produce data at a very high rate and a large volume, Klepsydra can be used to process them in a more efficient way in real time. 
  • Processor intensive algorithms, like convolutions in artificial intelligence, kalman filters, matrix multiplication etc. This is the case of encryption algorithms. 

 In this article, a benchmark application using the Rijndael Algorithm is presented to demonstrate the power of Klepsydra SDK for encryption. 

Why this implementation and what are the benefits? 

  • With the separation in event loops, there is control over the CPU and, therefore, the number of cores dedicated to the encryption can be configured.  
  • The consumption of the CPU decreases, because pipelines tend to reduce significantly the CPU consumption. 
  • The throughput increases as well since the parallelization in a pipeline optimises the use of the available cores. 

How is encryption optimised?

Klepsydra SDK has a tool, the streaming API, that enables acceleration of processor intensive algorithms. There are the two main approaches that can be used to optimise algorithms: pipelining and parallelization. Both methods are explained below. 

Pipelining

First, the event loop pipelining: the parallelization is done in a pipeline, that looks like an assembly line, where the encryption algorithm is divided in smaller parts and each of them is executed in a different event loop. 

 In the case of Rijndael Algorithm, this is quite a straightforward because Rijndael encrypts block by block. First, the first block of 16 bytes, then the next block etc. A very straightforward implementation with Klepsydra, is where the first 16-byte block is processed by the 1st event loop, the second 16-byte block by the second event loop and so on. 

Encryption

Why this implementation and what are the benefits? 

  • With the separation in event loops, there is control over the CPU and, therefore, the number of cores dedicated to the encryption can be configured.  
  • The consumption of the CPU decreases, because pipelines tend to reduce significantly the CPU consumption. 
  • The throughput increases as well since the parallelization in a pipeline optimises the use of the available cores. 

Parallelization

There is, however, another approach to optimization, which is using Klepsydra data multiplexer parallelization. 

 The SDK has two APIs: the event-loop, above presented, and the data multiplexer, which consists of processing the same piece of data in parallel by multiple consumers.  

 In this approach, the streaming passes the full string to the data multiplexer and each consumer will process one block, so the first consumer processes the first 16-byte block, the second consumer the second 16-byte block and so on. 

 At the end there is a requirement to put it all together, a final synchronization, that is done also by the event-loop automatically. 

parallelization

What are the benefits of this approach? 

  • Speed, because of the parallelization in 16-byte blocks, the latency for the encryption is very low. 
  • Although the CPU consumption is higher than with the previous example, the throughput is also high. 

Which approach to use?

It depends on the requirement of the user:  if what the user needs is power, then the event-loop pipelining can be used and if what the user is looking for low latency, then the data multiplexer parallelization is a better option. 

The benchmark application

The encryption performance benchmark consists of:  

  • Use of the Rijndael Algorithm.
  • Google benchmarks to measure the performance. 
  • This application consists of randomly generated strings that will be encrypted with variations on: 
  • Size of the string 
  • Publication rate of the strings 

 The Rijndael Algorithm is quite simple: a plain text is divided in 16-byte blocks, and each block is encrypted separately. 

The benchmark results

Klepsydra uses the CPU in a more linear way as the data to process increases. Morevoer, this optimised algorithm can encrypt up to four times more data in real time with respect to more traditional techniques.

The implementation of the algorithm does not change, and it is quite simple to adapt to Klepsydra Streaming. The main change required is that the API of the Rijndael encryption goes from synchronous to asynchronous. 

SDK Encryption
sdk code

Conclusion

Implementing encryption with Klepsydra has a lot of benefits: 

  • High efficiency and navigation of the algorithm. Latency and CPU consumption can be lower, whereas throughput can be higher. 
  • Full control of the CPU resources dedicated to encryption. Launching an encryption and using all the resources of the computer maxing it out is not necessary anymore. 
  • With Klepsydra API, the migration or the integration of existing algorithm requires minor effort, thus can be achieved in relatively short time.