<?xml version="1.0" encoding="US-ASCII"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd">
<?rfc strict="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="no"?>
<?rfc toc="yes"?>
<?rfc tocdepth="4"?>
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes"?>
<rfc ipr="trust200902" category="info" submissionType="IETF" docName="draft-ribose-cfrg-sm4-03">
<front>
  <title abbrev="SM4 Blockcipher Algorithm">The SM4 Blockcipher Algorithm And Its Modes Of Operations</title>
  <author fullname="Ronald Henry Tse" surname="Tse" initials="R. H.">
    <organization>Ribose</organization>
    <address>
      <postal>
        <street>Suite 1111, 1 Pedder Street</street>
        <city>Central</city>
        <region>Hong Kong</region>
        <country>People's Republic of China</country>
      </postal>
      <email>ronald.tse@ribose.com</email>
      <uri>https://www.ribose.com</uri>
    </address>
  </author>
  <author fullname="Wai Kit Wong" surname="Wong" initials="W. K.">
    <organization>Hang Seng Management College</organization>
    <address>
      <postal>
        <street>Hang Shin Link, Siu Lek Yuen</street>
        <city>Shatin</city>
        <region>Hong Kong</region>
        <country>People's Republic of China</country>
      </postal>
      <email>wongwk@hsmc.edu.hk</email>
      <uri>https://www.hsmc.edu.hk</uri>
    </address>
  </author>
  <date day="20" month="November" year="2017"/>
  <area>cfrg</area>
  <workgroup>Crypto Forum Research Group</workgroup>

<abstract><t>This document describes the SM4 symmetric blockcipher algorithm
published as GB/T 32907-2016 by the Organization of State Commercial
Administration of China (OSCCA).</t>
<t>This document is a product of the Crypto Forum Research Group (CFRG).</t></abstract>
</front><middle>
<section anchor="_introduction" title="Introduction"><t>SM4 <xref target="GBT.32907-2016"/> <xref target="ISO.IEC.18033-3.AMD2"/> is a cryptographic standard
issued by the Organization of State Commercial Administration of China <xref target="OSCCA"/>
as an authorized cryptographic algorithm for the use within China.
The algorithm is published in public.</t>
<t>SM4 is a symmetric encryption algorithm, specifically a blockcipher,
designed for data encryption.</t>
<section anchor="_purpose" title="Purpose"><t>This document does not aim to introduce a new algorithm, but to
provide a clear and open description of the SM4 algorithm in English,
and also to serve as a stable reference for IETF documents that utilize
this algorithm.</t>
<t>While this document is similar to <xref target="SM4-En"/> in nature, <xref target="SM4-En"/> is a textual
translation of the "SMS4" algorithm <xref target="SM4"/> published in 2006, while this
document follows the updated description and structure of <xref target="GBT.32907-2016"/>
published in 2016. Sections 1 to 7 of this document directly map to the
corresponding sections numbers of the <xref target="GBT.32907-2016"/> standard for
convenience of the reader.</t>
<t>This document also provides additional information on the design
considerations of the algorithm <xref target="SM4-Details"/>, practical usage and
implementation of SM4 specifying modes of operations that are known
to be used with SM4 (see <xref target="sm4-modes"/>), and providing the
SM4 OIDs (see <xref target="sm4-oids"/>).</t></section>
<section anchor="_history" title="History"><t>The "SMS4" algorithm (the former name of SM4) was invented by
Shu-Wang Lu <xref target="LSW-Bio"/>, first published in 2003 as part of
<xref target="GB.15629.11-2003"/>, then published independently in 2006 <xref target="SM4"/> by the OSCCA,
officially renamed to "SM4" in 2012 in <xref target="GMT-0002-2012"/> published by the OSCCA,
and finally standardized in 2016 as a Chinese National Standard (GB Standard)
<xref target="GBT.32907-2016"/>. SM4 is also standardized in <xref target="ISO.IEC.18033-3.AMD2"/>
by the International Organization for Standardization in 2017.</t>
<t>SMS4 was originally created for use in protecting wireless networks <xref target="SM4"/>,
and is mandated in the Chinese National Standard for Wireless LAN WAPI (Wired
Authentication and Privacy Infrastructure) <xref target="GB.15629.11-2003"/>. A proposal
was made to adopt SMS4 into the IEEE 802.11i standard, but the algorithm
was eventually not included due to concerns of introducing inoperability
with existing ciphers.</t>
<t>The latest SM4 standard <xref target="GBT.32907-2016"/> was proposed by the OSCCA,
standardized through TC 260 of the Standardization Administration of the
People&#8217;s Republic of China (SAC), and was drafted by the following
individuals at the Data Assurance and Communication Security Research
Center (DAS Center) of the Chinese Academy of Sciences, the China
Commercial Cryptography Testing Center and the Beijing Academy of
Information Science &amp; Technology (BAIST):</t>
<t>
  <list style="symbols">
    <t>Shu-Wang Lu</t>
    <t>Dai-Wai Li</t>
    <t>Kai-Yong Deng</t>
    <t>Chao Zhang</t>
    <t>Peng Luo</t>
    <t>Zhong Zhang</t>
    <t>Fang Dong</t>
    <t>Ying-Ying Mao</t>
    <t>Zhen-Hua Liu</t>
  </list>
</t></section></section>
<section anchor="_terms_and_definitions" title="Terms and Definitions"><t>The key words "<spanx style="strong">MUST</spanx>", "<spanx style="strong">MUST NOT</spanx>", "<spanx style="strong">REQUIRED</spanx>", "<spanx style="strong">SHALL</spanx>",
"<spanx style="strong">SHALL NOT</spanx>", "<spanx style="strong">SHOULD</spanx>", "<spanx style="strong">SHOULD NOT</spanx>", "<spanx style="strong">RECOMMENDED</spanx>",
"<spanx style="strong">MAY</spanx>", and "<spanx style="strong">OPTIONAL</spanx>" in this document are to be interpreted
as described in <xref target="RFC2119"/>.</t>
<t>The following terms and definitions apply to this document.</t>
<t>
  <list style="hanging">
    <t hangText="block length"><vspace blankLines="1"/>Bit-length of a message block.</t>
    <t hangText="key length"><vspace blankLines="1"/>Bit-length of a key.</t>
    <t hangText="key expansion algorithm"><vspace blankLines="1"/>An operation that converts a key into a round key.</t>
    <t hangText="rounds"><vspace blankLines="1"/>The number of iterations that the round function is run.</t>
    <t hangText="round key"><vspace blankLines="1"/>A key used in each round on the blockcipher, derived from the input key, also called a subkey.</t>
    <t hangText="word"><vspace blankLines="1"/>a 32-bit quantity</t>
    <t hangText="S-box"><vspace blankLines="1"/>The S (substitution) box function produces 8-bit output from 8-bit input, represented as S(.)</t>
  </list>
</t></section>
<section anchor="_symbols_and_abbreviations" title="Symbols And Abbreviations">
  <t>
  <list style="hanging">
    <t hangText="S xor T"><vspace blankLines="1"/>bitwise exclusive-or of two 32-bit vectors S and T.
S and T will always have the same length.</t>
    <t hangText="a &lt;&lt;&lt; i"><vspace blankLines="1"/>32-bit bitwise cyclic shift on a with i bits shifted left.</t>
  </list>
</t>
</section>
<section anchor="_compute_structure" title="Compute Structure"><t>The SM4 algorithm is a blockcipher, with block size of 128 bits and a key
length of 128 bits.</t>
<t>Both encryption and key expansion use 32 rounds of a nonlinear key schedule
per block. Each round processes one of the four 32-bit words that constitute
the block.</t>
<t>The structure of encryption and decryption are identical, except that the round key
schedule has its order reversed during decryption.</t>
<t>Using a 8-bit S-box, it only uses exclusive-or, cyclic bit shifts and S-box
lookups to execute.</t></section>
<section anchor="_key_and_key_parameters" title="Key And Key Parameters"><t>Encryption key is 128 bits long, and represented below, where each
MK_i, (i = 0, 1, 2, 3) is 32 bits long.</t>
<t>
MK = (MK_0, MK_1, MK_2, MK_3)
</t>
<t>The round key schedule is derived from the encryption key, represented as below
where each rk_i (i = 0, ..., 31) is 32 bits long:</t>
<t>
(rk_0, rk_1, ... , rk_31)
</t>
<t>The family key used for key expansion is represented as FK, where
each FK_i (i = 0, ..., 3) is 32 bits long:</t>
<t>
FK = (FK_0, FK_1, FK_2, FK_3)
</t>
<t>The constant key used for key expansion is represented as CK, where
each CK_i (i = 0, ..., 31) is 32 bits long:</t>
<t>
CK = (CK_0, CK_1, ... , CK_31)
</t></section>
<section anchor="_functions" title="Functions"><section anchor="_round_function_f" title="Round Function F"><t>The round function F is defined as:</t>
<t>
F(X_0, X_1, X_2, X_3, rk) = X_0 xor T(X_1 xor X_2 xor X_3 xor rk)
</t>
<t>Where:</t>
<t>
  <list style="symbols">
    <t>Each $$X_i$ is 32-bit wide.</t>
    <t>The round key rk is 32-bit wide.</t>
  </list>
</t></section>
<section anchor="_permutation_t_and_t" title="Permutation T and T'"><t>T is a reversible permutation that outputs 32 bits from a 32-bit input.</t>
<t>It consists of a nonlinear transform tau and linear transform L.</t>
<t>
T(.) = L(tau(.))
</t>
<t>The permutation T' is created from T by replacing the
linear transform function L with L'.</t>
<t>
T'(.) = L'(tau(.))
</t>
<section anchor="_nonlinear_transformation_tau" title="Nonlinear Transformation tau"><t>tau is composed of four parallel S-boxes.</t>
<t>Given a 32-bit input A, where each a_i is a 8-bit string:</t>
<t>
A = (a_0, a_1, a_2, a_3)
</t>
<t>The output is a 32-bit B, where each b_i is a 8-bit string:</t>
<t>
B = (b_0, b_1, b_2, b_3)
</t>
<t>B is calculated as follows:</t>
<t>
(b_0, b_1, b_2, b_3) = tau(A)
</t>
<t>
tau(A) = (S(a_0), S(a_1), S(a_2), S(a_3))
</t></section>
<section anchor="_linear_transformation_l_and_l" title="Linear Transformation L and L'"><t>The output of nonlinear transformation function tau is used as input
to linear transformation function L.</t>
<t>Given B, a 32-bit input.</t>
<t>The linear transformation L' is defined as follows.</t>
<t>
L(B) = B xor (B &lt;&lt;&lt; 2) xor (B &lt;&lt;&lt; 10) xor (B &lt;&lt;&lt; 18) xor (B &lt;&lt;&lt; 24)
</t>
<t>The linear transformation L' is defined as follows.</t>
<t>
L'(B) = B xor (B &lt;&lt;&lt; 13) xor (B &lt;&lt;&lt; 23)
</t></section>
<section anchor="_s_box_s" title="S-box S"><t>The S-box S used in nonlinear transformation tau is given in
the lookup table shown in <xref target="diagram-sm4-sbox"/> with hexadecimal values.</t>
<figure anchor="diagram-sm4-sbox" align="center" title="SM4 S-box Values">
  <artwork align="center">   |  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
---|-------------------------------------------------
 0 | D6 90 E9 FE CC E1 3D B7 16 B6 14 C2 28 FB 2C 05
 1 | 2B 67 9A 76 2A BE 04 C3 AA 44 13 26 49 86 06 99
 2 | 9C 42 50 F4 91 EF 98 7A 33 54 0B 43 ED CF AC 62
 3 | E4 B3 1C A9 C9 08 E8 95 80 DF 94 FA 75 8F 3F A6
 4 | 47 07 A7 FC F3 73 17 BA 83 59 3C 19 E6 85 4F A8
 5 | 68 6B 81 B2 71 64 DA 8B F8 EB 0F 4B 70 56 9D 35
 6 | 1E 24 0E 5E 63 58 D1 A2 25 22 7C 3B 01 21 78 87
 7 | D4 00 46 57 9F D3 27 52 4C 36 02 E7 A0 C4 C8 9E
 8 | EA BF 8A D2 40 C7 38 B5 A3 F7 F2 CE F9 61 15 A1
 9 | E0 AE 5D A4 9B 34 1A 55 AD 93 32 30 F5 8C B1 E3
 A | 1D F6 E2 2E 82 66 CA 60 C0 29 23 AB 0D 53 4E 6F
 B | D5 DB 37 45 DE FD 8E 2F 03 FF 6A 72 6D 6C 5B 51
 C | 8D 1B AF 92 BB DD BC 7F 11 D9 5C 41 1F 10 5A D8
 D | 0A C1 31 88 A5 CD 7B BD 2D 74 D0 12 B8 E5 B4 B0
 E | 89 69 97 4A 0C 96 77 7E 65 B9 F1 09 C5 6E C6 84
 F | 18 F0 7D EC 3A DC 4D 20 79 EE 5F 3E D7 CB 39 48</artwork>
</figure>
<t>For example, input "EF" will produce an output read from the S-box table
row E and column F, giving the result S(EF) = 84.</t></section></section></section>
<section anchor="_algorithm" title="Algorithm"><section anchor="sm4-encryption" title="Encryption"><t>The encryption algorithm consists of 32 rounds and 1 reverse transform R.</t>
<t>Given a 128-bit plaintext input, where each X_i is 32-bit wide:</t>
<figure>
  <artwork>(X_0, X_1, X_2, X_3)</artwork>
</figure>
<t>The output is a 128-bit ciphertext, where each Y_i is 32-bit wide:</t>
<figure>
  <artwork>(Y_0, Y_1, Y_2, Y_3)</artwork>
</figure>
<t>Each round key is designated as rk_i, where each rk_i is 32-bit wide
and i = 0, 1, 2, ..., 31.</t>
<t>
  <list style="letters">
    <t>32 rounds of calculation<figure>
  <artwork>i = 0, 1, ..., 31

X_{i+4} = F(X_i, X_{i+1}, X_{i+2}, X_{i+3}, rk_i)</artwork>
</figure></t>
    <t>reverse transformation<figure>
  <artwork>(Y_0, Y_1, Y_2, Y_3) = R(X_32, X_33, X_34, X_35)

R(X_32, X_33, X_34, X_35) = (X_35, X_34, X_33, X_32)</artwork>
</figure></t>
  </list>
</t>
<t>Please refer to <xref target="appendix-a"/> for sample calculations.</t>
<t>A flow of the calculation is given in <xref target="diagram-sm4-flow"/>.</t>
<figure anchor="diagram-sm4-flow" title="SM4 Encryption Flow">
  <artwork align="center">
                   128-bits plaintext
              \___________________________/
                            |
                            v
               X_0     X_1     X_2     X_3
                |       |       |       |
                v       v       v       v
              +---------------------------+
  Round 1     |      Round Function       | &lt;--rk_0
              +---------------------------+
                |       |       |       |
               X_1     X_2     X_3     X_4
                |       |       |       |
                v       v       v       v
              +---------------------------+
  Round 2     |      Round Function       | &lt;--rk_1
              +---------------------------+
                |       |       |       |
               X_2     X_3     X_4     X_5
                |       |       |       |
                v       v       v       v
                           ...

               X_31    X_32    X_33    X_34
                |       |       |       |
                v       v       v       v
              +---------------------------+
  Round 32    |      Round Function       | &lt;--rk_31
              +---------------------------+
                |       |       |       |
               X_32    X_33    X_34    X_35
                |       |       |       |
                v       v       v       v
              +---------------------------+
              | Reverse Transformation R  |
              +---------------------------+
                |       |       |       |
               Y_0     Y_1     Y_2     Y_3

              \___________________________/
                            |
                            v
                   128-bits ciphertext
</artwork>
</figure></section>
<section anchor="sm4-decryption" title="Decryption"><t>Decryption takes an identical process as encryption, with the only difference
the order of the round key sequence.</t>
<t>During decryption, the round key sequence is:</t>
<figure>
  <artwork>(rk_31, rk_30, ..., rk_0)</artwork>
</figure></section>
<section anchor="_key_schedule" title="Key Schedule"><t>Round keys used during encryption are derived from the encryption key.</t>
<t>Specifically, given the encryption key MK, where each MK_i is 32-bit
wide:</t>
<figure>
  <artwork>MK = (MK_0, MK_1, MK_2, MK_3)</artwork>
</figure>
<t>Each round key rk_i is created as follows, where i = 0, 1, ..., 31.</t>
<figure>
  <artwork>(K_0, K_1, K_2, K_3) =
    (MK_0 xor FK_0, MK_1 xor FK_1, MK_2 xor FK_2, MK_3 xor FK_3)

rk_i = K_{i + 4}

K_{i + 4} =
    K_i xor T' (K_{i + 1} xor K_{i + 2} xor K_{i + 3} xor CK_i)</artwork>
</figure>
<t>Since the decryption key is identical to the encryption key, the round keys
used in the decryption process are derived from the decryption key through
the identical process to that of during encryption.</t>
<t><xref target="diagram-round-function"/> depicts the i-th round of SM4.</t>
<figure anchor="diagram-round-function" title="SM4 Round Function For the i-th Round">
  <artwork align="center">
  X_i                 rk_i  X_{i+1} X_{i+2} X_{i+3}
   |                   |      |       |       |
   |                   |      |       |       |
   |                   v      |       |       |
 +---+     +---+     +---+    |       |       |
 | X |     |   |     | X | &lt;--+       |       |
 | O | &lt;-- | T | &lt;-- | O | &lt;----------+       |
 | R |     |   |     | R | &lt;------------------+
 +---+     +---+     +---+    |       |       |
   |                         /       /       /
   |                        /       /       /
   |                       /       /       /
    \----------------------------------------=
                         /       /       /    \
                        /       /       /     |
     /-----------------/       /       /      |
    |                         |       |       |
 X_{i+1}                   X_{i+2} X_{i+3} X_{i+4}
</artwork>
</figure>
<section anchor="_family_key_fk" title="Family Key FK"><t>Family key FK given in hexadecimal notation, is:</t>
<figure>
  <artwork align="center">FK_0 = A3B1BAC6
FK_1 = 56AA3350
FK_2 = 677D9197
FK_3 = B27022DC</artwork>
</figure></section>
<section anchor="_constant_key_ck" title="Constant Key CK"><t>The method to retrieve values from the constant key CK is as follows.</t>
<t>Let ck_{i, j} be the j-th byte (i = 0, 1, ..., 31; j = 0, 1, 2, 3) of CK_i.</t>
<t>Therefore, each ck_{i, j} is a 8-bit string, and each CK_i a 32-bit word.</t>
<figure>
  <artwork>CK_i = (ck_{i, 0}, ck_{i, 1}, ck_{i, 2}, ck_{i, 3})</artwork>
</figure>
<figure>
  <artwork>ck_{i, j} = (4i + j) x 7 (mod 256)</artwork>
</figure>
<t>The values of the constant key CK_i, where (i = 0, 1, ..., 31), in
hexadecimal, are:</t>
<figure>
  <artwork align="center">CK_0  = 00070E15   CK_16 = C0C7CED5
CK_1  = 1C232A31   CK_17 = DCE3EAF1
CK_2  = 383F464D   CK_18 = F8FF060D
CK_3  = 545B6269   CK_19 = 141B2229
CK_4  = 70777E85   CK_20 = 30373E45
CK_5  = 8C939AA1   CK_21 = 4C535A61
CK_6  = A8AFB6BD   CK_22 = 686F767D
CK_7  = C4CBD2D9   CK_23 = 848B9299
CK_8  = E0E7EEF5   CK_24 = A0A7AEB5
CK_9  = FC030A11   CK_25 = BCC3CAD1
CK_10 = 181F262D   CK_26 = D8DFE6ED
CK_11 = 343B4249   CK_27 = F4FB0209
CK_12 = 50575E65   CK_28 = 10171E25
CK_13 = 6C737A81   CK_29 = 2C333A41
CK_14 = 888F969D   CK_30 = 484F565D
CK_15 = A4ABB2B9   CK_31 = 646B7279</artwork>
</figure></section></section></section>
<section anchor="sm4-modes" title="Modes of Operation"><t>This document defines multiple modes of operation for the SM4 blockcipher
algorithm.</t>
<t>The CBC (Cipher Block Chaining), ECB (Electronic CodeBook), CFB (Cipher
FeedBack), OFB (Output FeedBack) and CTR (Counter) modes are defined in
<xref target="NIST.SP.800-38A"/> and utilized with the SM4 algorithm in the following
sections.</t>
<section anchor="_variables_and_primitives" title="Variables And Primitives"><t>Hereinafter we define:</t>
<t>
  <list style="hanging">
    <t hangText="SM4Encrypt(P, K)"><vspace blankLines="1"/>The SM4 algorithm that encrypts plaintext P with key K, described in <xref target="sm4-encryption"/></t>
    <t hangText="SM4Decrypt(C, K)"><vspace blankLines="1"/>The SM4 algorithm that decrypts ciphertext C with key K, described in <xref target="sm4-decryption"/></t>
    <t hangText="b"><vspace blankLines="1"/>block size in bits, defined as 128 for SM4</t>
    <t hangText="P_j"><vspace blankLines="1"/>block j of ciphertext bitstring P</t>
    <t hangText="C_j"><vspace blankLines="1"/>block j of ciphertext bitstring C</t>
    <t hangText="NBlocks(B, b)"><vspace blankLines="1"/>Number of blocks of size b-bit in bitstring B</t>
    <t hangText="IV"><vspace blankLines="1"/>Initialization vector</t>
    <t hangText="LSB(b, S)"><vspace blankLines="1"/>Least significant b bits of the bitstring S</t>
    <t hangText="MSB(b, S)"><vspace blankLines="1"/>Most significant b bits of the bitstring S</t>
  </list>
