<!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 Study of Implementations of CRCs Algorithms</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Sergey V. Klimenko, Valentin V. Yakovlev</string-name>
          <email>s.klimenko@live.ru, jakovlev@pgups.ru</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Boris V. Sokolov</string-name>
          <email>sokolov_boris@inbox.ru</email>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Department of Information Systems and</institution>
          ,
          <addr-line>Technologies, Emperor Alexander I St.</addr-line>
          ,
          <institution>Petersburg State Transport University</institution>
          ,
          <addr-line>Saint Petersburg</addr-line>
          ,
          <country country="RU">Russia</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Laboratory of Information Technologies in, System Analysis and Modeling, St. Petersburg Institute for Informatics and, Automation of the RAS</institution>
          ,
          <addr-line>Saint Petersburg</addr-line>
          ,
          <country country="RU">Russia</country>
        </aff>
      </contrib-group>
      <fpage>27</fpage>
      <lpage>32</lpage>
      <abstract>
        <p>Objective: To give comparative assessment of the basic ways of generating a checksum (CRC code) based on direct, table and matrix algorithms. Methods: Algorithms were compared by means of mathematical methods. In order to achieve the result Java Development Kit software version 1.8 and NetBeans IDE 8.2 development environment were used. Results: The methods of generating checksums by means of algorithms were described in detail. For each method under consideration, the time characteristics of their work were given. The comparison of the analyzed methods was conducted. Practical importance: Based on the results of the experiment, it was concluded which method was optimal for the generation of checksums. Copyright © by the papers' authors. Copying permitted for private and academic purposes. In: S. V. Klimenko, V. V. Yakovlev (eds.): Selected Papers of the Workshop Computer Science and Engineering in the framework of the 5th International Scientific-Methodical</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1 Introduction</title>
      <p>Error detection methods are intended to detect
distortions in messages when they are transmitted
through noisy channels. For this, the transmitter
calculates a number, called a checksum, which is a
function of the message, and adds it to this message.
Receiver, using the same algorithm, calculates the
checksum of the received message and compares it
with the transmitted value [1].1</p>
      <p>CRC (Cyclic Redundancy Check) checksum is a
value calculated from a data set using mathematical
algorithms that provide hash-collision resistance [2].
Hash-collision is a checksum equality for various
input blocks of data. Checksums are widely used to
control the correctness of stored and transmitted
information.</p>
      <p>The CRC was invented by W. Wesley Peterson
in 1961; the 32-bit CRC function, used in Ethernet
and many other standards, is the work of several
researchers and was published in 1975.</p>
      <p>The logical prerequisite for using this type of
checksum is that the size of the checksum is much
smaller than the format of the converted numbers /
messages, therefore, the probability of distorting the
checksum (when transmitting information through
any channel or when it is stored on a data storage
device) is significantly lower than the probability of
distorting an array of information.</p>
      <p>CRCs are so called because the check (data
verification) value is a redundancy (it expands the
message without adding information) and the
algorithm is based on cyclic codes. CRCs are
popular because they are simple to implement in
binary hardware, easy to analyze mathematically,
and particularly good at detecting common errors
caused by noise in transmission channels. Because
the check value has a fixed length, the function that
generates it is occasionally used as a hash function.</p>
      <p>The basic idea of the CRC algorithm is to present
the message as a huge binary number, divide it by
another fixed binary number, and use the rest of this
division as a checksum. Having received the
message, the recipient can perform a similar action
and compare the balance received with the
“checksum”.</p>
      <p>The simplest error-detection system, the parity
bit, is in fact a 1-bit CRC: it uses the generator
polynomial x + 1 (two terms), and has the name
CRC-1.</p>
      <p>Cyclic redundant codes (CRC) are a subclass of
block codes and are used in HDLC, Token Ring,
Token
Bus protocols, Ethernet protocol families and in
other protocols of a link level. The popularity of
CRC codes is due to the fact that the procedures
encoding and decoding are fairly simple and do not
require large computational resources.</p>
      <p>Conference "Problems of Mathematical and
Natural-Scientific Training in Engineering
Education", St.-Petersburg, Russia, 8–9
November, 2018, published at
http://ceurws.org</p>
      <p>The CRC algorithm is based on the properties of
