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

Dan Brown <danibrown@blackberry.com> Tue, 12 May 2020 16:32 UTC

Return-Path: <danibrown@blackberry.com>
X-Original-To: tls@ietfa.amsl.com
Delivered-To: tls@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id E1A183A03FE; Tue, 12 May 2020 09:32:00 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.271
X-Spam-Level:
X-Spam-Status: No, score=-2.271 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.173, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=unavailable autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=blackberry.com
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 3RH331WddlPa; Tue, 12 May 2020 09:31:58 -0700 (PDT)
Received: from smtp-pc10.blackberry.com (smtp-pc10.blackberry.com [74.82.81.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 416653A0404; Tue, 12 May 2020 09:31:56 -0700 (PDT)
Received: from pps.filterd (mhs400cnc.rim.net [127.0.0.1]) by mhs400cnc.rim.net (8.16.0.27/8.16.0.27) with SMTP id 04CGO2H6023621; Tue, 12 May 2020 12:31:43 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackberry.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : mime-version; s=corp19; bh=S8UuIR1oOsu3v6+fAHgd+TliIeeDN3bNMCgTiz022NA=; b=nljcQakk+o3Fxk7MTgRT+mEMAABPvwymRSGH1XoSoC5YmXpyGwUeTt8THFRu4sA5gtF+ qtxFrjFLPFSklr7YfWKzmUz9nXGMlj+2YF/P6HSCVFsqsggxM8FBHZ5n/z1MV3RtJ0iY cF/9uwSMqfo/2xJmCOnwJe8wPK9GpnWlWMmAhbzj2gUXAsSQUrpI3O6cZtqkK4C+MCOW 6jj+iNBMAv42Wo0X4IbImdmslBF8B8uX+w9SfB7MZoPxrIKgwtrDr9vYJ/R5THwx+ttU P0xqj9gmGR1Rl8yjsxHvJqAT4LSsLO08GLI2IZK4k6Cr7BSyrILgMiSN7u5kvMJjokVZ Xw==
Received: from xch210cnc.rim.net (xch210cnc.rim.net [10.3.27.115]) by mhs400cnc.rim.net with ESMTP id 30yy2wr16x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Tue, 12 May 2020 12:31:43 -0400
Received: from XCH210YKF.rim.net (10.2.27.110) by XCH210CNC.rim.net (10.3.27.115) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1913.5; Tue, 12 May 2020 12:31:42 -0400
Received: from XCH210YKF.rim.net ([fe80::81ca:ad34:fc3:5ce8]) by XCH210YKF.rim.net ([fe80::81ca:ad34:fc3:5ce8%5]) with mapi id 15.01.1913.007; Tue, 12 May 2020 12:31:42 -0400
From: Dan Brown <danibrown@blackberry.com>
To: Phillip Hallam-Baker <phill@hallambaker.com>, Hugo Krawczyk <hugo@ee.technion.ac.il>
CC: "Dang, Quynh H. (Fed)" <quynh.dang=40nist.gov@dmarc.ietf.org>, "cfrg@ietf.org" <cfrg@ietf.org>, "tls@ietf.org" <tls@ietf.org>, "Salz, Rich" <rsalz=40akamai.com@dmarc.ietf.org>
Thread-Topic: [TLS] [Cfrg] NIST crypto group and HKDF (and therefore TLS 1.3)
Thread-Index: AQHWJXY75SUMYNJzo0q8VSbsRy8U7aiiv0STgAConwCAADfrAIAAmnSAgABaSAA=
Date: Tue, 12 May 2020 16:31:42 +0000
Message-ID: <ff7ab616c7714a9789d387028df14bd0@blackberry.com>
References: <07D37E65-0951-49BB-B86E-BD3167ADB352@akamai.com> <BY5PR09MB4755E58AF9CDF696C0E7F649F3A10@BY5PR09MB4755.namprd09.prod.outlook.com> <CAMm+LwiPZm-sC0-pi+3gNb6BvSPw475j89oFh9sOBJioLdkyxw@mail.gmail.com> <CADi0yUOgWN4UR2D1AbSEpo4ZiiJQysy=b1_WTGR6RiFuqRftTQ@mail.gmail.com> <CAMm+LwhUiv44zHrh8rUrcGHmTSA6ZYt9+t3WWU0xx4GeB-oMHQ@mail.gmail.com>
In-Reply-To: <CAMm+LwhUiv44zHrh8rUrcGHmTSA6ZYt9+t3WWU0xx4GeB-oMHQ@mail.gmail.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach: yes
X-MS-TNEF-Correlator:
x-originating-ip: [100.64.97.142]
Content-Type: multipart/signed; micalg="2.16.840.1.101.3.4.2.1"; protocol="application/x-pkcs7-signature"; boundary="----=_NextPart_000_00D2_01D62859.492C2AC0"
MIME-Version: 1.0
X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.676 definitions=2020-05-12_05:2020-05-11, 2020-05-12 signatures=0
Archived-At: <https://mailarchive.ietf.org/arch/msg/tls/-HpGYspBnoA3D1W62FYZIC6eFEE>
Subject: Re: [TLS] [Cfrg] NIST crypto group and HKDF (and therefore TLS 1.3)
X-BeenThere: tls@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "This is the mailing list for the Transport Layer Security working group of the IETF." <tls.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/tls>, <mailto:tls-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/tls/>
List-Post: <mailto:tls@ietf.org>
List-Help: <mailto:tls-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/tls>, <mailto:tls-request@ietf.org?subject=subscribe>
X-List-Received-Date: Tue, 12 May 2020 16:32:02 -0000

Hi Hugo,

 

Some curious molehill questions. Please take with a grain of salt.

 

In short, does HKDF-Extract suffer from related-salt and repeated-IKM?

 

To elaborate:

 

Phillip raises a good point below about HMAC suffering from key-extension (by zero bytes).  You are right that this is not a MAC attack, the main intended use of HMAC, but now the scope of HMAC has expanded to non-MAC purposes.   

 

Surely HMAC has good PRF properties, so non-MAC applications make sense.  For what little it’s worth, I had just presumed that HKDF always used HMAC with the a strong secret key, like a good PRF should.  (I failed to verify this, though.)

 

But Phillip seems to want to use structured HMAC keys (i.e. not uniformly distributed keys), specifically the salts in HKDF-Extract, I presume.  Under my presumption, this would not be best practice (using structure or related keys).

 

So, I went to the HKDF RFC, basically expecting to find this clearly disallowed.  Re-reading the RFC, it was unclear to me what kind of salt was allowed. (The eprint might be clearer, but it is longer to find this needle.) Would it (dis)allow the structured salts Phillip described? 

 

Then, I saw a phrase in the HKDF RFC that salts were unlike IKM, because they could be re-used.  I inferred that IKM was not to be re-used.  If so, related salts should cause no problem for extraction, because a different IKM would always be used.  But might IKM be re-used?  For example, the rare event that TLS client and server both re-use their ECDHE keys.  So, I went to look at TLS 1.3.

 

In TLS 1.3, HKDF-Extract is used with both structured salts (e.g. 0), and structured IKMs (e.g. 0).  In the end, all is fine, because at least one of the salt or IKM has lots of entropy, and there were no related salts.  (The case HKDF-Extract(0,0) is mentioned in TLS 1.3, but very clearly that this case does not provide security.)  I presume TLS 1.3 designers were adhering to the intended use of HKDF-Extract.  

 

To summarize, related-salt + repeated-IKM in HKDF-Extract might lead to repeated PRK, right? This could be bad if PRK used in HKDF-Expand to create two identical stream cipher keys.  If two identical authentication keys, perhaps an unexpected replay attack might apply?  Are these a concern?  Is TLS 1.3 fine, mainly because HKDF was used correctly?  Are these related-salts really realistic: would an implementer do this? Do you think better implementer guidance is needed to prevent this type of accident?  

 

Best regards,

​​​​​

Dan

 

PS

 

The HKDF RFC clearly excludes an adversary causing related salts, so that’s good.

 

I really like both defense in depth and provable security, but I would also like it to be clear that is the main motivation for HKDF in key derivation.  To wit, HMAC itself internally derives two closely-related keys using XOR ipad and XOR opad.   You have proved this turns out fine, despite the relatedness of the two keys, because the robust property of hash function.  My point here, is if we assumed the derived keys are used in robust algorithms, e.g. AES-GCM, could they tolerate simpler ways of deriving keys, i.e. XORing a key with a non-random separation string?  To repeat, I am totally fine to use robust key derivation, like HKDF, but I would want the reason to be clear.  E.g. TLS 1.3 handshake uses HKDF as hedge against possible related-key attacks on the symmetric-key crypto in the record layer, or for better or simpler security proofs (e.g. compared to past key derivation methods).

 

As many know, hashes were, once upon a time, only used for message digests in signatures. Message-extension in hashes did not result in signature forgery.   But then people naturally wanted to use hashes (as a “utility function” in Phillip’s terms) for a MAC.  But hashes with message extension suffer from MAC forgery. Along came HMAC to the rescue, saving the day, and the rest is history.  (To exaggerate: it is, on a minute scale, repeating;)

 

 

From: TLS <tls-bounces@ietf.org> On Behalf Of Phillip Hallam-Baker
Sent: Tuesday, May 12, 2020 1:49 AM
To: Hugo Krawczyk <hugo@ee.technion.ac.il>
Cc: Dang, Quynh H. (Fed) <quynh.dang=40nist.gov@dmarc.ietf.org>; cfrg@ietf.org; tls@ietf.org; Salz, Rich <rsalz=40akamai.com@dmarc.ietf.org>
Subject: Re: [TLS] [Cfrg] NIST crypto group and HKDF (and therefore TLS 1.3)

 

 

 

On Mon, May 11, 2020 at 4:36 PM Hugo Krawczyk <hugo@ee.technion.ac.il <mailto:hugo@ee.technion.ac.il> > wrote:

There is no flaw if you use HMAC and HKDF as intended. See details below.

 

One time pads aren't flawed if you use them right. When they become a two time pad, there is a problem.

 

My point is that if we are developing schemes that are supposed to be used as utility building blocks, we need to consider all the ways they might be used and not just limit ourselves to the ones we expect. That was the argument made for defining authenticated encryption modes, it holds here as well.

 

The bottom line advise is: If you are using related (not random) salt values in HKDF, you are probably using it with  domain separation functionality. In HKDF, domain separation is enforced via the info field not the salt. Read the HKDF RFC and paper for background and rationale.

 

I am already using the info field for domain separation. I use info to generate separate keys for encryption, authentication, any IVs etc. by concatenating the IANA protocol name and the encryption function. So I don't want to put any more in there.

 

It is easy enough to fix if you are aware of it. I noticed the issue while I was implementing HMAC by hand. But the person who is using the function using a library call (i.e. myself five years from now) might not be aware.

 

Saying 'read my paper' really isn't an argument. I know the design rationale. I am saying it is the wrong one for the future. And regardless, I don't see mention of the issue in section 4.2 of the paper you cite nor is there mention of the issue in RFC 2104.

 

If I have to go hunting to find security issues with a standard, that is a problem in itself.

 

 

BTW, the reason it came up with DARE was an attempt to address the problem of 'encrypting the subject header' and other metadata separately from the content data. But under the same key. Bearing in mind that we want to be able to encrypt multiple data items under a single key exchange.

 

So starting from the result of the key agreement, I add in a per envelope salt which is typically 128 bits. That allows for erasure of the message by overwriting the salt value. The main data content is encrypted under a KDF with the IKM and envelope salt. If additional encrypted data sequences are required, they are encrypted under the IKM, salt and an additional counter.

 

Now I can fix my designs, but others won't. Considering the EDS counter to be an extension to the key led to the unexpected result that the EDS and content were encrypted with the same key. Now, it is arguably better considered to be a part of the salt which is where I think the current code is (have to check). But my general point stands, this should be a utility function but the Feb 1997 spec does not meet our standards today.

 

 

 

 

----------------------------------------------------------------------
This transmission (including any attachments) may contain confidential information, privileged material (including material protected by the solicitor-client or other applicable privileges), or constitute non-public information. Any use of this information by anyone other than the intended recipient is prohibited. If you have received this transmission in error, please immediately reply to the sender and delete this information from your system. Use, dissemination, distribution, or reproduction of this transmission by unintended recipients is not authorized and may be unlawful.