Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp988399imu; Wed, 9 Jan 2019 09:36:21 -0800 (PST) X-Google-Smtp-Source: ALg8bN5vA+Aw3i61M28XzSpLQ+TKpa+WldcYJKweHgisYJ3NKHQqRtb3C3ty/ajnWxwRrBv+nVQG X-Received: by 2002:a63:8b41:: with SMTP id j62mr6321996pge.182.1547055381163; Wed, 09 Jan 2019 09:36:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547055381; cv=none; d=google.com; s=arc-20160816; b=zPztMxw/s1YxS41mvYwY1ryf0Gsr1fb81tlwAkYIIiP4RgWJbnVTFCR4DMTiCckPGd 3/h4j9ieXBBNM7lfT9cl6/SRGe9rDa7r5G/3f3xSCm/hsZ2iLV43gd3GDFLfzJrzlcrL dWplBaOi6pZVvQ7D934gY9yedbNm0/B87MkmhfsQj62tI3lEuix90Ia0Gve6ffLE3P5K CvI4wZWOxl0tVRCDDKnyZ9uACkFylFYnIn7ZJztzRpW4wt4aTvg429Q+xLmXy8vxrU5G uwls+dqhyw4zGPxwLOYNKw+B5na+YoPmt1YWwqI46A1tllpYomMNZabjh004qxkxUVR2 UoQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ayx2MgJl3XCTV5joE9vbTda2g2sVHzyB9RUNMpCV5IA=; b=qrSO1XARhqW7tTB7i/ETvAHT9dOQg9sKAmILmKDzr5/VbhR5fdbNm/fRF46O+TDxUZ dEliQ5Jscr5473b55BZ8tCOXU+QIT1bjvC3c2kAzEX9hrBVRjhdoJNGnV6zeF0ZFAZSs aRAcx85vvMDKoqPt91bxCwllfxLg4NnY/pVqWVehtAq0QSIjpbJL+hrcCPb7pEL0/wY5 n1FI75K1k65oJJrLfwgxq9ewMJ5+UHi9vuBwQwUq1u7lwvgxUtgKLLkRIyKFZqdVCQDq gFkF+rLt720JNPL5+q8qoRwkfj/ooSDI251ooRx5FMknjIEvsVCZMSXxQ7Z2x1r3Yvc7 5C1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nVjxO7sH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e6si34053852pgd.428.2019.01.09.09.36.05; Wed, 09 Jan 2019 09:36:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nVjxO7sH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726940AbfAIRe7 (ORCPT + 99 others); Wed, 9 Jan 2019 12:34:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:33700 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726446AbfAIRe6 (ORCPT ); Wed, 9 Jan 2019 12:34:58 -0500 Received: from gmail.com (unknown [104.132.1.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9D055206BB; Wed, 9 Jan 2019 17:34:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547055297; bh=XCMs1JHLKW8yUEThiH5H4LK1zaopKG2S5ef0xFv4hC8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nVjxO7sH1XLw16NC/hIOJg64WVq5Rgo87CrLQhYdrxGZuSmuMYaBVXT4gcZj8KgPd Ab56kcbpQTk2xHTrYlm3gaTPKMOToWx+z0pZGkEBBGTuXv9TGYQxPIlweh5tElQXxO vrx9qu0OW4MKDhEdRGXf8gZYbXG3C57X3wPS2E+M= Date: Wed, 9 Jan 2019 09:34:55 -0800 From: Eric Biggers To: Stephan Mueller Cc: James Bottomley , Andy Lutomirski , Herbert Xu , "Lee, Chun-Yi" , "Rafael J . Wysocki" , Pavel Machek , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, keyrings@vger.kernel.org, "Rafael J. Wysocki" , Chen Yu , Oliver Neukum , Ryan Chen , David Howells , Giovanni Gherdovich , Randy Dunlap , Jann Horn , Andy Lutomirski Subject: Re: [PATCH 1/5 v2] PM / hibernate: Create snapshot keys handler Message-ID: <20190109173454.GB249140@gmail.com> References: <20190103143227.9138-1-jlee@suse.com> <1894062.aDvIuj92vB@tauon.chronox.de> <20190109082103.GA8586@sol.localdomain> <2344329.gmPllosFfp@tauon.chronox.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2344329.gmPllosFfp@tauon.chronox.de> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 09, 2019 at 11:17:45AM +0100, Stephan Mueller wrote: > Am Mittwoch, 9. Januar 2019, 09:21:04 CET schrieb Eric Biggers: > > Hi Eric, > > > > FWIW, it's been very slow going since I've been working on other projects > > and I also need to be very sure to get the API changes right, but I still > > plan to change the KDF in fscrypt (a.k.a. ext4/f2fs/ubifs encryption) to > > HKDF-SHA512 as part of a larger set of improvements to how fscrypt > > encryption keys are managed. I sent the last patchset a year ago > > (https://marc.info/?l=linux-fsdevel&m=150879493206257) but I'm working to > > revive it. In the work-in-progress version in my git tree, this is the > > commit that adds a HKDF implementation as fs/crypto/hkdf.c: > > https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git/commit/?id=e8a78767131c9717ee838f0c4e307948d65a4427 > > It basically just wraps a crypto_shash for "hmac(sha512)". > > > > I'd be fine with using a common implementation instead, provided that it > > gives the same functionality, including supporting user-specified salt and > > application-specific info strings, and isn't slower or more complex to use. > > > > (This comment is solely on the tangential discussion about KDF > > implementations; I've not looked at the hibernation image encryption stuff > > yet.) > > Thanks for the clarification. I have started a generic HKDF implementation for > the kernel crypto API which lead to the questions above. I would then also try > to provide a HKDF proposal. > > To use the (H)KDF, I currently envision 2 calls apart from alloc/free. The > following code would serve as an example. > > * Example without proper error handling: > * char *keying_material = "\x00\x11\x22\x33\x44\x55\x66\x77"; > * char *label_context = "\xde\xad\xbe\xef\x00\xde\xad\xbe\xef"; > * kdf = crypto_alloc_rng(name, 0, 0); > * crypto_rng_reset(kdf, keying_material, 8); > * crypto_rng_generate(kdf, label_context, 9, outbuf, outbuflen); > > That hopefully should be simple enough. > > For HKDF, as mentioned, I would envision to use a struct instead of a char * > for the label_context to communicate IKM, Salt, and the label/info > information. > > Ciao > Stephan > That would not meet my performance requirements as I want to precompute HKDF-Extract, and then do HKDF-Expand many times. Also the HKDF-Expand part should be thread-safe and not require allocating memory, especially not a whole crypto_shash tfm every time. So presumably with crypto_rng, crypto_rng_reset() would need to take the input keyring material and salt and do HKDF-Extract (like my fscrypt_init_hkdf()), and crypto_rng_generate() would need to take the application-specific info string and do HKDF-Expand (like my fscrypt_hkdf_expand()). It is ugly though. Please also consider just having simple crypto_hkdf_*() helper functions which wrap a HMAC tfm along the lines of my patch, rather than shoehorning it into the crypto_rng API. - Eric