division with the remainder of binary polynomials,
thus, the CRC value is the remainder from dividing
the polynomial corresponding to the input data by
some fixed generating polynomial [1].</p>
      <p>The most important task of constructing CRC codes
is the choice of the generating polynomial. There are
many standardized and recommended by various
organizations generating polynomials used to
generate CRC. For example, CRC32 generating
polynomial of IEEE 802.3 standard looks like this:
"# + #% + #" + ## + &amp;% + &amp;# + &amp;&amp; + &amp;' +
( + ) + * + + + # +  + 1 =
004117(in hexadecimal form) =
100110000010001110110110111</p>
      <p>(in binary form).</p>
      <p>One of the main conditions for choosing a
polynomial is that the coefficients in the high and
low bits were equal to one.</p>
      <p>The mathematical model of finding the checksum
is presented below:</p>
      <p>() = () · J mod (), (1)
where R(x) – polynomial which represents the value
of CRC; P(x) – polynomial, in which coefficients
represent input blocks of data; G(x) – generating
polynomial; N – degree o generating polynomial (1≤
N ≤ 256).</p>
      <p>Thus, the CRC calculation is possible to implement
on the basis of any programming language by using
XOR (Exclusive or) and SHL ("shift to the left")
logical operations, because they are included into
any programming language [3, 4].</p>
      <p>An example of the execution of the algorithm
for calculating the CRC remainder is shown in Fig.
1, where the polynomial 10011 is selected as the
generator.</p>
      <p>
        The probability that the distortion of a
transmitted message in several positions will be such
that the final checksum does not change is
determined by the formula [
        <xref ref-type="bibr" rid="ref4 ref8">5–8</xref>
        ]:
 = #&amp;L (2)
      </p>
      <p>CRCs are specifically designed to protect
against common types of errors on communication
channels, where they can provide quick and
reasonable assurance of the integrity of messages
delivered. However, they are not suitable for
protecting against intentional alteration of data.</p>
      <p>Firstly, as there is no authentication, an attacker
can edit a message and recompute the CRC without
the substitution being detected. When stored
alongside the data, CRCs and cryptographic hash
functions by themselves do not protect against
intentional modification of data. Any application
that requires protection against such attacks must use
cryptographic authentication mechanisms, such as
message authentication codes or digital signatures
(which are commonly based on cryptographic hash
functions).</p>
      <p>Secondly, unlike cryptographic hash functions,
CRC is an easily reversible function, which makes it
unsuitable for use in digital signatures.</p>
      <p>Thirdly, CRC is a linear function with a property
that:</p>
      <p>(⨁⨁) = ()⨁()⨁() (3)</p>
    </sec>
    <sec id="sec-2">
      <title>2 Brief description of CRC counting algorithms</title>
      <p>The direct CRC calculation algorithm determines
the control CRC bit by bit [9], it is described as
follows in accordance with (1):
1) add zeros to the original message for alignment
(the number of zeros is determined by the degree of
the generating polynomial)()´ = ()000 … ;
2) do SHL operation of the bit sequence of the
message P (x) ´ until the bit in the cell becomes equal
to one or the number of bits becomes less than in the
divider;
3) if high bit becomes equal to one, then perform an
XOR operation between the message and the
generating polynomial and repeat step 2;
4) the final residue of the sequence P (x)´ is a
CRCresidue.</p>
      <p>In the above description, G (x) is a polynomial,
N is the degree of the polynomial, P (x) is the
original message, and P (x) ´ is the augmented
original message.</p>
      <p>The need to perform multiple iterations when
generating the CRC checksum results in significant
time costs.</p>
      <p>The tabular CRC calculation algorithm is used to
accelerate the calculation of the CRC checksum.</p>
      <p>Acceleration is accomplished by replacing eight
shift operations with a single search operation in the
table, which contains 256 values. Therefore, when
calculating the CRC checksum, a cycle is performed
on 256 values.</p>
      <p>The prerequisite for the appearance of the table
was the fact that when performing a XOR operation
with a constant value at different shifts, there will
always be some value, which, when applying an
XOR operation with the original content, will give
the same result. Therefore, it is possible to build a
table of such values, where index is the original
content [1].</p>
      <p>Table building algorithm:
