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 X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14CF0C4360D for ; Wed, 25 Sep 2019 16:14:04 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DD1BA21D7B for ; Wed, 25 Sep 2019 16:14:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="pHWGu9UF"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="sVEBaPJK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DD1BA21D7B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=3jGcRqjcvQ9VYoDI7zULExA+idF1aDwZPkvN5HzOSRI=; b=pHWGu9UFnqg/87 H5lXRfJ9AmZTVaBYQnjH/U8c54WSPrs1a87dQogL1npR9HH33X1ucboQWxoITKyh6fhIbl0STGRW6 eqx9Kt8IT/gE9ja7fq3y0N43RzxPsz4owlg1nytUrYj0jtHJ//C3PPngBWoyK8JCdyJvjuXQVGPbb IgZ2Rm7wXHUb87RAQuMZlKDHs2LWhUAMfAC3S1HRip+OntlNj8IiPtjKqf/h84sOEgr5BQohlMmSo OGhK2QCEDtRkWvo6NJq2qbA3OayPDkMI66mXS0jv2pK+DGH+Fn6MOkgvJIDNqyqacbJEknkoSM0Bh T8t/eUd2OF6NNt5gKB5Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iD9vN-0003sz-TD; Wed, 25 Sep 2019 16:13:53 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by bombadil.infradead.org with esmtps (Exim 4.92.2 #3 (Red Hat Linux)) id 1iD9vJ-0003s2-Nu for linux-arm-kernel@lists.infradead.org; Wed, 25 Sep 2019 16:13:51 +0000 Received: by mail-wm1-x341.google.com with SMTP id i16so6392391wmd.3 for ; Wed, 25 Sep 2019 09:13:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Tn6PuyCvHzBYqw98o/h7jtBUwnaA2ySt5tvs6NRZxxw=; b=sVEBaPJKCR8iK0Ti7MEQI9T+ABca2s8phVUtojeWGaOvvOnjGzCAWbIcwzTp83jDXY m5r+f8qSrlBt5lQOpjo4PbCjfXkKE1E7AhkpXc7Gewyt0NaJ1VnNP6JhkqSfMoqmY7GF j8xyagkcnqsJPh13J/t3KvX77GFGnCn2aaaOo208psPIV4dtHsVaEJ/ehJH3zSYUCemn 4MlEFV8zbH5FzW68MLAwQC6BkiilCT/nnAaN30Tx0lJxhAMMEHA1RjS7B96k4pywgs/l E8RSZdVJ1XxGKuaBONZ5Q7tUfH03ni0EiUQRWdXTdNNWtPojWjjnjsAtJEFlLJjTztif q7sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Tn6PuyCvHzBYqw98o/h7jtBUwnaA2ySt5tvs6NRZxxw=; b=XG7n9qHRYUEH8Y9RBBXM4Y7aJYyOv1x/aqsDBH6bGfPapDadFc8aPwe8rEfAS4RI47 Tpsw3J6F1/K7UtEr7GF9mvaWP8qmThZpbaJmVodccymwzYAUWWytSVWHqGO3WyjSXs5i xLuztyiiphloNEmVU1mMjA6RUQLXQgWBxaq0DvsxOqwQYKcVt4Y71j8WUZbbm2BL4yjx /TZk6zgnld2HUIUPi8DfiZMRjMxq/LAnjStLwMIK94uH9g9GkQcSsO+ecTyPEIO6yNfu bXZhm7cNNUHMzyLH1Sju/oxA/+iIiOVQdZJ6KsParqrFi/Ps2VavO/2I61eN+EJOC5f6 p6Ow== X-Gm-Message-State: APjAAAWo5wp/RzxKHv7rG46D7JEn4vE6K5m7yBUsfD9pdaQVSIk/hKm0 nclk7xtZ57x7RxqHZIhHy+oSJg== X-Google-Smtp-Source: APXvYqyiGoS0vuNCTz14AtTm1UOuqGwmutm4W/PM/ZgKxsJ2voQXgcF4hUOWb9WVVS3FaxjAQLdoPg== X-Received: by 2002:a1c:a516:: with SMTP id o22mr5410877wme.116.1569428028214; Wed, 25 Sep 2019 09:13:48 -0700 (PDT) Received: from localhost.localdomain (laubervilliers-657-1-83-120.w92-154.abo.wanadoo.fr. [92.154.90.120]) by smtp.gmail.com with ESMTPSA id o70sm4991085wme.29.2019.09.25.09.13.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2019 09:13:47 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Subject: [RFC PATCH 01/18] crypto: shash - add plumbing for operating on scatterlists Date: Wed, 25 Sep 2019 18:12:38 +0200 Message-Id: <20190925161255.1871-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190925161255.1871-1-ard.biesheuvel@linaro.org> References: <20190925161255.1871-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190925_091349_779370_4E818665 X-CRM114-Status: GOOD ( 16.78 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Jason A . Donenfeld" , Catalin Marinas , Herbert Xu , Arnd Bergmann , Ard Biesheuvel , Greg KH , Eric Biggers , Samuel Neves , Will Deacon , Dan Carpenter , Andy Lutomirski , Marc Zyngier , Linus Torvalds , David Miller , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add an internal method to the shash interface that permits templates to invoke it with a scatterlist. Drivers implementing the shash interface can opt into using this method, making it more straightforward for templates to pass down data provided via scatterlists without forcing the underlying shash to process each scatterlist entry with a discrete update() call. This will be used later in the SIMD accelerated Poly1305 to amortize SIMD begin()/end() calls over the entire input. Signed-off-by: Ard Biesheuvel --- crypto/ahash.c | 18 +++++++++++++++ crypto/shash.c | 24 ++++++++++++++++++++ include/crypto/hash.h | 3 +++ include/crypto/internal/hash.h | 19 ++++++++++++++++ 4 files changed, 64 insertions(+) diff --git a/crypto/ahash.c b/crypto/ahash.c index 3815b363a693..aecb48f0f50c 100644 --- a/crypto/ahash.c +++ b/crypto/ahash.c @@ -144,6 +144,24 @@ int crypto_hash_walk_first(struct ahash_request *req, } EXPORT_SYMBOL_GPL(crypto_hash_walk_first); +int crypto_shash_walk_sg(struct shash_desc *desc, struct scatterlist *sg, + int nbytes, struct crypto_hash_walk *walk, int flags) +{ + walk->total = nbytes; + + if (!walk->total) { + walk->entrylen = 0; + return 0; + } + + walk->alignmask = crypto_shash_alignmask(desc->tfm); + walk->sg = sg; + walk->flags = flags; + + return hash_walk_new_entry(walk); +} +EXPORT_SYMBOL_GPL(crypto_shash_walk_sg); + int crypto_ahash_walk_first(struct ahash_request *req, struct crypto_hash_walk *walk) { diff --git a/crypto/shash.c b/crypto/shash.c index e83c5124f6eb..b16ab5590dc4 100644 --- a/crypto/shash.c +++ b/crypto/shash.c @@ -121,6 +121,30 @@ int crypto_shash_update(struct shash_desc *desc, const u8 *data, } EXPORT_SYMBOL_GPL(crypto_shash_update); +int crypto_shash_update_from_sg(struct shash_desc *desc, struct scatterlist *sg, + unsigned int len, bool atomic) +{ + struct crypto_shash *tfm = desc->tfm; + struct shash_alg *shash = crypto_shash_alg(tfm); + struct crypto_hash_walk walk; + int flags = 0; + int nbytes; + + if (!atomic) + flags = CRYPTO_TFM_REQ_MAY_SLEEP; + + if (shash->update_from_sg) + return shash->update_from_sg(desc, sg, len, flags); + + for (nbytes = crypto_shash_walk_sg(desc, sg, len, &walk, flags); + nbytes > 0; + nbytes = crypto_hash_walk_done(&walk, nbytes)) + nbytes = crypto_shash_update(desc, walk.data, nbytes); + + return nbytes; +} +EXPORT_SYMBOL_GPL(crypto_shash_update_from_sg); + static int shash_final_unaligned(struct shash_desc *desc, u8 *out) { struct crypto_shash *tfm = desc->tfm; diff --git a/include/crypto/hash.h b/include/crypto/hash.h index ef10c370605a..0b83d85a3828 100644 --- a/include/crypto/hash.h +++ b/include/crypto/hash.h @@ -158,6 +158,7 @@ struct shash_desc { * struct shash_alg - synchronous message digest definition * @init: see struct ahash_alg * @update: see struct ahash_alg + * @update_from_sg: variant of update() taking a scatterlist as input [optional] * @final: see struct ahash_alg * @finup: see struct ahash_alg * @digest: see struct ahash_alg @@ -175,6 +176,8 @@ struct shash_alg { int (*init)(struct shash_desc *desc); int (*update)(struct shash_desc *desc, const u8 *data, unsigned int len); + int (*update_from_sg)(struct shash_desc *desc, struct scatterlist *sg, + unsigned int len, int flags); int (*final)(struct shash_desc *desc, u8 *out); int (*finup)(struct shash_desc *desc, const u8 *data, unsigned int len, u8 *out); diff --git a/include/crypto/internal/hash.h b/include/crypto/internal/hash.h index bfc9db7b100d..6f4bfa057bea 100644 --- a/include/crypto/internal/hash.h +++ b/include/crypto/internal/hash.h @@ -50,6 +50,8 @@ extern const struct crypto_type crypto_ahash_type; int crypto_hash_walk_done(struct crypto_hash_walk *walk, int err); int crypto_hash_walk_first(struct ahash_request *req, struct crypto_hash_walk *walk); +int crypto_shash_walk_sg(struct shash_desc *desc, struct scatterlist *sg, + int nbytes, struct crypto_hash_walk *walk, int flags); int crypto_ahash_walk_first(struct ahash_request *req, struct crypto_hash_walk *walk); @@ -242,5 +244,22 @@ static inline struct crypto_shash *__crypto_shash_cast(struct crypto_tfm *tfm) return container_of(tfm, struct crypto_shash, base); } +/** + * crypto_shash_update_from_sg() - add data from a scatterlist to message digest + * for processing + * @desc: operational state handle that is already initialized + * @data: scatterlist with input data to be added to the message digest + * @len: length of the input data + * @atomic: whether or not the call is permitted to sleep + * + * Updates the message digest state of the operational state handle. + * + * Context: Any context. + * Return: 0 if the message digest update was successful; < 0 if an error + * occurred + */ +int crypto_shash_update_from_sg(struct shash_desc *desc, struct scatterlist *sg, + unsigned int len, bool atomic); + #endif /* _CRYPTO_INTERNAL_HASH_H */ -- 2.20.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel