<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>The implementation of "Kuznyechik" encryption algorithm using NVIDIA CUDA technology</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>A N Borisov</string-name>
          <email>borisovalexey1996@gmail.com</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>E V Myasnikov</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Samara National Research University</institution>
          ,
          <addr-line>Moskovskoe Shosse 34А, Samara, Russia, 443086</addr-line>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2019</year>
      </pub-date>
      <fpage>308</fpage>
      <lpage>313</lpage>
      <abstract>
        <p>In this paper, we discuss various options for implementing the "Kuznyechik" block encryption algorithm using the NVIDIA CUDA technology. We use lookup tables as a basis for the implementation. In experiments, we study the in uence of the size of the block of threads and the location of lookup tables on the encryption speed. We show that the best results are obtained when the lookup tables are stored in the global memory. The peak encryption speed reaches 30.83 Gbps on the NVIDIA GeForce GTX 1070 graphics processor .</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <p>Cryptographic protection is an important part of a modern IT infrastructure. Nowadays, both
the volume of information and computing power are continually increasing. Accordingly, there
are growing demands on both the robustness and speed of cryptographic algorithms.</p>
      <p>
        The idea of using graphics processors to speed up encryption algorithms appeared almost
simultaneously with the idea of using them for general-purpose computing[
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]. As known, the
maximum pro t from the use of graphics processors can be achieved only with massive parallel
tasks. It is not surprising that the most noticeable results in this eld were obtained for block
encryption in the ECB (electronic code book) and CTR (gamming) modes, since the blocks of
plain text are processed independently in this case.
      </p>
      <p>
        At present, there is a lot of papers, which focuses on using graphics processors for encryption.
Most of the papers are devoted to the AES encryption algorithm. In particular, in the paper [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ],
authors study the dependence of the encryption speed on the location of round keys. Experiments
are carried out on NVIDIA GeForce GTX 780, NVIDIA GeForce GTX 1080 and NVIDIA
GeForce Titan X graphics cards. In the paper [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], authors study popular block ciphers, namely,
AES-128, CAST-128, Camelia, SEED, IDEA, Blow sh, and Three sh, using NVIDIA GeForce
GTX 980. Inboth papers, the reported encryption speed exceeds 200 Gbit/s (25 GB/s).
      </p>
      <p>
        The "Kuznyechik" cipher is a new symmetric encryption standard, which was introduced
in Russia in 2015 [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]. By design, "Kuznyechik" is an SP-network with ten rounds of
transformations, the size of a block equals to 128 bits, and the size of a key is 256 bits.
      </p>
      <p>
        Because of a novelty and the limited use of chipher, fewer papers focus on the 'Kuznyechik"
algorithm, most of them focuses on cryptoanalysis [
        <xref ref-type="bibr" rid="ref5 ref6 ref7">5,6,7</xref>
        ] rather than
implementation of cipher.The paper [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ] describes the optimization of the algorithm based on
lookup tables.
effective
      </p>
      <p>
        The reported speed is 54 Mbps on a four-core CPU. The paper [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ] is a direct continuation of the
paper [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ], which is devoted to the cryptanalysis of the ”Magma” and ”Kuznyechik” algorithms using
CUDA to speed up a slide attack. The paper [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ] describes the implementation of Kuznyechik cipher for
FPGA using OpenCL, the reported troughput reaches 41 Gbit/s. In this paper, we study several possible
implementations of the ”Kuznyechik” cipher using the NVIDIA CUDA technology. The paper has the
following structure. In Section 2, we givebritehfeoretical foundations of the algorithm. In Section 3,
we brie y discuss some features of the NVIDIA CUDA technology, which are necessary to
understand this paper. Section 4 describes possible implementations of the cipher using the above
technology. In Section 4, we provide the results of experiments. The paper ends up with the
conclusion and reference list.
      </p>
    </sec>
    <sec id="sec-2">
      <title>2. The description of the algorithm</title>
      <p>
        As it was outlined earlier, the "Kuznyechik" algorithm is a ten-round cipher based on an SP
network with the key length of 256 bits and the block length of 128 bits. An exhaustive
description of the algorithm can be found in [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ].
      </p>
      <sec id="sec-2-1">
        <title>2.1. Key expansion algorithm</title>
        <p>Before the encryption, ten 128-bit round keys K1; :::; K10 are generated based on the main