1) calculate the value in the table for each byte from
0x00 to 0xff:
a) perform the “right shift” operation 8 times, and if
the low bit is equal to one, then the XOR operation
is performed with the polynomial G;
b) all that remains of two bytes becomes the value in
the table.</p>
      <p>Calculating algorithm the CRC checksum using
the table:
1) each byte of the P (x) message is viewed:
a) an XOR operation is performed on the low byte of
the current CRC value and the current byte of the
message — this is the index in the table;
b) the high byte of the current CRC value shifts to
the right by 8 and becomes low, then merged by
XOR with the value of the table - this will be the new
CRC value;
2) the result is the CRC value.</p>
      <p>The matrix CRC calculation algorithm is used to
calculate the checksum and is similar to the tabular
one, except for that instead of a table, the vector
multiplication operation (extended byte) by the
matrix is used.</p>
      <p>
        The main advantage of the matrix algorithm over
the tabular is the size of the memory required to store
the table. So, for the implementation of the tabular
algorithm, 1 Kb (256 elements of 4 bytes each) of the
memory is required to store the table, while for the
matrix algorithm, only 32 bytes are required (8
elements of 4 bytes each) [
        <xref ref-type="bibr" rid="ref10 ref3">10</xref>
        ].
      </p>
    </sec>
    <sec id="sec-3">
      <title>3 Evaluation of temporal effectiveness</title>
      <p>In order to compare the considered methods of
generating CRC by performance under the same
conditions, an application was written in the
highlevel language Java, which allows to get statistics for
each of the methods with the generating polynomial
0xEDB88320 for CRC32 and 0xd800000000000000
for CRC64. Statistics show the dependence of their
execution time on the size of the source line
(message).</p>
      <p>The Java Development Kit version 1.8 and the
NetBeans IDE 8.2 development environment are
used to write the application. The experiment was
conducted using the following hardware and
software resources:
1) Windows 10 operating system (64-bit);
2) dual-core processor Intel Core i7-7600U with a
clock frequency of 2.8 GHz;
3) 16 GB of RAM;
4) SSD with 512 Gb capacity.</p>
      <p>The application generates strings (messages) in a
randomly specified size based on the characters:
“A”–“Z”, “a”–“z”, “0”–“9”, and punctuation marks,
after that a checksum is constructed for the obtained
string using the methods described earlier. For
example, a randomly generated string consisting of
12 characters, looks like this:</p>
      <p>ℎ 3 + 71.</p>
      <p>To determine the running time of the algorithms,
the nanoTime () static method of the System class of
the java.lang package was used, which returns the
current time value.</p>
      <p>Thus, it is possible to calculate the running time of
the entire application or its separate fragment (it is
shown at the Figure 2). In considered case, were used
the possibility of this method and the measurement
of the operating time of a separate fragment
(method) of the application, determined by the type
of algorithm.</p>
      <p>The analysis was performed for randomly
generated rows of the following sizes (h, in MB):
1, 2, 4, 8, 16, 32, 64 and 128.</p>
      <p>To calculate the arithmetic average of the
checksum calculation time, the following formula
was used:</p>
      <p>̅ = _&amp; · ∑a_b &amp; a, (4)
a is the time for calculating the i checksum, P – total
number.</p>
      <p>Standard deviation was calculated as follows:
&amp;
 = d _ · ∑a_b &amp;(a − ̅),
where t is the average value.
(5)
Set the number of repetitions N</p>
      <p>N = 0 ?
NO</p>
      <p>YES
Generate a random string of size n
Start time = System.nanoTime()</p>
      <p>Calculate the string checksum
Total Time = System.nanoTime ()</p>
      <p>Start Time
Reduce the number of N repetitions by</p>
      <p>one
int poly = 0xEDB88320
byte[] bytes = str.toString().getBytes()
int inx = 0</p>
      <p>inx &lt; bytes.length
false
true
crc = crc ^ 0xffffffff
crc = (crc &gt;&gt;&gt;8) ^ temp
inx ++</p>
      <p>byte b = bytes[inx]
int temp = (crc^b) &amp; 0xff
int i = 0</p>
      <p>i &lt; 8
