From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B219C77B7A for ; Fri, 26 May 2023 07:23:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242108AbjEZHXI (ORCPT ); Fri, 26 May 2023 03:23:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236681AbjEZHXG (ORCPT ); Fri, 26 May 2023 03:23:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A16979B; Fri, 26 May 2023 00:23:05 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1EB5A64D88; Fri, 26 May 2023 07:23:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D370C433D2; Fri, 26 May 2023 07:23:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685085784; bh=Z+s29jQiBKqU2l46jPccXJdvd9jdYJHsfjEWMx9TRx4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=cO9AGl9ps5XpW7/aAs6LaRMSKLZ1cqcbu2Z+46QILzHNiwtf+EwAt9g9m5eSnbEqI r1hv7FzcVRviZlyvezLBCR8xF52yBI8s7LWkZTZSidKN5OY3Ne3NJzcj7bo2IZ5Qbs HvW1tCT4NqlDYUQXRyo5vbKNqwB1WIzNrZGoUahJ8IFi5b6dAgIrNM2ouWTK/W/PHl suqEYo/I0NqUVeSf1wVwdUPMEFD48zm9+OmkkJJ9rUxHRzPTrUdJHGlSbBNvLBusDW /JxJB6FvRBBemQWV1cwTv3exX0djxv0RnSgR6BnVJ99K9hJRB7P+Sx3SG5j0IWVNG4 GSjtfJJtfQY+Q== Date: Fri, 26 May 2023 00:23:01 -0700 From: Eric Biggers To: "Chang S. Bae" Cc: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, dm-devel@redhat.com, elliott@hpe.com, gmazyland@gmail.com, luto@kernel.org, dave.hansen@linux.intel.com, tglx@linutronix.de, bp@alien8.de, mingo@kernel.org, x86@kernel.org, herbert@gondor.apana.org.au, ardb@kernel.org, dan.j.williams@intel.com, bernie.keany@intel.com, charishma1.gairuboyina@intel.com, lalithambika.krishnakumar@intel.com, nhuck@google.com, "David S. Miller" , Ingo Molnar , "H. Peter Anvin" Subject: Re: [PATCH v7 12/12] crypto: x86/aes-kl - Implement the AES-XTS algorithm Message-ID: <20230526072301.GC875@sol.localdomain> References: <20230410225936.8940-1-chang.seok.bae@intel.com> <20230524165717.14062-1-chang.seok.bae@intel.com> <20230524165717.14062-13-chang.seok.bae@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230524165717.14062-13-chang.seok.bae@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 24, 2023 at 09:57:17AM -0700, Chang S. Bae wrote: > == API Limitation == > > The setkey() function transforms an AES key into a handle. But, an > extended key is a usual outcome of setkey() in other AES cipher > implementations. For this reason, a setkey() failure does not fall > back to the other. So, expose AES-KL methods via synchronous > interfaces only. I don't understand what this paragraph is trying to say. > +/* > + * The below wrappers for the encryption/decryption functions > + * incorporate the feature availability check: > + * > + * In the rare event of hardware failure, the wrapping key can be lost > + * after wake-up from a deep sleep state. Then, this check helps to > + * avoid any subsequent misuse with populating a proper error code. > + */ > + > +static inline int aeskl_enc(const void *ctx, u8 *out, const u8 *in) > +{ > + if (!valid_keylocker()) > + return -ENODEV; > + > + return __aeskl_enc(ctx, out, in); > +} Is it not sufficient for the valid_keylocker() check to occur at the top level (in xts_encrypt() and xts_decrypt()), which would seem to be a better place to do it? Is this because valid_keylocker() needs to be checked in every kernel_fpu_begin() section separately, to avoid a race condition? If that's indeed the reason, can you explain that in the comment? > +static inline int xts_keylen(struct skcipher_request *req, u32 *keylen) > +{ > + struct aes_xts_ctx *ctx = aes_xts_ctx(crypto_skcipher_reqtfm(req)); > + > + if (ctx->crypt_ctx.key_length != ctx->tweak_ctx.key_length) > + return -EINVAL; > + > + *keylen = ctx->crypt_ctx.key_length; > + return 0; > +} This is odd. Why would the key lengths be different here? > + err = simd_register_skciphers_compat(aeskl_skciphers, ARRAY_SIZE(aeskl_skciphers), > + aeskl_simd_skciphers); > + if (err) > + return err; > + > + return 0; This can be simplified to: return simd_register_skciphers_compat(aeskl_skciphers, ARRAY_SIZE(aeskl_skciphers), aeskl_simd_skciphers); - Eric