﻿<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd">
<?xml-stylesheet type='text/xsl' href='rfc2629.xslt' ?>
<?rfc toc="yes"?>
<?rfc tocdepth="4"?>
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes" ?>
<?rfc compact="no" ?>



<rfc category="info" docName="draft-smyshlyaev-tls13-gost-suites-03" ipr="trust200902">

    <front>
        <title abbrev="GOST Cipher Suites for TLS 1.3">
            GOST Cipher Suites for Transport Layer Security (TLS) Protocol Version 1.3
        </title>

        <author fullname="Stanislav Smyshlyaev" initials="S.V." role="editor" surname="Smyshlyaev">
            <organization>CryptoPro</organization>
            <address>
                <postal>
                    <street>18, Suschevsky val </street>
                    <city>Moscow</city>
                    <code>127018</code>
                    <country>Russian Federation</country>
                </postal>
                <phone>+7 (495) 995-48-20</phone>
                <email>svs@cryptopro.ru</email>
            </address>
        </author>

      <author fullname="Evgeny Alekseev" initials="E.K." surname="Alekseev">
          <organization>CryptoPro</organization>
            <address>
                <postal>
                    <street>18, Suschevsky val </street>
                    <city>Moscow</city>
                    <code>127018</code>
                    <country>Russian Federation</country>
                </postal>
                <email>alekseev@cryptopro.ru</email>
            </address>
        </author>

        <author fullname="Ekaterina Griboedova" initials="E.S." surname="Griboedova">
          <organization>CryptoPro</organization>
          <address>
              <postal>
                  <street>18, Suschevsky val </street>
                  <city>Moscow</city>
                  <code>127018</code>
                  <country>Russian Federation</country>
              </postal>
            <email>griboedova.e.s@gmail.com</email>
          </address>
        </author>

        <author fullname="Alexandra Babueva" initials="A.A." surname="Babueva">
          <organization>CryptoPro</organization>
            <address>
                <postal>
                    <street>18, Suschevsky val </street>
                    <city>Moscow</city>
                    <code>127018</code>
                    <country>Russian Federation</country>
                </postal>
                <email>babueva@cryptopro.ru</email>
            </address>
        </author>

        <date year="2020" />
        <!--если не указываем число и месяц, они подставляются автоматически-->
        <area>General</area>
        <!--как в rfc7748-->
        <workgroup>Network Working Group</workgroup>
        <keyword>GOST, cipher suite, TLS 1.3, signature scheme</keyword>

        <abstract>
            <t>
                The purpose of this document is to make the Russian cryptographic standards
                available to the Internet community for their implementation in the Transport Layer Security (TLS)
                Protocol Version 1.3.
            </t>
            <t>
                This specification defines four new cipher suites and seven new signature schemes 
                based on GOST R 34.12-2015, GOST R 34.11-2012 and GOST R 34.10-2012 algorithms.
            </t>
        </abstract>
    </front>


    <middle>
        <section anchor="Introduction" title="Introduction" >
            <t>
                This document defines four new cipher suites (the TLS13_GOST cipher suites) and seven new signature schemes (the TLS13_GOST signature schemes)
                for the Transport Layer Security (TLS) Protocol Version 1.3, that are based on Russian cryptographic standards
                GOST R 34.12-2015  <xref target="GOST3412-2015"/> (the English version can be found in <xref target="RFC7801"/>),
                GOST R 34.11-2012  <xref target="GOST3411-2012"/> (the English version can be found in <xref target="RFC6986"/>) and
                GOST R 34.10-2012  <xref target="GOST3410-2012"/> (the English version can be found in <xref target="RFC7091"/>).
            </t>
            <t>
                The TLS13_GOST cipher suites (see <xref target="CipherSuites"/>) have the following values:
                <list style = "empty">
                    <t>
                        TLS_GOSTR341112_256_WITH_KUZNYECHIK_MGM_L = {0xC1, 0x03};
                        TLS_GOSTR341112_256_WITH_MAGMA_MGM_L = {0xC1, 0x04};
                        TLS_GOSTR341112_256_WITH_KUZNYECHIK_MGM_S = {0xC1, 0x05};
                        TLS_GOSTR341112_256_WITH_MAGMA_MGM_S = {0xC1, 0x06}.
                    </t>
                </list>
            </t>
            <t>
                Each TLS13_GOST cipher suite specifies a pair (record protection algorithm, hash algorithm) such that:
                <list style="symbols">
                    <t>
                        The record protection algorithm is the AEAD algorithm (see <xref target="AEAD"/>) based on the GOST R 34.12-2015 block cipher
                        <xref target="RFC7801"/> in the Multilinear Galois Mode (MGM) <xref target="DraftMGM"/> and the external re-keying approach
                        (see <xref target="RFC8645"/>) intended for increasing the lifetime of symmetric keys used to protect records.
                    </t>
                    <t>
                        The hash algorithm is the GOST R 34.11-2012 algorithm <xref target="RFC6986"/>.
                    </t>
                </list>
            </t>
            <t>
                Note: The TLS13_GOST cipher suites are divided into two types (depending on the key lifetime limitations, see <xref target="TLSTREE"/> and
                <xref target="SNMAX"/>): the "_S" (strong) cipher suites and the "_L" (light) cipher suites.
            </t>
            <t>
                The TLS13_GOST signature schemes that can be used with the TLS13_GOST cipher suites have the following values:
                <list style = "empty">
                    <t>
                        gostr34102012_256a = 0x0709;
                    </t>
                    <t>
                        gostr34102012_256b = 0x070A;
                    </t>
                    <t>
                        gostr34102012_256c = 0x070B;
                    </t>
                    <t>
                        gostr34102012_256d = 0x070C;
                    </t>
                    <t>
                        gostr34102012_512a = 0x070D;
                    </t>
                    <t>
                        gostr34102012_512b = 0x070E;
                    </t>
                    <t>
                        gostr34102012_512c = 0x070F.
                    </t>
                </list>
            </t>
            <t>
                Each TLS13_GOST signature scheme specifies a pair (signature algorithm, elliptic curve) such that:
                <list style="symbols">
                    <t>
                        The signature algorithm is the GOST R 34.10-2012 algorithm <xref target="RFC7091"/>.
                    </t>
                    <t>
                        The elliptic curve is one of the curves defined in <xref target ="EllipticCurve"/>.
                    </t>
                </list>
            </t>
            <t>
                Additionally, this document specifies the key exchange and authentication process in case of negotiating
                TLS13_GOST cipher suites (see <xref target="KEA"/>).
            </t>
            
        </section>

        <section title="Conventions Used in This Document">
            <t>
                The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT",
                "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted
                as described in BCP 14 <xref target="RFC2119"/> <xref target="RFC8174"/> when, and only when,
                they appear in all capitals, as shown here.
            </t>
        </section>

        <section anchor="Definition" title="Basic Terms and Definitions">
        <t>
            This document uses the following terms and definitions for the sets and operations
            on the elements of these sets:
                <list style = "hanging" hangIndent = "16">
                    <t hangText = "B_t">
                        the set of byte strings of length t, t >= 0, for t = 0 the
                        B_t set consists of a single empty string of zero length.
                        If A is an element of B_t, then A = (a_1, a_2,
                        ... , a_t), where a_1, a_2, ... , a_t are in {0, ... , 255};
                    </t>
                    <t hangText = "B*">
                        the set of all byte strings of a finite length
                        (hereinafter referred to as strings), including the empty
                        string;
                    </t>
                    <t hangText = "A[i..j]">
                        the string A[i..j] = (a_i, a_{i+1}, ... , a_j) in B_{j-i+1}, where A = (a_1, a_2, ... , a_t) in B_t and 1&lt;=i&lt;=j&lt;=t;
                    </t>
                    <t hangText ="|A|">
                        the byte length of the string A;
                    </t>
                    <t hangText = "A | C">
                        the concatenation of strings A and C both belonging to B*, i.e.,
                        a string in B_{|A|+|C|}, where the left substring in
                        B_|A| is equal to A, and the right substring in B_|C| is
                        equal to C;
                    </t>
                    <t hangText = "i &amp; j">
                        bitwise AND of integers i and j;
                    </t>
                    <t hangText = "STR_t">
                        the byte string STR_t(i) = (i_1, ... , i_t) in B_t corresponding to
                        an integer i = 256^{t-1} * i_1 + ... + 256 * i_{t-1} + i_t
                        (the interpretation of the integer as a byte string in big-endian format);
                    </t>
                    <t hangText = "str_t">
                        the byte string str_t(i) = (i_1, ... , i_t) in B_t corresponding to
                        an integer i = 256^{t-1} * i_t + ... + 256 * i_2 + i_1
                        (the interpretation of the integer as a byte string in little-endian format);
                    </t>
                    <t hangText = "k">
                        the byte-length of the block cipher key;
                    </t>
                    <t hangText = "n">
                        the byte-length of the block cipher block;
                    </t>
                    <t hangText = "IVlen">
                        the byte-length of the initialization vector;
                    </t>
                    <t hangText = "S">
                        the byte-length of the authentication tag;
                    </t>
                    <t hangText = "E_i">
                        the elliptic curve indicated by client in "supported_groups" extension;
                    </t>
                    <t hangText = "O_i">
                        the zero point of the elliptic curve E_i;
                    </t>
                    <t hangText = "m_i">
                      the order of group of points belonging to the elliptic curve E_i;
                    </t>
                    <t hangText = "q_i">
                      the cyclic subgroup order of group of points belonging to the elliptic curve E_i;
                    </t>
                    <t hangText = "h_i">
                      the cyclic subgroup cofactor which is equal to m_i / q_i;
                    </t>
                    <t hangText = "Q_sign">
                      the public key stored in endpoint's certificate;
                    </t>
                    <t hangText = "d_sign">
                      the private key that corresponds to the Q_sign key;
                    </t>
                    <t hangText = "P_i">
                      the point of the elliptic curve E_i of the order q_i;
                    </t>
                    <t hangText = "(d_C^i, Q_C^i)">
                      the client's ephemeral key pair which consists of the private key and the public key corresponding to the elliptic curve E_i;
                    </t>
                    <t hangText = "(d_S^i, Q_S^i)">
                      the server's ephemeral key pair which consists of the private key and the public key corresponding to the elliptic curve E_i.
                    </t>
                </list>
            </t>
        </section>

        <section anchor="CipherSuites" title="Cipher Suite Definition">
            <t>
                The cipher suite value is used to indicate a record protection algorithm and a hash algorithm which an endpoint supports (see Section 4.1.2 of <xref target="RFC8446"/>).
            </t>
            <t>
                This section defines the following four TLS13_GOST cipher suites that can be used to support Russian cryptographic algorithms:
            </t>
            <t>
                <figure>
                    <artwork>
                        <![CDATA[
CipherSuite TLS_GOSTR341112_256_WITH_KUZNYECHIK_MGM_L = {0xC1, 0x03};
CipherSuite TLS_GOSTR341112_256_WITH_MAGMA_MGM_L = {0xC1, 0x04};
CipherSuite TLS_GOSTR341112_256_WITH_KUZNYECHIK_MGM_S = {0xC1, 0x05};
CipherSuite TLS_GOSTR341112_256_WITH_MAGMA_MGM_S = {0xC1, 0x06};
                        ]]>
                    </artwork>
                </figure>
            </t>
            <t>
                Each cipher suite specifies a pair of the record protection algorithm (see <xref target="RecordProtection"/>) and the hash algorithm (<xref target="HASH"/>).
            </t>

            <section anchor="RecordProtection" title="Record Protection Algorithm">
                <t>
                    In accordance with Section 5.2 of <xref target="RFC8446"/> the record protection algorithm translates a TLSPlaintext structure into a TLSCiphertext structure.
                    If TLS13_GOST cipher suite is negotiated, the encrypted_record field of the TLSCiphertext structure MUST be set to the AEADEncrypted value computed as follows:
                    <list style="empty">
                        <t>
                            AEADEncrypted = AEAD-Encrypt(sender_record_write_key, nonce, associated_data, plaintext),
                        </t>
                    </list>
                </t>
                <t>
                    where
                    <list style="symbols">
                        <t>
                            the AEAD-Encrypt function is defined in <xref target="AEAD"/>;
                        </t>
                        <t>
                            the sender_record_write_key is derived from the sender_write_key (see Section 7.3 of <xref target="RFC8446"/>) using
                            TLSTREE function defined in <xref target = "TLSTREE"/> and sequence number seqnum as follows:
                            <list style="empty">
                                <t>
                                    sender_record_write_key = TLSTREE(sender_write_key, seqnum);
                                </t>
                            </list>
                        </t>
                        <t>
                            the nonce value is derived from the record sequence number seqnum and the sender_write_iv value (see Section 7.3 
                            of <xref target="RFC8446"/>) in accordance with Section 5.3 of <xref target="RFC8446"/>;
                        </t>
                        <t>
                            the associated_data value is the record header that is generated in accordance with Section 5.2 of <xref target="RFC8446"/>;
                        </t>
                        <t>
                            the plaintext value is the TLSInnerPlaintext structure encoded in accordance with Section 5.2 of <xref target="RFC8446"/>.
                        </t>
                    </list>
                </t>

                <t>
                    Note1: The AEAD-Encrypt function is exactly the same as the AEAD-Encrypt function defined in <xref target="RFC8446"/> except the key
                    (the first argument) is calculated from the sender_write_key and sequence number seqnum for each message separately to support external
                    re-keying approach according to <xref target="RFC8645"/>.
                </t>

                <t>
                    Note2: The record sequence number is the value in the range 0-SNMAX, where the SNMAX value is defined in <xref target="SNMAX"/>.
                    The SNMAX parameter is specified by the particular TLS13_GOST cipher suite to limit the amount of data that can be encrypted under 
                    the same traffic key material (sender_write_key, sender_write_iv).
                </t>

                <t>
                    The record deprotection algorithm reverses the process of the record protection. In order to decrypt and verify the protected record with sequence number
                    seqnum the algorithm takes as input the sender_record_write_key is derived from the sender_write_key, nonce, associated_data and the AEADEncrypted value 
                    and outputs the res value which is either the plaintext or an error indicating that the decryption failed.
                    If TLS13_GOST cipher suite is negotiated, the res value MUST be computed as follows:
                    <list style="empty">
                        <t>
                            res = AEAD-Decrypt(sender_record_write_key, nonce, associated_data, AEADEncrypted),
                        </t>
                    </list>
                </t>
                <t>
                    where the AEAD-Decrypt function is defined in <xref target="AEAD"/>.
                </t>
                <t>
                    Note: The AEAD-Decrypt function is exactly the same as the AEAD-Decrypt function defined in <xref target="RFC8446"/> except the key
                    (the first argument) is calculated from the sender_write_key and sequence number seqnum for each message separately to support external
                    re-keying approach according to <xref target="RFC8645"/>.
                </t>

                <section anchor="AEAD" title="AEAD Algorithm">
                    <t>
                        The AEAD-Encrypt and AEAD-Decrypt functions are defined as follows.
                    </t>
                    <t>
                        <figure>
                            <artwork>
                                <![CDATA[
+-------------------------------------------------------------------+
|  AEAD-Encrypt(K, nonce, A, P)                                     |
|-------------------------------------------------------------------|
|  Input:                                                           |
|  - encryption key K in B_k,                                       |
|  - unique vector nonce in B_IVlen,                                |
|  - associated authenticated data A in B_r, r >= 0,                |
|  - plaintext P in B_t, t >= 0.                                    |
|  Output:                                                          |
|  - ciphertext C in B_{|P|},                                       |
|  - authentication tag T in B_S.                                   |
|-------------------------------------------------------------------|
|  1. MGMnonce = nonce[1..1] & 0x7f | nonce[2..IVlen];              |
|  2. (MGMnonce, A, C, T) = MGM-Encrypt(K, MGMnonce, A, P);         |
|  3. Return C | T.                                                 |
+-------------------------------------------------------------------+

+-------------------------------------------------------------------+
|  AEAD-Decrypt(K, nonce, A, C | T)                                 |
|-------------------------------------------------------------------|
|  Input:                                                           |
|  - encryption key K in B_k,                                       |
|  - unique vector nonce in B_IVlen,                                |
|  - associated authenticated data A in B_r, r >= 0,                |
|  - ciphertext C in B_t, t >= 0,                                   |
|  - authentication tag T in B_S.                                   |
|  Output:                                                          |
|  - plaintext P in B_{|C|} or FAIL.                                |
|-------------------------------------------------------------------|
|  1. MGMnonce = nonce[1..1] & 0x7f | nonce[2..IVlen];              |
|  2. res' = MGM-Decrypt(K, MGMnonce, A, C, T);                     |
|  3. IF res' = FAIL then return FAIL;                              |
|  4. IF res' = (A, P) then return P.                               |
+-------------------------------------------------------------------+
                            ]]>
                            </artwork>
                        </figure>
                    </t>
                    <t>
                        where
                        <list style = "symbols">
                            <t>
                                MGM-Encrypt and MGM-Decrypt functions are defined in <xref target="DraftMGM"/>. The size of the authentication tag T is equal to n bytes (S = n).
                                The size of the nonce parameter is equal to n bytes (IVlen = n).
                            </t>
                        </list>
                    </t>
                    
                    <t>
                        The cipher suites TLS_GOSTR341112_256_WITH_KUZNYECHIK_MGM_L and TLS_GOSTR341112_256_WITH_KUZNYECHIK_MGM_S MUST use Kuznyechik <xref target="RFC7801"/>
                        as a base block cipher for the AEAD algorithm. The block length n is 16 bytes (n = 16) and the key length k is 32 bytes (k = 32).
                    </t>
                    <t>
                        The cipher suites TLS_GOSTR341112_256_WITH_MAGMA_MGM_L and TLS_GOSTR341112_256_WITH_MAGMA_MGM_S MUST use Magma <xref target ="GOST3412-2015"/>
                        as a base block cipher for the AEAD algorithm. The block length n is 8 bytes (n = 8) and the key length k is 32 bytes (k = 32).
                    </t>
                </section>

                <section anchor ="TLSTREE" title ="TLSTREE">
                    <t>
                        The TLS13_GOST cipher suites use the TLSTREE function for the external re-keying approach (see <xref target="RFC8645"/>). The TLSTREE function is defined as follows:
                        <list style = "empty">
                            <t>
                                TLSTREE(K_root, i) = KDF_3(KDF_2(KDF_1(K_root, STR_8(i &amp; C_1)), STR_8(i &amp; C_2)), STR_8(i &amp; C_3)),
                            </t>
                        </list>
                    </t>
                    <t>
                        where
                        <list style = "symbols">
                            <t>
                                K_root in B_32;
                            </t>
                            <t>
                                i in {0, 1, ... , 2^64 - 1};
                            </t>
                            <t>
                                KDF_j(K, D), j = 1, 2, 3, is the key derivation function defined as follows: <vspace/>
                                <vspace/>
                                KDF_1(K, D) = KDF_GOSTR3411_2012_256(K, "level1", D),<vspace/>
                                KDF_2(K, D) = KDF_GOSTR3411_2012_256(K, "level2", D),<vspace/>
                                KDF_3(K, D) = KDF_GOSTR3411_2012_256(K, "level3", D),<vspace/>
                                <vspace/>
                                where the KDF_GOSTR3411_2012_256 function is defined in <xref target="RFC7836"/>, K in B_32, D in B_8.
                            </t>
                            <t>
                                C_1, C_2, C_3 are constants defined by the particular cipher suite as follows:
                            </t>
                        </list>
                    </t>
                    <t>
                        <figure>
                            <artwork>
                                <![CDATA[
+------------------------------------------+----------------------+
|               CipherSuites               |    C_1, C_2, C_3     |
+------------------------------------------+----------------------+
|TLS_GOSTR341112_256_WITH_KUZNYECHIK_MGM_L |C_1=0xf800000000000000|
|                                          |C_2=0xfffffff000000000|
|                                          |C_3=0xffffffffffffe000|
+------------------------------------------+----------------------+
|TLS_GOSTR341112_256_WITH_MAGMA_MGM_L      |C_1=0xffe0000000000000|
|                                          |C_2=0xffffffffc0000000|
|                                          |C_3=0xffffffffffffff80|
+------------------------------------------+----------------------+
|TLS_GOSTR341112_256_WITH_KUZNYECHIK_MGM_S |C_1=0xffffffffe0000000|
|                                          |C_2=0xffffffffffff0000|
|                                          |C_3=0xfffffffffffffff8|
+------------------------------------------+----------------------+
|TLS_GOSTR341112_256_WITH_MAGMA_MGM_S      |C_1=0xfffffffffc000000|
|                                          |C_2=0xffffffffffffe000|
|                                          |C_3=0xffffffffffffffff|
+------------------------------------------+----------------------+
                           Table 1
                                ]]>
                            </artwork>
                        </figure>
                    </t>
                </section>
       
                <section anchor ="SNMAX" title="SNMAX parameter">
                    <t>
                        The SNMAX parameter is the maximum number of records encrypted under the same traffic key material (sender_write_key and sender_write_iv)
                        and is defined by the particular cipher suite as follows:
                    </t>
                    <t>
                        <figure>
                            <artwork>
                                <![CDATA[
+------------------------------------------+--------------------+
|               CipherSuites               |        SNMAX       |
+------------------------------------------+--------------------+
|TLS_GOSTR341112_256_WITH_KUZNYECHIK_MGM_L | SNMAX = 2^64 - 1   |
+------------------------------------------+--------------------+
|TLS_GOSTR341112_256_WITH_MAGMA_MGM_L      | SNMAX = 2^64 - 1   |
+------------------------------------------+--------------------+
|TLS_GOSTR341112_256_WITH_KUZNYECHIK_MGM_S | SNMAX = 2^42 - 1   |
+------------------------------------------+--------------------+
|TLS_GOSTR341112_256_WITH_MAGMA_MGM_S      | SNMAX = 2^39 - 1   |
+------------------------------------------+--------------------+
                           Table 2
                                    ]]>
                            </artwork>
                        </figure>
                    </t>
                </section>
            </section>

            <section anchor ="HASH" title="Hash Algorithm">
                <t>
                    The Hash algorithm is used for key derivation process (see Section 7.1 of <xref target="RFC8446"/>),
                    Finished message calculation (see Section 4.4.4 of <xref target="RFC8446"/>), Transcript-Hash function computation
                    (see Section 4.4.1 of <xref target="RFC8446"/>), PSK binder value calculation (see Section 4.2.11.2 of <xref target="RFC8446"/>),
                    external re-keying approach (see <xref target = "TLSTREE"/>) and other purposes.
                </t>
                <t>
                    In case of negotiating a TLS13_GOST cipher suite the Hash algorithm MUST be the GOST R 34.11-2012 <xref target = "RFC6986"/> 
                    hash algorithm with 32-byte (256-bit) hash value.
                </t>
            </section>
        </section>

        <section anchor="SSD" title="Signature Scheme Definition">
            <t>
                The signature scheme value is used to indicate a single signature algorithm and a curve that can be used in digital signature (see Section 4.2.3 of <xref target="RFC8446"/>).
            </t>
            <t>
                This section defines the following seven TLS13_GOST signature schemes that can be used to support Russian cryptographic algorithms:
            </t>
            <t>
                <figure>
                    <artwork>
                        <![CDATA[
enum {
    gostr34102012_256a(0x0709),
    gostr34102012_256b(0x070A),
    gostr34102012_256c(0x070B),
    gostr34102012_256d(0x070C),
    gostr34102012_512a(0x070D),
    gostr34102012_512b(0x070E),
    gostr34102012_512c(0x070F)
} SignatureScheme;
                        ]]>
                    </artwork>
                </figure>
            </t>
            <t>
                If TLS13_GOST cipher suite is negotiated and authentication via certificates is required one of the TLS13_GOST signature schemes listed above SHOULD be used.
            </t>
            <t>
                Each signature scheme specifies a pair of the signature algorithm (see <xref target="SignatureAlgorithm"/>) and the elliptic curve (see <xref target="EllipticCurve"/>).
            </t>

            <section anchor="SignatureAlgorithm" title="Signature Algorithm">
                <t>
                    Signature algorithms corresponding to the TLS13_GOST signature schemes are defined as follows:
                </t>
                <t>
                    <figure>
                        <artwork>
                            <![CDATA[
+------------------+--------------------------------------+--------+
| SignatureScheme  |          Signature Algorithm         | Refe-  |
|      Value       |                                      | rences |
+------------------+--------------------------------------+--------+
|gostr34102012_256a|GOST R 34.10-2012 , 32-byte key length|RFC 7091|
+------------------+--------------------------------------+--------+
|gostr34102012_256b|GOST R 34.10-2012 , 32-byte key length|RFC 7091|
+------------------+--------------------------------------+--------+
|gostr34102012_256c|GOST R 34.10-2012 , 32-byte key length|RFC 7091|
+------------------+--------------------------------------+--------+
|gostr34102012_256d|GOST R 34.10-2012 , 32-byte key length|RFC 7091|
+------------------+--------------------------------------+--------+
|gostr34102012_512a|GOST R 34.10-2012 , 64-byte key length|RFC 7091|
+------------------+--------------------------------------+--------+
|gostr34102012_512b|GOST R 34.10-2012 , 64-byte key length|RFC 7091|
+------------------+--------------------------------------+--------+
|gostr34102012_512c|GOST R 34.10-2012 , 64-byte key length|RFC 7091|
+------------------+--------------------------------------+--------+
                            Table 3
                            ]]>
                        </artwork>
                    </figure>
                </t>
            </section>

            <section anchor="EllipticCurve" title="Elliptic Curve">
                <t>
                    Elliptic curves corresponding to the TLS13_GOST signature schemes are defined as follows:
                </t>
                <t>
                    <figure>
                        <artwork>
                            <![CDATA[
+------------------+--------------------------------------+--------+
| SignatureScheme  |        Curve Identifier Value        | Refe-  |
|      Value       |                                      | rences |
+------------------+--------------------------------------+--------+
|gostr34102012_256a| id-tc26-gost-3410-2012-256-paramSetA |RFC 7836|
+------------------+--------------------------------------+--------+
|gostr34102012_256b|id-GostR3410-2001-CryptoPro-A-ParamSet|RFC 4357|
+------------------+--------------------------------------+--------+
|gostr34102012_256c|id-GostR3410-2001-CryptoPro-B-ParamSet|RFC 4357|
+------------------+--------------------------------------+--------+
|gostr34102012_256d|id-GostR3410-2001-CryptoPro-C-ParamSet|RFC 4357|
+------------------+--------------------------------------+--------+
|gostr34102012_512a|  id-tc26-gost-3410-12-512-paramSetA  |RFC 7836|
+------------------+--------------------------------------+--------+
|gostr34102012_512b|  id-tc26-gost-3410-12-512-paramSetB  |RFC 7836|
+------------------+--------------------------------------+--------+
|gostr34102012_512c| id-tc26-gost-3410-2012-512-paramSetC |RFC 7836|
+------------------+--------------------------------------+--------+
                            Table 4
                            ]]>
                        </artwork>
                    </figure>
                </t>
            </section>


            <section anchor="SIGN" title="SIGN function">
                <t>
                    If TLS13_GOST signature scheme is used, the signature value in CertificateVerify message (see <xref target="CV"/>)
                    MUST be calculated using the SIGN function defined as follows:
                </t>
                <t>
                    <figure>
                        <artwork>
                            <![CDATA[
+-----------------------------------------------------+
|  SIGN(d_sign, M)                                    |
|-----------------------------------------------------|
|  Input:                                             |
|  - the sign key d_sign: 0 < d_sign < q;             |
|  - the byte string M in B*.                         |
|  Output:                                            |
|  - signature value sgn in B_{2*l}.                  |
|-----------------------------------------------------|
|  1. (r, s) = SIGNGOST(d_sign, M)                    |
|  2. Return str_l(r) | str_l(s).                     |
|-----------------------------------------------------+
                            ]]>
                        </artwork>
                    </figure>
                </t>
                <t>
                    where
                    <list style="symbols">
                        <t>
                            q is the subgroup order of group of points of the elliptic curve;
                        </t>
                        <t>
                            l is defined as follows:
                            <list style="symbols">
                                <t>
                                    l = 32 for gostr34102012_256a, gostr34102012_256b, gostr34102012_256c
                                    and gostr34102012_256d signature schemes;
                                </t>
                                <t>
                                    l = 64 for gostr34102012_512a, gostr34102012_512b and gostr34102012_512c
                                    signature schemes;
                                </t>
                            </list>
                        </t>
                        <t>
                            SIGNGOST is an algorithm which takes as an input private key d_sign and message M and returns a pair of integers (r, s)
                            calculated during signature generation process in accordance with the GOST R 34.10-2012 signature algorithm
                            (see Section 6.1 of <xref target="RFC7091"/>).
                        </t>
                    </list>
                </t>
                <t>
                    Note: The signature value sgn is the concatenation of two strings that are byte representations of r and s values in the little-endian format.
                </t>
            </section>
        </section>


        <section anchor="KEA" title ="Key Exchange and Authentication">
            <t>
                Key exchange and authentication process in case of using TLS13_GOST cipher suites is defined in 
                <xref target="KE"/>, <xref target="Auth"/> and <xref target="HandshakeMessages"/>.
            </t>

            <section anchor="KE" title="Key Exchange">
                <t>
                    TLS13_GOST cipher suites support three basic key exchange modes which are defined in <xref target="RFC8446"/>: ECDHE, PSK-only and PSK-with-ECDHE.
                </t>
                <t>
                    Note: In accordance with <xref target="RFC8446"/> TLS 1.3 also supports key exchange modes based on Diffie-Hellman protocol 
                    over finite fields. However, TLS13_GOST cipher suites MUST use only modes based on Diffie-Hellman protocol over elliptic curves.
                </t>
                <t>
                    In accordance with <xref target="RFC8446"/> PSKs can be divided into two types:
                    <list style="symbols">
                        <t>
                            internal PSKs which can be established during the previous connection;
                        </t>
                        <t>
                            external PSKs which can be established out of band.
                        </t>
                    </list>
                </t>
                <t>
                    If TLS13_GOST cipher suite is negotiated, PSK-only key exchange mode SHOULD be established only via the internal PSKs, and external PSKs
                    SHOULD be used only in PSK-with-ECDHE mode (see more in <xref target="Security"/>).
                </t>
                <t>
                    If TLS13_GOST cipher suite is negotiated and ECDHE or PSK-with-ECDHE key exchange mode is used the ECDHE shared secret value should be calculated 
                    in accordance with <xref target="ECDHE"/> on the basis of one of the elliptic curves defined in <xref target="SGR"/>.
                </t>
                <section anchor="ECDHE" title="ECDHE Shared Secret Calculation">
                        <t>
                            If TLS13_GOST cipher suite is negotiated, ECDHE shared secret value should be calculated in accordance with <xref target="ClientECDHECalc"/> 
                            and <xref target="ServerECDHECalc"/>. The public ephemeral keys used to obtain ECDHE shared secret value should be represented in format 
                            described in <xref target="EphKeyRepr"/>.
                        </t>
                    <section anchor="ClientECDHECalc" title="ECDHE Shared Secret Calculation on Client Side">
                        <t>
                            The client calculates ECDHE shared secret value in accordance with the following steps:
                        </t>
                        <t>
                            1. Chooses from all supported curves E_1, ..., E_R the set of curves E_{i_1}, ..., E_{i_r}, 1 &#x2264; i_1 &#x2264; i_r &#x2264; R, where
                            <list style="symbols">
                                <t>
                                    r &#x2265; 1 in the case of the first ClientHello message;
                                </t>
                                <t>
                                    r = 1 in the case of responding to HelloRetryRequest message, E_{i_1} corresponds to the curve
                                    indicated in the "key_share" extension in the HelloRetryRequest message.
                                </t>
                            </list>
                        </t>
                        <t>
                            2. Generates ephemeral key pairs (d_C^{i_1}, Q_C^{i_1}), ..., (d_C^{i_r}, Q_C^{i_r}) corresponding to
                            the curves E_{i_1}, ..., E_{i_r}, where for each i in {i_1, ..., i_r}:
                            <list style="symbols">
                                <t>
                                    d_C^i is chosen from {1, ..., q_i - 1} at random;
                                </t>
                                <t>
                                    Q_C^i = d_C^i * P_i.
                                </t>
                            </list>
                        </t>
                        <t>
                            3. Sends ClientHello message specified in accordance with Section 4.1.2 of <xref target="RFC8446"/>
                            and <xref target="HelloMessages"/>, which contains:
                            <list style="symbols">
                                <t>
                                    "key_share" extension with public ephemeral keys Q_C^{i_1}, ..., Q_C^{i_r} generated in accordance with
                                    Section 4.2.8 of <xref target="RFC8446"/>;
                                </t>
                                <t>
                                    "supported_groups" extension with supported curves E_1, ..., E_R generated in accordance with
                                    Section 4.2.7 of <xref target="RFC8446"/>.
                                </t>
                            </list>
                        </t>
                        <t>
                            Note: Client MAY send an empty "key_share" extension in the first ClientHello in order to request group
                            selection from the server in the HelloRetryRequest message and to generate ephemeral key for the selected group only.
                            The ECDHE value may be calculated without sending HelloRetryRequest, if the "key_share" extension in the first
                            ClientHello message consists the value corresponded to the curve that will be selected by the server.
                        </t>
                        <t>
                            4. In case of receiving HelloRetryRequest message client MUST return to step 1 and correct parameters in accordance
                            with Section 4.1.2 of <xref target="RFC8446"/>.
                            In case of receiving ServerHello message client proceeds to the next step. In other cases client MUST terminate the
                            connection with "unexpected_message" alert.
                        </t>
                        <t>
                            5. Extracts curve E_res and ephemeral key Q_S^res, res in {1, ..., R}, from ServerHello message and checks whether
                            the Q_S^res belongs to E_res. If this check fails, the client MUST abort the handshake with "handshake_failure" alert.
                        </t>
                        <t>
                            6. Generates Q^ECDHE:
                            <list style="empty">
                                <t>
                                    Q^ECDHE = (X^ECDHE, Y^ECDHE) = (h_res * d_C^res) * Q_S^res.
                                </t>
                            </list>
                        </t>
                        <t>
                            7. Client MUST check whether the computed shared secret Q^ECDHE is not equal to the zero point O_res. If this check fails, 
                            the client MUST abort the handshake with "handshake_failure" alert.
                        </t>
                        <t>
                            8. Shared secret value ECDHE is the byte representation of the coordinate X^ECDHE of point Q^ECDHE in the little-endian format:
                            <list style="empty">
                                <t>
                                    ECDHE = str_{coordinate_length}(X^ECDHE),
                                </t>
                            </list>
                        </t>
                        <t>
                            where the coordinate_length value is defined by the particular elliptic curve (see <xref target="SGR"/>).
                        </t>
                    </section>

                    <section anchor ="ServerECDHECalc" title="ECDHE Shared Secret Calculation on Server Side">
                        <t>
                            Upon receiving the ClientHello message, the server calculates ECDHE shared secret value in accordance with the following steps:
                        </t>
                        <t>
                            1. Chooses the curve E_res, res in {1, ..., R}, from the list of the curves E_1, ..., E_R indicated in "supported_groups"
                            extension in ClientHello message and the corresponding public ephemeral key value Q_C^res from the list Q_C^{i_1}, ..., Q_C^{i_r},
                            1 &#x2264; i_1 &#x2264; i_r &#x2264; R, indicated in "key_share" extension. If no corresponding public ephemeral key value is found
                            (res in {1, ..., R}\{i_1, ..., i_r}), server MUST send HelloRetryRequest message with "key_share" extension indicating the selected
                            elliptic curve E_res and wait for the new ClientHello message.
                        </t>
                        <t>
                            2. Checks whether Q_C^res belongs to E_res. If this check fails, the server MUST abort the handshake with "handshake_failure" alert.
                        </t>
                        <t>
                            3. Generates ephemeral key pair (d_S^res, Q_S^res) corresponding to E_res:
                            <list style="symbols">
                                <t>
                                    d_S^res is chosen from {1, ..., q_res - 1} at random;
                                </t>
                                <t>
                                    Q_S^res = d_S^res * P_res.
                                </t>
                            </list>
                        </t>
                        <t>
                            4. Sends ServerHello message generated in accordance with Section 4.1.3 of <xref target="RFC8446"/>
                            and <xref target="HelloMessages"/> with "key_share" extension which contains public ephemeral key
                            value Q_S^res corresponding to E_res.
                        </t>
                        <t>
                            5. Generates Q^ECDHE:
                            <list style="empty">
                                <t>
                                    Q^ECDHE = (X^ECDHE, Y^ECDHE) = (h_res * d_S^res) * Q_C^res.
                                </t>
                            </list>
                        </t>
                        <t>
                            6. Server MUST check whether the computed shared secret Q^ECDHE is not equal to the zero point O_res. If this check fails, the server MUST
                            abort the handshake with "handshake_failure" alert.
                        </t>
                        <t>
                            7. Shared secret value ECDHE is the byte representation of the coordinate X^ECDHE of point Q^ECDHE in the little-endian format:
                            <list style="empty">
                                <t>
                                    ECDHE = str_{coordinate_length}(X^ECDHE),
                                </t>
                            </list>
                        </t>
                        <t>
                            where the coordinate_length value is defined by the particular elliptic curve (see <xref target="SGR"/>).
                        </t>
                    </section>

                    <section anchor="EphKeyRepr" title="Public ephemeral key representation">
                        <t>
                            This section defines the representation format of the public ephemeral keys generated during ECDHE shared secret calculation
                            (see <xref target="ClientECDHECalc"/> and <xref target="ServerECDHECalc"/>).
                        </t>
                        <t>
                            If TLS13_GOST cipher suite is negotiated and ECDHE or PSK-with-ECDHE key exchange mode is used, the public ephemeral key Q
                            indicated in the KeyShareEntry.key_exchange field MUST contain the data defined by the following structure:
                        </t>
                        <t>
                            <figure>
                                <artwork>
                                    <![CDATA[
struct {
    opaque X[coordinate_length];
    opaque Y[coordinate_length];
} PlainPointRepresentation;
                                    ]]>
                                </artwork>
                            </figure>
                        </t>
                        <t>
                            where X and Y, respectively, contain the byte representations of the x and the y values of point Q (Q = (x, y)) in the little-endian format
                            and are specified as follows:
                            <list style="empty">
                                <t>
                                    X = str_{coordinate_length}(x);
                                </t>
                                <t>
                                    Y = str_{coordinate_length}(y).
                                </t>
                            </list>
                        </t>
                        <t>
                            The coordinate_length value is defined by the particular elliptic curve (see <xref target="SGR"/>).
                        </t>
                    </section>
                </section>

                <section anchor="SGR" title="Values for the TLS Supported Groups Registry">
                    <t>
                        The "supported_groups" extension is used to indicate the set of the elliptic curves supported by an endpoint and is defined
                        in Section 4.2.7 <xref target="RFC8446"/>. This extension is always contained in ClientHello message and optionally
                        in EncryptedExtensions message.
                    </t>
                    <t>
                        This section defines the following seven elliptic curves that can be used to support Russian cryptographic algorithms:
                    </t>
                    <t>
                        <figure>
                            <artwork>
                                <![CDATA[
enum {
    GC256A(0x22), GC256B(0x23), GC256C(0x24), GC256D(0x25), 
    GC512A(0x26), GC512B(0x27), GC512C(0x28) 
} NamedGroup;
                                ]]>
                            </artwork>
                        </figure>
                    </t>
                    <t>
                        If TLS13_GOST cipher suite is negotiated and ECDHE or PSK-with-ECDHE key exchange mode is established, one of the elliptic curves listed above SHOULD be used.
                    </t>
                    <t>
                        Each curve corresponds to the particular identifier and specifies the value of coordinate_length parameter (see "cl" column) as follows:
                    </t>
                    <t>
                        <figure>
                            <artwork>
                                <![CDATA[
+-----------+--------------------------------------+----+---------+
|Description|       Curve Identifier Value         | cl |Reference|
+-----------+--------------------------------------+----+---------+
|  GC256A   | id-tc26-gost-3410-2012-256-paramSetA | 32 | RFC 7836|
+-----------+--------------------------------------+----+---------+
|  GC256B   |id-GostR3410-2001-CryptoPro-A-ParamSet| 32 | RFC 4357|
+-----------+--------------------------------------+----+---------+
|  GC256C   |id-GostR3410-2001-CryptoPro-B-ParamSet| 32 | RFC 4357|
+-----------+--------------------------------------+----+---------+
|  GC256D   |id-GostR3410-2001-CryptoPro-C-ParamSet| 32 | RFC 4357|
+-----------+--------------------------------------+----+---------+
|  GC512A   |  id-tc26-gost-3410-12-512-paramSetA  | 64 | RFC 7836|
+-----------+--------------------------------------+----+---------+
|  GC512B   |  id-tc26-gost-3410-12-512-paramSetB  | 64 | RFC 7836|
+-----------+--------------------------------------+----+---------+
|  GC512C   | id-tc26-gost-3410-2012-512-paramSetC | 64 | RFC 7836|
+-----------+--------------------------------------+----+---------+
                             Table 5
                                ]]>
                            </artwork>
                        </figure>
                    </t>
                    <t>
                        Note: The identifier values and the corresponding elliptic curves are the same as in <xref target="DraftGostTLS12"/>.
                    </t>
                </section>
            </section>

            <section anchor="Auth" title="Authentication">
                <t>
                    In accordance with <xref target="RFC8446"/> authentication can happen via signature with certificate or via symmetric pre-shared key (PSK).
                    The server side of the channel is always authenticated; the client side is optionally authenticated.
                </t>
                <t>
                    PSK-based authentication happens as a side effect of key exchange. If TLS13_GOST cipher suite is negotiated, external PSKs SHOULD be combined 
                    only with the mutual authentication (see more in <xref target="Security"/>).
                </t>
                <t>
                    Certificate-based authentication happens via Authentication messages and optional CertificateRequest message (sent if client authentication is required).
                    In case of negotiating TLS13_GOST cipher suites the signature schemes used for certificate-based authentication are defined in <xref target="SSD"/>
                    and the Authentication messages are specified in <xref target="Cert"/> and <xref target="CV"/>. The CertificateRequest message is specified in <xref target="CR"/>.
                </t>
            </section>

            <section anchor="HandshakeMessages" title ="Handshake Messages">
                <t>
                    The TLS13_GOST cipher suites specify the ClientHello, ServerHello, CertificateRequest, Certificate 
                    and CertificateVerify handshake messages that are described in further detail below.
                </t>

                <section anchor="HelloMessages" title ="Hello Messages">
                    <t>
                        The ClientHello message is sent when a client first connects to a server or responds 
                        to a HelloRetryRequest message and is specified in accordance with <xref target="RFC8446"/> as follows.
                    </t>
                    <t>
                        <figure>
                            <artwork>
                                <![CDATA[
struct {
    ProtocolVersion legacy_version = 0x0303;    /* TLS v1.2 */
    Random random;
    opaque legacy_session_id<0..32>;
    CipherSuite cipher_suites<2..2^16-2>;
    opaque legacy_compression_methods<1..2^8-1>;
    Extension extensions<8..2^16-1>;
} ClientHello;
                                ]]>
                            </artwork>
                        </figure>
                    </t>
                    <t>
                        In order to negotiate a TLS13_GOST cipher suite, the ClientHello message MUST meet the following requirements.
                        <list style="symbols">
                            <t>
                                The ClientHello.cipher_suites field MUST contain the values defined in <xref target="CipherSuites"/>.
                            </t>
                            <t>
                                If server authentication via a certificate is required, the extension_data field 
                                of the "signature_algorithms" extension MUST contain the values defined in <xref target="SSD"/>, 
                                which correspond to the GOST R 34.10-2012 signature algorithm.
                            </t>
                            <t> 
                                If server authentication via a certificate is required and the client uses optional
                                "signature_algorithms_cert" extension, the extension_data field of this extension SHOULD contain the
                                values defined in <xref target="SSD"/>, which correspond to the GOST R 34.10-2012 signature algorithm.
                            </t>
                            <t>
                                If client wants to establish TLS 1.3 connection using ECDHE shared secret value, the extension_data field 
                                of the "supported_groups" extension MUST contain the elliptic curve identifiers defined 
                                in <xref target="SGR"/>.
                            </t>
                        </list>
                    </t>
                    <t> 
                        The ServerHello message is sent by the server in response to a ClientHello message to negotiate 
                        an acceptable set of handshake parameters based on the ClientHello and is specified in accordance 
                        with <xref target="RFC8446"/> as follows.
                    </t>
                    <t>
                        <figure>
                            <artwork>
                                <![CDATA[
struct {
    ProtocolVersion legacy_version = 0x0303;    /* TLS v1.2 */
    Random random;
    opaque legacy_session_id_echo<0..32>;
    CipherSuite cipher_suite;
    uint8 legacy_compression_method = 0;
    Extension extensions<6..2^16-1>;
} ServerHello;
                                ]]>
                            </artwork>
                        </figure>
                    </t>
                    <t> 
                        In case of negotiating a TLS13_GOST cipher suite, the ServerHello message MUST meet the following requirements.
                        <list style="symbols">
                            <t>
                                The ServerHello.cipher_suite field MUST contain one of the values defined 
                                in <xref target="CipherSuites"/>.
                            </t>
                            <t>
                                If server decides to establish TLS 1.3 connection using ECDHE shared secret value, 
                                the extension_data field of the "key_share" extension MUST contain the elliptic curve 
                                identifier and the public ephemeral key that satisfy the following conditions.
                                <list style="symbols">
                                   <t>
                                        The elliptic curve identifier corresponds to a value that was provided in the 
                                        "supported_groups" and the "key_share" extensions in the ClientHello message.
                                   </t> 
                                   <t>
                                        The elliptic curve identifier is one of the values defined in <xref target="SGR"/>.
                                   </t> 
                                   <t>
                                        The public ephemeral key corresponds to the elliptic curve specified by the 
                                        KeyShareEntry.group identifier.
                                   </t> 
                                </list>
                            </t>
                        </list>
                    </t>
                </section>

                <section anchor="CR" title ="CertificateRequest">
                    <t> 
                        This message is sent when server requests client authentication via a certificate and is specified in 
                        accordance with <xref target="RFC8446"/> as follows.
                    </t>
                    <t>
                        <figure>
                            <artwork>
                                <![CDATA[
struct {
    opaque certificate_request_context<0..2^8-1>;
    Extension extensions<2..2^16-1>;
} CertificateRequest;
                                ]]>
                            </artwork>
                        </figure>
                    </t>
                    <t>
                        If TLS13_GOST cipher suite is negotiated, the CertificateRequest message MUST meet the following 
                        requirements.
                        <list style="symbols">
                            <t>
                                The extension_data field of the "signature_algorithms" extension MUST contain only the values 
                                defined in <xref target="SSD"/>.
                            </t>
                            <t>
                                If server uses optional "signature_algorithms_cert" extension, the extension_data field
                                of this extension SHOULD contain only the values defined in <xref target="SSD"/>.
                            </t>
                        </list>
                    </t>
                </section>

                <section anchor="Cert" title ="Certificate">
                    <t> 
                        This message is sent to convey the endpoint's certificate chain to the peer and is specified in 
                        accordance with <xref target="RFC8446"/> as follows.
                    </t>
                    <t>
                        <figure>
                            <artwork>
                                <![CDATA[
struct {
    opaque certificate_request_context<0..2^8-1>;
    CertificateEntry certificate_list<0..2^24-1>;
} Certificate;
                                ]]>
                            </artwork>
                        </figure>
                    </t>
                    <t>
                        If TLS13_GOST cipher suite is negotiated, the Certificate message MUST meet the following requirements.
                        <list style="symbols">
                            <t>
                                Each endpoint's certificate provided to the peer MUST be signed using the algorithm 
                                which corresponds to a signature scheme indicated by the peer in its "signature_algoritms_cert" 
                                extension, if present (or in the "signature_algorithms" extension, otherwise).
                            </t>
                            <t> 
                                The signature algorithm used for signing certificates SHOULD correspond to the one of the 
                                signature schemes defined in <xref target="SSD"/>.
                            </t>
                        </list>
                    </t>
                    <!--<t>
                        Note: A certificate containing a key for one signature algorithm MAY be signed using 
                        a different signature algorithm, but all the signature algoritms used by an endpoint to create 
                        certificate chain MUST correspond to the signature schemes indicated by the peer in its
                        "signature_algoritms_cert" extension, if present (or "signature_algorithms" extension, otherwise).
                    </t>
                    <t>
                        Note: If the server cannot produce a certificate chain that is signed only via the indicated supported algorithms 
                        (for example, if all of the server certificates in the chain are signed with the old signature algorithms 
                        such as GOST R 34.10-94which don't have the values to be indicated by the client in its "signature_algorithms_cert" 
                        extension), then it SHOULD continue the handshake by sending the client a certificate chain of its choice that may 
                        include algorithms that are not known to be supported by the client. Client MUST abort the handshake with a 
                        "bad_certificate" alert if the server Certificate message contains at least one certificate signed with an 
                        unsupported signature algorithm.
                    </t>-->
                </section>

                <section anchor="CV" title ="CertificateVerify">
                    <t>
                        This message is sent to provide explicit proof that an endpoint possesses the private key 
                        corresponding to the public key indicated in its certificate and is specified in accordance 
                        with <xref target="RFC8446"/> as follows.
                    </t>
                    <t>
                        <figure>
                            <artwork>
                                <![CDATA[
struct {
    SignatureScheme algorithm;
    opaque signature<0..2^16-1>;
} CertificateVerify;
                                ]]>
                            </artwork>
                        </figure>
                    </t>
                    <t>
                        If TLS13_GOST cipher suite is negotiated, the CertificateVerify message MUST meet the following requirements.
                        <list style="symbols">
                            <t>
                                The CertificateVerify.algorithm field MUST contain the signature scheme identifier which 
                                corresponds to the value indicated in the peer's "signature_algorithms" extension and 
                                which is one of the values defined in <xref target="SSD"/>.
                            </t>
                            <t>
                                The CertificateVerify.signature field contains the sgn value, which is computed as follows:
                                <list style="empty">
                                    <t>
                                        sgn = SIGN(d_sign, M),
                                    </t>
                                </list>
                            </t>
                            <t>
                                where
                                <list style="symbols">
                                    <t>
                                        the SIGN function is defined in <xref target="SSD"/>,
                                    </t>
                                    <t>
                                        d_sign is the sender long-term private key that corresponds to
                                        the sender long-term public key Q_sign from the sender's certificate,
                                    </t>
                                    <t>
                                        the message M is defined in accordance with Section 4.4.3 of <xref target="RFC8446"/>.
                                    </t>
                                </list>
                            </t>
                        </list>
                    </t>
                </section>
            </section>
        </section>

        <section anchor="IANACON" title="IANA Considerations">
            <t>
                IANA has added numbers {0xC1, 0x03}, {0xC1, 0x04}, {0xC1, 0x05} and {0xC1, 0x06} with the names
                TLS_GOSTR341112_256_WITH_KUZNYECHIK_MGM_L,
                TLS_GOSTR341112_256_WITH_MAGMA_MGM_L,
                TLS_GOSTR341112_256_WITH_KUZNYECHIK_MGM_S,
                TLS_GOSTR341112_256_WITH_MAGMA_MGM_S to
                the "TLS Cipher Suites" registry with this document as reference, as shown below.
            </t>
            <t>
                <figure>
                    <artwork>
                        <![CDATA[
+----------+-----------------------------+-------+-----------+
|   Value  |         Description         |DTLS-OK| Reference |
+----------+-----------------------------+-------+-----------+
|0xC1, 0x03|    TLS_GOSTR341112_256_     |   N   | this RFC  |
|          |   _WITH_KUZNYECHIK_MGM_L    |       |           |
+----------+-----------------------------+-------+-----------+
|0xC1, 0x04|    TLS_GOSTR341112_256_     |   N   | this RFC  |
|          |     _WITH_MAGMA_MGM_L       |       |           |
+----------+-----------------------------+-------+-----------+
|0xC1, 0x05|    TLS_GOSTR341112_256_     |   N   | this RFC  |
|          |   _WITH_KUZNYECHIK_MGM_S    |       |           |
+----------+-----------------------------+-------+-----------+
|0xC1, 0x06|    TLS_GOSTR341112_256_     |   N   | this RFC  |
|          |     _WITH_MAGMA_MGM_S       |       |           |
+----------+-----------------------------+-------+-----------+
                          Table 6
                        ]]>
                    </artwork>
                </figure>
            </t>
            <t>
                IANA has added numbers 0x0709, 0x070A, 0x070B, 0x070C, 0x070D, 0x070E and 0x070F with the names
                gostr34102012_256a,
                gostr34102012_256b,
                gostr34102012_256c,
                gostr34102012_256d,
                gostr34102012_512a,
                gostr34102012_512b,
                gostr34102012_512c
                to the "TLS SignatureScheme" registry, as shown below.
            </t>
            <t>
                <figure>
                    <artwork>
                        <![CDATA[
+-----------+----------------------+---------+----------+
|   Value   |      Description     | DTLS-OK | Reference|
+-----------+----------------------+---------+----------+
|  0x0709   |  gostr34102012_256a  |    N    | this RFC |
+-----------+----------------------+---------+----------+
|  0x070A   |  gostr34102012_256b  |    N    | this RFC |
+-----------+----------------------+---------+----------+
|  0x070B   |  gostr34102012_256c  |    N    | this RFC |
+-----------+----------------------+---------+----------+
|  0x070C   |  gostr34102012_256d  |    N    | this RFC |
+-----------+----------------------+---------+----------+
|  0x070D   |  gostr34102012_512a  |    N    | this RFC |
+-----------+----------------------+---------+----------+
|  0x070E   |  gostr34102012_512b  |    N    | this RFC |
+-----------+----------------------+---------+----------+
|  0x070F   |  gostr34102012_512c  |    N    | this RFC |
+-----------+----------------------+---------+----------+
                         Table 7
                        ]]>
                     </artwork>
                </figure>
            </t>
        </section>

        <section anchor="Historical" title="Historical considerations">
            <t>
                Due to historical reasons in addition to the curve identifier values listed in Table 5
                there exist some additional identifier values that correspond to
                the signature schemes as follows.
            </t>
            <t>
                <figure>
                    <artwork>
                        <![CDATA[
+--------------------+-------------------------------------------+
|     Description    |          Curve Identifier Value           | 
+--------------------+-------------------------------------------+
| gostr34102012_256b | id-GostR3410_2001-CryptoPro-XchA-ParamSet |
|                    | id-tc26-gost-3410-2012-256-paramSetB      |
+--------------------+-------------------------------------------+
| gostr34102012_256c | id-tc26-gost-3410-2012-256-paramSetC      |
+--------------------+-------------------------------------------+
| gostr34102012_256d | id-GostR3410-2001-CryptoPro-XchB-ParamSet |
|                    | id-tc26-gost-3410-2012-256-paramSetD      |
+--------------------+-------------------------------------------+
                         Table 8
                        ]]>
                    </artwork>
                </figure>
            </t>
            <t>
                Client should be prepared to handle any of them correctly if corresponding signature scheme is included in the "signature_algorithms"
                or "signature_algorithms_cert" extensions.
            </t>
        </section>

        <section anchor="Security" title="Security Considerations">
            <t>
                In order to create an effective implementation client and server SHOULD follow the rules below.
            </t>
            <t>
                1. While using TLSTREE algorithm function KDF_j, j = 1, 2, 3, SHOULD be invoked only if the record sequence number seqnum reaches such a value that
                <list  style = "empty">
                    <t>
                        seqnum &amp; C_j != (seqnum - 1) &amp; C_j.
                    </t>
                </list>
            </t>
            <t>
                Otherwise the previous value should be used.
            </t>
            <t>
                2. For each pre-shared key value PSK the binder_key value should be computed only once within all connections where ClientHello message contains a
                "pre_shared_key" extension indicating this PSK value.
            </t>
            <t>
                In order to ensure the secure TLS 1.3 connection client and server SHOULD fulfil the following requirements.
            </t>
            <t>
                1. An internal PSK value is NOT RECOMMENDED to be used to establish more than one TLS 1.3 connection.
            </t>
            <t>
                2. 0-RTT data SHOULD NOT be sent during TLS 1.3 connection. The reasons for this restriction are that the 0-RTT data is not forward secret and 
                is not resistant to replay attacks (see more in Section 2.3 of <xref target="RFC8446"/>).
            </t>
            <t>
                3. If client authentication is required, server SHOULD NOT send Application Data, NewSessionTicket and KeyUpdate messages
                prior to receiving the client's Authentication messages since any data sent at that point is
                being sent to an unauthenticated peer.
            </t>
            <t>
                4. External PSKs SHOULD be used only in PSK-with-ECDHE mode. In case of using external PSK in PSK-only mode the attack described in <xref target="Selfie"/> 
                is possible which leads to the situation when client establishes connection to itself. One of the mitigations proposed in <xref target="Selfie"/> is to use 
                certificates, however, in that case, an impersonation attack as in <xref target="AASS19"/> occurs.
                If the connections are established with additional usage
                of key_share extension (in PSK-with-ECDHE mode), then the adversary which just echoes messages cannot reveal the traffic
                key material (as long as the used group is secure).
            </t>
            <t>
                5. In case of using external PSK, the mutual authentication MUST be provided by the external PSK distribution mechanism between the endpoints
                which guarantees that the derived external PSK is unknown to anyone but the endpoints. In addition, the endpoint roles (i.e. client and server) 
                MUST be fixed during this mechanism and each role can match only to one endpoint during the whole external PSK lifetime.
            </t>
        </section>

    </middle>


    <back>
        <references title="Normative References">
            <?rfc include='http://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml' ?>
            <?rfc include='http://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.7801.xml' ?>
            <?rfc include='http://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.6986.xml' ?>
            <?rfc include='http://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.7091.xml' ?>
            <?rfc include='http://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.7836.xml' ?>
            <?rfc include='http://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.8174.xml' ?>
            <?rfc include='http://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.8446.xml' ?>
            <?rfc include='http://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.8645.xml' ?>
            <reference anchor="DraftMGM" target="https://tools.ietf.org/html/draft-smyshlyaev-mgm-17">
              <front>
                <title> Multilinear Galois Mode (MGM)</title>
                <author initials="S." surname="Smyshlyaev" fullname="S. Smyshlyaev">
                  <organization> CryptoPro </organization>
                </author>
                <author initials="V." surname="Nozdrunov" fullname="V. Nozdrunov">
                  <organization>TC 26</organization>
                </author>
                <author initials="V." surname="Shishkin" fullname="V. Shishkin">
                  <organization>TC 26</organization>
                </author>
                <author initials="E." surname="Smyshlyaeva" fullname="E. Smyshlyaeva">
                  <organization>CryptoPro</organization>
                </author>
                <date year="2019"/>
              </front>
            </reference>
            <reference anchor="DraftGostTLS12" target="https://tools.ietf.org/html/draft-smyshlyaev-tls12-gost-suites-08">
              <front>
                <title>
                  GOST Cipher Suites for Transport Layer Security (TLS) Protocol Version 1.2
                </title>
                <author initials="S." surname="Smyshlyaev" fullname="S. Smyshlyaev">
                 <organization> CryptoPro </organization>
                </author>
                <author initials="D." surname="Belyavsky" fullname="D. Belyavsky">
                  <organization> Cryptocom </organization>
                </author>
                <author initials="M." surname="Saarinen" fullname="M. Saarinen">
                  <organization> Independent Consultant </organization>
                </author>
                <date year="2019"/>
             </front>
           </reference>
        </references>

        <references title="Informative References">

            <reference anchor="GOST3412-2015">
                <front>
                    <title>
                        Information technology. Cryptographic data security. Block ciphers
                    </title>
                    <author>
                        <organization>
                            Federal Agency on Technical Regulating and Metrology
                        </organization>
                    </author>
                    <date year="2015"/>
                </front>
                <seriesInfo name="GOST R" value="34.12-2015"/>
            </reference>
            
            <reference anchor="GOST3410-2012">
                <front>
                    <title>
                        Information technology. Cryptographic data security. Signature and verification
                        processes of [electronic] digital signature
                    </title>
                    <author>
                        <organization>
                            Federal Agency on Technical Regulating and Metrology
                        </organization>
                    </author>
                    <date year="2012"/>
                </front>
                <seriesInfo name="GOST R" value="34.10-2012"/>
            </reference>

            <reference anchor="GOST3411-2012">
                <front>
                    <title>
                        Information technology. Cryptographic Data Security. Hashing function
                    </title>
                    <author>
                        <organization>
                            Federal Agency on Technical Regulating and Metrology
                        </organization>
                    </author>
                    <date year="2012"/>
                </front>
                <seriesInfo name="GOST R" value="34.11-2012"/>
            </reference>

            <reference anchor="Selfie" target="https://eprint.iacr.org/2019/347.pdf">
                <front>
                    <title>
                        Selfie: reflections on TLS 1.3 with PSK
                    </title>
                    <author initials="N." surname="Drucker" fullname="N. Drucker">
                        <organization> University of Haifa </organization>
                    </author>
                    <author initials="S." surname="Gueron" fullname="S. Gueron">
                        <organization> Amazon </organization>
                    </author>
                    <date year="2019" month="April"/>
                </front>
                <seriesInfo name="Cryptology ePrint Archive" value="Report 2019/347"/>
            </reference>

            <reference anchor="AASS19" target="https://eprint.iacr.org/2019/421.pdf">
                <front>
                    <title>
                        Continuing to reflect on TLS 1.3 with external PSK
                    </title>
                    <author initials="L." surname="Akhmetzyanova" fullname="L. Akhmetzyanova">
                        <organization> CryptoPro </organization>
                    </author>
                    <author initials="E." surname="Alekseev" fullname="E. Alekseev">
                        <organization> CryptoPro </organization>
                    </author>
                    <author initials="E." surname="Smyshlyaeva" fullname="E. Smyshlyaeva">
                        <organization> CryptoPro </organization>
                    </author>
                    <author initials="A." surname="Sokolov" fullname="A. Sokolov">
                        <organization> CryptoPro </organization>
                    </author>
                    <date year="2019" month="April"/>
                </front>
                <seriesInfo name="Cryptology ePrint Archive" value="Report 2019/421"/>
            </reference>
        </references>

        <section anchor="Appendix" title="Test Examples">
          <t>
            TODO
          </t>
        </section>

        <section anchor="contributors" title="Contributors">
            <t>
                <list style="symbols">
                    <t>
                        Lilia Akhmetzyanova <vspace />
                        CryptoPro<vspace/>
                        lah@cryptopro.ru
                    </t>
                    <t>
                        Alexandr Sokolov <vspace/>
                        CryptoPro <vspace/>
                        sokolov@cryptopro.ru
                    </t>
                    <t>
                        Vasily Nikolaev<vspace/>
                        CryptoPro<vspace />
                        nikolaev@cryptopro.ru
                    </t>
                    <t>
                        Lidia Nikiforova<vspace/>
                        CryptoPro<vspace />
                        nikiforova@cryptopro.ru
                    </t>
                </list>
            </t>
         </section>

        <section title="Acknowledgments">

        </section>

    </back>
</rfc>