false</p>
      <p>true
temp = (temp &gt;&gt;&gt; 1)</p>
      <p>i++
The results of calculations by formulas (4) - (5) are
shown in the table 1 (CRC32) and table 2(CRC64).</p>
      <p>0</p>
      <sec id="sec-3-1">
        <title>String size, Mb</title>
      </sec>
      <sec id="sec-3-2">
        <title>String size, Mb</title>
        <p>lower than #&amp;fg versus #hi</p>
        <p>As can be seen from the results given in Tables
1-2, the time spent on the calculation of the
checksum CRC32 and CRC64 by the direct
algorithm is almost the same. But, the calculation of
CRC32 in tabular way gives a gain of 2 two times
compared with CRC64.</p>
        <p>In turn, it is worth noting that in CRC64 the
probability of not detecting an error is significantly
&amp; .</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>5 Conclusion</title>
      <p>The article describes the direct, tabular and
matrix algorithms for calculating the checksum
CRC32 and CRC64(tabular and direct). A
comparison of the operating time is made (Fig. 3,
Fig. 4).
As a result, it was established that the tabular
algorithm is optimal in terms of the calculation speed
of the checksum CRC32. Acceleration in it
compared to the direct algorithm was achieved by
replacing eight shift operations with a single search
operation in the table, which contains 256 values. It
is also important that the use of the matrix algorithm
can be conditioned to significant memory savings
compared to the table algorithm.</p>
    </sec>
    <sec id="sec-5">
      <title>Acknowledgments</title>
      <p>Research carried out on this topic was carried
