From patchwork Fri Feb 9 22:04:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephan Mueller X-Patchwork-Id: 10210043 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0864D60247 for ; Fri, 9 Feb 2018 22:08:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E78F129904 for ; Fri, 9 Feb 2018 22:08:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA7CE299B2; Fri, 9 Feb 2018 22:08:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B754429904 for ; Fri, 9 Feb 2018 22:08:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753077AbeBIWIZ (ORCPT ); Fri, 9 Feb 2018 17:08:25 -0500 Received: from mo4-p00-ob.smtp.rzone.de ([81.169.146.220]:18704 "EHLO mo4-p00-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753076AbeBIWIY (ORCPT ); Fri, 9 Feb 2018 17:08:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1518214102; s=strato-dkim-0002; d=chronox.de; h=Content-Type:Content-Transfer-Encoding:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:X-RZG-CLASS-ID:X-RZG-AUTH; bh=y22Qa2tcvD9GyadHr5sMJPLIV8umdOAJrhEv6RfTNCU=; b=TxDPsbIgFrRLJOQZb8OwHdO2Q55GiFrK/s+hJ1B7hhM67EuwmANSOVRX6AMhRmeKs+ Lw+jxN3w1mgK+T9ZDqZuGOe8Itfzd4jO5hPCnB/egF0nWwqgEIwinSMGdtV+YCp7Cf9U 0ND5B91Fuk1t/a6JXQ4Oc4dDHBnBYIfki02Z1oBhgYVzC2EeXksIxLWUWtRdBqsbkLmU eD4fU7P+22sTIrIkyEq1T8TgWjcY2eLqeEhglPJ4TEZX39WLN9W7984oOs5z3nzHQbiV paHQ7FEoHRpsF6xoUKAf+yos5U5Mu947L0IiMzYD6XtYOf9eyzy9iOTEHEwCKVPsmiLP dWPw== X-RZG-AUTH: :P2ERcEykfu11Y98lp/T7+hdri+uKZK8TKWEqNyiHySGSa9k9zW4DNhHoQE+naq7U3N6ocg/72u03zfn1jZed42GlB4KwpVzBpvDR X-RZG-CLASS-ID: mo00 Received: from positron.chronox.de (200116b8424f7d00d18a04af20749840.dip.versatel-1u1.de [IPv6:2001:16b8:424f:7d00:d18a:4af:2074:9840]) by smtp.strato.de (RZmta 42.18 AUTH) with ESMTPSA id d03d5au19M8K3GH (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Fri, 9 Feb 2018 23:08:20 +0100 (CET) From: Stephan =?ISO-8859-1?Q?M=FCller?= To: Herbert Xu Cc: Jonathan Cameron , Gilad Ben-Yossef , Harsh Jain , Linux Crypto Mailing List , linuxarm@huawei.com Subject: [PATCH v3 4/4] crypto: add CRYPTO_TFM_REQ_IV_SERIALIZE flag Date: Fri, 09 Feb 2018 23:04:52 +0100 Message-ID: <3191772.GlMloJJ0Yf@positron.chronox.de> In-Reply-To: <2808558.OTeCt0oKkL@positron.chronox.de> References: <2118226.LQArbCsRu5@tauon.chronox.de> <1842104.0gXuQuQB9D@positron.chronox.de> <2808558.OTeCt0oKkL@positron.chronox.de> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Crypto drivers may implement a streamlined serialization support for AIO requests that is reported by the CRYPTO_ALG_SERIALIZES_IV_ACCESS flag to the crypto user. When the user decides that he wants to send multiple AIO requests concurrently and wants the crypto driver to handle the serialization, the caller has to set CRYPTO_TFM_REQ_IV_SERIALIZE to notify the crypto driver. Only when this flag is enabled, the crypto driver shall apply its serialization logic for handling IV updates between requests. If this flag is not provided, the serialization logic shall not be applied by the driver as the caller decides that it does not need it (because no parallel AIO requests are sent) or that it performs its own serialization. Signed-off-by: Stephan Mueller Tested-by: Gilad Ben-Yossef --- crypto/algif_aead.c | 15 ++++++++++++--- crypto/algif_skcipher.c | 15 ++++++++++++--- include/linux/crypto.h | 1 + 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/crypto/algif_aead.c b/crypto/algif_aead.c index 619147792cc9..5ec4dec6e6a1 100644 --- a/crypto/algif_aead.c +++ b/crypto/algif_aead.c @@ -66,13 +66,22 @@ static int aead_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) { struct sock *sk = sock->sk; struct alg_sock *ask = alg_sk(sk); + struct af_alg_ctx *ctx = ask->private; struct sock *psk = ask->parent; struct alg_sock *pask = alg_sk(psk); struct aead_tfm *aeadc = pask->private; - struct crypto_aead *tfm = aeadc->aead; - unsigned int ivsize = crypto_aead_ivsize(tfm); + struct crypto_aead *aead = aeadc->aead; + struct crypto_tfm *tfm = crypto_aead_tfm(aead); + unsigned int ivsize = crypto_aead_ivsize(aead); + int ret = af_alg_sendmsg(sock, msg, size, ivsize); + + if (ret < 0) + return ret; - return af_alg_sendmsg(sock, msg, size, ivsize); + if (ctx->iiv == ALG_IV_SERIAL_PROCESSING) + tfm->crt_flags |= CRYPTO_TFM_REQ_IV_SERIALIZE; + + return ret; } static int crypto_aead_copy_sgl(struct crypto_skcipher *null_tfm, diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c index cf27dda6a181..fd2a0ba32feb 100644 --- a/crypto/algif_skcipher.c +++ b/crypto/algif_skcipher.c @@ -43,12 +43,21 @@ static int skcipher_sendmsg(struct socket *sock, struct msghdr *msg, { struct sock *sk = sock->sk; struct alg_sock *ask = alg_sk(sk); + struct af_alg_ctx *ctx = ask->private; struct sock *psk = ask->parent; struct alg_sock *pask = alg_sk(psk); - struct crypto_skcipher *tfm = pask->private; - unsigned ivsize = crypto_skcipher_ivsize(tfm); + struct crypto_skcipher *skc = pask->private; + struct crypto_tfm *tfm = crypto_skcipher_tfm(skc); + unsigned int ivsize = crypto_skcipher_ivsize(skc); + int ret = af_alg_sendmsg(sock, msg, size, ivsize); + + if (ret < 0) + return ret; - return af_alg_sendmsg(sock, msg, size, ivsize); + if (ctx->iiv == ALG_IV_SERIAL_PROCESSING) + tfm->crt_flags |= CRYPTO_TFM_REQ_IV_SERIALIZE; + + return ret; } static int _skcipher_recvmsg(struct socket *sock, struct msghdr *msg, diff --git a/include/linux/crypto.h b/include/linux/crypto.h index 4860aa2c9be4..4d54f2b30692 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h @@ -133,6 +133,7 @@ #define CRYPTO_TFM_REQ_WEAK_KEY 0x00000100 #define CRYPTO_TFM_REQ_MAY_SLEEP 0x00000200 #define CRYPTO_TFM_REQ_MAY_BACKLOG 0x00000400 +#define CRYPTO_TFM_REQ_IV_SERIALIZE 0x00000800 #define CRYPTO_TFM_RES_WEAK_KEY 0x00100000 #define CRYPTO_TFM_RES_BAD_KEY_LEN 0x00200000 #define CRYPTO_TFM_RES_BAD_KEY_SCHED 0x00400000