Re: [Cfrg] NIST crypto group and HKDF (and therefore TLS 1.3)

"\"Torsten Schütze\"" <Torsten.Schuetze@gmx.net> Tue, 12 May 2020 12:36 UTC

Return-Path: <Torsten.Schuetze@gmx.net>
X-Original-To: cfrg@ietfa.amsl.com
Delivered-To: cfrg@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 64BFB3A0864; Tue, 12 May 2020 05:36:15 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.099
X-Spam-Level:
X-Spam-Status: No, score=-2.099 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (1024-bit key) header.d=gmx.net
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UdoDaa1bmOXh; Tue, 12 May 2020 05:36:13 -0700 (PDT)
Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 892413A085A; Tue, 12 May 2020 05:36:10 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1589286961; bh=bSp0ZR4UjmyKaBgij5JkarTe8kQ7Iiy1m1alZ5mx43A=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=e3d62clWl9hOnn62bpodOgX589djsWnYUYMLS4OFAFw2E/Jge0f73KuVRxEh0d/Q1 xaQds/4qv1lRCZzR/7MRS+85QM/MwiCZ8+0QytxDdYZ5BZ2uza4IZfByxiPXrVekuq aF7qjohQfXLwPkfPgQKuXCp+UpoiiTWyz84uiqps=
X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c
Received: from [80.246.32.33] ([80.246.32.33]) by web-mail.gmx.net (3c-app-gmx-bap51.server.lan [172.19.172.121]) (via HTTP); Tue, 12 May 2020 14:36:01 +0200
MIME-Version: 1.0
Message-ID: <trinity-363f5b58-667b-4ea0-883e-b8bcb998d051-1589286961057@3c-app-gmx-bap51>
From: =?UTF-8?Q?=22Torsten_Sch=C3=BCtze=22?= <Torsten.Schuetze@gmx.net>
To: "Dang, Quynh H. (Fed)" <quynh.dang@nist.gov>
Cc: "Hugo Krawczyk" <hugo@ee.technion.ac.il>, "cfrg@ietf.org" <cfrg@ietf.org>, "tls@ietf.org" <tls@ietf.org>, "rsalz@akamai.com" <rsalz@akamai.com>
Content-Type: text/plain; charset=UTF-8
Date: Tue, 12 May 2020 14:36:01 +0200
Importance: normal
Sensitivity: Normal
In-Reply-To: <BY5PR09MB47550508109A23C190D4326CF3BE0@BY5PR09MB4755.namprd09.prod.outlook.com>
References: <07D37E65-0951-49BB-B86E-BD3167ADB352@akamai.com> <BY5PR09MB4755E58AF9CDF696C0E7F649F3A10@BY5PR09MB4755.namprd09.prod.outlook.com> <CADi0yUMuV0U=YWB2cFMYRsitLHeWEaV2WM9XVTdKqDkOsyvaGA@mail.gmail.com> <trinity-5bbd0a19-0945-419f-a806-5b2757ed2c42-1589283598300@3c-app-gmx-bs46> <BY5PR09MB47550508109A23C190D4326CF3BE0@BY5PR09MB4755.namprd09.prod.outlook.com>
Content-Transfer-Encoding: quoted-printable
X-UI-Message-Type: mail
X-Priority: 3
X-Provags-ID: V03:K1:0jm1oQnIGjsHa//PcFcV+a0DuRQPa/x4MfW+w+zO7+E/ZtG6jmfn2YxMfp804qH8SCLyL hMXA6ty19RHlLEYsatufkcqLHymErrOT+E2nOwnh5u4a4MfzjL2CwKMETgGTrGb1na8iE3AYROun QCBzrG5WmG9c0mqw3krp+05XBSRPbpVIF2hBFkNNWBiLczL1YSka2RFSA+3YqRyTkC49pCAdJMtg bET7ixKA4ie5vxDBuzTBCyXj1omb0yeoDws1pe5J/7eEwIKhsjNL4TTZ2TQJhA2vWvIMmbERQYen Go=
X-UI-Out-Filterresults: notjunk:1;V03:K0:7JekzwyXwu8=:mIzs6gm3mWbiLxULb8uH2m iUT9Xlkm9oc3OgXQhs+SOtjej52yBAr+VwVVyWqieNCklXFCJSg9WuCDDoZSzDE43iMnDfOiS WYZ85m49o6dyffKbP3k9prGapihPgerg8S6vZWa5HMTJ3jmWwWch/rUBW3ETzqrdOntcO9DEu O3e2lQcOM1hJb9uLut35BKYSgVGoL9j+SAD46Y6p4i1OgeoUPjfzyla2gMMfLVE5KiZDPWPUL yLz+JXIjbBVWdcSYtE8RC7BIlkaKOP5lvir9ooxWqTp7UnRabg5+1u6JvuB9NDw1i3A2izrYm 5Byswe2qMW5nQSU1b/wimhEE53EFThUm1ID2rjDnpemSiWBiJC4gbJu6W2nN9Wd2BIP/hWtdu ZZOqc+cT0clDgOP74DQR3fyfZUvWWsLjF1Rp15Pf00fgya7O9yG3f6N1a8PxSA0RQIFb3fv3V nx8TJsflWEPIL5J/4LBcxIpCkq4DJyLr3G8kyMdNpzAuvG4vHqZ2X3altTQZizArNm5uWryRj xq5WO6qKtGFqMbnZBfuVhcq9JpSWx2pBUAYW4MI2uLd3c5sk62kNScLRFm5OF1lRmXU1QaXwO yGtfHRbFTCoPPtOv7/DsauBWAWyJpEk9sx1GsmsVw/vg28+wYKn+3fZ9LWLLlU/QYLgb6VbHi mkIuQ8wRbQJ0WvLG2NDhXBHLziv6Ox01g8jtj36hrDkJkbn4FTDsdzLWu3Mmv9q6t0dE=
Archived-At: <https://mailarchive.ietf.org/arch/msg/cfrg/ce3jbAxfseqpvgGywHNWJzXYSq0>
Subject: Re: [Cfrg] NIST crypto group and HKDF (and therefore TLS 1.3)
X-BeenThere: cfrg@irtf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Crypto Forum Research Group <cfrg.irtf.org>
List-Unsubscribe: <https://www.irtf.org/mailman/options/cfrg>, <mailto:cfrg-request@irtf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/cfrg/>
List-Post: <mailto:cfrg@irtf.org>
List-Help: <mailto:cfrg-request@irtf.org?subject=help>
List-Subscribe: <https://www.irtf.org/mailman/listinfo/cfrg>, <mailto:cfrg-request@irtf.org?subject=subscribe>
X-List-Received-Date: Tue, 12 May 2020 12:36:15 -0000

Hi Quynh,

thank you for your quick response. I knew that omitting some fields was allowed, but not that permutations are allowed, too. Okay, this makes HKDF RFC 5869 definitely to a NIST SP800-56C rev 2 compliant KDF. But what to do about the CAVP tests or approved test vectors. Couldn't NIST provide for the very often used RFC 5869 HKDF approved test vectors? I coulnd't find any. Only for some older, application specific KDFs. Of course, I can generate them by myself with an independent implementation, but I'm talking about evaluation/approval business here.

Regards 

Torsten
 

Gesendet: Dienstag, 12. Mai 2020 um 14:04 Uhr
Von: "Dang, Quynh H. (Fed)" <quynh.dang@nist.gov>
An: "Torsten Schütze" <Torsten.Schuetze@gmx.net>et>, "Hugo Krawczyk" <hugo@ee.technion.ac.il>
Cc: "cfrg@ietf.org" <cfrg@ietf.org>rg>, "tls@ietf.org" <tls@ietf.org>rg>, "rsalz@akamai.com" <rsalz@akamai.com>
Betreff: Re: [Cfrg] NIST crypto group and HKDF (and therefore TLS 1.3)

Hi Torsten,
 
Thank you for the review. I think the review helps many people to understand the HKDF's spec and its NIST's approval better. 
 
In SP 800-108 (https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-108.pdf, at the end of Section 5. (before 5.1), it says that "  Alternative orders for the input data fields may be used
for different KDFs. " .
 
And, at the end of the paragraph before that, it says "One or more of these fixed input data fields may be omitted unless required for
certain purposes as discussed in Section 7.5 and Section 7.6.".
 
After an extraction step, the output is a pseudorandom key. The KDFs in SP 800-108 are NIST's approved KDFs to derive key(s) from a pseudorandom key.  The purpose of any of these KDFs in SP 800-108 is the same with the purpose of the expansion step. Therefore, they are allowed for being used as expansion steps. 
 
Regards,
Quynh. 
 
 
 
------------------------------------------------------------

From: "Torsten Schütze" <Torsten.Schuetze@gmx.net>
Sent: Tuesday, May 12, 2020 7:39 AM
To: Hugo Krawczyk <hugo@ee.technion.ac.il>
Cc: Dang, Quynh H. (Fed) <quynh.dang@nist.gov>ov>; cfrg@ietf.org <cfrg@ietf.org>rg>; tls@ietf.org <tls@ietf.org>rg>; rsalz@akamai.com <rsalz@akamai.com>
Subject: Re: [Cfrg] NIST crypto group and HKDF (and therefore TLS 1.3)
 

Hi Hugo, hi Quynh,
 
on Monday, 2020-05-11 Hugo Krawzcyk wrote: 
 
> I haven't looked at the revisions. But in previous versions you needed lawyer skills to go through the language to see that RFC 5869 was indeed compliant with the NIST recommendation. It would be nice if this time it would make very explicit that RFC 5869 is compliant with this Recommendation.
 
Indeed. In SP800-56C Rev. 2 draft we have in lines 545, 546:

"[RFC 5869] specifies a version of the above extraction-then-expansion key-derivation procedure using HMAC for both the extraction and expansion steps."  so one would assume that HKDF according to RFC 5869 is compliant with SP800-56CR2.

However, for key expansion it refers in line 533, 532 to

"2. Call KDF( K_DK, L, {IV,} FixedInfo ) to obtain DerivedKeyingMaterial or an error indicator (see [SP 800-108] for details)."

Everything would be fine if we find KDF( K_DK, L, {IV}, FixedInfo) as

HKDF-Expand(PRK, info, L) -> OKM

The output OKM is calculated as follows:

   N = ceil(L/HashLen)
   T = T(1) | T(2) | T(3) | ... | T(N)
   OKM = first L octets of T

   where:
   T(0) = empty string (zero length)
   T(1) = HMAC-Hash(PRK, T(0) | info | 0x01)
   T(2) = HMAC-Hash(PRK, T(1) | info | 0x02)
   T(3) = HMAC-Hash(PRK, T(2) | info | 0x03)

i.e. the definitions of RFC 5869 in SP800-108. Unfortunately, the closest one could find in SP800-108 is

5.2 KDF in Feedback Mode

1.  n: = \ceil{L/h}.
2.  If n > 2^{32} -1, then indicate an error and stop.
3.  result(0):= ∅ and K(0):= IV.
4.  For i = 1 to n, do
    a.
        K(i) := PRF (KI, K(i-1) {|| [i]2 }|| Label || 0x00 || Context || [L]2)
    b.
        result(i) := result(i-1) || K(i)
5. Return: K_O := the leftmost L bits of result(n).

With the substitutions PRK = KI, HashLen = h, N = n, T(i) = K(i-1) 0x01, 0x02 = [i]_2, PKM = K_O and info = Label || 0x00 || Context || [L]_2 one is almost there, EXCEPT

- the counter 0x01, 0x02, 0x03 is at the end of the string in HKDF RFC 5869 and right-after the K(i-1), respectively T(i), in SP800-108. At least this gives different results. (This is what already Dan Brown wrote in a recent mail). I don't think this has security implications, but I'm no expert.

- With HKDF, it is only allowed to iterate up to N = 255 as L \le 255 HashLen while in SP800-108 we have n \le 2^{32}-1.

So, with this interpretation I don't see that HKDF RFC5869 is a concrete instantiation of SP800-56C rev2 draft + SP800-108. At least I couldn't find any official CAVP test vectors for such an HKDF-HMAC-SHA-256 construct. BTW, while we have such test vectors in RFC 5869 for SHA-384 (and SHA-1) there are no such things for SHA-384 or SHA-512, i.e. higher security levels. As a practitioner I would first test my HKDF RFC 5869 implementation if it is allows to iterate above N = 255. BTW, I don't have a good feeling with extracting up to 2^{32}-1 keys from a single IKM.

I would like to hear from NIST if there are any plans to provide CAVP test vectors for HKDF-HMAC-SHA-2 according to RFC 5869. In my opinion, SP800-56C rev2 draft is suboptimal as it refers for a very important component, i.e. key expansion, to another, quite old document.

Torsten