</t></section>
<section anchor="_initialization_vectors" title="Initialization Vectors"><t>The CBC, CFB and OFB modes require an additional input to the encryption process,
called the initialization vector (IV). The identical IV is used in the input
of encryption as well as the decryption of the corresponding ciphertext.</t>
<t>Generation of IV values <spanx style="strong">MUST</spanx> take into account of the considerations
in <xref target="security-considerations"/> recommended by <xref target="BC-EVAL"/>.</t></section>
<section anchor="_sm4_ecb" title="SM4-ECB"><t>In SM4-ECB, the same key is utilized to create a
fixed assignment for a plaintext block with a ciphertext block, meaning
that a given plaintext block always gets encrypted to the same ciphertext
block. As described in <xref target="NIST.SP.800-38A"/>, this mode should be avoided if
this property is undesirable.</t>
<t>This mode requires input plaintext to be a multiple of the block size,
which in this case of SM4 it is 128-bit. It also allows multiple blocks
to be computed in parallel.</t>
<section anchor="_sm4_ecb_encryption" title="SM4-ECB Encryption"><t>Inputs:</t>
<t>
  <list style="symbols">
    <t>P, plaintext, length <spanx style="strong">MUST</spanx> be multiple of b</t>
    <t>K, SM4 128-bit encryption key</t>
  </list>
</t>
<t>Output:</t>
<t>
  <list style="symbols">
    <t>C, ciphertext, length is a multiple of b</t>
  </list>
</t>
<t>C is defined as follows.</t>
<figure>
  <artwork>_____________________________________________________________________

n = NBlocks(P, b)

for i = 1 to n
  C_i = SM4Encrypt(P_i, K)
end for

C = C_1 || ... || C_n
_____________________________________________________________________</artwork>
</figure></section>
<section anchor="_sm4_ecb_decryption" title="SM4-ECB Decryption"><t>Inputs:</t>
<t>
  <list style="symbols">
    <t>C, ciphertext, length <spanx style="strong">MUST</spanx> be multiple of b</t>
    <t>K, SM4 128-bit encryption key</t>
  </list>
</t>
<t>Output:</t>
<t>
  <list style="symbols">
    <t>P, plaintext, length is a multiple of b</t>
  </list>
</t>
<t>P is defined as follows.</t>
<figure>
  <artwork>_____________________________________________________________________

n = NBlocks(C, b)

for i = 1 to n
  P_i = SM4Decrypt(C_i, K)
end for

P = P_1 || ... || P_n
_____________________________________________________________________</artwork>
</figure></section></section>
<section anchor="_sm4_cbc" title="SM4-CBC"><t>SM4-CBC is similar to SM4-ECB that the input plaintext <spanx style="strong">MUST</spanx> be a multiple
of the block size, which is 128-bit in SM4. SM4-CBC requires
an additional input, the IV, that is unpredictable for a particular
execution of the encryption process.</t>
<t>Since CBC encryption relies on a forward cipher operation that depend on results
of the previous operation, it cannot be parallelized. However, for decryption,
since ciphertext blocks are already available, CBC parallel decryption is
possible.</t>
<section anchor="_sm4_cbc_encryption" title="SM4-CBC Encryption"><t>Inputs:</t>
<t>
  <list style="symbols">
    <t>P, plaintext, length <spanx style="strong">MUST</spanx> be multiple of b</t>
    <t>K, SM4 128-bit encryption key</t>
    <t>IV, 128-bit, unpredictable, initialization vector</t>
  </list>
</t>
<t>Output:</t>
<t>
  <list style="symbols">
    <t>C, ciphertext, length is a multiple of b</t>
  </list>
</t>
<t>C is defined as follows.</t>
<figure>
  <artwork>_____________________________________________________________________

n = NBlocks(P, b)

C_1 = SM4Encrypt(P_1 xor IV, K)

for i = 2 to n
  C_i = SM4Encrypt(P_i xor C_{i - 1}, K)
end for

C = C_1 || ... || C_n
_____________________________________________________________________</artwork>
</figure></section>
<section anchor="_sm4_cbc_decryption" title="SM4-CBC Decryption"><t>Inputs:</t>
<t>
  <list style="symbols">
    <t>C, ciphertext, length <spanx style="strong">MUST</spanx> be a multiple of b</t>
    <t>K, SM4 128-bit encryption key</t>
    <t>IV, 128-bit, unpredictable, initialization vector</t>
  </list>
</t>
<t>Output:</t>
<t>
  <list style="symbols">
    <t>P, plaintext, length is multiple of b</t>
  </list>
</t>
<t>P is defined as follows.</t>
<figure>
  <artwork>_____________________________________________________________________

n = NBlocks(C, b)

P_1 = SM4Decrypt(C_1, K) xor IV

for i = 2 to n
  P_i = SM4Decrypt(C_i, K) xor C_{i - 1}
end for

P = P_1 || ... || P_n
_____________________________________________________________________</artwork>
</figure></section></section>
<section anchor="_sm4_cfb" title="SM4-CFB"><t>SM4-CFB relies on feedback provided by successive ciphertext segments to
generate output blocks. The plaintext given must be a multiple of the block
size.</t>
<t>Similar to SM4-CBC, SM4-CFB requires an IV that is unpredictable for a particular
execution of the encryption process.</t>
<t>SM4-CFB further allows setting a positive integer parameter s, that is less than or
equal to the block size, to specify the size of each data segment. The same
segment size must be used in encryption and decryption.</t>
<t>In SM4-CFB, since the input block to each forward cipher function depends
on the output of the previous block (except the first that depends on the IV),
encryption is not parallelizable. Decryption, however, can be parallelized.</t>
<section anchor="_sm4_cfb_variants" title="SM4-CFB Variants"><t>SM4-CFB takes an integer s to determine segment size in its encryption and
decryption routines. We define the following variants of SM4-CFB for
various s:</t>
<t>
  <list style="symbols">
    <t>SM4-CFB-1, the 1-bit SM4-CFB mode, where s is set to 1.</t>
    <t>SM4-CFB-8, the 8-bit SM4-CFB mode, where s is set to 8.</t>
    <t>SM4-CFB-64, the 64-bit SM4-CFB mode, where s is set to 64.</t>
    <t>SM4-CFB-128, the 128-bit SM4-CFB mode, where s is set to 128.</t>
  </list>
</t></section>
<section anchor="_sm4_cfb_encryption" title="SM4-CFB Encryption"><t>Inputs:</t>
<t>
  <list style="symbols">
    <t>P#, plaintext, length <spanx style="strong">MUST</spanx> be multiple of s</t>
    <t>K, SM4 128-bit encryption key</t>
    <t>IV, 128-bit, unpredictable, initialization vector</t>
    <t>s, an integer 1 &lt;= s &lt;= b that defines segment size</t>
  </list>
</t>
<t>Output:</t>
<t>
  <list style="symbols">
    <t>C#, ciphertext, length is a multiple of s</t>
  </list>
</t>
<t>C# is defined as follows.</t>
<figure>
  <artwork>_____________________________________________________________________

n = NBlocks(P#, s)

I_1 = IV
for i = 2 to n
  I_i = LSB(b - s, I_{i - 1}) || C#_{j - 1}
end for

for i = 1 to n
  O_j = SM4Encrypt(I_i, K)
end for

for i = 1 to n
  C#_i = P#_1 xor MSB(s, O_j)
end for

C# = C#_1 || ... || C#_n
_____________________________________________________________________</artwork>
</figure></section>
<section anchor="_sm4_cfb_decryption" title="SM4-CFB Decryption"><t>Inputs:</t>
<t>
  <list style="symbols">
    <t>C#, ciphertext, length <spanx style="strong">MUST</spanx> be a multiple of s</t>
    <t>K, SM4 128-bit encryption key</t>
    <t>IV, 128-bit, unpredictable, initialization vector</t>
    <t>s, an integer 1 &#8656; s &#8656; b that defines segment size</t>
  </list>
</t>
<t>Output:</t>
<t>
  <list style="symbols">
    <t>P#, plaintext, length is multiple of s</t>
  </list>
</t>
<t>P# is defined as follows.</t>
<figure>
  <artwork>_____________________________________________________________________

n = NBlocks(P#, s)

I_1 = IV
for i = 2 to n
  I_i = LSB(b - s, I_{i - 1}) || C#_{j - 1}
end for

for i = 1 to n
  O_j = SM4Encrypt(I_i, K)
end for

for i = 1 to n
  P#_i = C#_1 xor MSB(s, O_j)
end for

P# = P#_1 || ... || P#_n
_____________________________________________________________________</artwork>
</figure></section></section>
<section anchor="_sm4_ofb" title="SM4-OFB"><t>SM4-OFB is the application of SM4 through the Output Feedback mode.
This mode requires that the IV is a nonce, meaning that the IV <spanx style="strong">MUST</spanx>
be unique for each execution for an input key. OFB does not require the
input plaintext to be a multiple of the block size.</t>
<t>In OFB, the routines for encryption and decryption are identical. As
each forward cipher function (except the first) depends on previous
results, both routines cannot be parallelized. However given a known IV, output
blocks could be generated prior to the input of plaintext (encryption)
or ciphertext (decryption).</t>
<section anchor="_sm4_ofb_encryption" title="SM4-OFB Encryption"><t>Inputs:</t>
<t>
  <list style="symbols">
    <t>P, plaintext, composed of (n - 1) blocks of size b, with the last block P_n of size 1 &#8656; u &#8656; b</t>
    <t>K, SM4 128-bit encryption key</t>
    <t>IV, a nonce (a unique value for each execution per given key)</t>
  </list>
</t>
<t>Output:</t>
<t>
  <list style="symbols">
    <t>C, ciphertext, composed of (n - 1) blocks of size b, with the last block C_n of size 1 &#8656; u &#8656; b</t>
  </list>
</t>
<t>C is defined as follows.</t>
<figure>
  <artwork>_____________________________________________________________________

n = NBlocks(P, b)

I_1 = IV
for i = 1 to (n - 1)
  O_i = SM4Encrypt(I_i)
  I_{i + 1} = O_i
end for

for i = 1 to (n - 1)
  C_i = P_i xor O_i
end for

C_n = P_n xor MSB(u, O_n)

C = C_1 || ... || C_n
_____________________________________________________________________</artwork>
</figure></section>
<section anchor="_sm4_ofb_decryption" title="SM4-OFB Decryption"><t>Inputs:</t>
<t>
  <list style="symbols">
    <t>C, ciphertext, composed of (n - 1) blocks of size b, with the last block C_n of size 1 &#8656; u &#8656; b</t>
    <t>K, SM4 128-bit encryption key</t>
    <t>IV, the nonce used during encryption</t>
  </list>
</t>
<t>Output:</t>
<t>
  <list style="symbols">
    <t>P, plaintext, composed of (n - 1) blocks of size b, with the last block P_n of size 1 &#8656; u &#8656; b</t>
  </list>
</t>
<t>C is defined as follows.</t>
<figure>
  <artwork>_____________________________________________________________________

n = NBlocks(C, b)

I_1 = IV
for i = 1 to (n - 1)
  O_i = SM4Encrypt(I_i)
  I_{i + 1} = O_i
end for

for i = 1 to (n - 1)
  P_i = C_i xor O_i
end for

P_n = C_n xor MSB(u, O_n)

P = P_1 || ... || P_n
_____________________________________________________________________</artwork>
</figure></section></section>
<section anchor="_sm4_ctr" title="SM4-CTR"><t>SM4-CTR is an implementation of a stream cipher through a blockcipher
primitive. It generates a "keystream" of keys that are used to
encrypt successive blocks, with the keystream created from the input key,
a nonce (the IV) and an incremental counter. The counter could be any
sequence that does not repeat within the block size.</t>
<t>Both SM4-CTR encryption and decryption routines could be parallelized, and
random access is also possible.</t>
<section anchor="_sm4_ctr_encryption" title="SM4-CTR Encryption"><t>Inputs:</t>
<t>
  <list style="symbols">
    <t>P, plaintext, composed of (n - 1) blocks of size b, with the last block P_n of size 1 &#8656; u &#8656; b</t>
    <t>K, SM4 128-bit encryption key</t>
    <t>IV, a nonce (a unique value for each execution per given key)</t>
    <t>T, a sequence of counters from T_1 to T_n</t>
  </list>
</t>
<t>Output:</t>
<t>
  <list style="symbols">
    <t>C, ciphertext, composed of (n - 1) blocks of size b, with the last block C_n of size 1 &#8656; u &#8656; b</t>
  </list>
</t>
<t>C is defined as follows.</t>
<figure>
  <artwork>_____________________________________________________________________

n = NBlocks(P, b)

for i = 1 to n
  O_i = SM4Encrypt(T_i)
end for

for i = 1 to (n - 1)
  C_i = P_i xor O_i
end for

C_n = P_n xor MSB(u, O_n)

C = C_1 || ... || C_n
_____________________________________________________________________</artwork>
</figure></section>
<section anchor="_sm4_ctr_decryption" title="SM4-CTR Decryption"><t>Inputs:</t>
<t>
  <list style="symbols">
    <t>C, ciphertext, composed of (n - 1) blocks of size b, with the last block C_n of size 1 &lt;= u &lt;= b</t>
    <t>K, SM4 128-bit encryption key</t>
    <t>IV, a nonce (a unique value for each execution per given key)</t>
    <t>T, a sequence of counters from T_1 to T_n</t>
  </list>
</t>
<t>Output:</t>
<t>
  <list style="symbols">
    <t>P, plaintext, composed of (n - 1) blocks of size b, with the last block P_n of size 1 &lt;= u &lt;= b</t>
  </list>
</t>
<t>P is defined as follows.</t>
<figure>
  <artwork>_____________________________________________________________________

n = NBlocks(C, b)

for i = 1 to n
  O_i = SM4Encrypt(T_i)
end for

for i = 1 to (n - 1)
  P_i = C_i xor O_i
end for

P_n = C_n xor MSB(u, O_n)

C = C_1 || ... || C_n
_____________________________________________________________________</artwork>
</figure></section></section></section>
<section anchor="sm4-oids" title="Object Identifier"><t>The Object Identifier for SM4 is identified through these OIDs.</t>
<section anchor="_gm_t_oid" title="GM/T OID">
  <t>"1.2.156.10197.1.104" for "SM4 Algorithm" <xref target="GMT-0006-2012"/>.</t>
</section>
<section anchor="_iso_oid" title="ISO OID"><t>"1.0.18033.3.2.4" for "id-bc128-sm4" <xref target="ISO.IEC.18033-3.AMD2"/>,
described below.</t>
<t>
  <list style="symbols">
    <t>"is18033-3" {iso(1) standard(0) is18033(18033) part3(3)}</t>
    <t>"id-bc128" {is18033-3 block-cipher-128-bit(2)}</t>
    <t>"id-bc128-sm4" {id-bc128 sm4(4)}</t>
  </list>
</t></section></section>
<section anchor="_design_considerations" title="Design Considerations"><section anchor="_basic_transformation" title="Basic Transformation"><t>The chaos principle and the diffusion principle are two basic principles of
block cipher design. A well-designed blockcipher algorithm should be based on a
cryptographically sound basic transformation structure, with its round
calculation based on a cryptographically sound basic transformation.</t>
<t>The cryptographic properties of the basic transformation determines the
efficiency of the resulting encryption transformation.</t>
<t>The SM4 algorithm is structured on orthomorphic permutation. Its round
transformation is an orthomorphic permutation, and its cryptographic properties
can be deduced from the characteristics of orthomorphic permutations.</t>
<t>Let the single round of the SM4 block cipher algorithm be P, for any given
plaintext X, P (X, K ')! = P (X, K) if the key K'! = K.</t>
<t>The conclusion shows that if X is a row variable and K is a column
variable, the square P(X, K) forms a Latin square. There are two
conclusions about the nature of cryptography:</t>
<t>
  <list style="numbers">
    <t>The SM4 blockcipher algorithm will produce different round transformations
given different keys.</t>
    <t>The SM4 blockcipher algorithm, within a single round, will produce a
different output given the same input with different keys.</t>
  </list>
</t></section>
<section anchor="_nonlinear_transformation" title="Nonlinear Transformation"><t>An S-box can be viewed as a bijection:</t>
<t>S(X) = (f_1(X), f_2(X), ... , f_m(X)) : F_2^n -&gt; F_2^m.</t>
<t>S(x): F_2^n -&gt; F_2^m can be represented as a multi-output boolean function
with n-bit input and m-bit output, or a n x m S-box (an S-box with n inputs
and m outputs), usually realized as a substitution that takes an n-bit input
and produces a m-bit output. In SM4, the S-box takes n = m = 8.</t>
<t>In many blockciphers, the S-box is the sole element providing nonlinearity, for
the purpose of mixing, in order to reduce linearity and to hide its variable
structure.</t>
<t>The cryptographic properties of the S-box directly affects the resulting
cryptographic strength of the blockcipher. When designing a blockcipher, the
cryptographic strength of the S-box must be taken into account. The
cryptographic strength of an S-box can be generally measured by factors such as
its nonlinearity and differential distribution.</t>
<section anchor="_s_box_algebraic_expression" title="S-box algebraic expression"><t>In order to prevent insertion attacks, the algebraic formula used for
cryptographic substitution should be a high degree polynomial and contain a
large number of terms.</t>
<t>The algebraic expression of the SM4 S-box <xref target="SM4-Sbox"/> is determined through Lagrange&#8217;s
interpolation to be a polynomial of the 254th degree with 255 terms, providing
the highest level of complexity based on its size:</t>
<figure>
  <artwork>f(x) : sum_{i=0}^{255} y_i
                PI_{j!=i, j=0}^255 ((x - x_j) / (x_i - x_j))</artwork>
</figure></section>
<section anchor="_algebraic_degree_and_distribution_of_terms" title="Algebraic degree and distribution of terms"><t>Any n boolean function f(x): F_2^n -&gt; F_2 can be represented
uniquely in its algebraic normal form shown below:</t>
<figure>
  <artwork>f(X) = a_0 + sum_{1&lt;=i_i&lt;...&lt;i_k&lt;=n, 1&lt;=k&lt;=n}
                      a_{i_1 i_2 ... i_k} x_{i_1} x_{i_2} ... x_{i_k}

X = (x_1, x_2, ..., x_n)

a_0, a_{i_1, i_2, ... i_k} element-of F_2</artwork>
</figure>
<t>The "algebraic degree" of the n-boolean function f(X) is defined to be the
algebraic degree of the highest algebraic degree of its terms with a nonzero
coefficient in its ANF representation. The constant of the i-th term of f(x) in
ANF representation is called the i-th term of f(X), the total number of all
i-th (0&lt;=i&lt;=n) terms is called the "number of terms" of f(X).</t>
<t>///(X)&#30340;&#27425;&#25968;;&#23427;&#30340;&#20195;&#25968;&#27491;&#35268;&#24418;&#24335;&#20013;&#30340;f&#27425;&#39033;&#30340;&#20010; &#25968;&#31216;&#20026;/&#12295;&#12295;&#30340;f&#27425;&#39033;&#25968;;&#25152;&#26377;&#27425;&#39033;&#25968;</t>
<t>S(X) can be represented as a m-component function
S(X) = (f_1(X), f_2(X), ... f_m(X)): F_2^n -&gt; F_2^m.
Consider S(X) to be a random substitution, each of its component functions
would be best to have algebraic degree of n-1, each component function i-th
coefficient should be near C_n^i/2. If the algebraic degree is too low, for
example, each component function has a degree of 2, then the algorithm can be
easily attacked by advanced differential cryptanalysis. If the number of terms
are insufficient, then it may improve the success probability of insert
attacks.</t>
<t>The algebraic degrees and number of terms of the SM4 S-box are described in
<xref target="diagram-sm4-degrees-terms"/>.</t>
<figure anchor="diagram-sm4-degrees-terms" align="center" title="SM4 S-box Component Functions Algebraic Degree And Terms">
  <artwork align="center">+----------------------------------------------------------+
| Component |            Algebraic degree                  |
| Function  +----------------------------------------------+
|           |  8  |  7 |  6 |  5 |  4 |  3 |  2 |  1 |  0  |
+----------------------------------------------------------+
|   Y_0     |  0  |  3 | 15 | 31 | 28 | 29 | 14 |  3 |  1  |
|   Y_1     |  0  |  3 | 12 | 34 | 40 | 33 | 12 |  4 |  1  |
|   Y_2     |  0  |  5 | 17 | 24 | 40 | 24 | 11 |  3 |  0  |
|   Y_3     |  0  |  2 | 11 | 31 | 34 | 27 | 15 |  5 |  1  |
|   Y_4     |  0  |  5 | 15 | 28 | 33 | 24 | 13 |  5 |  0  |
|   Y_5     |  0  |  5 | 11 | 25 | 41 | 25 | 16 |  4 |  1  |
|   Y_6     |  0  |  4 | 15 | 29 | 27 | 32 | 18 |  4 |  1  |
|   Y_7     |  0  |  4 | 14 | 32 | 35 | 30 | 16 |  3 |  0  |
+----------------------------------------------------------+
| Expected  | 1/2 |  4 | 14 | 28 | 35 | 28 | 14 |  4 | 1/2 |
| Value     |     |    |    |    |    |    |    |    |     |
+----------------------------------------------------------+</artwork>
</figure></section>
<section anchor="_differential_distribution" title="Differential Distribution"><t>The definition of differential distribution has been given in <xref target="BC-Design"/>.</t>
<t>Differential cryptanalysis is a chosen-plaintext attack, with the understanding
that analysis of selected plaintexts of differentials can retrive the most
probable key. Differential distribution is an attribute to measure the
resistance of a cryptographic function against differential cryptanalysis.</t>
<figure>
  <artwork>delta_S = 1/2^n max_{a in F_2^n, a!=0} max_{beta in F_2^m} |
  { X in F_2^n : S(X and alpha) - S(X) = beta } |</artwork>
</figure>
<t><spanx style="verb">delta_S</spanx> is the differential distribution of the S-box <spanx style="verb">S</spanx>.</t>
<t>According to the definition of differential distribution,
2^{-m} &lt;= delta_S &lt;= 2^{m-n},
if there is a delta_S = 2^{m-n} then S is considered a fully nonlinear
function from F_2^n to F_2^m. For resistance against differential
cryptanalysis, the differential distribution should be as low as possible.</t>
<t>The highest differential distribution of the SM4 S-box is 2^{-6}, meaning
it has a good resistance against differential cryptanalysis.</t></section>
<section anchor="_nonlinearity" title="Nonlinearity"><t>The nonlinearity of an S-box is described by <xref target="BC-Design"/>.</t>
<t>Let S(X) = (f_1(X), f_2(X), ... , f_m(X)) : F_2^n -&gt; F_2^m be a
multi-output function. The nonlinearity of S(X) is defined as
N_S = min_{l in L_n, 0 != u in F_2^m} d_H (u . S(X), l(X)).</t>
<t>L_n is the group of all n-boolean functions, d_H(f, l) is the Hamming distance
between f and l. The nonlinearity of the S-box is in fact the minimum Hamming
distance between all the Boolean functions and all affine functions.</t>
<t>The upper-bound of nonlinearity is known to be 2^{n-1} - 2^{n/2 - 1}, where
a Boolean function that reaches this bound is called a "bent function".</t>
<t>The nonlinearity of a Boolean function is used to measure resistance against
linear attacks. The higher the nonlinearity, the higher resistance that the
Boolean function f(x) has against linear attacks. On the contrary, the lower
the nonlinearity, the Boolean function f(x) has lower resistance against linear
attacks.</t>
<t>The nonlinearity of the SM4 S-box is 112.</t></section>
<section anchor="_maximum_linearity_advantage" title="Maximum Linearity Advantage"><t>Linear approximation of a S-box is defined in <xref target="BC-Design"/>. Given a S-box with
n inputs and m outputs, any linear approximation can be represented as : a .
X = b . Y, where a in F_2^n, b in F_2^m.</t>
<t>The probability p that satisfies a . X = b . Y is</t>
<t>| p - 1/2 | &lt;= 1/2 - N_S / 2^n, where | p - 1/2 | is the advantage of
the linear approximation equation, lambda_S = 1/2 - N_s / 2^n is the
maximum advantage of the S-box.</t>
<t>The maximum advantage of the SM4 S-box is 2^{-4}.</t></section>
<section anchor="_balance" title="Balance"><t>A S-box S(X) = (f_1(X), f_2(X), ... , f_m(X)) : F_2^n -&gt; F_2^m is
considered "balanced" if for any beta in F_2^m,
there are 2^{n-m} x in F_2^n, such that S(x) = beta.</t>
<t>The SM4 S-box is balanced.</t></section>
<section anchor="_completness_and_avalanche_effect" title="Completness and Avalanche Effect"><t>A S-box S(X) = (f_1(X), f_2(X), ... , f_m(X)) : F_2^n -&gt; F_2^m is
considered "complete" if every input bit directly correlates to an output bit.</t>
<t>In algebraic expression, each component function contains the unknown variables
x_1, x_2, ... x_n, such that for any
(s, t) in { (i, j) | 1 &lt;= i &lt;= n, 1 &lt;= j &lt;= m}, there is an X that
S(X) and S(X and e_s) would contain a different bit t.</t>
<t>Avalanche effect refers to a single bit change in the input would correspond to
a change of half of the output bits.</t>
<t>The SM4 S-box satisfies completness and the avalanche effect.</t></section></section>
<section anchor="_linear_transform" title="Linear Transform"><t>Linear transformation is used to provide diffusion in SM4. A blockcipher
algorithm often adopts m x m S-boxes to form an obfuscation layer.</t>
<t>Since the m-bits output by one S-box are only related to the m bits of its
input and are irrelevant to the input of other S boxes, the introduction of a
linear transform would disrupt and mix the output m-bits so that they seem
correlating to the other S-box inputs.</t>
<t>A sound linear transform design will diffuse the S-box output, allowing the
blockcipher to resist differential and linear cryptanalysis.</t>
<t>An important measure of the diffusivity of a linear transform is its branch
number.</t>
<t>The "branch number" of a linear transform is defined in <xref target="BC-Design"/>:</t>
<figure>
  <artwork>B(theta) = min_{x!=0} w_b(x) + w_b(theta(x))</artwork>
</figure>
<t>Where B(theta) is the branch number of transform theta, w_b(x) is a
non-zero integer x_i (1 &#8656; i &#8656; m), and x_i is called the "bundle weight".</t>
<t>The branch number can be used to quantify the resistance of the block cipher
algorithm to differential cryptanalysis and linear cryptanalysis.</t>
<t>Similar to differential cryptanalysis and linear cryptanalysis, the
differential branch number and linear branch number of theta can be defined as
follows.</t>
<t>The differential branch number of theta is:</t>
<figure>
  <artwork>B_d(theta) = min_{x, x!= x*}
               (w_b(x and x*) + w_b(theta(x)) and theta(x*))</artwork>
</figure>
<t>The linear branch number of theta is:</t>
<figure>
  <artwork>B_l(theta) = min_{a, b, c (x . alpha^t , theta(x) . beta) != 0}
               (w_b(alpha) + w_b(beta))

  where,
    c (x . a^t , theta(x) . beta) =
                      2 X Pr(x . alpha^t = theta(x) . beta) - 1
    x . alpha^t  is a matrix multiplication.</artwork>
</figure>
<t>The branch number in a linear transformation reflects its diffusivity. The
higher the branch number, the better the diffusion effect.</t>
<t>This means that the larger the differential branch number or linear branch
number, the more known plaintexts will be required for differential or linear
cryptanalysis respectively.</t>
<t>The linear transform differential branch number and linear branch number of SM4
are both 5.</t></section>
<section anchor="_key_expansion_algorithm" title="Key Expansion Algorithm"><t>The SM4 key schedule is designed to fulfill the security requirements of the
encryption algorithm and achieve ease of implementation for performance
reasons.</t>
<t>All subkeys are derived from the encryption key, and therefore, subkeys are
always statistically relevant. In the context of a blockcipher, it is not
possible to have non-statistical-correlated subkeys, but the designer can only
aim to have subkeys achieve near statistical independence <xref target="BC-Design"/>.</t>
<t>The purpose of the key schedule, generated through the key expansion algorithm,
is to mask the statistical correlation between subkeys to make this
relationship difficult to exploit.</t>
<t>The SM4 key expansion algorithm satisfies the following design criteria:</t>
<t>
  <list style="numbers">
    <t>There are no obvious statistical correlation between subkeys;</t>
    <t>There are no weak subkeys;</t>
    <t>The speed of key expansion is not slower than the encryption algorithm, and
uses less resources;</t>
    <t>Every subkey can be directly generated from the encryption key.</t>
  </list>
</t></section></section>
<section anchor="cryptanalysis" title="Cryptanalysis Results"><t>SM4 has been heavily cryptanalyzed by international researchers since
it was first published in January 2016. Nearly all currently known
cryptanalysis techniques have already been applied to SM4,
but there have been no known feasible attacks against the full SM4
blockcipher and results demonstrate that SM4 currently provides a
suitable security margin, by the time of publishing this document.</t>
<t>A summary of cryptanalysis results are presented in the following
sections.</t>
<t>A number of attacks have been attempted on SM4, such as <xref target="SM4-LDA"/>
<xref target="SM4-LinearLiu"/>.</t>
<t>There are, however, security concerns with regards to side-channel attacks
<xref target="SideChannel"/> when the SM4 algorithm is implemented in a hardware device
<xref target="SM4-Power"/>.</t>
<t>For instance, <xref target="SM4-Power"/> illustrated an attack by measuring the power
consumption of the device. A chosen ciphertext attack, assuming a fixed
correlation between the round keys and data mask, is able to recover the round
key successfully. When the SM4 algorithm is implemented in hardware, the
parameters and keys <spanx style="strong">SHOULD</spanx> be randomly generated without fixed correlation.</t>
<t>There have been improvements to the hardware embodiment design for SM4, such
as <xref target="SM4-VLSI"/>, that may resist such attacks.</t>
<t>In order to improve security of the SM4 cryptographic process, secure white-box
implementations such as <xref target="SM4-WhiteBox"/> have been proposed. Speed enhancements,
such as <xref target="SM4-HiSpeed"/>, have also been proposed.</t>
<section anchor="_differential_cryptanalysis" title="Differential Cryptanalysis"><t>In 2008, Zhang et al. <xref target="SM4-DiffZhang1"/> gave a 21-round differential analysis
with data complexity 2^188, time complexity 2^126.8 encryptions.</t>
<t>In 2009, Zhang et al. (differing first author but overlapping team)
<xref target="SM4-DiffZhang2"/> gave a 18-round differential characteristics with an attack
that reaches the 22nd round, with data complexity 2^117 and time complexity
2^112.3.</t>
<t>In 2010, Zhang et al. (with no relation to above) <xref target="SM4-DiffZhang3"/>
utilized 18-round differential characteristics for the 22nd round with
2^117 chosen plaintexts with time complexity 2^123 encryptions, storage
complexity of 2^112.</t>
<t>In 2011, Su et al. <xref target="SM4-DiffSu"/> gave a 19 round differential characteristics
and pushed their attack to the 23rd round, with data complexity of 2^118
chosen plaintexts, time complexity 2^126.7 encryptions, and storage
complexity 2^120.7.</t></section>
<section anchor="_linear_cryptanalysis" title="Linear Cryptanalysis"><t>In 2008 Etrog et al. <xref target="SM4-LinearEtrog"/> provided a linear cryptanalysis result
for 22 rounds of SM4, the data complexity is given as 2^188.4 known
plaintexts, time complexity 2^117 encrypt operations.</t>
<t>In 2011 Dong <xref target="SM4-LinearDong"/> presented a linear cryptanalysis result for 20
rounds, 2^110.4 known ciphertexts, 2^106.8 encryption operations,
storage complexity 2^90.</t>
<t>In 2014 Liu et al. <xref target="SM4-LinearLiu"/> presented their linear cryptanalysis for
23-rounds of SM4, time complexity 2^112 encryption
operations, data complexity 2^126.54 known ciphertexts, storage complexity
2^116.</t>
<t>In 2017 Liu et al. <xref target="SM4-NLC"/> presented an attack based on linear
cryptanalysis on 24-rounds of SM4, with time complexity of 2^122.6
encryptions, data complexity of 2^122.6 known ciphertexts, and storage
complexity of 2^85.</t></section>
<section anchor="_multi_dimensional_linear_cryptanalysis" title="Multi-dimensional Linear Cryptanalysis"><t>In 2010, Liu et al. <xref target="SM4-MLLiu"/> constructed a series of 18 rounds of linear
traces based on a 5-round circular linear trace, capable of attacking 22 rounds
of SM4. The required data complexity was 2^112 known plaintexts, time
complexity 2^124.21 encryption operations, with storage complexity of
2^118.83.</t>
<t>In 2010 Cho et al. <xref target="SM4-MLCho"/> gave a linear analysis of 23 rounds of SM4
with a data complexity of 2^126.7 known plaintexts and a time complexity of
2^127, storage complexity of 2^120.7.</t>
<t>In 2014, Liu et al. <xref target="SM4-LinearLiu"/> gave the results of multi-dimensional
linear analysis of 23 rounds of SM4 algorithm. The time complexity was
2^122.7, data complexity was 2^122.6 known plaintext with storage
complexity 2^120.6.</t></section>
<section anchor="_impossible_differential_cryptanalysis" title="Impossible Differential Cryptanalysis"><t>In 2007 Lu et al. <xref target="SM4-IDCLu"/> first presented 16 rounds of impossible differential
analysis of SM4 with the required data complexity 2^105 chosen plaintexts,
time complexity 2^107 encryption operations.</t>
<t>In 2008 Toz et al. <xref target="SM4-IDCToz"/> revised the results of <xref target="SM4-IDCLu"/>, that the data
complexity is actually 2^117.05 chosen plaintexts, time complexity
2^132.06 encryptions, but its complexity is already beyond the 2^128
limit.</t>
<t>In 2010 Wang et al. <xref target="SM4-IDCWang"/> pushed the impossible differential
cryptanalysis to 17 rounds of SM4, the data complexity is 2^117 chosen
ciphertexts, time complexity 2^132 memory queries.</t></section>
<section anchor="_zero_correlation_linear_cryptanalysis" title="Zero-correlation Linear Cryptanalysis">
  <t>In 2015 Ma et al. <xref target="SM4-ZCLC"/> gives the results of multi-dimensional
zero-correlation linear cryptanalysis of a 14-round SM4 algorithm. The required
data complexity is 2^123.5 known plaintexts, time complexity is 2^120.7
encryption operations and storage complexity of 2^73 blocks.</t>
</section>
<section anchor="_integral_cryptanalysis" title="Integral Cryptanalysis"><t>In 2007 Liu et al. <xref target="SM4-ICLiu"/> first gave a 13-round integral analysis of
SM4, which required 2^16 chosen plaintexts and time complexity of 2^114
encryption operations.</t>
<t>In 2008 Zhong et al. <xref target="SM4-ICZhong"/> constructed a 12-round distinguisher of
SM4 to attack 14-round SM4, with data complexity of 2^32 chosen plaintexts
and time complexity 2^96.5 encryptions.</t></section>
<section anchor="_algebraic_attacks" title="Algebraic Attacks">
  <t>In 2009 Ji et al. (2009) <xref target="SM4-AAJi"/> and in 2010 Erickson et al. <xref target="SM4-AAEr"/>
utilized algebraic methods such as XL, Groebner base and SAT to analyze the
resistance of SM4 against algebraic attacks. The results demonstrate that SM4
is safe against algebraic attacks, and specifically, has a higher resistance
against algebraic attacks than AES.</t>
</section>
<section anchor="_matrix_attacks" title="Matrix Attacks"><t>In 2007 Lu et al. <xref target="SM4-IDCLu"/> provided a matrix attack against 14-round SM4, with
data complexity 2^121.82 chosen plaintexts, time complexity 2^116.66
encryptions.</t>
<t>In 2008 Toz et al. <xref target="SM4-IDCToz"/> lowered both data and time complexity of
the aformentioned attack to 2^106.89 chosen ciphertexts and time complexity
of 2^107.89.</t>
<t>In 2008, Zhang et al. <xref target="SM4-DiffZhang1"/> provided a matrix
attack against 16-round SM4, which required a data complexity of 2^125
chosen plaintexts and time complexity of 2^116 encryptions.</t>
<t>She&#8217;s Master dissertation <xref target="SM4-MatrixShe"/> provided a SM4
16-round matrix distinguisher that can attack 18-round SM4, with data
complexity of 2^127 chosen plaintexts and time complexity 2^110.77
encryptions with memory storage of 2^130.</t>
<t>In 2012 Wei et al. <xref target="SM4-MatrixWei"/> applied differential analysis and algebraic attack
techniques on 20-round SM4 and discovered that the combined attack results on
20-round SM4 are superior than using pure differential cryptanalysis.</t></section>
<section anchor="_provable_security_against_differential_and_linear_cryptanalysis" title="Provable Security Against Differential And Linear Cryptanalysis"><t>SM4 uses a novel structure differing from the general Feistel and SP
structures.</t>
<t><xref target="SM4-Random"/> has proven that the SM4 non-balanced Feistel structure is
pseudo-random.</t>
<t><xref target="SM4-SLDC"/> analyzes the SM4 non-balanced Feistel structure on its resistance
against differential and linear cryptanalysis techniques. Under SP type round
functions with branch number 5, it is proven that in a 27-round SM4 guarantees
at least 22 active S-boxes, therefore SM4 is secure against differential
attacks.</t>
<t><xref target="SM4-SLC"/> has analyzed resistance of SM4 against linear cryptanalysis.</t></section>
<section anchor="_provable_security_against_related_key_differential_cryptanalysis" title="Provable Security Against Related-Key Differential Cryptanalysis"><t>Related-key differential cryptanalysis is related to the encryption algorithm
and key schedule. When performing a related-key attack, the attacker
simultaneously insert differences in both the key and the message.</t>
<t>In <xref target="AutoDC"/>, Sun et al. proposed an automated differential route search
method based on MILP (mixed-integer linear programming) that can be used to
assess the security bounds of a blockcipher under (related-key) differential
cryptanalysis.</t>
<t><xref target="SM4-RKDC"/> describes the lower bounds of active S-boxes within SM4
and is shown in <xref target="diagram-sm4-lower-sbox"/>.</t>
<figure anchor="diagram-sm4-lower-sbox" align="center" title="Lower Bounds of Active SM4 S-boxes">
  <artwork align="center">+--------------+---------------------------------------+
| Round        |  3 |  4 |  5 |  6 |  7 |  8 |  9 | 10 |
| Single Key   |  0 |  1 |  2 |  2 |  5 |  6 |  7 |  8 |
| Related Key  |  0 |  1 |  2 |  4 |  6 |  8 |  9 | 10 |
+--------------+---------------------------------------+
| Round        | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| Single Key   |  9 | 10 | 10 | 10 | 13 | 14 | 15 | 16 |
| Related Key  | 11 | 13 | 14 | 14 | 16 | 18 | 19 | 20 |
+--------------+---------------------------------------+
| Round        | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| Single Key   | 18 | 18 | 19 | 20 | 22 | 23 | 23 | 24 |
| Related Key  | 22 | -  | -  | -  | -  | -  | -  | -  |
+--------------+---------------------------------------+
                 ("-" denotes unknown)</artwork>
</figure>
<t>As the maximal probability of the SM4 S-box is 2^&#8722;6, when the minimum active
S-boxes reach 22 the differential characteristics will have probability
2^132, which is higher than enumeration (2^128).</t>
<t>This indicates that 19 rounds and 23 rounds under related key and single key
settings will provide a minimum of 22 active S-boxes and is able to resist
related-key differential attacks.</t></section>
<section anchor="_strongest_attacks_against_sm4" title="Strongest Attacks Against SM4"><t>As of the publication of this document, no open research results have provided
a method to successfully attack beyond 24 rounds of SM4.</t>
<t>The traditional view suggests that SM4 provides an extra safety margin
compared to blockciphers adopted in <xref target="ISO.IEC.18033-3"/> that already have
full-round attacks, including MISTY1 <xref target="MISTY1-IC"/> <xref target="MISTY1-270"/> and AES
<xref target="AES-CA"/> <xref target="AES-BC"/> <xref target="AES-RKC"/>.</t></section></section>
<section anchor="security-considerations" title="Security Considerations">
  <t>
  <list style="symbols">
    <t>Products and services that utilize cryptography are regulated by the OSCCA
<xref target="OSCCA"/>; they must be explicitly approved or certified by the OSCCA before being
allowed to be sold or used in China.</t>
    <t>SM4 is a blockcipher symmetric algorithm with key length of 128 bits. It is
considered as an alternative to AES-128 <xref target="NIST.FIPS.197"/>.</t>
    <t>SM4 <xref target="GBT.32907-2016"/> is a blockcipher certified by the OSCCA <xref target="OSCCA"/>.
No formal proof of security is provided. There are no known feasible
attacks against SM4 algorithm by the time of publishing this document, but
there are security concerns with regards to side-channel attacks when the
SM4 algorithm is implemented in hardware. See <xref target="cryptanalysis"/> for more
details.</t>
    <t>The IV does not have to be secret. The IV itself, or criteria enough to
determine it, <spanx style="strong">MAY</spanx> be transmitted with ciphertext.</t>
    <t>SM4-ECB: ECB is one of the four original modes defined for DES. With its
problem well known to "leak quite a large amount of information" <xref target="BC-EVAL"/>,
it <spanx style="strong">SHOULD NOT</spanx> be used in most cases.</t>
    <t>SM4-CBC, SM4-CFB, SM4-OFB: CBC, CFB and OFB are IV-based modes of operation
originally defined for DES.<vspace blankLines="1"/>When using these modes of operation, the IV <spanx style="strong">SHOULD</spanx> be random to preserve
message confidentiality <xref target="BC-EVAL"/>. It is shown in the same document that
CBC, CFB, OFB, the variants #CBC, #CFB that utilize the recommendation of
<xref target="NIST.SP.800-38A"/> to make CBC and CFB nonce-based, are SemCPA secure as
probabilistic encryption schemes.
<vspace blankLines="1"/>Various attack scenarios have been described in <xref target="BC-EVAL"/> and these modes
<spanx style="strong">SHOULD NOT</spanx> be used unless for compatibility reasons.</t>
    <t>SM4-CTR: CTR is considered to be the "best" mode of operation within
<xref target="NIST.SP.800-38A"/> as it is considered SemCPA secure as a nonce-based
encryption scheme, providing provable-security guarantees as good as
the classic modes of operation (ECB, CBC, CFB, OFB) <xref target="BC-EVAL"/>.<vspace blankLines="1"/>Users with no need of authenticity, non-malleablility and chosen-ciphertext
(CCA) security <spanx style="strong">MAY</spanx> utilize this mode of operation <xref target="BC-EVAL"/>.</t>
  </list>
</t>
</section>
<section anchor="_iana_considerations" title="IANA Considerations">
  <t>This document does not require any action by IANA.</t>
</section>
</middle><back>
<references title="Normative References">
  <reference anchor="GBT.32907-2016" target="http://www.gb688.cn/bzgk/gb/newGbInfo?hcno=7803DE42D3BC5E80B0C3E5D8E873D56A">
  <front>
    <title>GB/T 32907-2016: Information security technology -- SM4 block cipher algorithm</title>
    <author>
      <organization>Standardization Administration of the People's Republic of China</organization>
      <address>
        <postal>
         <street>9 Madian Donglu, Haidian District</street>
         <city>Beijing</city>
         <region>Beijing</region>
         <code>100088</code>
         <country>People's Republic of China</country>
        </postal>
        <phone>+86 (0)10 8226-2609</phone>
        <uri>http://www.sac.gov.cn</uri>
      </address>
    </author>
    <date day="29" month="August" year="2016"/>
  </front>
</reference>
  <reference anchor="ISO.IEC.18033-3.AMD2" target="https://www.iso.org/standard/54531.html">
  <front>
    <title>ISO/IEC WD1 18033-3/AMD2 -- Encryption algorithms -- Part 3: Block ciphers -- Amendment 2</title>
    <author>
      <organization>International Organization for Standardization</organization>
      <address>
        <postal>
          <street>BIBC II</street>
          <street>Chemin de Blandonnet 8</street>
          <street>CP 401</street>
          <city>Vernier</city>
          <region>Geneva</region>
          <code>1214</code>
          <country>Switzerland</country>
        </postal>
        <phone>+41 22 749 01 11</phone>
        <email>central@iso.org</email>
        <uri>https://www.iso.org/</uri>
      </address>
    </author>
    <date day="13" month="June" year="2017"/>
  </front>
</reference>
  <reference anchor="RFC2119" target="https://www.rfc-editor.org/info/rfc2119">
<front>
<title>Key words for use in RFCs to Indicate Requirement Levels</title>
<author initials="S." surname="Bradner" fullname="S. Bradner"><organization/></author>
<date year="1997" month="March"/>
<abstract><t>In many standards track documents several words are used to signify the requirements in the specification.  These words are often capitalized. This document defines these words as they should be interpreted in IETF documents.  This document specifies an Internet Best Current Practices for the Internet Community, and requests discussion and suggestions for improvements.</t></abstract>
</front>
<seriesInfo name="BCP" value="14"/>
<seriesInfo name="RFC" value="2119"/>
<seriesInfo name="DOI" value="10.17487/RFC2119"/>
</reference>
</references>
<references title="Informative References">
  <reference anchor="AES-BC" target="https://doi.org/10.1007/978-3-642-25385-0_19">
  <front>
    <title>Biclique Cryptanalysis of the Full AES</title>
    <author initials="A." surname="Bogdanov" fullname="Andrey Bogdanov">
      <organization>K.U.</organization>
      <address>
        <postal>
          <street/>
          <city>Leuven</city>
          <country>Belgium</country>
        </postal>
      </address>
    </author>
    <author initials="D." surname="Khovratovich" fullname="Dmitry Khovratovich">
      <organization>Microsoft Research</organization>
      <address>
        <postal>
          <street/>
          <city>Redmond</city>
          <region>WA</region>
          <country>USA</country>
        </postal>
      </address>
    </author>
    <author initials="C." surname="Rechberger" fullname="Christian Rechberger">
      <organization>ENS Paris and Chaire France Telecom</organization>
      <address>
        <postal>
          <street/>
          <country>France</country>
        </postal>
      </address>
    </author>
    <date year="2011"/>
  </front>
</reference>
  <reference anchor="AES-CA" target="https://doi.org/10.1007/3-540-44706-7_15">
  <front>
    <title>Improved Cryptanalysis of Rijndael</title>
    <author initials="N." surname="Ferguson" fullname="Niels Ferguson">
      <organization>Counterpane Internet Security, Inc.</organization>
      <address>
        <postal>
          <street/>
          <city>San Jose</city>
          <region>CA</region>
          <country>USA</country>
        </postal>
      </address>
    </author>
    <author initials="J." surname="Kelsey" fullname="John Kelsey">
      <organization>Counterpane Internet Security, Inc.</organization>
      <address>
        <postal>
          <street/>
          <city>San Jose</city>
          <region>CA</region>
          <country>USA</country>
        </postal>
      </address>
    </author>
    <author initials="S." surname="Lucks" fullname="Stephan Lucks">
      <organization>University of Mannheim</organization>
      <address>
        <postal>
          <street/>
          <city>Mannheim</city>
          <country>Germany</country>
        </postal>
      </address>
    </author>
    <author initials="B." surname="Schneier" fullname="Bruce Schneier">
      <organization>Counterpane Internet Security, Inc.</organization>
      <address>
        <postal>
          <street/>
          <city>San Jose</city>
          <region>CA</region>
          <country>USA</country>
        </postal>
      </address>
    </author>
    <author initials="M." surname="Stay" fullname="Mike Stay">
      <organization>Access Data Corp.</organization>
      <address>
        <postal>
          <street>2500 N. University</street>
          <city>Provo</city>
          <region>UT</region>
          <country>USA</country>
        </postal>
      </address>
    </author>
    <author initials="D." surname="Wagner" fullname="David Wagner">
      <organization>University of California Berkeley</organization>
      <address>
        <postal>
          <street/>
          <city>Berkeley</city>
          <region>CA</region>
          <country>USA</country>
        </postal>
      </address>
    </author>
    <author initials="D." surname="Whiting" fullname="Doug Whiting">
      <organization>Hi/fn, Inc.</organization>
      <address>
        <postal>
          <street/>
          <city>Carlsbad</city>
          <country>USA</country>
        </postal>
      </address>
    </author>
    <date day="18" month="Jan" year="2002"/>
  </front>
</reference>
  <reference anchor="AES-RKC" target="https://doi.org/10.1007/978-3-642-10366-7_1">
  <front>
    <title>Related-Key Cryptanalysis of the Full AES-192 and AES-256</title>
    <author initials="A." surname="Biryukov" fullname="Alex Biryukov">
      <organization>University of Luxembourg</organization>
    </author>
    <author initials="D." surname="Khovratovich" fullname="Dmitry Khovratovich">
      <organization>University of Luxembourg</organization>
    </author>
    <date year="2009"/>
  </front>
</reference>
  <reference anchor="AutoDC" target="https://doi.org/10.1007/978-3-662-45611-8_9">
  <front>
    <title>Automatic Security Evaluation and (Related-key) Differential Characteristic Search: Application to SIMON, PRESENT, LBlock, DES(L) and Other Bit-Oriented Block Ciphers</title>
    <author initials="S." surname="Siwei" fullname="Siwei Sun">
      <organization>State Key Laboratory of Information Security</organization>
      <address>
        <postal>
          <street>Chinese Academy of Sciences</street>
          <city>Beijing</city>
          <country>China</country>
        </postal>
      </address>
    </author>
    <author initials="L." surname="Hu" fullname="Lei Hu">
      <organization>State Key Laboratory of Information Security</organization>
      <address>
        <postal>
          <street>Chinese Academy of Sciences</street>
          <city>Beijing</city>
          <country>China</country>
        </postal>
      </address>
    </author>
    <author initials="P." surname="Wang" fullname="Peng Wang">
      <organization>State Key Laboratory of Information Security</organization>
      <address>
        <postal>
          <street>Chinese Academy of Sciences</street>
          <city>Beijing</city>
          <country>China</country>
        </postal>
      </address>
    </author>
    <author initials="K." surname="Qiao" fullname="Kexin Qiao">
      <organization>State Key Laboratory of Information Security</organization>
      <address>
        <postal>
          <street>Chinese Academy of Sciences</street>
          <city>Beijing</city>
          <country>China</country>
        </postal>
      </address>
    </author>
    <author initials="X." surname="Ma" fullname="Xiaoshuang Ma">
      <organization>State Key Laboratory of Information Security</organization>
      <address>
        <postal>
          <street>Chinese Academy of Sciences</street>
          <city>Beijing</city>
          <country>China</country>
        </postal>
      </address>
    </author>
    <author initials="L." surname="Song" fullname="Ling Song">
      <organization>State Key Laboratory of Information Security</organization>
      <address>
        <postal>
          <street>Chinese Academy of Sciences</street>
          <city>Beijing</city>
          <country>China</country>
        </postal>
      </address>
    </author>
    <date year="2014"/>
  </front>
</reference>
  <reference anchor="BC-Design" target="http://www.tup.tsinghua.edu.cn/booksCenter/book_03193701.html">
  <front>
    <title>Block Cipher Design and Analysis (in Chinese)</title>
    <author initials="W." surname="Wu" fullname="Wenling Wu">
      <organization>Tsinghua University Press</organization>
    </author>
    <date day="1" month="October" year="2009"/>
  </front>
</reference>
  <reference anchor="BC-EVAL" target="http://web.cs.ucdavis.edu/rogaway/papers/modes.pdf">
  <front>
    <title>Evaluation of Some Blockcipher Modes of Operation</title>
    <author initials="P." surname="Rogaway" fullname="Phillip Rogaway">
      <organization>University of California, Davis</organization>
      <address>
        <postal>
          <street>Dept. of Computer Science</street>
          <street>Kemper Hall of Engineering, #3009</street>
          <street>One Shields Avenue</street>
          <city>Davis</city>
          <region>California</region>
          <code>95616-8562</code>
          <country>United States of America</country>
        </postal>
        <phone>+1 530 752 7583</phone>
        <email>rogaway@cs.ucdavis.edu</email>
        <uri>http://www.cs.ucdavis.edu/rogaway</uri>
      </address>
    </author>
    <date day="10" month="February" year="2011"/>
  </front>
</reference>
  <reference anchor="BOTAN" target="https://botan.randombit.net">
  <front>
    <title>Botan: Crypto and TLS for C++11</title>
    <author initials="J. E." surname="Lloyd" fullname="Jack E. Lloyd">
      <organization>Botan Project</organization>
      <address>
        <postal>
          <street/>
          <country>United States of America</country>
        </postal>
        <email>jack@randombit.net</email>
        <uri>https://botan.randombit.net</uri>
      </address>
    </author>
    <date day="18" month="October" year="2017"/>
  </front>
</reference>
  <reference anchor="GB.15629.11-2003" target="http://www.gb688.cn/bzgk/gb/newGbInfo?hcno=74B9DD11287E72408C19C4D3A360D1BD">
  <front>
    <title>Information technology -- Telecommunications and information exchange between systems -- Local and metropolitan area networks -- Specific requirements -- Part 11: Wireless LAN Medium Access Control (MAC) and Physical Layer (PHY) Specifications</title>
    <author>
      <organization>Standardization Administration of the People's Republic of China</organization>
      <address>
        <postal>
         <street>No. 9 Madian Donglu, Haidian District</street>
         <city>Beijing</city>
         <region>Beijing</region>
         <code>100088</code>
         <country>People's Republic of China</country>
        </postal>
        <phone>+86 (0)10 8226-2609</phone>
        <!--<email>contact@oscca.gov.cn</email>-->
        <uri>http://www.sac.gov.cn</uri>
      </address>
    </author>
    <date day="12" month="May" year="2003"/>
  </front>
</reference>
  <reference anchor="GMT-0002-2012" target="http://www.oscca.gov.cn/Column/Column_32.htm">
  <front>
    <title>GM/T 0002-2012: SM4 block cipher algorithm</title>
    <author>
      <organization>Organization of State Commercial Administration of China</organization>
      <address>
        <postal>
         <street>7 Dian Chang Lu, Fengtai Qu</street>
         <city>Beijing</city>
         <region>Beijing</region>
         <code>100036</code>
         <country>People's Republic of China</country>
        </postal>
        <phone>+86 (0)10 5970-3789</phone>
        <!--<email>contact@oscca.gov.cn</email>-->
        <uri>http://www.oscca.gov.cn</uri>
      </address>
    </author>
    <date day="21" month="March" year="2012"/>
  </front>
</reference>
  <reference anchor="GMT-0006-2012" target="http://www.oscca.gov.cn/Column/Column_32.htm">
  <front>
    <title>GM/T 0006-2012: Cryptographic Application Identifier Criterion Specification</title>
    <author>
      <organization>Organization of State Commercial Administration of China</organization>
      <address>
        <postal>
         <street>7 Dian Chang Lu, Fengtai Qu</street>
         <city>Beijing</city>
         <region>Beijing</region>
         <code>100036</code>
         <country>People's Republic of China</country>
        </postal>
        <phone>+86 (0)10 5970-3789</phone>
        <!--<email>contact@oscca.gov.cn</email>-->
        <uri>http://www.oscca.gov.cn</uri>
      </address>
    </author>
    <date day="21" month="March" year="2012"/>
  </front>
</reference>
  <reference anchor="IEEE.1619-2007" target="http://ieeexplore.ieee.org/document/4493450/">
  <front>
    <title>IEEE P1619-2007: The XTS-AES Tweakable Block Cipher</title>
    <author>
      <organization>Institute of Electrical and Electronics Engineers, Inc</organization>
      <address>
        <postal>
          <street>Three Park Avenue</street>
          <city>New York</city>
          <region>NY</region>
          <code>10016-5997</code>
          <country>United States</country>
        </postal>
        <uri>http://www.ieee.org/</uri>
      </address>
    </author>
    <date day="18" month="April" year="2008"/>
  </front>
</reference>
  <reference anchor="ISO.IEC.18033-3" target="https://www.iso.org/standard/54531.html">
  <front>
    <title>ISO/IEC 18033-3:2010 -- Encryption algorithms -- Part 3: Block ciphers</title>
    <author>
      <organization>International Organization for Standardization</organization>
      <address>
        <postal>
          <street>BIBC II</street>
          <street>Chemin de Blandonnet 8</street>
          <street>CP 401</street>
          <city>Vernier</city>
          <region>Geneva</region>
          <code>1214</code>
          <country>Switzerland</country>
        </postal>
        <phone>+41 22 749 01 11</phone>
        <email>central@iso.org</email>
        <uri>https://www.iso.org/</uri>
      </address>
    </author>
    <date day="1" month="December" year="2017"/>
  </front>
</reference>
  <reference anchor="LSW-Bio" target="http://press.ustc.edu.cn/sites/default/files/fujian/field_fujian_multi/20120113/%E5%90%95%E8%BF%B0%E6%9C%9B%20%E5%AF%86%E7%A0%81%E4%B8%80%E6%A0%B7%E7%9A%84%E4%BA%BA%E7%94%9F.pdf">
 <!-- &#26032;&#21326;&#20070;&#30446;&#25253; 2010&#24180;11&#26376;25&#26085; &#23385;&#26790;&#23005; -->
  <front>
    <title>Lv Shu Wang -- A life in cryptography</title>
    <author initials="M." surname="Sun" fullname="Mengshu Sun">
      <organization>Xinhua Catalog</organization>
    </author>
    <date day="25" month="November" year="2010"/>
  </front>
</reference>
  <reference anchor="MISTY1-270" target="https://doi.org/10.1007/978-3-662-53018-4_16">
  <front>
    <title>A 2^{70} Attack on the Full MISTY1</title>
    <author initials="A." surname="Bar-On" fullname="Achiya Bar-On">
      <organization>Bar Ilan University</organization>
      <address>
        <postal>
          <street/>
          <city>Ramat Gan</city>
          <country>Israel</country>
        </postal>
        <email>abo1000@gmail.com</email>
      </address>
    </author>
    <author initials="N." surname="Keller" fullname="Nathan Keller">
      <organization>Bar Ilan University</organization>
      <address>
        <postal>
          <street/>
          <city>Ramat Gan</city>
          <country>Israel</country>
        </postal>
        <email>abo1000@gmail.com</email>
      </address>
    </author>
    <date year="2016"/>
  </front>
</reference>
  <reference anchor="MISTY1-IC" target="https://doi.org/10.1007/s00145-016-9240-x">
  <front>
    <title>Integral Cryptanalysis on Full MISTY1</title>
    <author initials="Y." surname="Todo" fullname="Yosuke Todo">
      <organization>NTT Secure Platform Laboratories</organization>
      <address>
        <postal>
          <street/>
          <city>Tokyo</city>
          <country>Japan</country>
        </postal>
        <email>todo.yosuke@lab.ntt.co.jp</email>
      </address>
    </author>
    <date year="2015"/>
  </front>
</reference>
  <reference anchor="NIST.FIPS.197" target="https://doi.org/10.6028/NIST.FIPS.197">
  <front>
    <title>NIST FIPS 197: Advanced Encryption Standard (AES)</title>
    <author>
      <organization>National Institute of Standards and Technology</organization>
      <address>
        <postal>
          <street>100 Bureau Drive</street>
          <city>Gaithersburg</city>
          <region>MD</region>
          <code>20899-8900</code>
          <country>United States</country>
        </postal>
        <uri>http://www.nist.gov/</uri>
      </address>
    </author>
    <date month="November" year="2001"/>
  </front>
</reference>
  <reference anchor="NIST.SP.800-38A" target="http://dx.doi.org/10.6028/NIST.SP.800-38A">
  <front>
    <title>NIST Special Publication 800-38A: Recommendation for Block Cipher Modes of Operation -- Methods and Techniques</title>
    <author initials="M." surname="Dworkin" fullname="Morris Dworkin">
      <organization>National Institute of Standards and Technology</organization>
      <address>
        <postal>
          <street>100 Bureau Drive</street>
          <city>Gaithersburg</city>
          <region>MD</region>
          <code>20899-8930</code>
          <country>United States</country>
        </postal>
        <uri>http://www.nist.gov/</uri>
      </address>
    </author>
    <date month="December" year="2001"/>
  </front>
</reference>
  <reference anchor="NIST.SP.800-38E" target="http://dx.doi.org/10.6028/NIST.SP.800-38E">
  <front>
    <title>NIST Special Publication 800-38E: Recommendation for Block Cipher Modes of Operation: the XTS-AES Mode for Confidentiality on Storage Devices</title>
    <author initials="M." surname="Dworkin" fullname="Morris Dworkin">
      <organization>National Institute of Standards and Technology</organization>
      <address>
        <postal>
          <street>100 Bureau Drive</street>
          <city>Gaithersburg</city>
          <region>MD</region>
          <code>20899-8930</code>
          <country>United States</country>
        </postal>
        <uri>http://www.nist.gov/</uri>
      </address>
    </author>
    <date month="January" year="2010"/>
  </front>
</reference>
  <reference anchor="OPENSSL" target="https://www.openssl.org">
  <front>
    <title>OpenSSL: Cryptography and SSL/TLS Toolkit</title>
    <author>
      <organization>OpenSSL Software Foundation</organization>
      <address>
        <postal>
          <street>20-22 Wenlock Road</street>
          <city>London</city>
          <code>N1 7GU</code>
          <country>United Kingdom</country>
        </postal>
        <phone>+44 17 8550 8015</phone>
        <email>info@opensslfoundation.org</email>
        <uri>https://www.openssl.org</uri>
      </address>
    </author>
    <date day="18" month="October" year="2017"/>
  </front>
</reference>
  <reference anchor="OSCCA" target="http://www.oscca.gov.cn">
  <front>
    <title>Organization of State Commercial Administration of China</title>
    <author>
      <organization>Organization of State Commercial Administration of China</organization>
      <address>
        <postal>
         <street>7 Dian Chang Lu, Fengtai Qu</street>
         <city>Beijing</city>
         <region>Beijing</region>
         <code>100036</code>
         <country>People's Republic of China</country>
        </postal>
        <phone>+86 (0)10 5970-3789</phone>
        <!--<email>contact@oscca.gov.cn</email>-->
        <uri>http://www.oscca.gov.cn</uri>
      </address>
    </author>
    <date month="May" year="2017"/>
  </front>
</reference>
  <reference anchor="SM4-AAEr" target="https://doi.org/10.1007/978-3-642-14423-3_6">
  <front>
    <title>Algebraic Cryptanalysis of SMS4: Gr&#246;bner Basis Attack and SAT Attack Compared</title>
    <author initials="J." surname="Erickson" fullname="Jeremy Erickson">
      <organization> The University of North Carolina at Chapel Hill</organization>
      <address>
        <postal>
          <street/>
          <city>Chapel Hill</city>
          <region>NC</region>
          <country>United States of America</country>
        </postal>
      </address>
    </author>
    <author initials="J." surname="Ding" fullname="Jintai Ding">
      <organization>Department of Mathematical Sciences</organization>
      <address>
        <postal>
          <street>University of Cincinnati</street>
          <city>Cincinnati</city>
          <region>OH</region>
          <code>45221</code>
          <country>United States of America</country>
        </postal>
      </address>
    </author>
    <author initials="C." surname="Christensen" fullname="Chris Christensen">
      <organization>Northern Kentucky University</organization>
      <address>
        <postal>
          <street/>
          <city/>
          <country>United States of America</country>
        </postal>
      </address>
    </author>
    <date year="2010"/>
  </front>
</reference>
  <reference anchor="SM4-AAJi" target="https://doi.org/10.1109/IAS.2009.171">
  <front>
    <title>Algebraic Attack to SMS4 and the Comparison with AES</title>
    <author initials="J." surname="Wen" fullname="Wen Ji">
      <organization>Beijing Electron. Sci. and Technol. Inst.</organization>
      <address>
        <postal>
          <street/>
          <city>Beijing</city>
          <country>China</country>
        </postal>
      </address>
    </author>
    <author initials="H." surname="Lei" fullname="Lei Hu">
      <organization>State Key Lab. of Inf. Security</organization>
      <address>
        <postal>
          <street>Graduate School of Chinese Academy of Sciences</street>
          <city>Beijing</city>
          <code>100049</code>
          <country>China</country>
        </postal>
      </address>
    </author>
    <author initials="H." surname="Ou" fullname="Haiwen Ou">
      <organization>Beijing Electron. Sci. and Technol. Inst.</organization>
      <address>
        <postal>
          <street/>
          <city>Beijing</city>
          <country>China</country>
        </postal>
      </address>
    </author>
    <date year="2009"/>
  </front>
</reference>
  <reference anchor="SM4-Details" target="http://ris.sic.gov.cn/EN/Y2016/V2/I11/995">
  <front>
    <title>Overview on SM4 Algorithm</title>
    <author initials="S." surname="Lu" fullname="Shuwang Lu">
      <organization>Data Assurance  Communication Security Center, Chinese Academy of Science</organization>
      <address>
        <postal>
          <street/>
          <city>Beijing</city>
          <code>100093</code>
          <country>People's Republic of China</country>
        </postal>
        <email>swlu@ustc.edu.cn</email>
      </address>
    </author>
    <author initials="B." surname="Su" fullname="Bozhan Su">
      <organization>State Key Laboratory of Cryptology</organization>
      <address>
        <postal>
          <street/>
          <city>Beijing</city>
          <code>100878</code>
          <country>People's Republic of China</country>
        </postal>
        <email>subozhan@163.com</email>
      </address>
    </author>
    <author initials="P." surname="Peng" fullname="Peng Wang">
      <organization>Institute of InformationEngineering, Chinese Academy of Science</organization>
      <address>
        <postal>
          <street/>
          <city>Beijing</city>
          <code>100093</code>
          <country>People's Republic of China</country>
        </postal>
        <email>wp@is.ac.cn</email>
      </address>
    </author>
    <author initials="Y." surname="Miao" fullname="Yingying Mao">
      <organization>Commercial Cryptography Testing Center</organization>
      <address>
        <postal>
          <street/>
          <city>Beijing</city>
          <code>100036</code>
          <country>People's Republic of China</country>
        </postal>
        <email>maoyy2000@163.com</email>
      </address>
    </author>
    <author initials="L." surname="Huo" fullname="Lili Huo">
      <organization>Commercial Cryptography Testing Center</organization>
      <address>
        <postal>
          <street/>
          <city>Beijing</city>
          <code>100093</code>
          <country>People's Republic of China</country>
        </postal>
        <email>lily.home.hao@163.com</email>
      </address>
    </author>
    <date day="25" month="October" year="2016"/>
  </front>
</reference>
  <reference anchor="SM4-DiffSu" target="https://doi.org/10.1007/s11390-011-9420-y">
  <front>
    <title>Security of the SMS4 Block Cipher Against Differential Cryptanalysis</title>
    <author initials="B." surname="Su" fullname="Bozhan Su">
      <organization>State Key Laboratory of Information Security, Institute of Information Engineering, Chinese Academy of Sciences</organization>
      <address>
        <postal>
          <street>Institute of Software, Chinese Academy of Sciences</street>
          <street>4 South Fourth Street</street>
          <city>Zhong Guan Cun</city>
          <region>Beijing</region>
          <code>100190</code>
          <country>People's Republic of China</country>
        </postal>
        <email>subozhan@is.iscas.ac.cn</email>
        <uri>http://www.is.cas.cn/</uri>
      </address>
    </author>
    <author initials="W." surname="Wu" fullname="Wenling Wu">
      <organization>State Key Laboratory of Information Security, Institute of Information Engineering, Chinese Academy of Sciences</organization>
      <address>
        <postal>
          <street>Institute of Software, Chinese Academy of Sciences</street>
          <street>4 South Fourth Street</street>
          <city>Zhong Guan Cun</city>
          <region>Beijing</region>
          <code>100190</code>
          <country>People's Republic of China</country>
        </postal>
        <uri>http://www.is.cas.cn/</uri>
      </address>
    </author>
    <author initials="W." surname="Zhang" fullname="Wentao Zhang">
      <organization>State Key Laboratory of Information Security, Institute of Information Engineering, Chinese Academy of Sciences</organization>
      <address>
        <postal>
          <street>Institute of Software, Chinese Academy of Sciences</street>
          <street>4 South Fourth Street</street>
          <city>Zhong Guan Cun</city>
          <region>Beijing</region>
          <code>100190</code>
          <country>People's Republic of China</country>
        </postal>
        <uri>http://www.is.cas.cn/</uri>
      </address>
    </author>
    <date day="11" month="January" year="2011"/>
  </front>
</reference>
  <reference anchor="SM4-DiffZhang1" target="https://doi.org/10.1007/978-3-540-70500-0_16">
  <front>
    <title>Cryptanalysis of Reduced-Round SMS4 Block Cipher</title>
    <author initials="L." surname="Zhang" fullname="Lei Zhang">
      <organization>State Key Laboratory of Information Security, Institute of Information Engineering, Chinese Academy of Sciences</organization>
      <address>
        <postal>
          <street>Institute of Software, Chinese Academy of Sciences</street>
          <street>4 South Fourth Street</street>
          <city>Zhong Guan Cun</city>
          <region>Beijing</region>
          <code>100190</code>
          <country>People's Republic of China</country>
        </postal>
        <email>zhanglei1015@is.iscas.ac.cn</email>
        <uri>http://www.is.cas.cn/</uri>
      </address>
    </author>
    <author initials="W." surname="Zhang" fullname="Wentao Zhang">
      <organization>State Key Laboratory of Information Security, Institute of Information Engineering, Chinese Academy of Sciences</organization>
      <address>
        <postal>
          <street>Institute of Software, Chinese Academy of Sciences</street>
          <street>4 South Fourth Street</street>
          <city>Zhong Guan Cun</city>
          <region>Beijing</region>
          <code>100190</code>
          <country>People's Republic of China</country>
        </postal>
        <email>zhangwt06@yahoo.com</email>
        <uri>http://www.is.cas.cn/</uri>
      </address>
    </author>
    <author initials="W." surname="Wu" fullname="Wenling Wu">
      <organization>State Key Laboratory of Information Security, Institute of Information Engineering, Chinese Academy of Sciences</organization>
      <address>
        <postal>
          <street>Institute of Software, Chinese Academy of Sciences</street>
          <street>4 South Fourth Street</street>
          <city>Zhong Guan Cun</city>
          <region>Beijing</region>
          <code>100190</code>
          <country>People's Republic of China</country>
        </postal>
        <email>wwl@is.iscas.ac.cn</email>
        <uri>http://www.is.cas.cn/</uri>
      </address>
    </author>
    <date day="7" month="July" year="2008"/>
  </front>
</reference>
  <reference anchor="SM4-DiffZhang2" target="https://doi.org/10.1007/978-3-642-00843-6_28">
  <front>
    <title>Some New Observations on the SMS4 Block Cipher in the Chinese WAPI Standard</title>
    <author initials="W." surname="Zhang" fullname="Wentao Zhang">
      <organization>State Key Laboratory of Information Security, Institute of Information Engineering, Chinese Academy of Sciences</organization>
      <address>
        <postal>
          <street>Institute of Software, Chinese Academy of Sciences</street>
          <street>4 South Fourth Street</street>
          <city>Zhong Guan Cun</city>
          <region>Beijing</region>
          <code>100190</code>
          <country>People's Republic of China</country>
        </postal>
        <email>zhangwt06@yahoo.com</email>
        <uri>http://www.is.cas.cn/</uri>
      </address>
    </author>
    <author initials="W." surname="Wu" fullname="Wenling Wu">
      <organization>State Key Laboratory of Information Security, Institute of Information Engineering, Chinese Academy of Sciences</organization>
      <address>
        <postal>
          <street>Institute of Software, Chinese Academy of Sciences</street>
          <street>4 South Fourth Street</street>
          <city>Zhong Guan Cun</city>
          <region>Beijing</region>
          <code>100190</code>
          <country>People's Republic of China</country>
        </postal>
        <email>wwl@is.iscas.ac.cn</email>
        <uri>http://www.is.cas.cn/</uri>
      </address>
    </author>
    <author initials="D." surname="Feng" fullname="Dengguo Feng">
      <organization>State Key Laboratory of Information Security, Institute of Information Engineering, Chinese Academy of Sciences</organization>
      <address>
        <postal>
          <street>Institute of Software, Chinese Academy of Sciences</street>
          <street>4 South Fourth Street</street>
          <city>Zhong Guan Cun</city>
          <region>Beijing</region>
          <code>100190</code>
          <country>People's Republic of China</country>
        </postal>
        <uri>http://www.is.cas.cn/</uri>
      </address>
    </author>
    <author initials="B." surname="Su" fullname="Bozhan Su">
      <organization>State Key Laboratory of Information Security, Institute of Information Engineering, Chinese Academy of Sciences</organization>
      <address>
        <postal>
          <street>Institute of Software, Chinese Academy of Sciences</street>
          <street>4 South Fourth Street</street>
          <city>Zhong Guan Cun</city>
          <region>Beijing</region>
          <code>100190</code>
          <country>People's Republic of China</country>
        </postal>
        <uri>http://www.is.cas.cn/</uri>
      </address>
    </author>
    <date year="2009"/>
  </front>
</reference>
  <reference anchor="SM4-DiffZhang3" target="http://www.airitilibrary.com/Publication/alDetailedMesh?docid=05296579-201003-201004120040-201004120040-43-47">
  <!-- &#24352;&#32654;&#29618;&#65292;&#21016;&#26223;&#32654;&#65292;&#29579;&#26032;&#26757;.22-&#36718;SM4&#30340;&#24046;&#20998;&#20998;&#26512;[J].&#20013; &#23665;&#22823;&#23398;&#23398;&#25253;&#65306;&#33258;&#28982;&#31185;&#23398;&#29256;&#65292;2010&#65292;49(2): 43-47 -->
  <front>
    <title>22-Round SMS4 Differential Cryptanalysis</title>
    <author initials="M." surname="Zhang" fullname="Meiling Zhang">
      <organization>National Key Lab of Integrated Service Networks</organization>
      <address>
        <postal>
          <street>Xidian University</street>
          <city>Xi'an</city>
          <code>710071</code>
          <country>China</country>
        </postal>
      </address>
    </author>
    <author initials="J." surname="Liu" fullname="Jingmei Liu">
      <organization>National Key Lab of Integrated Service Networks</organization>
      <address>
        <postal>
          <street>Xidian University</street>
          <city>Xi'an</city>
          <code>710071</code>
          <country>China</country>
        </postal>
      </address>
    </author>
    <author initials="X." surname="Wang" fullname="Xinmei Wang">
      <organization>National Key Lab of Integrated Service Networks</organization>
      <address>
        <postal>
          <street>Xidian University</street>
          <city>Xi'an</city>
          <code>710071</code>
          <country>China</country>
        </postal>
      </address>
    </author>
    <date year="2010"/>
  </front>
</reference>
  <reference anchor="SM4-En" target="https://www.iacr.org/cryptodb/data/paper.php?pubkey=18006">
  <front>
    <!-- https://www.iacr.org/cryptodb/data/paper.php?pubkey=18006 -->
    <title>SMS4 Encryption Algorithm for Wireless Networks</title>
    <author initials="W." surname="Diffie" fullname="Whitfield Diffie">
      <organization>Sun Microsystems</organization>
      <address>
        <postal>
          <street>4150 Network Circle</street>
          <city>Santa Clara</city>
          <region>CA</region>
          <code>95054</code>
          <country>United States of America</country>
        </postal>
        <email>whitfielddiffie@gmail.com</email>
        <uri>https://cisac.fsi.stanford.edu/</uri>
      </address>
    </author>
    <author initials="G." surname="Ledin" fullname="George Ledin">
      <organization>Sonoma State University</organization>
      <address>
        <postal>
          <street>Darwin 116, 1801 East Cotati Ave.</street>
          <city>Rohnert Park</city>
          <region>CA</region>
          <code>94928</code>
          <country>United States of America</country>
        </postal>
        <email>george.ledin@sonoma.edu</email>
        <uri>http://www.cs.sonoma.edu/</uri>
      </address>
    </author>
    <date day="15" month="May" year="2008"/>
  </front>
</reference>
  <reference anchor="SM4-FPGA" target="https://www.researchgate.net/publication/287081686_Improvements_of_SM4_algorithm_and_application_in_Ethernet_encryption_system_based_on_FPGA">
  <front>
    <!-- article{article,
    author = {Cheng, H and Zhai, S and Fang, L and Ding, Q and Huang, C},
    year = {2014},
    month = {07},
    pages = {518-526},
    title = {Improvements of SM4 algorithm and application in Ethernet encryption system based on FPGA},
    volume = {5},
    booktitle = {Journal of Information Hiding and Multimedia Signal Processing}
    } -->
    <!-- Cryptology ePrint Archive, Report 2013/626 -->
    <title>Improvements of SM4 Algorithm and Application in Ethernet Encryption System Based on FPGA</title>
    <author initials="H." surname="Cheng" fullname="Hai Cheng">
      <organization>Key Laboratory of Electronic Engineering, University of Heilongjiang</organization>
      <address>
        <postal>
          <street>74 Xuefu Road</street>
          <city>Harbin</city>
          <region>Heilongjiang</region>
          <code>150080</code>
          <country>People's Republic of China</country>
        </postal>
        <email>chengh@hlju.edu.cn</email>
        <uri>httphttp://www.hlju.edu.cn/</uri>
      </address>
    </author>
    <author initials="S." surname="Zhai" fullname="Shuxia Zhai">
      <organization>Key Laboratory of Electronic Engineering, University of Heilongjiang</organization>
      <address>
        <postal>
          <street>74 Xuefu Road</street>
          <city>Harbin</city>
          <region>Heilongjiang</region>
          <code>150080</code>
          <country>People's Republic of China</country>
        </postal>
        <uri>httphttp://www.hlju.edu.cn/</uri>
      </address>
    </author>
    <author initials="L." surname="Fang" fullname="Lianzhong Fang">
      <organization>Key Laboratory of Electronic Engineering, University of Heilongjiang</organization>
      <address>
        <postal>
          <street>74 Xuefu Road</street>
          <city>Harbin</city>
          <region>Heilongjiang</region>
          <code>150080</code>
          <country>People's Republic of China</country>
        </postal>
        <email>chengh@hlju.edu.cn</email>
        <uri>httphttp://www.hlju.edu.cn/</uri>
      </address>
    </author>
    <author initials="Q." surname="Ding" fullname="Qun Ding">
      <organization>Key Laboratory of Electronic Engineering, University of Heilongjiang</organization>
      <address>
        <postal>
          <street>74 Xuefu Road</street>
          <city>Harbin</city>
          <region>Heilongjiang</region>
          <code>150080</code>
          <country>People's Republic of China</country>
        </postal>
        <email>qunding@aliyun.cn</email>
        <uri>httphttp://www.hlju.edu.cn/</uri>
      </address>
    </author>
    <author initials="C." surname="Huang" fullname="Chunguang Huang">
      <organization>Key Laboratory of Electronic Engineering, University of Heilongjiang</organization>
      <address>
        <postal>
          <street>74 Xuefu Road</street>
          <city>Harbin</city>
          <region>Heilongjiang</region>
          <code>150080</code>
          <country>People's Republic of China</country>
        </postal>
        <email>chenghdahuangr@163.com</email>
        <uri>http://www.hlju.edu.cn/</uri>
      </address>
    </author>
    <date day="01" month="July" year="2014"/>
  </front>
</reference>
  <reference anchor="SM4-HiSpeed" target="http://dx.doi.org/10.14257/ijsia.2016.10.9.01">
<!-- International Journal of Security and its Applications
Vol. 10, No. 9 (2016), pp.1-8
http://dx.doi.org/10.14257/ijsia.2016.10.9.01 -->
  <front>
    <title>High-speed Encryption  Decryption System Based on SM4</title>
    <author initials="Q." surname="Lv" fullname="Qian Lv">
      <organization>Binzhou Polytechnic</organization>
      <address>
        <postal>
          <street>391 Huanghe Road</street>
          <city>Binzhou</city>
          <region>Shandong</region>
          <code>256600</code>
          <country>People's Republic of China</country>
        </postal>
        <email>ihappylucy@outlook.com</email>
        <uri>http://www.bzu.edu.cn/</uri>
      </address>
    </author>
    <author initials="L." surname="Li" fullname="Li Li">
      <organization>Binzhou Polytechnic</organization>
      <address>
        <postal>
          <street>391 Huanghe Road</street>
          <city>Binzhou</city>
          <region>Shandong</region>
          <code>256600</code>
          <country>People's Republic of China</country>
        </postal>
        <email>lili_thesky@163.com</email>
        <uri>http://www.bzu.edu.cn/</uri>
      </address>
    </author>
    <author initials="Y." surname="Cao" fullname="Yan-yan Cao">
      <organization>Binzhou Polytechnic</organization>
      <address>
        <postal>
          <street>391 Huanghe Road</street>
          <city>Binzhou</city>
          <region>Shandong</region>
          <code>256600</code>
          <country>People's Republic of China</country>
        </postal>
        <email>yaya_sd@163.com</email>
        <uri>http://www.bzu.edu.cn/</uri>
      </address>
    </author>
    <date day="22" month="July" year="2016"/>
  </front>
</reference>
  <reference anchor="SM4-ICLiu" target="https://doi.org/10.1007/978-3-540-73458-1_13">
  <front>
    <title>Analysis of the SMS4 Block Cipher</title>
    <author initials="F." surname="Liu" fullname="Fen Liu">
      <organization>State Key Laboratory of Information Security</organization>
      <address>
        <postal>
          <street>Graduate School of Chinese Academy of Sciences</street>
          <city>Beijing</city>
          <code>100049</code>
          <country>China</country>
        </postal>
      </address>
    </author>
    <author initials="W." surname="Ji" fullname="Wen Ji">
      <organization>State Key Laboratory of Information Security</organization>
      <address>
        <postal>
          <street>Graduate School of Chinese Academy of Sciences</street>
          <city>Beijing</city>
          <code>100049</code>
          <country>China</country>
        </postal>
      </address>
    </author>
    <author initials="L." surname="Hu" fullname="Lei Hu">
      <organization>State Key Laboratory of Information Security</organization>
      <address>
        <postal>
          <street>Graduate School of Chinese Academy of Sciences</street>
          <city>Beijing</city>
          <code>100049</code>
          <country>China</country>
        </postal>
      </address>
    </author>
    <author initials="J." surname="Ding" fullname="Jintai Ding">
      <organization>Department of Mathematical Sciences</organization>
      <address>
        <postal>
          <street>University of Cincinnati</street>
          <city>Cincinnati</city>
          <region>OH</region>
          <code>45221</code>
          <country>USA</country>
        </postal>
        <email/>
      </address>
    </author>
    <author initials="S." surname="Lv" fullname="Shuwang Lv">
      <organization>State Key Laboratory of Information Security</organization>
      <address>
        <postal>
          <street>Graduate School of Chinese Academy of Sciences</street>
          <city>Beijing</city>
          <code>100049</code>
          <country>China</country>
        </postal>
      </address>
    </author>
    <author initials="A." surname="Pyshkin" fullname="Andrei Pyshkin">
      <organization>Fachbereich Informatik</organization>
      <address>
        <postal>
          <street>Technische Universit&#228;t Darmstadt</street>
          <city>Darmstadt</city>
          <code>64289</code>
          <country>Germany</country>
        </postal>
        <email/>
      </address>
    </author>
    <author initials="R.P." surname="Weinmann" fullname="Ralf-Philipp Weinmann">
      <organization>Fachbereich Informatik</organization>
      <address>
        <postal>
          <street>Technische Universit&#228;t Darmstadt</street>
          <city>Darmstadt</city>
          <code>64289</code>
          <country>Germany</country>
        </postal>
        <email/>
      </address>
    </author>
    <date year="2007"/>
  </front>
</reference>
  <reference anchor="SM4-ICZhong" target="http://www.cnki.com.cn/Article/CJFDTotal-XDKD200801019.htm">
  <!-- [26] &#38047;&#21517;&#23500;&#65292;&#32993;&#20104;&#28654;&#65292;&#38472;&#26480;.&#20998;&#32452;&#23494;&#30721;&#31639;&#27861;SM4&#30340;14&#36718; Square&#25915;&#20987;[J].&#35199;&#23433;&#30005;&#23376;&#31185;&#25216;&#22823;&#23398;&#23398;&#25253;&#65306;&#33258;&#28982;&#31185;&#23398;&#29256;&#65292; 2008, 35(1)&#65306; 105-109 -->
  <front>
    <title>14-Round Square Attack on Blockcipher SMS4</title>
    <author initials="M." surname="Zhong" fullname="Mingfu Zhong">
      <organization>Computer Network and Information Security Ministry of Education Key Laboratory</organization>
      <address>
        <postal>
          <street>Xidian University</street>
          <country>People's Republic of China</country>
        </postal>
      </address>
    </author>
    <author initials="Y." surname="Hu" fullname="Yupou Hu">
      <organization>Computer Network and Information Security Ministry of Education Key Laboratory</organization>
      <address>
        <postal>
          <street>Xidian University</street>
          <country>People's Republic of China</country>
        </postal>
      </address>
    </author>
    <author initials="J." surname="Chen" fullname="Jie Chen">
      <organization>Computer Network and Information Security Ministry of Education Key Laboratory</organization>
      <address>
        <postal>
          <street>Xidian University</street>
          <country>People's Republic of China</country>
        </postal>
      </address>
    </author>
    <date year="2008"/>
  </front>
</reference>
  <reference anchor="SM4-IDCLu" target="https://doi.org/10.1007/978-3-540-77048-0_24">
  <front>
    <title>Attacking Reduced-Round Versions of the SMS4 Block Cipher in the Chinese WAPI Standard</title>
    <author initials="J." surname="Lu" fullname="Jiqiang Lu">
      <organization>University of London, Information Security Group</organization>
      <address>
        <postal>
          <street>Royal Holloway</street>
          <city>Egham</city>
          <region>Surrey</region>
          <code>TW20 0EXUK</code>
          <country>United Kingdom</country>
        </postal>
      </address>
    </author>
    <date year="2007"/>
  </front>
</reference>
  <reference anchor="SM4-IDCToz" target="https://doi.org/10.1007/978-3-540-88625-9_10">
  <front>
    <title>Analysis of Two Attacks on Reduced-Round Versions of the SMS4</title>
    <author initials="D." surname="Toz" fullname="Deniz Toz">
      <organization>Institute of Applied Mathematics</organization>
      <address>
        <postal>
          <street>Middle East Technical University</street>
          <city>Ankara</city>
          <country>Turkey</country>
        </postal>
      </address>
    </author>
    <author initials="O." surname="Dunkelman" fullname="Orr Dunkelman">
      <organization>Department of Electronical Engineering ESAT SDC-COSIC and Interdisciplinary Institute for BroadBand Technology</organization>
      <address>
        <postal>
          <street>Katholieke Universiteit Leuven</street>
          <city>Leuven-Heverlee</city>
          <country>Belgium</country>
        </postal>
      </address>
    </author>
    <date year="2008"/>
  </front>
</reference>
  <reference anchor="SM4-IDCWang" target="http://ieeexplore.ieee.org/document/5629201/">
  <front>
    <title>Improved Impossible Differential Cryptanalysis on SMS4</title>
    <author initials="G." surname="Wang" fullname="Gaoli Wang">
      <organization>School of Computer Science and Technology</organization>
      <address>
        <postal>
          <street>Donghua University</street>
          <city>Shanghai</city>
          <country>China</country>
        </postal>
      </address>
    </author>
    <date month="October" day="13" year="2010"/>
  </front>
</reference>
  <reference anchor="SM4-LDA" target="https://eprint.iacr.org/2008/281">
  <front>
    <!-- Cryptology ePrint Archive, Report 2008/281 -->
    <title>Linear and Differential Cryptanalysis of Reduced SMS4 Block Cipher</title>
    <author initials="T." surname="Kim" fullname="Taehyun Kim">
      <organization>Center for Information Security Technologies (CIST), Korea University</organization>
      <address>
        <postal>
          <street>Room 615, International Center for Conversing Technology Building</street>
          <street>Anam Campus(Science), Korea University</street>
          <street>145 Anam-ro</street>
          <city>Seongbuk-gu</city>
          <region>Seoul</region>
          <code>02841</code>
          <country>Republic of Korea</country>
        </postal>
        <email>kimth714@cist.korea.ac.kr</email>
        <uri>http://gss.korea.edu/</uri>
      </address>
    </author>
    <author initials="J." surname="Kim" fullname="Jongsung Kim">
      <organization>Center for Information Security Technologies (CIST), Korea University</organization>
      <address>
        <postal>
          <street>Room 615, International Center for Conversing Technology Building</street>
          <street>Anam Campus(Science), Korea University</street>
          <street>145 Anam-ro</street>
          <city>Seongbuk-gu</city>
          <region>Seoul</region>
          <code>02841</code>
          <country>Republic of Korea</country>
        </postal>
        <email>joshep@cist.korea.ac.kr</email>
        <uri>http://gss.korea.edu/</uri>
      </address>
    </author>
    <author initials="S." surname="Kim" fullname="Seokhie Kim">
      <organization>Center for Information Security Technologies (CIST), Korea University</organization>
      <address>
        <postal>
          <street>Room 615, International Center for Conversing Technology Building</street>
          <street>Anam Campus(Science), Korea University</street>
          <street>145 Anam-ro</street>
          <city>Seongbuk-gu</city>
          <region>Seoul</region>
          <code>02841</code>
          <country>Republic of Korea</country>
        </postal>
        <email>hsh@cist.korea.ac.kr</email>
        <uri>http://gss.korea.edu/</uri>
      </address>
    </author>
    <author initials="J." surname="Sung" fullname="Jaechul Sung">
      <organization>Department of Mathematics, University of Seoul</organization>
      <address>
        <postal>
          <street>Department of Mathematical Sciences</street>
          <street>Seoul National University</street>
          <street>1 Gwan Ak-ro</street>
          <city>Gwanak-gu</city>
          <region>Seoul</region>
          <code>08826</code>
          <country>Republic of Korea</country>
        </postal>
        <email>jcsung@uos.ac.kr</email>
        <uri>http://uos.ac.kr/</uri>
      </address>
    </author>
    <date day="22" month="June" year="2008"/>
  </front>
</reference>
  <reference anchor="SM4-LinearDong" target="http://kns.cnki.net/KCMS/detail/detail.aspx?dbcode=CDFD&amp;dbname=CDFD1214&amp;filename=1013114416.nh">
  <front>
    <title>Security Analysis of the blockciphers AES and SM4</title>
    <author initials="X." surname="Dong" fullname="Xiaoli Dong">
      <organization>Xidian University</organization>
      <address>
        <postal>
          <street/>
          <city>Xian</city>
          <country>China</country>
        </postal>
      </address>
    </author>
    <date year="2011"/>
  </front>
</reference>
  <reference anchor="SM4-LinearEtrog" target="https://doi.org/10.1007/978-3-642-04159-4_4">
  <front>
    <title>The Cryptanalysis of Reduced-Round SMS4</title>
    <author initials="J." surname="Etrog" fullname="Jonathan Etrog">
      <organization>Orange Labs</organization>
      <address>
        <postal>
          <street>Issy les Moulineaux</street>
          <city>Cedex</city>
          <country>France</country>
        </postal>
      </address>
    </author>
    <author initials="M." surname="Robshaw" fullname="Matt J.B. Robshaw">
      <organization>Orange Labs</organization>
      <address>
        <postal>
          <street>Issy les Moulineaux</street>
          <city>Cedex</city>
          <country>France</country>
        </postal>
      </address>
    </author>
    <date year="2009"/>
  </front>
</reference>
  <reference anchor="SM4-LinearLiu" target="https://doi.org/10.1007/s11390-014-1495-9">
  <front>
    <!-- Journal of Computer Science and Technology, November 2014, Volume 29, Issue 6, pp 1123&#8211;1133 -->
    <title>Improved Linear Attacks on the Chinese Block Cipher Standard</title>
    <author initials="M." surname="Liu" fullname="Mingjie Liu">
      <organization>Beijing International Center for Mathematical Research, Peking University</organization>
      <address>
        <postal>
          <street>5 Yiheyuan Road Haidian District</street>
          <city>Beijing</city>
          <code>100871</code>
          <country>People's Republic of China</country>
        </postal>
        <email>liumj9705@pku.edu.cn</email>
        <uri>http://www.bicmr.org</uri>
      </address>
    </author>
    <author initials="J." surname="Chen" fullname="Jiazhe Chen">
      <organization>China Information Technology Security Evaluation Center</organization>
      <address>
        <postal>
          <street>Building 1, No.8, Shangdi West Road, Haidian District</street>
          <city>Beijing</city>
          <code>100085</code>
          <country>People's Republic of China</country>
        </postal>
        <email>jiazhechen@gmail.com</email>
        <uri>http://www.itsec.gov.cn</uri>
      </address>
    </author>
    <date day="17" month="November" year="2014"/>
  </front>
</reference>
  <reference anchor="SM4-MLCho" target="https://scholar.google.com.hk/scholar?cluster=13432379689578293076">
  <front>
    <title>Improved linear cryptanalysis of SM4 block cipher</title>
    <author initials="J.Y." surname="Cho">
      <address>
        <postal>
          <street/>
          <city>Vienna</city>
          <country>Austria</country>
        </postal>
      </address>
    </author>
    <author initials="K." surname="Nyberg">
      <address>
        <postal>
          <street/>
          <city>Vienna</city>
          <country>Austria</country>
        </postal>
      </address>
    </author>
    <date year="2010"/>
  </front>
</reference>
  <reference anchor="SM4-MLLiu" target="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.215.8314">
  <front>
    <title>Multiple Linear Cryptanalysis of Reduced-Round SMS4 Block Cipher</title>
    <author initials="L." surname="Zhiqiang" fullname="Liu Zhiqiang">
      <organization>Department of Computer Science and Engineering</organization>
      <address>
        <postal>
          <street>Shanghai Jiao Tong University</street>
          <city>Shanghai</city>
          <code>200240</code>
          <country>China</country>
        </postal>
        <email>ilu_zq@sjtu.edu.cn</email>
      </address>
    </author>
    <author initials="G." surname="Dawu" fullname="Gu Dawu">
      <organization>Department of Computer Science and Engineering</organization>
      <address>
        <postal>
          <street>Shanghai Jiao Tong University</street>
          <city>Shanghai</city>
          <code>200240</code>
          <country>China</country>
        </postal>
      </address>
    </author>
    <author initials="Z." surname="Jing" fullname="Zhang Jing">
      <organization>Department of Computer Science and Engineering</organization>
      <address>
        <postal>
          <street>Shanghai Jiao Tong University</street>
          <city>Shanghai</city>
          <code>200240</code>
          <country>China</country>
        </postal>
      </address>
    </author>
    <date year="2010"/>
  </front>
</reference>
  <reference anchor="SM4-MatrixShe" target="http://cdmd.cnki.com.cn/Article/CDMD-10422-1012464969.htm">
  <!-- &#34203;&#33805;.&#20998;&#32452;&#23494;&#30721;&#31639;&#27861;SMS4&#30340;&#30697;&#24418;&#25915;&#20987;[D].&#27982;&#21335;&#65306;&#23665;&#19996;&#22823;&#23398;&#65292;2012 -->
  <front>
    <title>Matrix Attack On Blockcipher SMS4</title>
    <author initials="S." surname="Ping" fullname="She Ping">
      <organization>Shandong University</organization>
      <address>
        <postal>
          <street/>
          <city>Jinan</city>
          <region>Shandong</region>
          <country>China</country>
        </postal>
      </address>
    </author>
    <date year="2012"/>
  </front>
</reference>
  <reference anchor="SM4-MatrixWei" target="http://www.cnki.com.cn/Article/CJFDTotal-CDDD201202017.htm">
  <!-- [30] &#39759;&#33322;&#65292;&#23828;&#20250;&#20029;&#65292;&#21525;&#26195;&#24198;.SM4&#20998;&#32452;&#23494;&#30721;&#31639;&#27861;&#30340;&#24046;&#20998;-&#20195;&#25968;&#20998;&#26512;[J].&#25104;&#37117;&#22823;&#23398;&#23398;&#25253;&#65306;&#33258;&#28982;&#31185;&#23398;&#29256;&#65292;2012, 31(2): 158-160 -->
  <front>
    <title>Differential-Algebraic Analysis of the SMS4 Block Cipher</title>
    <author initials="H" surname="Wei" fullname="Hang Wei">
      <organization>Chengdu University of Technology</organization>
    </author>
    <author initials="H." surname="Cui" fullname="Huili Cui">
      <organization>Chengdu University of Technology</organization>
    </author>
    <author initials="X." surname="Lu" fullname="Xiaoxing Lu">
      <organization>Chengdu University of Technology</organization>
    </author>
    <date year="2012"/>
  </front>
</reference>
  <reference anchor="SM4-NLC" target="https://doi.org/10.1155/2017/1461520">
  <front>
    <title>New Linear Cryptanalysis of Chinese Commercial Block Cipher Standard SM4</title>
    <author initials="Y." surname="Liu" fullname="Yu Liu">
      <organization>Key Laboratory of Cryptologic Technology and Information Security, Ministry of Education, Shandong University</organization>
      <address>
        <postal>
         <street>27 Shan Da Nan Lu, Licheng Qu</street>
         <city>Jinan</city>
         <region>Shandong</region>
         <code>250100</code>
         <country>People's Republic of China</country>
        </postal>
      </address>
    </author>
    <author initials="H." surname="Liang" fullname="Huicong Liang">
      <organization>Key Laboratory of Cryptologic Technology and Information Security, Ministry of Education, Shandong University</organization>
      <address>
        <postal>
         <street>27 Shan Da Nan Lu, Licheng Qu</street>
         <city>Jinan</city>
         <region>Shandong</region>
         <code>250100</code>
         <country>People's Republic of China</country>
        </postal>
      </address>
    </author>
    <author initials="W." surname="Wang" fullname="Wei Wang">
      <organization>Key Laboratory of Cryptologic Technology and Information Security, Ministry of Education, Shandong University</organization>
      <address>
        <postal>
         <street>27 Shan Da Nan Lu, Licheng Qu</street>
         <city>Jinan</city>
         <region>Shandong</region>
         <code>250100</code>
         <country>People's Republic of China</country>
        </postal>
      </address>
    </author>
    <author initials="M." surname="Wang" fullname="Meiqin Wang">
      <organization>Key Laboratory of Cryptologic Technology and Information Security, Ministry of Education, Shandong University</organization>
      <address>
        <postal>
         <street>27 Shan Da Nan Lu, Licheng Qu</street>
         <city>Jinan</city>
         <region>Shandong</region>
         <code>250100</code>
         <country>People's Republic of China</country>
        </postal>
        <email>mqwang@sdu.edu.cn</email>
      </address>
    </author>
    <date day="8" month="June" year="2017"/>
  </front>
</reference>
  <reference anchor="SM4-Power" target="http://dx.doi.org/10.6028/NIST.FIPS.180-4">
  <front>
    <!-- Journal on Communications Vol. 36 No 10. -->
    <title>Improved chosen-plaintext power analysis attack against SM4 at the round-output</title>
    <author initials="Z." surname="Du" fullname="Zhibo Du">
      <organization>College of Information Security Engineering, Chengdu University of Information Technology</organization>
      <address>
        <postal>
          <street>Block 1, 24 Xuefu Road</street>
          <city>Chengdu</city>
          <region>MD</region>
          <code>610225</code>
          <country>China</country>
        </postal>
        <uri>http://www.cuit.edu.cn/</uri>
      </address>
    </author>
    <author initials="Z." surname="Wu" fullname="Zhen Wu">
      <organization>College of Information Security Engineering, Chengdu University of Information Technology</organization>
      <address>
        <postal>
          <street>Block 1, 24 Xuefu Road</street>
          <city>Chengdu</city>
          <region>MD</region>
          <code>610225</code>
          <country>China</country>
        </postal>
        <uri>http://www.cuit.edu.cn/</uri>
      </address>
    </author>
    <author initials="M." surname="Wang" fullname="Min Wang">
      <organization>College of Information Security Engineering, Chengdu University of Information Technology</organization>
      <address>
        <postal>
          <street>Block 1, 24 Xuefu Road</street>
          <city>Chengdu</city>
          <region>MD</region>
          <code>610225</code>
          <country>China</country>
        </postal>
        <uri>http://www.cuit.edu.cn/</uri>
      </address>
    </author>
    <author initials="J." surname="Rao" fullname="Jin-tao Rao">
      <organization>College of Information Security Engineering, Chengdu University of Information Technology</organization>
      <address>
        <postal>
          <street>Block 1, 24 Xuefu Road</street>
          <city>Chengdu</city>
          <region>MD</region>
          <code>610225</code>
          <country>China</country>
        </postal>
        <uri>http://www.cuit.edu.cn/</uri>
      </address>
    </author>
    <date month="October" year="2015"/>
  </front>
</reference>
  <reference anchor="SM4-RKDC" target="http://doi.org/10.1007/978-3-319-49151-6_5">
  <front>
    <title>Security of SM4 Against (Related-Key) Differential Cryptanalysis</title>
    <author initials="J." surname="Zhang" fullname="Jian Zhang">
      <organization>Institute of Software, Chinese Academy of Sciences</organization>
      <address>
        <postal>
         <street>4 South Fourth Street, Zhong Guan Cun</street>
         <city>Beijing</city>
         <region>Beijing</region>
         <code>100190</code>
         <country>People's Republic of China</country>
        </postal>
        <email>zhangjian@tca.iscas.ac.cn</email>
      </address>
    </author>
    <author initials="W." surname="Wu" fullname="Wenling Wu">
      <organization>Institute of Software, Chinese Academy of Sciences</organization>
      <address>
        <postal>
         <street>4 South Fourth Street, Zhong Guan Cun</street>
         <city>Beijing</city>
         <region>Beijing</region>
         <code>100190</code>
         <country>People's Republic of China</country>
        </postal>
        <email>wwl@tca.iscas.ac.cn</email>
      </address>
    </author>
    <author initials="Y." surname="Zheng" fullname="Yafei Zheng">
      <organization>Institute of Software, Chinese Academy of Sciences</organization>
      <address>
        <postal>
         <street>4 South Fourth Street, Zhong Guan Cun</street>
         <city>Beijing</city>
         <region>Beijing</region>
         <code>100190</code>
         <country>People's Republic of China</country>
        </postal>
        <email>zhengyafei@tca.iscas.ac.cn</email>
      </address>
    </author>
    <date day="16" month="November" year="2016"/>
  </front>
</reference>
  <reference anchor="SM4-Random" target="http://www.cnki.com.cn/Article/CJFDTOTAL-JSJX200907008.htm">
  <!-- &#24352;&#31435;&#24311;&#65292;&#21556;&#25991;&#29618;.&#20351;&#29992;&#21387;&#32553;&#20989;&#25968;&#30340;&#38750;&#24179;&#34913;Feistel&#32467;&#26500;&#30340;&#20266;&#38543;&#26426;&#24615;&#21644;&#36229;&#20266;&#38543;&#26426;&#24615;[J].&#35745;&#31639;&#26426;&#23398;&#25253;&#65292;2009, 32(7): 1320-1330) -->
  <front>
    <title>Pseudorandomness and Super-pseudorandomness of a non-balanced Feistel Structure using compressed functions</title>
    <author initials="L." surname="Zhang" fullname="Liyen Zhang">
      <organization>State Key Laboratory of Information Security, Institute of Information Engineering, Chinese Academy of Sciences</organization>
      <address>
        <postal>
          <street>Institute of Software, Chinese Academy of Sciences</street>
          <street>4 South Fourth Street</street>
          <city>Zhong Guan Cun</city>
          <region>Beijing</region>
          <code>100190</code>
          <country>People's Republic of China</country>
        </postal>
        <email>liyen.zhang@is.cas.cn</email>
        <uri>http://www.is.cas.cn/</uri>
      </address>
    </author>
    <author initials="W." surname="Wu" fullname="Wenling Wu">
      <organization>State Key Laboratory of Information Security, Institute of Information Engineering, Chinese Academy of Sciences</organization>
      <address>
        <postal>
          <street>Institute of Software, Chinese Academy of Sciences</street>
          <street>4 South Fourth Street</street>
          <city>Zhong Guan Cun</city>
          <region>Beijing</region>
          <code>100190</code>
          <country>People's Republic of China</country>
        </postal>
        <uri>http://www.is.cas.cn/</uri>
      </address>
    </author>
    <date day="1" month="January" year="2009"/>
  </front>
</reference>
  <reference anchor="SM4-SLC" target="https://doi.org/10.1007/s11432-011-4448-8">
  <front>
    <title>Practical security against linear cryptanalysis for SMS4-like ciphers with SP round function</title>
    <author initials="B." surname="Zhang" fullname="Zhang Bin">
      <address>
        <postal>
          <street>PO. Box 1936</street>
          <city>Beijing</city>
          <code>100193</code>
          <country>China</country>
        </postal>
        <email>dzjszhangbin@126.com</email>
      </address>
    </author>
    <author initials="J." surname="Chenhui" fullname="Jin Chenhui">
      <organization>Electronic Technology Institute</organization>
      <address>
        <postal>
          <street>Information Engineering University</street>
          <city>Zhengzhou</city>
          <country>China</country>
        </postal>
      </address>
    </author>
    <date year="2012"/>
  </front>
</reference>
  <reference anchor="SM4-SLDC" target="http://www.ajetr.org/vol15/no1/n09.pdf">
  <front>
    <title>Practically Secure against Differential Cryptanalysis for Block Cipher SMS4</title>
    <author initials="M." surname="Zhang" fullname="Meiling Zhang">
      <organization>School of Communication and Information Engineering</organization>
      <address>
        <postal>
          <street>Xi'an University of Post and Telecommunications</street>
          <city>Xi'an</city>
          <country>China</country>
        </postal>
      </address>
    </author>
    <author initials="Y." surname="Liu" fullname="Yuanhua Liu">
      <organization>School of Communication and Information Engineering</organization>
      <address>
        <postal>
          <street>Xi'an University of Post and Telecommunications</street>
          <city>Xi'an</city>
          <country>China</country>
        </postal>
      </address>
    </author>
    <author initials="J." surname="Liu" fullname="Jingmei Liu">
      <organization>National Key Lab of Integrated Service Networks</organization>
      <address>
        <postal>
          <street>Xidian University</street>
          <city>Xi'an</city>
          <code>710071</code>
          <country>China</country>
        </postal>
      </address>
    </author>
    <author initials="X." surname="Min" fullname="Min Xiangshen">
      <organization>School of Communication and Information Engineering</organization>
      <address>
        <postal>
          <street>Xi'an University of Post and Telecommunications</street>
          <city>Xi'an</city>
          <country>China</country>
        </postal>
      </address>
    </author>
    <date year="2011"/>
  </front>
</reference>
  <reference anchor="SM4-Sbox" target="http://www.cnki.com.cn/Article/CJFDTotal-JSJC200805057.htm">
  <front>
    <title>Cryptographic Properties of S-box in SMS4</title>
    <author initials="J." surname="Liu" fullname="Jia Liu">
      <organization>Department of Electronic and Communications Engineering, Sun Yat-Sen University</organization>
      <address>
        <postal>
          <street>Building 3, Gezhi Yuan</street>
          <street>132 Outer Ring East Road</street>
          <street>University City </street>
          <street>Punyu District</street>
          <city>Guangzhou</city>
          <region>Guangdong</region>
          <code>510275</code>
          <country>People's Republic of China</country>
        </postal>
        <uri>http://sece.sysu.edu.cn</uri>
      </address>
    </author>
    <author initials="B." surname="Wei" fullname="Baodian Wei">
      <organization>Department of Electronic and Communications Engineering, Sun Yat-Sen University</organization>
      <address>
        <postal>
          <street>Building 3, Gezhi Yuan</street>
          <street>132 Outer Ring East Road</street>
          <street>University City </street>
          <street>Punyu District</street>
          <city>Guangzhou</city>
          <region>Guangdong</region>
          <code>510275</code>
          <country>People's Republic of China</country>
        </postal>
        <uri>http://sece.sysu.edu.cn</uri>
      </address>
    </author>
    <author initials="X." surname="Dai" fullname="Xianhua Dai">
      <organization>Department of Electronic and Communications Engineering, Sun Yat-Sen University</organization>
      <address>
        <postal>
          <street>Building 3, Gezhi Yuan</street>
          <street>132 Outer Ring East Road</street>
          <street>University City </street>
          <street>Punyu District</street>
          <city>Guangzhou</city>
          <region>Guangdong</region>
          <code>510275</code>
          <country>People's Republic of China</country>
        </postal>
        <uri>http://sece.sysu.edu.cn</uri>
      </address>
    </author>
    <date day="11" month="January" year="2011"/>
  </front>
</reference>
  <reference anchor="SM4-VLSI" target="https://doi.org/10.3233/JIFS-169011">
<!-- Journal of Intelligent & Fuzzy Systems 31 (2016) 795&#8211;803
DOI:10.3233/JIFS-169011
IOS Press -->
  <front>
    <title>A VLSI implementation of an SM4 algorithm resistant to power analysis</title>
    <author initials="S." surname="Yu" fullname="Siyang Yu">
      <organization>College of Information Science and Engineering, Hunan University</organization>
      <address>
        <postal>
          <street>Lushan Road S, Yuelu District</street>
          <city>Changsha</city>
          <region>Hunan</region>
          <code>410082</code>
          <country>People's Republic of China</country>
        </postal>
        <email>nickysy@hnu.edu.cn</email>
        <uri>http://www.hnu.edu.cn/</uri>
      </address>
    </author>
    <author initials="K." surname="Li" fullname="Kenli Li">
      <organization>Department of Computer Science, New Platz, State University of New York</organization>
      <address>
        <postal>
          <street>SUNY New Paltz, 1 Hawk Drive</street>
          <city>New Paltz</city>
          <region>NY</region>
          <code>12561</code>
          <country>United States of America</country>
        </postal>
        <uri>http://www.hnu.edu.cn/</uri>
      </address>
    </author>
    <author initials="K." surname="Li" fullname="Keqin Li">
      <organization>College of Information Science and Engineering, Hunan University</organization>
      <address>
        <postal>
          <street>Lushan Road S, Yuelu District</street>
          <city>Changsha</city>
          <region>Hunan</region>
          <code>410082</code>
          <country>People's Republic of China</country>
        </postal>
        <uri>http://www.hnu.edu.cn/</uri>
      </address>
    </author>
    <author initials="Y." surname="Qin" fullname="Yunchuan Qin">
      <organization>College of Information Science and Engineering, Hunan University</organization>
      <address>
        <postal>
          <street>Lushan Road S, Yuelu District</street>
          <city>Changsha</city>
          <region>Hunan</region>
          <code>410082</code>
          <country>People's Republic of China</country>
        </postal>
        <uri>http://www.hnu.edu.cn/</uri>
      </address>
    </author>
    <author initials="Z." surname="Tong" fullname="Zhao Tong">
      <organization>College of Mathematics and Computer Science, Performance Computing and Stochastic Information Processing, (Ministry of Education of China), Hunan Normal University</organization>
      <address>
        <postal>
          <street>36 Lushan Rd., Yuelu District</street>
          <city>Changsha</city>
          <region>Hunan</region>
          <code>410081</code>
          <country>People's Republic of China</country>
        </postal>
        <uri>http://www.hunnu.edu.cn/</uri>
      </address>
    </author>
    <date day="22" month="July" year="2016"/>
  </front>
</reference>
  <reference anchor="SM4-WhiteBox" target="http://dx.doi.org/10.1002/sec.1394">
  <!-- @article {SEC:SEC1394,
  author = {Bai, Kunpeng and Wu, Chuankun},
  title = {A secure white-box SM4 implementation},
  journal = {Security and Communication Networks},
  volume = {9},
  number = {10},
  issn = {1939-0122},
  url = {http://dx.doi.org/10.1002/sec.1394},
  doi = {10.1002/sec.1394},
  pages = {996-1006},
  keywords = {white-box cryptography, SM4, secure implementation, lookup tables, obfuscation},
  year = {2016},
  note = {sec.1394},
  } -->
  <front>
    <title>A secure white-box SM4 implementation</title>
    <author initials="K." surname="Bai" fullname="Kunpeng Bai">
      <organization>State Key Laboratory of Information Security, Institute of Information Engineering, Chinese Academy of Sciences</organization>
      <address>
        <postal>
          <street>Institute of Software, Chinese Academy of Sciences</street>
          <street>4 South Fourth Street</street>
          <city>Zhong Guan Cun</city>
          <region>Beijing</region>
          <code>100190</code>
          <country>People's Republic of China</country>
        </postal>
        <uri>http://www.is.cas.cn/</uri>
      </address>
    </author>
    <author initials="C." surname="Wu" fullname="Chuankun Wu">
      <organization>State Key Laboratory of Information Security, Institute of Information Engineering, Chinese Academy of Sciences</organization>
      <address>
        <postal>
          <street>Institute of Software, Chinese Academy of Sciences</street>
          <street>4 South Fourth Street</street>
          <city>Zhong Guan Cun</city>
          <region>Beijing</region>
          <code>100190</code>
          <country>People's Republic of China</country>
        </postal>
        <email>ckwu@iie.ac.cn</email>
        <uri>http://www.is.cas.cn/</uri>
      </address>
    </author>
    <date day="15" month="May" year="2008"/>
  </front>
</reference>
  <reference anchor="SM4-ZCLC" target="http://www.jcr.cacrnet.org.cn:8080/mmxb/CN/abstract/abstract105.shtml">
  <front>
    <title>Multidimensional Zero-correlation Linear Cryptanalysis on SMS4 Algorithm</title>
    <author initials="M." surname="Ma" fullname="Meng Ma">
      <organization>State Key Laboratory of Mathematical Engineering and Advanced Computing</organization>
      <address>
        <postal>
          <street>Information Engineering University</street>
          <city>Zhengzhou</city>
          <code>450001</code>
          <country>China</country>
        </postal>
      </address>
    </author>
    <author initials="Y." surname="Zhao" fullname="Yaqun Zhao">
      <organization>State Key Laboratory of Mathematical Engineering and Advanced Computing</organization>
      <address>
        <postal>
          <street>Information Engineering University</street>
          <city>Zhengzhou</city>
          <code>450001</code>
          <country>China</country>
        </postal>
      </address>
    </author>
    <author initials="Q." surname="Liu" fullname="Qingcong Liu">
      <organization>State Key Laboratory of Mathematical Engineering and Advanced Computing</organization>
      <address>
        <postal>
          <street>Information Engineering University</street>
          <city>Zhengzhou</city>
          <code>450001</code>
          <country>China</country>
        </postal>
      </address>
    </author>
    <author initials="F." surname="Liu" fullname="Fengmei Liu">
      <organization>Science and Technology on Information Assurance Laboratory</organization>
      <address>
        <postal>
          <street/>
          <city>Beijing</city>
          <code>100072</code>
          <country>China</country>
        </postal>
      </address>
    </author>
    <date year="2015" month="September" day="15"/>
  </front>
</reference>
  <reference anchor="SM4" target="http://www.oscca.gov.cn/UpFile/200621016423197990.pdf">
<!-- <reference anchor='SM4' target='http://info.dacas.cn/sharedimages/ARTICLES/SMAlgorithms/SM4.pdf'> -->
  <front>
    <title>SMS4 Cryptographic Algorithm For Wireless LAN Products</title>
    <author>
      <organization>Organization of State Commercial Administration of China</organization>
      <address>
        <postal>
         <street>7 Dian Chang Lu, Fengtai Qu</street>
         <city>Beijing</city>
         <region>Beijing</region>
         <code>100036</code>
         <country>People's Republic of China</country>
        </postal>
        <phone>+86 (0)10 5970-3789</phone>
        <!--<email>contact@oscca.gov.cn</email>-->
        <uri>http://www.oscca.gov.cn</uri>
      </address>
    </author>
    <date month="January" year="2006"/>
  </front>
</reference>
  <reference anchor="SideChannel" target="https://doi.org/10.1109/CIS.2015.102">
  <!-- 2015 11th International Conference on Computational Intelligence and Security (CIS), Shenzhen, 2015, pp. 398-401. -->
  <front>
    <title>Software Hardware Co-design for Side-Channel Analysis Platform on Security Chips</title>
    <author initials="Q." surname="Lei" fullname="Qian Lei">
      <organization>Tsinghua National Laboratory for Information Science and Technology, Tsinghua University</organization>
      <address>
        <postal>
          <street>Tsinghua University</street>
          <city>Haidian</city>
          <region>Beijing</region>
          <code>100190</code>
          <country>People's Republic of China</country>
        </postal>
        <uri>http://www.sist.tsinghua.edu.cn/</uri>
      </address>
    </author>
    <author initials="L." surname="Wu" fullname="Liji Wu">
      <organization>Tsinghua National Laboratory for Information Science and Technology, Tsinghua University</organization>
      <address>
        <postal>
          <street>Tsinghua University</street>
          <city>Haidian</city>
          <region>Beijing</region>
          <code>100190</code>
          <country>People's Republic of China</country>
        </postal>
        <uri>http://www.sist.tsinghua.edu.cn/</uri>
      </address>
    </author>
    <author initials="S." surname="Zhang" fullname="Shaohui Zhang">
      <organization>Tsinghua National Laboratory for Information Science and Technology, Tsinghua University</organization>
      <address>
        <postal>
          <street>Tsinghua University</street>
          <city>Haidian</city>
          <region>Beijing</region>
          <code>100190</code>
          <country>People's Republic of China</country>
        </postal>
        <uri>http://www.sist.tsinghua.edu.cn/</uri>
      </address>
    </author>
    <author initials="X." surname="Zhang" fullname="Xiangmin Zhang">
      <organization>Tsinghua National Laboratory for Information Science and Technology, Tsinghua University</organization>
      <address>
        <postal>
          <street>Tsinghua University</street>
          <city>Haidian</city>
          <region>Beijing</region>
          <code>100190</code>
          <country>People's Republic of China</country>
        </postal>
        <uri>http://www.sist.tsinghua.edu.cn/</uri>
      </address>
    </author>
    <author initials="X." surname="Li" fullname="Xiangyu Li">
      <organization>Tsinghua National Laboratory for Information Science and Technology, Tsinghua University</organization>
      <address>
        <postal>
          <street>Tsinghua University</street>
          <city>Haidian</city>
          <region>Beijing</region>
          <code>100190</code>
          <country>People's Republic of China</country>
        </postal>
        <uri>http://www.sist.tsinghua.edu.cn/</uri>
      </address>
    </author>
    <author initials="L." surname="Pan" fullname="Liyang Pan">
      <organization>Tsinghua National Laboratory for Information Science and Technology, Tsinghua University</organization>
      <address>
        <postal>
          <street>Tsinghua University</street>
          <city>Haidian</city>
          <region>Beijing</region>
          <code>100190</code>
          <country>People's Republic of China</country>
        </postal>
        <uri>http://www.sist.tsinghua.edu.cn/</uri>
      </address>
    </author>
    <author initials="Z." surname="Dong" fullname="Zhimeng Dong">
      <organization>Tsinghua National Laboratory for Information Science and Technology, Tsinghua University</organization>
      <address>
        <postal>
          <street>Tsinghua University</street>
          <city>Haidian</city>
          <region>Beijing</region>
          <code>100190</code>
          <country>People's Republic of China</country>
        </postal>
        <uri>http://www.sist.tsinghua.edu.cn/</uri>
      </address>
    </author>
    <date day="1" month="December" year="2015"/>
  </front>
</reference>
</references>
<section anchor="appendix-a" title="Appendix A: Example Calculations"><section anchor="_examples_from_gb_t_32907_2016" title="Examples From GB/T 32907-2016"><section anchor="_example_1" title="Example 1"><t>This is example 1 provided by <xref target="GBT.32907-2016"/> to demonstrate encryption of a
plaintext.</t>
<t>Plaintext:</t>
<figure>
  <artwork>01 23 45 67 89 AB CD EF FE DC BA 98 76 54 32 10</artwork>
</figure>
<t>Encryption key:</t>
<figure>
  <artwork>01 23 45 67 89 AB CD EF FE DC BA 98 76 54 32 10</artwork>
</figure>
<t>Status of the round key (rk_i) and round output (X_i) per round:</t>
<figure>
  <artwork>rk_0  = F12186F9   X_4  = 27FAD345
rk_1  = 41662B61   X_5  = A18B4CB2
rk_2  = 5A6AB19A   X_6  = 11C1E22A
rk_3  = 7BA92077   X_7  = CC13E2EE
rk_4  = 367360F4   X_8  = F87C5BD5
rk_5  = 776A0C61   X_9  = 33220757
rk_6  = B6BB89B3   X_10 = 77F4C297
rk_7  = 24763151   X_11 = 7A96F2EB
rk_8  = A520307C   X_12 = 27DAC07F
rk_9  = B7584DBD   X_13 = 42DD0F19
rk_10 = C30753ED   X_14 = B8A5DA02
rk_11 = 7EE55B57   X_15 = 907127FA
rk_12 = 6988608C   X_16 = 8B952B83
rk_13 = 30D895B7   X_17 = D42B7C59
rk_14 = 44BA14AF   X_18 = 2FFC5831
rk_15 = 104495A1   X_19 = F69E6888
rk_16 = D120B428   X_20 = AF2432C4
rk_17 = 73B55FA3   X_21 = ED1EC85E
rk_18 = CC874966   X_22 = 55A3BA22
rk_19 = 92244439   X_23 = 124B18AA
rk_20 = E89E641F   X_24 = 6AE7725F
rk_21 = 98CA015A   X_25 = F4CBA1F9
rk_22 = C7159060   X_26 = 1DCDFA10
rk_23 = 99E1FD2E   X_27 = 2FF60603
rk_24 = B79BD80C   X_28 = EFF24FDC
rk_25 = 1D2115B0   X_29 = 6FE46B75
rk_26 = 0E228AEB   X_30 = 893450AD
rk_27 = F1780C81   X_31 = 7B938F4C
rk_28 = 428D3654   X_32 = 536E4246
rk_29 = 62293496   X_33 = 86B3E94F
rk_30 = 01CF72E5   X_34 = D206965E
rk_31 = 9124A012   X_35 = 681EDF34</artwork>
</figure>
<t>Ciphertext:</t>
<figure>
  <artwork>68 1E DF 34 D2 06 96 5E 86 B3 E9 4F 53 6E 42 46</artwork>
</figure></section>
<section anchor="_example_2" title="Example 2"><t>This example is provided by <xref target="GBT.32907-2016"/> to demonstrate encryption of a
plaintext 1,000,000 times repeatedly, using a fixed encryption key.</t>
<t>Plaintext:</t>
<figure>
  <artwork>01 23 45 67 89 AB CD EF FE DC BA 98 76 54 32 10</artwork>
</figure>
<t>Encryption Key:</t>
<figure>
  <artwork>01 23 45 67 89 AB CD EF FE DC BA 98 76 54 32 10</artwork>
</figure>
<t>Ciphertext:</t>
<figure>
  <artwork>59 52 98 C7 C6 FD 27 1F 04 02 F8 04 C3 3D 3F 66</artwork>
</figure></section></section>
<section anchor="_examples_for_various_modes_of_operations" title="Examples For Various Modes Of Operations"><t>The following examples can be verified using open-source cryptographic
libraries including:</t>
<t>
  <list style="symbols">
    <t>the Botan cryptographic library <xref target="BOTAN"/> with SM4 support, and</t>
    <t>the OpenSSL Cryptography and SSL/TLS Toolkit <xref target="OPENSSL"/> with SM4 support</t>
  </list>
</t>
<section anchor="_sm4_ecb_example" title="SM4-ECB Example"><t>Plaintext:</t>
<figure>
  <artwork>AA AA AA AA BB BB BB BB CC CC CC CC DD DD DD DD
EE EE EE EE FF FF FF FF AA AA AA AA BB BB BB BB</artwork>
</figure>
<t>Encryption Key:</t>
<figure>
  <artwork>01 23 45 67 89 AB CD EF FE DC BA 98 76 54 32 10</artwork>
</figure>
<t>Ciphertext:</t>
<figure>
  <artwork>5E C8 14 3D E5 09 CF F7 B5 17 9F 8F 47 4B 86 19
2F 1D 30 5A 7F B1 7D F9 85 F8 1C 84 82 19 23 04
00 2A 8A 4E FA 86 3C CA D0 24 AC 03 00 BB 40 D2</artwork>
</figure></section>
<section anchor="_sm4_cbc_example" title="SM4-CBC Example"><t>Plaintext:</t>
<figure>
  <artwork>AA AA AA AA BB BB BB BB CC CC CC CC DD DD DD DD
EE EE EE EE FF FF FF FF AA AA AA AA BB BB BB BB</artwork>
</figure>
<t>Encryption Key:</t>
<figure>
  <artwork>01 23 45 67 89 AB CD EF FE DC BA 98 76 54 32 10</artwork>
</figure>
<t>IV:</t>
<figure>
  <artwork>00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F</artwork>
</figure>
<t>Ciphertext:</t>
<figure>
  <artwork>78 EB B1 1C C4 0B 0A 48 31 2A AE B2 04 02 44 CB
4C B7 01 69 51 90 92 26 97 9B 0D 15 DC 6A 8F 6D
40 D8 41 32 E9 99 74 A4 A8 80 88 68 42 07 48 59</artwork>
</figure></section>
<section anchor="_sm4_ofb_example" title="SM4-OFB Example"><t>Plaintext:</t>
<figure>
  <artwork>AA AA AA AA BB BB BB BB CC CC CC CC DD DD DD DD
EE EE EE EE FF FF FF FF AA AA AA AA BB BB BB BB</artwork>
</figure>
<t>Encryption Key:</t>
<figure>
  <artwork>01 23 45 67 89 AB CD EF FE DC BA 98 76 54 32 10</artwork>
</figure>
<t>IV:</t>
<figure>
  <artwork>00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F</artwork>
</figure>
<t>Ciphertext:</t>
<figure>
  <artwork>AC 32 36 CB 86 1D D3 16 E6 41 3B 4E 3C 75 24 B7
1D 01 AC A2 48 7C A5 82 CB F5 46 3E 66 98 53 9B</artwork>
</figure></section>
<section anchor="_sm4_cfb_example" title="SM4-CFB Example"><t>Plaintext:</t>
<figure>
  <artwork>AA AA AA AA BB BB BB BB CC CC CC CC DD DD DD DD
EE EE EE EE FF FF FF FF AA AA AA AA BB BB BB BB</artwork>
</figure>
<t>Encryption Key:</t>
<figure>
  <artwork>01 23 45 67 89 AB CD EF FE DC BA 98 76 54 32 10</artwork>
</figure>
<t>IV:</t>
<figure>
  <artwork>00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F</artwork>
</figure>
<t>Ciphertext:</t>
<figure>
  <artwork>AC 32 36 CB 86 1D D3 16 E6 41 3B 4E 3C 75 24 B7
69 D4 C5 4E D4 33 B9 A0 34 60 09 BE B3 7B 2B 3F</artwork>
</figure></section>
<section anchor="_sm4_ctr_example" title="SM4-CTR Example"><t>Plaintext:</t>
<figure>
  <artwork>AA AA AA AA AA AA AA AA BB BB BB BB BB BB BB BB
CC CC CC CC CC CC CC CC DD DD DD DD DD DD DD DD
EE EE EE EE EE EE EE EE FF FF FF FF FF FF FF FF
EE EE EE EE EE EE EE EE AA AA AA AA AA AA AA AA</artwork>
</figure>
<t>Encryption Key:</t>
<figure>
  <artwork>01 23 45 67 89 AB CD EF FE DC BA 98 76 54 32 10</artwork>
</figure>
<t>IV:</t>
<figure>
  <artwork>00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F</artwork>
</figure>
<t>Ciphertext:</t>
<figure>
  <artwork>AC 32 36 CB 97 0C C2 07 91 36 4C 39 5A 13 42 D1
A3 CB C1 87 8C 6F 30 CD 07 4C CE 38 5C DD 70 C7
F2 34 BC 0E 24 C1 19 80 FD 12 86 31 0C E3 7B 92
6E 02 FC D0 FA A0 BA F3 8B 29 33 85 1D 82 45 14</artwork>
</figure></section></section></section>
<section anchor="sample-implementation" title="Sample Implementation In C"><section anchor="_sm4_h" title="sm4.h"><t>"sm4.h" is the header file for the SM4 function.</t>
<figure>
  <artwork name="sm4.h" type="c">&lt;CODE BEGINS&gt;
#ifndef HEADER_SM4_H
# define HEADER_SM4_H

#include &lt;inttypes.h&gt;

# define SM4_BLOCK_SIZE    16
# define SM4_KEY_SCHEDULE  32

void sm4_encrypt(uint8_t key[],
    unsigned char plaintext[],
    unsigned char ciphertext[]);

void sm4_decrypt(uint8_t key[],
    unsigned char ciphertext[],
    unsigned char plaintext[]);

#endif

&lt;CODE ENDS&gt;</artwork>
</figure></section>
<section anchor="_sm4_c" title="sm4.c"><t>"sm4.c" contains the main implementation of SM4.</t>
<figure>
  <artwork name="sm4.c" type="c">&lt;CODE BEGINS&gt;
/* A sample implementation of SM4 */

#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
#include "sm4.h"
#include "print.h"

/* Operations */
/* Rotate Left 32-bit number */
#define ROTL32(X, n) (((X) &lt;&lt; (n)) | ((X) &gt;&gt; (32 - (n))))

static uint32_t sm4_ck[32] = {
  0x00070E15, 0x1C232A31, 0x383F464D, 0x545B6269,
  0x70777E85, 0x8C939AA1, 0xA8AFB6BD, 0xC4CBD2D9,
  0xE0E7EEF5, 0xFC030A11, 0x181F262D, 0x343B4249,
  0x50575E65, 0x6C737A81, 0x888F969D, 0xA4ABB2B9,
  0xC0C7CED5, 0xDCE3EAF1, 0xF8FF060D, 0x141B2229,
  0x30373E45, 0x4C535A61, 0x686F767D, 0x848B9299,
  0xA0A7AEB5, 0xBCC3CAD1, 0xD8DFE6ED, 0xF4FB0209,
  0x10171E25, 0x2C333A41, 0x484F565D, 0x646B7279
};

static uint8_t sm4_sbox[256] = {
  0xD6, 0x90, 0xE9, 0xFE, 0xCC, 0xE1, 0x3D, 0xB7,
  0x16, 0xB6, 0x14, 0xC2, 0x28, 0xFB, 0x2C, 0x05,
  0x2B, 0x67, 0x9A, 0x76, 0x2A, 0xBE, 0x04, 0xC3,
  0xAA, 0x44, 0x13, 0x26, 0x49, 0x86, 0x06, 0x99,
  0x9C, 0x42, 0x50, 0xF4, 0x91, 0xEF, 0x98, 0x7A,
  0x33, 0x54, 0x0B, 0x43, 0xED, 0xCF, 0xAC, 0x62,
  0xE4, 0xB3, 0x1C, 0xA9, 0xC9, 0x08, 0xE8, 0x95,
  0x80, 0xDF, 0x94, 0xFA, 0x75, 0x8F, 0x3F, 0xA6,
  0x47, 0x07, 0xA7, 0xFC, 0xF3, 0x73, 0x17, 0xBA,
  0x83, 0x59, 0x3C, 0x19, 0xE6, 0x85, 0x4F, 0xA8,
  0x68, 0x6B, 0x81, 0xB2, 0x71, 0x64, 0xDA, 0x8B,
  0xF8, 0xEB, 0x0F, 0x4B, 0x70, 0x56, 0x9D, 0x35,
  0x1E, 0x24, 0x0E, 0x5E, 0x63, 0x58, 0xD1, 0xA2,
  0x25, 0x22, 0x7C, 0x3B, 0x01, 0x21, 0x78, 0x87,
  0xD4, 0x00, 0x46, 0x57, 0x9F, 0xD3, 0x27, 0x52,
  0x4C, 0x36, 0x02, 0xE7, 0xA0, 0xC4, 0xC8, 0x9E,
  0xEA, 0xBF, 0x8A, 0xD2, 0x40, 0xC7, 0x38, 0xB5,
  0xA3, 0xF7, 0xF2, 0xCE, 0xF9, 0x61, 0x15, 0xA1,
  0xE0, 0xAE, 0x5D, 0xA4, 0x9B, 0x34, 0x1A, 0x55,
  0xAD, 0x93, 0x32, 0x30, 0xF5, 0x8C, 0xB1, 0xE3,
  0x1D, 0xF6, 0xE2, 0x2E, 0x82, 0x66, 0xCA, 0x60,
  0xC0, 0x29, 0x23, 0xAB, 0x0D, 0x53, 0x4E, 0x6F,
  0xD5, 0xDB, 0x37, 0x45, 0xDE, 0xFD, 0x8E, 0x2F,
  0x03, 0xFF, 0x6A, 0x72, 0x6D, 0x6C, 0x5B, 0x51,
  0x8D, 0x1B, 0xAF, 0x92, 0xBB, 0xDD, 0xBC, 0x7F,
  0x11, 0xD9, 0x5C, 0x41, 0x1F, 0x10, 0x5A, 0xD8,
  0x0A, 0xC1, 0x31, 0x88, 0xA5, 0xCD, 0x7B, 0xBD,
  0x2D, 0x74, 0xD0, 0x12, 0xB8, 0xE5, 0xB4, 0xB0,
  0x89, 0x69, 0x97, 0x4A, 0x0C, 0x96, 0x77, 0x7E,
  0x65, 0xB9, 0xF1, 0x09, 0xC5, 0x6E, 0xC6, 0x84,
  0x18, 0xF0, 0x7D, 0xEC, 0x3A, 0xDC, 0x4D, 0x20,
  0x79, 0xEE, 0x5F, 0x3E, 0xD7, 0xCB, 0x39, 0x48
};

static uint32_t sm4_fk[4] = {
  0xA3B1BAC6, 0x56AA3350, 0x677D9197, 0xB27022DC
};

static uint32_t load_u32_be(const uint8_t *b, uint32_t n)
{
  return ((uint32_t)b[4 * n + 3] &lt;&lt; 24) |
         ((uint32_t)b[4 * n + 2] &lt;&lt; 16) |
         ((uint32_t)b[4 * n + 1] &lt;&lt; 8)  |
         ((uint32_t)b[4 * n    ]);
}

static void store_u32_be(uint32_t v, uint8_t *b)
{
  b[3] = (uint8_t)(v &gt;&gt; 24);
  b[2] = (uint8_t)(v &gt;&gt; 16);
  b[1] = (uint8_t)(v &gt;&gt; 8);
  b[0] = (uint8_t)(v);
}

static void sm4_key_schedule(uint8_t key[], uint32_t rk[])
{
  uint32_t t, x, k[36];
  int i;

  for (i = 0; i &lt; 4; i++)
  {
    k[i] = load_u32_be(key, i) ^ sm4_fk[i];
  }

  /* T' */
  for (i = 0; i &lt; SM4_KEY_SCHEDULE; ++i)
  {
    x = k[i + 1] ^ k[i + 2] ^ k[i + 3] ^ sm4_ck[i];

    /* Nonlinear operation tau */
    t = ((uint32_t)sm4_sbox[(uint8_t)(x &gt;&gt; 24)]) &lt;&lt; 24 |
        ((uint32_t)sm4_sbox[(uint8_t)(x &gt;&gt; 16)]) &lt;&lt; 16 |
        ((uint32_t)sm4_sbox[(uint8_t)(x &gt;&gt;  8)]) &lt;&lt;  8 |
        ((uint32_t)sm4_sbox[(uint8_t)(x)]);

    /* Linear operation L' */
    k[i+4] = k[i] ^ (t ^ ROTL32(t, 13) ^ ROTL32(t, 23));
    rk[i] = k[i + 4];
  }


}

#define SM4_ROUNDS(k0, k1, k2, k3, F)   \
  do {                                  \
    X0 ^= F(X1 ^ X2 ^ X3 ^ rk[k0]); \
    X1 ^= F(X0 ^ X2 ^ X3 ^ rk[k1]); \
    X2 ^= F(X0 ^ X1 ^ X3 ^ rk[k2]); \
    X3 ^= F(X0 ^ X1 ^ X2 ^ rk[k3]); \
    debug_print("rk_%0.2i = %0.8x  " \
      "  X_%0.2i = %0.8x\n", k0, rk[k0], k0+4, X0); \
    debug_print("rk_%0.2i = %0.8x  " \
      "  X_%0.2i = %0.8x\n", k1, rk[k1], k1+4, X1); \
    debug_print("rk_%0.2i = %0.8x  " \
      "  X_%0.2i = %0.8x\n", k2, rk[k2], k2+4, X2); \
    debug_print("rk_%0.2i = %0.8x  " \
      "  X_%0.2i = %0.8x\n", k3, rk[k3], k3+4, X3); \
  } while(0)

static uint32_t sm4_t(uint32_t x)
{
  uint32_t t = 0;

  t |= ((uint32_t)sm4_sbox[(uint8_t)(x &gt;&gt; 24)]) &lt;&lt; 24;
  t |= ((uint32_t)sm4_sbox[(uint8_t)(x &gt;&gt; 16)]) &lt;&lt; 16;
  t |= ((uint32_t)sm4_sbox[(uint8_t)(x &gt;&gt; 8)]) &lt;&lt; 8;
  t |= sm4_sbox[(uint8_t)x];

  /*
   * L linear transform
   */
  return t ^ ROTL32(t, 2) ^ ROTL32(t, 10) ^
         ROTL32(t, 18) ^ ROTL32(t, 24);
}

void sm4_encrypt(uint8_t key[],
    unsigned char plaintext[],
    unsigned char ciphertext[])
{
  uint32_t rk[SM4_KEY_SCHEDULE], X0, X1, X2, X3;
  int i, j;

  sm4_key_schedule(key, rk);

  X0 = load_u32_be(plaintext, 0);
  X1 = load_u32_be(plaintext, 1);
  X2 = load_u32_be(plaintext, 2);
  X3 = load_u32_be(plaintext, 3);

  SM4_ROUNDS( 0,  1,  2,  3, sm4_t);
  SM4_ROUNDS( 4,  5,  6,  7, sm4_t);
  SM4_ROUNDS( 8,  9, 10, 11, sm4_t);
  SM4_ROUNDS(12, 13, 14, 15, sm4_t);
  SM4_ROUNDS(16, 17, 18, 19, sm4_t);
  SM4_ROUNDS(20, 21, 22, 23, sm4_t);
  SM4_ROUNDS(24, 25, 26, 27, sm4_t);
  SM4_ROUNDS(28, 29, 30, 31, sm4_t);

  store_u32_be(X3, ciphertext);
  store_u32_be(X2, ciphertext + 4);
  store_u32_be(X1, ciphertext + 8);
  store_u32_be(X0, ciphertext + 12);
}

void sm4_decrypt(uint8_t key[],
    unsigned char ciphertext[],
    unsigned char plaintext[])
{
  uint32_t rk[SM4_KEY_SCHEDULE], X0, X1, X2, X3;
  int i, j;

  sm4_key_schedule(key, rk);

  X0 = load_u32_be(ciphertext, 0);
  X1 = load_u32_be(ciphertext, 1);
  X2 = load_u32_be(ciphertext, 2);
  X3 = load_u32_be(ciphertext, 3);

  SM4_ROUNDS(31, 30, 29, 28, sm4_t);
  SM4_ROUNDS(27, 26, 25, 24, sm4_t);
  SM4_ROUNDS(23, 22, 21, 20, sm4_t);
  SM4_ROUNDS(19, 18, 17, 16, sm4_t);
  SM4_ROUNDS(15, 14, 13, 12, sm4_t);
  SM4_ROUNDS(11, 10,  9,  8, sm4_t);
  SM4_ROUNDS( 7,  6,  5,  4, sm4_t);
  SM4_ROUNDS( 3,  2,  1,  0, sm4_t);

  store_u32_be(X3, plaintext);
  store_u32_be(X2, plaintext + 4);
  store_u32_be(X1, plaintext + 8);
  store_u32_be(X0, plaintext + 12);
}

&lt;CODE ENDS&gt;</artwork>
</figure></section>
<section anchor="_sm4_main_c" title="sm4_main.c"><t>"sm4_main.c" is used to run the examples provided in this document
and print out internal state for implementation reference.</t>
<figure>
  <artwork name="sm4_main.c" type="c">&lt;CODE BEGINS&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
#include &lt;stdbool.h&gt;
#include "sm4.h"
#include "print.h"

typedef struct {
  unsigned char* key;
  unsigned char* message;
  unsigned char* expected;
  int iterations;
  bool encrypt;
} test_case;

int sm4_run_example(test_case tc)
{
  unsigned char input[SM4_BLOCK_SIZE] = {0};
  unsigned char output[SM4_BLOCK_SIZE] = {0};
  int i;

  debug_print("-----------------------"
      " Message Input m Begin "
      "-------------------------\n");
  print_bytes((unsigned int*)tc.message, SM4_BLOCK_SIZE);
  debug_print("----------------------- "
      "Message Input m End "
      "---------------------------\n");

  if (tc.encrypt)
  {
    debug_print("----------------------- "
        "Encrypt "
        "---------------------------\n");
    memcpy(input, tc.message, SM4_BLOCK_SIZE);
    for (i = 0; i != tc.iterations; ++i)
    {
      sm4_encrypt(tc.key,
          (unsigned char*)input,
          (unsigned char*)output);
      memcpy(input, output, SM4_BLOCK_SIZE);
    }
  }
  else
  {
    debug_print("----------------------- "
        "Decrypt "
        "---------------------------\n");
    memcpy(input, tc.message, SM4_BLOCK_SIZE);
    for (i = 0; i != tc.iterations; ++i)
    {
      sm4_decrypt(tc.key,
          (unsigned char*)input,
          (unsigned char*)output);
      memcpy(input, output, SM4_BLOCK_SIZE);
    }
  }

  debug_print("+++++++++++++++++++++++++++++++"
      " RESULT "
      "++++++++++++++++++++++++++++++++\n");
  debug_print("RESULTS:\n");
  debug_print(" Expected:\n");
  print_bytes((unsigned int*)tc.expected, SM4_BLOCK_SIZE);

  debug_print(" Output:\n");
  print_bytes((unsigned int*)output, SM4_BLOCK_SIZE);

  return memcmp(
    (unsigned char*)output,
    (unsigned char*)tc.expected,
    SM4_BLOCK_SIZE
  );
}

int main(int argc, char **argv)
{

  int i;
  unsigned char key[SM4_BLOCK_SIZE];
  unsigned char block[SM4_BLOCK_SIZE];

  test_case tests[4] = {0};

  /*
   * This test vector comes from Example 1 of GB/T 32907-2016,
   */
  static const unsigned int gbt32907k1[SM4_BLOCK_SIZE] = {
    0x01234567, 0x89abcdef,
    0xfedcba98, 0x76543210
  };
  static const unsigned int gbt32907m1[SM4_BLOCK_SIZE] = {
    0x01234567, 0x89abcdef,
    0xfedcba98, 0x76543210
  };
  static const unsigned int gbt32907e1[SM4_BLOCK_SIZE] = {
    0x681edf34, 0xd206965e,
    0x86b3e94f, 0x536e4246
  };
  test_case gbt32907t1 = {
    (unsigned char*)gbt32907k1,
    (unsigned char*)gbt32907m1,
    (unsigned char*)gbt32907e1,
    1,
    true
  };
  tests[0] = gbt32907t1;

  /*
   * This test vector comes from Example 2 from GB/T 32907-2016.
   * After 1,000,000 iterations.
   */
  static const unsigned int gbt32907e2[SM4_BLOCK_SIZE] = {
    0x595298c7, 0xc6fd271f,
    0x0402f804, 0xc33d3f66
  };
  test_case gbt32907t2 = {
    (unsigned char*)gbt32907k1,
    (unsigned char*)gbt32907m1,
    (unsigned char*)gbt32907e2,
    1000000,
    true
  };
  tests[1] = gbt32907t2;

  /*
   * This test vector reverses Example 1 of GB/T 32907-2016.
   * After decrypting 1 iteration.
   */
  test_case gbt32907t3 = {
    (unsigned char*)gbt32907k1,
    (unsigned char*)gbt32907e1,
    (unsigned char*)gbt32907m1,
    1,
    false
  };
  tests[2] = gbt32907t3;

  /*
   * This test vector reverses Example 2 of GB/T 32907-2016.
   * After decrypting 1,000,000 iterations.
   */
  test_case gbt32907t4 = {
    (unsigned char*)gbt32907k1,
    (unsigned char*)gbt32907e2,
    (unsigned char*)gbt32907m1,
    1000000,
    false
  };
  tests[3] = gbt32907t4;

  /* TODO: add more examples */

  for (i = 0; i &lt; 4; ++i)
  {
    printf("sm4_example[%2i]: %s\n", i,
      sm4_run_example(tests[i]) ?  "FAIL" : "PASS");
  }

  return 0;
}

&lt;CODE ENDS&gt;</artwork>
</figure></section>
<section anchor="_print_c_and_print_h" title="print.c and print.h"><t>"print.c" and "print.h" are used to provide pretty formatting used
to print out the examples for this document.</t>
<t>"print.h"</t>
<figure>
  <artwork name="print.h" type="c">&lt;CODE BEGINS&gt;
#ifndef SM3PRINT_H
#define SM3PRINT_H

#define DEBUG 0
#define debug_print(...) \
  do { if (DEBUG) fprintf(stderr, __VA_ARGS__); } while (0)

#include &lt;inttypes.h&gt;
#include &lt;stdio.h&gt;

void print_bytes(unsigned* buf, int n);
void print_block(unsigned* buf, int n);
void print_af(int i, uint32_t A, uint32_t B, uint32_t C, uint32_t D,
    uint32_t E, uint32_t F, uint32_t G, uint32_t H);
void print_hash(unsigned* buf);

#endif
&lt;CODE ENDS&gt;</artwork>
</figure>
<t>"print.c"</t>
<figure>
  <artwork name="print.c" type="c">&lt;CODE BEGINS&gt;
#include &lt;stdio.h&gt;
#include "print.h"

void print_bytes(unsigned int* buf, int n)
{
  unsigned char* ptr = (unsigned char*)buf;
  int i, j;

  for (i = 0; i &lt;= n/4; i++) {
    if (i &gt; 0 &amp;&amp; i % 8 == 0) {
      debug_print("\n");
    }
    for (j = 1; j &lt;= 4; j++) {
      if ((i*4+4-j) &lt; n) {
        debug_print("%.2X", ptr[(i*4)+4-j]);
      }
    }
    debug_print(" ");
  }
  debug_print("\n");
}

void print_block(unsigned int* buf, int n)
{
  print_bytes(buf, n * 4);
}

void print_hash(unsigned int* buf)
{
  print_block(buf, 8);
}

&lt;CODE ENDS&gt;</artwork>
</figure></section></section>
<section anchor="_acknowledgements" title="Acknowledgements"><t>The authors would like to thank the following persons for their valuable advice and input.</t>
<t>
  <list style="symbols">
    <t>Erick Borsboom for assisting the lengthy review of this document;</t>
    <t>Jack Lloyd and Daniel Wyatt of the Ribose RNP team for their input and implementation;</t>
    <t>Paul Yang for reviewing and proposing improvements to readability of this document.</t>
  </list>
</t></section>
</back>
</rfc>
