Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2214454rwd; Fri, 19 May 2023 02:33:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4kfXS1fQW7JQ3kljZlVnd6EIL58QKR8E89T9bMeIBPmN05v3dE24s9JF/kb4ub7OwC8mNL X-Received: by 2002:a05:6a00:2d26:b0:643:b489:246d with SMTP id fa38-20020a056a002d2600b00643b489246dmr2372753pfb.3.1684488813377; Fri, 19 May 2023 02:33:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684488813; cv=none; d=google.com; s=arc-20160816; b=eLE2HpJ3x7stIeG7idzP4wV/4WmHlvNU3JNRWDZqsLkRswxkt51cOwtibDvbvumwy7 ZEBcoiw+dg3t28yo/PdwoSRknuq0nEm8Mj7vPQsFtqxsOfN8V++W9i3uJnTw1pXjvA8d 6X4pGtXvVBZyrmjJkRRFa6eLfrzluyYeYAPi62N223r/6hkTgEmHnqK4CVpoVOUCmL5r TOD5J88YaaqqSis9LtVwsJbPMZxwxeF7w+ohlSwBKUbvZkazq2LRyjYjP6oJChNYUsBr 4ECjCMlKE0s0Heu/arStfqFTazTts5vnLsDrTgWo9xBuoXvLoYD6R+5nJAJbfAjqGXcj yK3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=wmanj/N1W3RYVOfphqi8kxbI+L2BSysecY3dtVlS5hc=; b=Sbz/ka/wrNxXDbwc2ELBe0xiFndiSyfbQzyQisq4hFEtdOwG00/2ebkldUZYAEjfjr TSL2DH/Y0X0619trpfJT5pzIVejXx8wmcg2vwNlImDZljZuzKUCm1ea0/wtuNL2LS6w0 axNIR4gNfl8n4cI46nhOXKwMQWQoAYWnYb9vMUGsGzrQOU2qnZtrqG3N31TarQZ5kLV5 qfKiezjs3vF+ieis1SQPNiev9CoHaZd1KbegEALMZ4KqqJG812tvrj77JE/W4rSEFGh4 GuCP0IhshGubKQGnxFwNc3Bx3gr+ILlOnYCva2X16Y/dYNrNIcqsYcTBkdN5NxQq256o l77w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jQPVl6A2; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y16-20020aa79e10000000b0063d24857c5bsi3639900pfq.43.2023.05.19.02.33.20; Fri, 19 May 2023 02:33:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jQPVl6A2; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-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 S231696AbjESJct (ORCPT + 99 others); Fri, 19 May 2023 05:32:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231523AbjESJcD (ORCPT ); Fri, 19 May 2023 05:32:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5AB3173F; Fri, 19 May 2023 02:31:45 -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 0F16464CDE; Fri, 19 May 2023 09:31:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 677DCC433EF; Fri, 19 May 2023 09:31:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684488704; bh=Wo6aGM9cMseGU3T2MfA5XaiUStVvCxymzAqjTPuQrOc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=jQPVl6A2pn0VQIrA1hVc1PlCbtNaL0uZhzqZNUzJwSWKH+Ic92iBAtIzk3CLt8qp5 +iaiLUHZv01bLmM3eUtVSJmUsB3MtvJDjGNibAmqqtF67kWMPEfEecnp7iqsnL8+vM xdBSA4o2KZPbkXs15rDyAg7mgLbX+FNZ3DFcUQfehCeDMl5C7jHVke2XdCPzdB26FE jWmoVpIzLR6UIWvAZVuP42wbiop4lB1XswWmdjPKUn/Zw7yLLWNB2rnvIEWnCetrss TB1F5JJ81ZEJWG6jGMfnw25IlqqZDjkfIFJTJjOpw37U0HK7H5iD2aosJjSwr3l3T5 p/9zBfQVMQxjQ== Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-4f27977aed6so3408683e87.2; Fri, 19 May 2023 02:31:43 -0700 (PDT) X-Gm-Message-State: AC+VfDz8gBZ0V1H49dzS1URe8wQcytUVM/N73dVg7gViqqNw3G1FkF3S uwtjkcjOzX6R5WPl2RvvhBnlBoHVihsro8UJSvU= X-Received: by 2002:ac2:519c:0:b0:4ef:efb5:bfea with SMTP id u28-20020ac2519c000000b004efefb5bfeamr668495lfi.37.1684488701391; Fri, 19 May 2023 02:31:41 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Ard Biesheuvel Date: Fri, 19 May 2023 11:31:30 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] crypto: shash - Allow cloning on algorithms with no init_tfm To: Herbert Xu Cc: Dmitry Safonov , Linux Crypto Mailing List , linux-kernel@vger.kernel.org, David Ahern , Eric Dumazet , Paolo Abeni , Jakub Kicinski , "David S. Miller" , Andy Lutomirski , Bob Gilligan , Dan Carpenter , David Laight , Dmitry Safonov <0x7f454c46@gmail.com>, Eric Biggers , "Eric W. Biederman" , Francesco Ruggeri , Hideaki YOSHIFUJI , Ivan Delalande , Leonard Crestez , Salam Noureddine , netdev@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Fri, 19 May 2023 at 11:04, Herbert Xu wrote: > > On Fri, May 19, 2023 at 10:54:11AM +0200, Ard Biesheuvel wrote: > > > > Does this imply that the cmac-aes-ce and cmac-aes-neon implementations > > for arm64 need a similar treatment? > > Good catch. Since these don't have init functions we can deal > with them at a higher level: > > ---8<--- > Some shash algorithms are so simple that they don't have an init_tfm > function. These can be cloned trivially. Check this before failing > in crypto_clone_shash. > OK. So IIUC, cloning a keyless hash just shares the TFM and bumps the refcount, but here we must actually allocate a new TFM referring to the same algo, and this new TFM needs its key to be set before use, as it doesn't inherit it from the clonee, right? And this works in the same way as cloning an instance of the generic HMAC template, as this will just clone the inner shash too, and will also leave the key unset. If so, Acked-by: Ard Biesheuvel If not, could you explain it to me again? :-) > Signed-off-by: Herbert Xu > > diff --git a/crypto/shash.c b/crypto/shash.c > index 717b42df3495..1fadb6b59bdc 100644 > --- a/crypto/shash.c > +++ b/crypto/shash.c > @@ -597,7 +597,7 @@ struct crypto_shash *crypto_clone_shash(struct crypto_shash *hash) > return hash; > } > > - if (!alg->clone_tfm) > + if (!alg->clone_tfm && (alg->init_tfm || alg->base.cra_init)) > return ERR_PTR(-ENOSYS); > > nhash = crypto_clone_tfm(&crypto_shash_type, tfm); > @@ -606,10 +606,12 @@ struct crypto_shash *crypto_clone_shash(struct crypto_shash *hash) > > nhash->descsize = hash->descsize; > > - err = alg->clone_tfm(nhash, hash); > - if (err) { > - crypto_free_shash(nhash); > - return ERR_PTR(err); > + if (alg->clone_tfm) { > + err = alg->clone_tfm(nhash, hash); > + if (err) { > + crypto_free_shash(nhash); > + return ERR_PTR(err); > + } > } > > return nhash; > -- > Email: Herbert Xu > Home Page: http://gondor.apana.org.au/~herbert/ > PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt