Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp417239ybg; Fri, 12 Jun 2020 05:08:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIE/SPt9+/g89LCgSdgo9D1SyMuBHlUvbpvv+i5lyE2f9gERtFEUA33d9/n/nqs5ZTOn0Z X-Received: by 2002:a17:906:784c:: with SMTP id p12mr12757054ejm.123.1591963727126; Fri, 12 Jun 2020 05:08:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591963727; cv=none; d=google.com; s=arc-20160816; b=jaouKmObaKJuZJRdXF6HTuSS+b5ghNyGdj272SaWq5Uwp7PkEaTuhMs2oufgNXM2FN iwBskJH6PRQ+alAdPVdn0lsr3tX/QJ1UmP6HEf8TEbdG7+uIVxNipEt33AVwgx0kANKx 7EwCFAznVTC8Z9vnZEK7Z6BU0H4UF37BFqCKqwAt/SMghsb1hBbtCuvdgXoP/0W8B5Jz tU+X88+W+C0KWp0WZYiQeeoZsVxFtWSsYs8KxoYkKiNsVyZK6J55dWx73R6yVbIsT9NH zPusbUOdYBQkioO1wFnnV2o6sslhP2iGMGpiFkqpIpVcMmaQMF6I5M4jiu1ups4Alk5v uQVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:to:references:subject:date :from; bh=krkyVOIwx+uPxaEipoudnluiRNOLSoKS4trIUye9x2w=; b=C7cS4ndP8SL/JOzQWC6XN1JWXWD9EaL5Kp+ucqMX9IBmgdpepXC+6O1cDwDmyIKPqH ORejpSuEEnsWfZ/fcw1qm+yHHSHqJ0UJXq5ovbnZaewOl+L0+DfQnwRWJLZZYn+rV2S9 gCYYGGipO1a03wq3pNvDN5AURd6hmlrsK+9ASNCKmJG3mXELpvG/MUZZu9VLWnmYIMCM vZOZB0Esek5mksqQs/kEn2czPpRU+qswjwXGClETWp2mR0GCfRJixqZw5dZLjYVXSp1Z CZHvduR8C5G8zROG/WuF2ULEf4FRmKV2lBanGm01Gy4JoKrgu1OWVUyo7vjjqWRWc6bW JZTw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l8si3586384edn.346.2020.06.12.05.08.12; Fri, 12 Jun 2020 05:08:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726101AbgFLMHj (ORCPT + 99 others); Fri, 12 Jun 2020 08:07:39 -0400 Received: from helcar.hmeau.com ([216.24.177.18]:39488 "EHLO fornost.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725791AbgFLMHj (ORCPT ); Fri, 12 Jun 2020 08:07:39 -0400 Received: from gwarestrin.arnor.me.apana.org.au ([192.168.0.7]) by fornost.hmeau.com with smtp (Exim 4.92 #5 (Debian)) id 1jjiTA-0005BO-9n; Fri, 12 Jun 2020 22:07:37 +1000 Received: by gwarestrin.arnor.me.apana.org.au (sSMTP sendmail emulation); Fri, 12 Jun 2020 22:07:36 +1000 From: "Herbert Xu" Date: Fri, 12 Jun 2020 22:07:36 +1000 Subject: [PATCH 1/3] crypto: skcipher - Add final chunk size field for chaining References: <20200612120643.GA15724@gondor.apana.org.au> To: Ard Biesheuvel , Linux Crypto Mailing List , Eric Biggers , Stephan Mueller Message-Id: Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Crypto skcipher algorithms in general allow chaining to break large operations into smaller ones based on multiples of the chunk size. However, some algorithms don't support chaining while others (such as cts) only support chaining for the leading blocks. This patch adds the necessary API support for these algorithms. In particular, a new request flag CRYPTO_TFM_REQ_MORE is added to allow chaining for algorithms such as cts that cannot otherwise be chained. A new algorithm attribute fcsize has also been added to indicate how many blocks at the end of a request that cannot be chained and therefore must be withheld if chaining is attempted. This attribute can also be used to indicate that no chaining is allowed. Its value should be set to -1 in that case. Signed-off-by: Herbert Xu --- include/crypto/skcipher.h | 24 ++++++++++++++++++++++++ include/linux/crypto.h | 1 + 2 files changed, 25 insertions(+) diff --git a/include/crypto/skcipher.h b/include/crypto/skcipher.h index 141e7690f9c31..8b864222e6ce4 100644 --- a/include/crypto/skcipher.h +++ b/include/crypto/skcipher.h @@ -97,6 +97,8 @@ struct crypto_sync_skcipher { * @walksize: Equal to the chunk size except in cases where the algorithm is * considerably more efficient if it can operate on multiple chunks * in parallel. Should be a multiple of chunksize. + * @fcsize: Number of bytes that must be processed together at the end. + * If set to -1 then chaining is not possible. * @base: Definition of a generic crypto algorithm. * * All fields except @ivsize are mandatory and must be filled. @@ -114,6 +116,7 @@ struct skcipher_alg { unsigned int ivsize; unsigned int chunksize; unsigned int walksize; + int fcsize; struct crypto_alg base; }; @@ -279,6 +282,11 @@ static inline unsigned int crypto_skcipher_alg_chunksize( return alg->chunksize; } +static inline int crypto_skcipher_alg_fcsize(struct skcipher_alg *alg) +{ + return alg->fcsize; +} + /** * crypto_skcipher_chunksize() - obtain chunk size * @tfm: cipher handle @@ -296,6 +304,22 @@ static inline unsigned int crypto_skcipher_chunksize( return crypto_skcipher_alg_chunksize(crypto_skcipher_alg(tfm)); } +/** + * crypto_skcipher_fcsize() - obtain number of final bytes + * @tfm: cipher handle + * + * For algorithms such as CTS the final chunks cannot be chained. + * This returns the number of final bytes that must be withheld + * when chaining. + * + * Return: number of final bytes + */ +static inline unsigned int crypto_skcipher_fcsize( + struct crypto_skcipher *tfm) +{ + return crypto_skcipher_alg_fcsize(crypto_skcipher_alg(tfm)); +} + static inline unsigned int crypto_sync_skcipher_blocksize( struct crypto_sync_skcipher *tfm) { diff --git a/include/linux/crypto.h b/include/linux/crypto.h index 763863dbc079a..d80dccf472595 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h @@ -110,6 +110,7 @@ #define CRYPTO_TFM_REQ_FORBID_WEAK_KEYS 0x00000100 #define CRYPTO_TFM_REQ_MAY_SLEEP 0x00000200 #define CRYPTO_TFM_REQ_MAY_BACKLOG 0x00000400 +#define CRYPTO_TFM_REQ_MORE 0x00000800 /* * Miscellaneous stuff.