out with partial financial support from RFBR grants
(No. 17-29-07073-ofi-m, 18-07-01272, 19–08–
00989), under the budget theme 0004.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [Ros93]
          <string-name>
            <given-names>N. W.</given-names>
            <surname>Ross</surname>
          </string-name>
          <article-title>A Painless guide to CRC error detection algorithms</article-title>
          .
          <source>Australia</source>
          ,
          <year>1993</year>
          . URL:http://www.ross.net/crc/download/crc _v3.
          <source>txt (accessed: 01.04</source>
          .
          <year>2018</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [Myt11]
          <string-name>
            <given-names>E. A.</given-names>
            <surname>Mytsko</surname>
          </string-name>
          ,
          <string-name>
            <surname>A. N.</surname>
          </string-name>
          <article-title>Malchukov Osobennosti programmnoy realizatsii vychisleniya kontrolnoy summy CRC32 na primere PKZIP, WINZIP, ETHERNET [The specifi cities of software implementation of CRC32 checksum calculation by the example of PKZIP, WINZIP</article-title>
          , ETHERNET].
          <source>Vestnik nauki Sibiri [The Siberian Science newsletter]</source>
          ,
          <year>2011</year>
          , no.
          <issue>1</issue>
          (
          <issue>1</issue>
          ), pp.
          <fpage>279</fpage>
          -
          <lpage>282</lpage>
          . (In Russian)
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [Mal10]
          <string-name>
            <given-names>A. N.</given-names>
            <surname>Malchukov</surname>
          </string-name>
          ,
          <string-name>
            <surname>A. N.</surname>
          </string-name>
          <article-title>Osokin Bystrodeistvuyushchiye algoritmy vychisleniya kontrolnoy summy na primere CRC8 [Fast algorithms for calculating the checksum using the example CRC8]. Molodezh I sovremennyye informatsionnyye tekhnologii: Sbornik trudov VIII Vseros. nauchno-prakt. konf. studentov, aspirantov i molodykh uchenykh [The youth and modern information technologies: Proceedings of the 8th AllRussian research and training conference of students, postgraduates and young scientists]</article-title>
          .
          <source>Tomsk, March</source>
          <volume>3</volume>
          -5th,
          <year>2010</year>
          . Tomsk, SPB Grafi ks,
          <year>2010</year>
          , pp.
          <fpage>34</fpage>
          -
          <lpage>35</lpage>
          . (In Russian)
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [Bur06]
          <string-name>
            <surname>Yu</surname>
            .
            <given-names>B.</given-names>
          </string-name>
          <string-name>
            <surname>Burkatovskaya</surname>
            ,
            <given-names>A. N.</given-names>
          </string-name>
          <string-name>
            <surname>Malchukov</surname>
            ,
            <given-names>A. N</given-names>
          </string-name>
          <string-name>
            <surname>Osokin</surname>
          </string-name>
          .
          <article-title>Bystrodeystvuyushchiye algoritmy deleniya polinomov v arifmetike po modulyu dva [Fast-acting algorithms for dividing polynomials in arithmetics modulo two]</article-title>
          .
          <source>Izvestiya Tomskogo politekhnicheskogo universiteta [Proceedings of Tomsk</source>
          Polytechnic University],
          <year>2006</year>
          , no.
          <volume>1</volume>
          (
          <issue>309</issue>
          ), pp.
          <fpage>19</fpage>
          -
          <lpage>24</lpage>
          . (In Russian)
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [Koo02]
          <string-name>
            <given-names>P.</given-names>
            <surname>Koopman</surname>
          </string-name>
          32-
          <article-title>Bit Cyclic Redundancy Codes for Internet Applications</article-title>
          .
          <source>Intern. Conf. on Dependable Systems and Networks (DSN)</source>
          (Washington,
          <year>July 2002</year>
          ). Washington, DC,
          <year>2002</year>
          , pp.
          <fpage>459</fpage>
          -
          <lpage>468</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [Jak15]
          <string-name>
            <given-names>V. V.</given-names>
            <surname>Jakovlev</surname>
          </string-name>
          ,
          <string-name>
            <surname>F. I.</surname>
          </string-name>
          <article-title>Kushnazarov Otsenka vlijanija pomekh na proizvoditelnost protokolov kanalnogo urovnya [Estimating the impact of interference on the performance of link layer protocols]</article-title>
          .
          <source>Izvestija Peterburgskogo universiteta putej soobshchenija [Proceedings of Petersburg State</source>
          Transport University],
          <year>2015</year>
          , issue
          <volume>1</volume>
          (
          <issue>42</issue>
          ), pp.
          <fpage>133</fpage>
          -
          <lpage>138</lpage>
          . (In Russian)
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [Hal96]
          <string-name>
            <given-names>F.</given-names>
            <surname>Halsall</surname>
          </string-name>
          <article-title>Data communications, computer networks and open systems</article-title>
          . AddisonWesley, Pearson Education Press.,
          <year>1996</year>
          ,
          <volume>907</volume>
          р.
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [Oli08]
          <string-name>
            <given-names>V. G.</given-names>
            <surname>Olifer</surname>
          </string-name>
          ,
          <string-name>
            <given-names>N. A.</given-names>
            <surname>Olifer</surname>
          </string-name>
          <article-title>Kompjuterniye sety</article-title>
          . Printsipy, tekhnologii, protokoly [Computer networks. Principles, technologies, protocols].
          <source>Saint Petersburg</source>
          , Peter Publ.,
          <year>2008</year>
          , 958 p. (
          <source>In Russian)</source>
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [Tem79]
          <string-name>
            <given-names>F. E.</given-names>
            <surname>Temnikov</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V. A.</given-names>
            <surname>Afonin</surname>
          </string-name>
          ,
          <string-name>
            <surname>V. I.</surname>
          </string-name>
          <article-title>Dmitriev Teoreticheskie osnovy informatsionnoy tekhniky: uchebnoye posobiye [Theoretical basis of information technology: study guide]</article-title>
          . Moscow, Energia Publ,
          <year>1979</year>
          , 512 p. (
          <source>In Russian)</source>
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [Mal10]
          <string-name>
            <given-names>A. N.</given-names>
            <surname>Malchukov</surname>
          </string-name>
          ,
          <string-name>
            <surname>A. N.</surname>
          </string-name>
          <article-title>Osokin Bystroje vychislenije kontrolnoy summy CRC: tablitsa protiv matritsy [Fast calculation of CRC checksum: table versus matrix]</article-title>
          .
          <source>Prikladnaja informatika [Applied Informatics]</source>
          ,
          <year>2010</year>
          , no.
          <volume>2</volume>
          (
          <issue>26</issue>
          ), pp.
          <fpage>58</fpage>
          -
          <lpage>63</lpage>
          . (In Russian)
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>