256-bit key K. The expansion procedure is a Feistel network. Its transformation function is
analogous to the round of the main cipher with a xed key. The rst two round keys K1; K2
are obtained from the halves of the main one. The rest of the keys are obtained by encrypting
with the Feistel network. The keys (K2i; K2i 1) are given to each round of the network as an
input, and the output is (K2i+2; K2i+1).</p>
        <p>The expansion procedure is strictly sequential. Besides, it can be executed only once to
obtain the array of round keys. Thus, we do not consider this procedure in the paper.</p>
      </sec>
      <sec id="sec-2-2">
        <title>2.2. Basic transformations</title>
        <p>The cipher is based on two transformations:
(i) Nonlinear transformation
(ii) Nonlinear transformation</p>
        <p>: GF (28) ! GF (28) implemented through the lookup table.
`(a15; :::; a0) = 148 a15 + 32 a14 + 133 a13 + 16 a12 + 194 a11 + 192 a10 + 1 a9 +
+251 a8 + 1 a7 + 192 a6 + 194 a5 + 16 a4 + 133 a3 + 32 a2 + 148 a1 + 1 a0; (1)
where ai 2 GF (28), and operations take place in the eld GF (28). In particular, "+" is equivalent
to the XOR operation).</p>
        <p>The transformations that are used directly in the encryption are based on two previous
transformations:</p>
        <p>S(a) =
R(a) =</p>
        <p>L(a) =
X[k](a) =</p>
        <p>S(a15jj:::jja0) = (a15)jj:::jj (a0);
R(a15jj:::jja0) = `(a15; :::; a0)jja15jj:::jja1;
R16(a);
k</p>
        <p>a;
where jj is the concatenation,
ai 2 GF (28),
k; a 2 GF (2128),</p>
        <p>R16(a) means that the R function is applied for a for 16 times.</p>
        <p>Using the above notations, the "Kuznyechik" algorithm can be described as follows:</p>
        <p>EK1;:::;K10 (a) = X[K10]LSX[K9]:::LSX[K2]LSX[K1](a);
where LSX[K](a) is equivalent to L(S(X[K](a))).
(2)
(3)
(4)
(5)
(6)</p>
      </sec>
      <sec id="sec-2-3">
        <title>2.3. Lookup tables</title>
        <p>It is easy to see that
`(a15; :::; a0) = `(a15; 0; :::; 0)
`(0; a14; 0; :::; 0)
:::</p>
        <p>`(0; 0; 0; :::; a0);
