Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2159043rwd; Fri, 19 May 2023 01:40:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7wSqIR4fwE2ZqHsa/f82AWJqtkxDlRJsOR2YMw+VREyiS2mlCeBbY02SWhuQS7okLVEqF/ X-Received: by 2002:a17:903:25ce:b0:1a9:5aef:1aea with SMTP id jc14-20020a17090325ce00b001a95aef1aeamr1687949plb.66.1684485617516; Fri, 19 May 2023 01:40:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684485617; cv=none; d=google.com; s=arc-20160816; b=gPyFpCyJFItiG/HPEs4eQ94dU3xyqMeQyLVb/O09dZXqkS2thka7IXESw1ec7m6ojy dBM6U02Hs0pBRQVYXkqJu+8n52R+bHZsamG/KvJZdnqRFgJ1tAzKXPjWqBPC9Eztj27P oJJtMPaDOLWyolsuzkTWES5GuRH7m4tl5BGYjgFp0UI/gaW2w0Z/1l/ONWwMSJKOLULY 73RpBpiNElDPTGAdwBFBvRMXP3QNAA46hlWnk0ih2T5ZJfO52nrmDwx9es00oxaA2GQ2 y/hNojkGlexiB1XmqWbmpmLGM3B61YjEGc8GYvIppclFSzjFMDM6QUSISSxRrr5quMGY pB7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:to:references:subject:date:from; bh=F4VzFW9WdoPbZhVaRCM2GKOt8DOeuiH3CuD5RJGH46k=; b=mvcBDvdLE2UP6beZfKFO+Sw7dz7lmgk6GkB5WGr1GMr9VjAKUYsJdpgCZ9tg3LVgsD r6opZt7Qa8dwWTVFupB/DOPdzy9JQyzpno7RLo2xORw17ehPODKvdvLwe3zHQR2UIaZF lmj+0xL/z4g85ro1eFUS19UP9MBFQNc7tFteuPYB9gVtTB9UPYMGXikuIbUCRdvv48vt FC/JqEnDArckbnYsY7IyKiWc2h+UBRmz4EHkDn4IpAlTDvwYHpiukvIRoqgHCVQtQFLm 286Q+Iz7f8k9gwWF4Jdp/wPm3PsgTcayrGy7/uL+/ilofqcTttAesAE618G8PlRKybVz mYhw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jc9-20020a17090325c900b001a6a636eb6dsi3090415plb.215.2023.05.19.01.40.05; Fri, 19 May 2023 01:40:17 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230076AbjESI3P (ORCPT + 99 others); Fri, 19 May 2023 04:29:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230150AbjESI3N (ORCPT ); Fri, 19 May 2023 04:29:13 -0400 Received: from 167-179-156-38.a7b39c.syd.nbn.aussiebb.net (167-179-156-38.a7b39c.syd.nbn.aussiebb.net [167.179.156.38]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E321E58; Fri, 19 May 2023 01:29:11 -0700 (PDT) Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.94.2 #2 (Debian)) id 1pzvTZ-00AnMQ-5M; Fri, 19 May 2023 16:28:38 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Fri, 19 May 2023 16:28:37 +0800 From: "Herbert Xu" Date: Fri, 19 May 2023 16:28:37 +0800 Subject: [PATCH 3/3] crypto: cmac - Add support for cloning References: To: Dmitry Safonov , Linux Crypto Mailing List , linux-kernel@vger.kernel.org, David Ahern , Eric Dumazet , Paolo Abeni , Jakub Kicinski , "David S. Miller" , Andy Lutomirski , Ard Biesheuvel , 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 Message-Id: X-Spam-Status: No, score=2.7 required=5.0 tests=BAYES_00,HELO_DYNAMIC_IPADDR2, RDNS_DYNAMIC,SPF_HELO_NONE,SPF_PASS,TVD_RCVD_IP,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: ** 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 Allow hmac to be cloned. The underlying cipher needs to support cloning by not having a cra_init function (all implementations of aes that do not require a fallback can be cloned). Signed-off-by: Herbert Xu --- crypto/cmac.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/crypto/cmac.c b/crypto/cmac.c index bcc6f19a4f64..fce6b0f58e88 100644 --- a/crypto/cmac.c +++ b/crypto/cmac.c @@ -213,7 +213,22 @@ static int cmac_init_tfm(struct crypto_shash *tfm) ctx->child = cipher; return 0; -}; +} + +static int cmac_clone_tfm(struct crypto_shash *tfm, struct crypto_shash *otfm) +{ + struct cmac_tfm_ctx *octx = crypto_shash_ctx(otfm); + struct cmac_tfm_ctx *ctx = crypto_shash_ctx(tfm); + struct crypto_cipher *cipher; + + cipher = crypto_clone_cipher(octx->child); + if (IS_ERR(cipher)) + return PTR_ERR(cipher); + + ctx->child = cipher; + + return 0; +} static void cmac_exit_tfm(struct crypto_shash *tfm) { @@ -280,6 +295,7 @@ static int cmac_create(struct crypto_template *tmpl, struct rtattr **tb) inst->alg.final = crypto_cmac_digest_final; inst->alg.setkey = crypto_cmac_digest_setkey; inst->alg.init_tfm = cmac_init_tfm; + inst->alg.clone_tfm = cmac_clone_tfm; inst->alg.exit_tfm = cmac_exit_tfm; inst->free = shash_free_singlespawn_instance;