`(a15
b15; :::; a0
b0) = `(a15; :::; a0)
`(b15; :::; b0):
(7)
(8)</p>
        <p>Based on this, the LS part of the round can be predicted in advance, with the result that
we get 16 lookup tables. Each of the lookup tables contains 256 entries of size 128 bit. When
using lookup tables, the entire encryption process comes down to 16 lookups across tables and
16 128-bit XOR operations (15 on the search results and 1 with a round key).</p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>3. CUDA</title>
      <p>
        CUDA is a proprietary API provided by NVIDIA that facilitates the use of video cards for
general purpose computing. This programming model is required since the graphics processor
can process hundreds of threads simultaneously according to the so-called SIMT model. A
detailed description of CUDA technology can be found in [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ]. We provide only the necessary
information below.
      </p>
      <p>The kernel is a function intended for the execution on the GPU. The unit of execution is a
thread. Threads are combined into blocks, and blocks are combined into a grid. The grid and
block con guration is speci ed when the kernel function is started. Resources for execution are
allocated per block, and not on every single thread.</p>
      <p>From a hardware point of view, the graphics processor is divided into multiprocessors, and
multiprocessors are divided into warps. The warps, in turn, consist of 32 stream processors
(terminal computing units). All stream processors inside one warp are synchronized. They
either execute the same instruction or idle.</p>
      <p>The memory organization on graphics processors has a number of features. A programmer
has access to a global, shared, constant, and texture memory. The global memory is equivalent
to RAM. The texture memory and constant memory are the areas of global memory with special
access features. The shared memory has low volume (64KB), but very high speed.</p>
      <p>Physically, it is divided into several independent areas, called banks (banks). An attempt
to simultaneously access di erent memory cells within one bank will lead to the subsequent
execution of requests. This situation is called a bank con ict. A large number of access con icts
reduce performance signi cantly.</p>
    </sec>
    <sec id="sec-4">
      <title>4. The implementation of "Kuznyechik" encryption algorithm using CUDA</title>
      <p>We use lookup tables as a base for the implementation of the algorithm. At rst, we execute
an initialization procedure, which copies the tables to the device. Before encryption, we
allocate bu ers on the device. We use the allocated bu ers to copy round keys and data to
be transformed. We copy data back and release the bu ers after the encryption. Encryption
keys are best to store in the shared memory. The memory consumption is small, and the access
pattern allows to avoid access con icts (all threads of a warp always read the same key).</p>
      <p>The issue of locating the lookup tables does not have such a straightforward solution. The
size of the LS tables does not allow them to be entirely located in the shared memory since
for the Pascal generation it is allowed to allocate only 48 KB per thread block. In addition,
random access to the tables will result in numerous access con icts, which signi cantly reduce
performance. From this it follows that there are only three options for storing the tables, namely,
the global, constant and texture memory. To provide an additional acceleration, we read the
global memory using the ldg() function.</p>
      <p>In addition, we should also nd out the optimal launch con guration of the kernel function.
It does not make sense to use more than one thread per block of text. Although one XOR
operation for 128-bit values is translated into two 64-bit operations, the use of two threads to
process one block of text will lead to undesirable consequences. First, an increase in the number
of threads will lead to an overall decrease in simultaneously processed blocks of text, since the
number of stream processors is limited. Second, since each thread needs to store its copies of
local variables, the number of occupied registers will increase. This also becomes a limiting
factor and reduces the amount of simultaneously processed blocks of text. However, it makes
sense to study how the size of the block of threads a ects the encryption speed.</p>
      <p>In this paper, we consider the following sizes of a block: 32, 64, 128,192, 256, 384, 512,
768, and 1024 threads. There is no sense to consider less than 32 threads in a block since the
minimum unit of execution on a graphics processor is a warp consisting of 32 stream processors.</p>
    </sec>
    <sec id="sec-5">
      <title>5. Experimental results</title>
      <p>We used the following con guration in our experiments:
CPU: Intel Core i5-6400
GPU: NVIDIA GeForce GTX 1070
RAM: 8 Gb DDR3</p>
      <p>In general speed tests, the number of threads in a block was 512. The volume of encrypted data
was equal to 256 MB in tests with changing block con guration. The CPU version of the
"Kuznyechik" algorithm executed in 4 threads using SSE instructions. We did not take into
account the time spent on copying data to the memory of the GPU and back.</p>
      <p>The results of performance measurements are presented in Tables 1 and 2 and Figures 1 and
2 shows the results of the experiments.
Let us consider the results in more detail.</p>
      <p>The CUDA SDK includes a pro ler, which allows getting information on the kernel execution
time, resources used by the kernel, multiprocessor loading, cache e ciency, and many other
parameters. The pro ler data is used for a more detailed analysis of the results.</p>
      <p>The fastest option is the global memory. The correct access pattern allows us to achieve more
than 90% hits fro L2 cache and about 20% hits for L1. However, even in this case, working with
memory is still an essential factor limiting performance.</p>
      <p>The texture memory is slower due to the greater number of registers used and the greater
memory load. When reading a single value, its neighbors are also loaded into the cache, so the
memory subsystem has to serve the greater number of readings. So cost of each cache miss is
high. In addition, in the Maxwell and Pascal architectures, the texture cache shared the memory
with L1 cache and therefore does not give any gain compared to it.</p>
      <p>For constant memory, the problem is a random access pattern, which causes frequent cache
misses. Another problem is the read data size - 16 bytes per request. As a result, the performance
degrades.</p>
      <p>Let us turn to the size of the thread blocks.</p>
      <p>No more than a certain number of threads, warps, and blocks can be executed on a
multiprocessor simultaneously. In addition, there are limiting factors, namely, the total number of
registers and shared memory. With small blocks, the overhead caused by the context switching is huge.
At the beginning of execution, time is spent for each block to copy round keys to the shared memory.
For large blocks, a multiprocessor simultaneously executes fewer blocks due to the presence of limiting
factors. Besides, the location of the block cannot be taken by another one until the block is completed.
In our case, the difference between thread block sizes for global memory is insignificant, since the main
limiting factor is the global memory latency. Constant memory case reaches maximum troughput with
32 threads per thread block, whereas texture memory case have its maximum at 32 threads per threads
block.</p>
    </sec>
    <sec id="sec-6">
      <title>6. Conclusion</title>
      <p>In this paper, we considered various options for implementing the \Kuznyechik" encryption
algorithm using CUDA technology. We used lookup tables as a basis for the implementation.
We discussed the global, constant, and texture memory as an option for the location of the
lookup tables. Besides, we considered the following sizes of thread blocks: 32, 64, 128, 192, 256,
384, 512. According to the experiments, the best results were obtained when search tables are
stored in the global memory. The peak speed of the encryption was equal to 30.83 Gbps on the
equipment used.
Acknowledgments
The work was funded by the Russian Federation Ministry of Science and Higher Education within a
state contract with the "Crystallography and Photonics" Research Center of the RAS under agreement
007-GZ/Ch3363/26.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <surname>Cook</surname>
            <given-names>D L</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ioannidis</surname>
            <given-names>J</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Keromytis</surname>
            <given-names>A D</given-names>
          </string-name>
          and
          <string-name>
            <surname>Luck J 2005 CryptoGraphics</surname>
          </string-name>
          <article-title>: secret key cryptography using graphicscards CT-</article-title>
          <source>RSA Lecture Notes in Computer Science</source>
          <volume>3376</volume>
          <fpage>334</fpage>
          -
          <lpage>350</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <surname>Abdelrahman</surname>
            <given-names>A</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Fouad Mand Dashan H 2017</surname>
          </string-name>
          <article-title>Analysis on theAES Implementation with Various Granularities on Different GPU Architectures Advances in Electrical and Electronic Engineering 1053</article-title>
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <surname>Lee</surname>
            <given-names>W K</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Cheong H S</surname>
            , Phan
            <given-names>R</given-names>
          </string-name>
          and
          <string-name>
            <surname>Goi B M 2016Fast</surname>
          </string-name>
          <article-title>implementation ofblock ciphers and PRNGs in Maxwell GPU architecture Cluster Comput</article-title>
          .
          <volume>19</volume>
          (
          <issue>01</issue>
          )
          <fpage>335</fpage>
          -
          <lpage>347</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <surname>GOST</surname>
            <given-names>R</given-names>
          </string-name>
          <year>34</year>
          .12
          <article-title>-2015 Information technology</article-title>
          .
          <article-title>Cryptographic data security</article-title>
          .
          <source>Block ciphers (Moskow: Standartinform)</source>
          p
          <fpage>21</fpage>
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <surname>Biryukov</surname>
            <given-names>A</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Perrin</surname>
            <given-names>L</given-names>
          </string-name>
          and
          <article-title>Udovenko A 2016 Reverse-engineering the S-Box of Streebog</article-title>
          ,
          <source>Kuznyechik and STRIBOBr1 Advances in Cryptology Lecture Notes in Computer Science</source>
          <volume>3376</volume>
          <fpage>372</fpage>
          -
          <lpage>402</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <surname>Ishchukova</surname>
            <given-names>E</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Babenko</surname>
            <given-names>L</given-names>
          </string-name>
          and
          <string-name>
            <surname>Koshucky</surname>
            <given-names>R 2015</given-names>
          </string-name>
          <article-title>Implementation of high speed data encryption using "</article-title>
          <source>Kuznyechik" cipher Auditorium</source>
          <volume>04</volume>
          (
          <issue>8</issue>
          )
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <surname>Ishchukova</surname>
            <given-names>E</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Babenko</surname>
            <given-names>L</given-names>
          </string-name>
          and
          <string-name>
            <surname>Anikeev M 2016 Fast Implementation</surname>
          </string-name>
          and
          <source>Cryptanalysis of GOST R 34</source>
          .
          <fpage>12</fpage>
          -2015
          <source>Block Ciphers Proc. 9th Int. Conf. on Security of Information and Networks</source>
          (New York: ACM)
          <fpage>104</fpage>
          -
          <lpage>111</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <surname>Korobeynikov</surname>
            <given-names>A 2019</given-names>
          </string-name>
          <article-title>E˙ective Implementation of "Kuznyechik" block ciphoenr FPGA with OpenCL Platform Proc</article-title>
          .
          <source>of IEEE Conf. of Russia Young Researchers in Electrical Elaenctdronic Engineering</source>
          <volume>1683</volume>
          -1686
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <surname>Sanders</surname>
            <given-names>J</given-names>
          </string-name>
          and
          <string-name>
            <surname>Kandrot E 2010 CUDA by Example</surname>
          </string-name>
          (New York: Addison-Wesley) p
          <fpage>313</fpage>
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>