From patchwork Mon Aug 14 13:17:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Labbe X-Patchwork-Id: 9898935 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 246C460230 for ; Mon, 14 Aug 2017 13:19:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14D1528606 for ; Mon, 14 Aug 2017 13:19:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 07D6728617; Mon, 14 Aug 2017 13:19:56 +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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable 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 697F728606 for ; Mon, 14 Aug 2017 13:19:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751510AbdHNNTm (ORCPT ); Mon, 14 Aug 2017 09:19:42 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:35651 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751482AbdHNNTj (ORCPT ); Mon, 14 Aug 2017 09:19:39 -0400 Received: by mail-wr0-f194.google.com with SMTP id u89so1264525wrc.2; Mon, 14 Aug 2017 06:19:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wkMWoySFdD6qDp3OGAqIFpcYdBf8FhptIej4xF42fqE=; b=sG7nZt9TO92nEHyGOmOrxBrHyn6P4rVBn4n2ZUnqZqx0Qh1XADiyJApe9PyV9snY57 o9CztiY9qRWAv7hTKp4u8h1i1dKwFlzqyyVWDo1zB6oRUUAutQEwezc4lG6xuwPFhWNk 3BpPA3i9aBCqFCOL/m6jhP7xarchBva3X+AvwwlgG7byM26IdNHFPIwv2rd3+LI1AmVu RkyZExTIJN0RUO2yvooZET2OLtkuXyIYv8k/gPxSz33/UmK6ke+x31SDE0YmjvvKJhPC 9bDhRtvNPObvZqZaM0M8+c0V9kLESvtvQAsNRZJ2bMW5YR/Z/9RciI+e7Jlc5/lldLDd 0TeQ== 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; bh=wkMWoySFdD6qDp3OGAqIFpcYdBf8FhptIej4xF42fqE=; b=hcCIX7seKiSjSLCypkG/fAdNBWUpy01MN0LL2Z3qEprD4rOrJ7RfVluXvXUDsNHteP NvGJhOXZ1zsOOM/2PEj06dECCTmmnBfqtUJ3RaTVjfhKL4s8q/XRldVJwOEamW6/aiNc GIyaOMwMM1PaDwQ/IlkyQq6EjSwOPjSrDkygxJguI86LLTwuPIaDsp5s9Mh9BtN+auas /5W6t7YnBvMGlf7H8Ndnb0/gzrj5vfBKc5pNzsKPNNVG2aTwZGrbdINJwq18p6wPK0ZY hOgvcEEGOJWoQJg5PeaJ4vstdPGsop+MV8itN4HSf45JUylzKFACWJE+mlPorrqhY11c uA7g== X-Gm-Message-State: AHYfb5gvIlWSXsOJ1MEYCfsGYxNoVhXfokrxb7eGb8SnbW1ytdYgGVQm Bg1Xd7FL3uYx3g== X-Received: by 10.223.161.139 with SMTP id u11mr865319wru.44.1502716778152; Mon, 14 Aug 2017 06:19:38 -0700 (PDT) Received: from Red.local (LFbn-1-7109-228.w90-116.abo.wanadoo.fr. [90.116.45.228]) by smtp.googlemail.com with ESMTPSA id x14sm13386675wmd.19.2017.08.14.06.19.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 Aug 2017 06:19:37 -0700 (PDT) From: Corentin Labbe To: herbert@gondor.apana.org.au, davem@davemloft.net Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Corentin Labbe Subject: [PATCH 3/3] crypto: engine - Permit to enqueue skcipher request Date: Mon, 14 Aug 2017 15:17:25 +0200 Message-Id: <20170814131725.9402-4-clabbe.montjoie@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170814131725.9402-1-clabbe.montjoie@gmail.com> References: <20170814131725.9402-1-clabbe.montjoie@gmail.com> 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 The crypto engine could actually only enqueue hash and ablkcipher request. This patch permit it to enqueue skcipher requets by adding all necessary functions. Signed-off-by: Corentin Labbe --- crypto/crypto_engine.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++ include/crypto/engine.h | 14 ++++++ 2 files changed, 128 insertions(+) diff --git a/crypto/crypto_engine.c b/crypto/crypto_engine.c index 74b840749074..8567224d7609 100644 --- a/crypto/crypto_engine.c +++ b/crypto/crypto_engine.c @@ -36,6 +36,7 @@ static void crypto_pump_requests(struct crypto_engine *engine, struct crypto_async_request *async_req, *backlog; struct ahash_request *hreq; struct ablkcipher_request *breq; + struct skcipher_request *skreq; unsigned long flags; bool was_busy = false; int ret; @@ -139,6 +140,23 @@ static void crypto_pump_requests(struct crypto_engine *engine, goto req_err; } return; + } else if (cratype == &crypto_skcipher_type2) { + skreq = skcipher_request_cast(engine->cur_req); + if (engine->prepare_skcipher_request) { + ret = engine->prepare_skcipher_request(engine, skreq); + if (ret) { + dev_err(engine->dev, "failed to prepare request: %d\n", + ret); + goto req_err; + } + engine->cur_req_prepared = true; + } + ret = engine->skcipher_one_request(engine, skreq); + if (ret) { + dev_err(engine->dev, "failed to cipher one request from queue\n"); + goto req_err; + } + return; } else { dev_err(engine->dev, "failed to prepare request of unknown type\n"); return; @@ -151,6 +169,9 @@ static void crypto_pump_requests(struct crypto_engine *engine, } else if (cratype == &crypto_ablkcipher_type) { breq = ablkcipher_request_cast(engine->cur_req); crypto_finalize_cipher_request(engine, breq, ret); + } else if (cratype == &crypto_skcipher_type2) { + skreq = skcipher_request_cast(engine->cur_req); + crypto_finalize_skcipher_request(engine, skreq, ret); } return; @@ -210,6 +231,49 @@ int crypto_transfer_cipher_request_to_engine(struct crypto_engine *engine, EXPORT_SYMBOL_GPL(crypto_transfer_cipher_request_to_engine); /** + * crypto_transfer_skcipher_request - transfer the new request into the + * enginequeue + * @engine: the hardware engine + * @req: the request need to be listed into the engine queue + */ +int crypto_transfer_skcipher_request(struct crypto_engine *engine, + struct skcipher_request *req, + bool need_pump) +{ + unsigned long flags; + int ret; + + spin_lock_irqsave(&engine->queue_lock, flags); + + if (!engine->running) { + spin_unlock_irqrestore(&engine->queue_lock, flags); + return -ESHUTDOWN; + } + + ret = crypto_enqueue_request(&engine->queue, &req->base); + + if (!engine->busy && need_pump) + kthread_queue_work(engine->kworker, &engine->pump_requests); + + spin_unlock_irqrestore(&engine->queue_lock, flags); + return ret; +} +EXPORT_SYMBOL_GPL(crypto_transfer_skcipher_request); + +/** + * crypto_transfer_skcipher_request_to_engine - transfer one request to list + * into the engine queue + * @engine: the hardware engine + * @req: the request need to be listed into the engine queue + */ +int crypto_transfer_skcipher_request_to_engine(struct crypto_engine *engine, + struct skcipher_request *req) +{ + return crypto_transfer_skcipher_request(engine, req, true); +} +EXPORT_SYMBOL_GPL(crypto_transfer_skcipher_request_to_engine); + +/** * crypto_transfer_hash_request - transfer the new request into the * enginequeue * @engine: the hardware engine @@ -289,6 +353,43 @@ void crypto_finalize_cipher_request(struct crypto_engine *engine, EXPORT_SYMBOL_GPL(crypto_finalize_cipher_request); /** + * crypto_finalize_skcipher_request - finalize one request if the request is done + * @engine: the hardware engine + * @req: the request need to be finalized + * @err: error number + */ +void crypto_finalize_skcipher_request(struct crypto_engine *engine, + struct skcipher_request *req, int err) +{ + unsigned long flags; + bool finalize_cur_req = false; + int ret; + + spin_lock_irqsave(&engine->queue_lock, flags); + if (engine->cur_req == &req->base) + finalize_cur_req = true; + spin_unlock_irqrestore(&engine->queue_lock, flags); + + if (finalize_cur_req) { + if (engine->cur_req_prepared && + engine->unprepare_skcipher_request) { + ret = engine->unprepare_skcipher_request(engine, req); + if (ret) + dev_err(engine->dev, "failed to unprepare request\n"); + } + spin_lock_irqsave(&engine->queue_lock, flags); + engine->cur_req = NULL; + engine->cur_req_prepared = false; + spin_unlock_irqrestore(&engine->queue_lock, flags); + } + + req->base.complete(&req->base, err); + + kthread_queue_work(engine->kworker, &engine->pump_requests); +} +EXPORT_SYMBOL_GPL(crypto_finalize_skcipher_request); + +/** * crypto_finalize_hash_request - finalize one request if the request is done * @engine: the hardware engine * @req: the request need to be finalized @@ -342,6 +443,19 @@ int crypto_engine_start(struct crypto_engine *engine) return -EBUSY; } + if (!engine->skcipher_one_request && !engine->cipher_one_request && + !engine->hash_one_request) { + spin_unlock_irqrestore(&engine->queue_lock, flags); + dev_err(engine->dev, "need at least one request type\n"); + return -EINVAL; + } + + if (engine->skcipher_one_request && engine->cipher_one_request) { + spin_unlock_irqrestore(&engine->queue_lock, flags); + dev_err(engine->dev, "Cannot use both skcipher and ablkcipher\n"); + return -EINVAL; + } + engine->running = true; spin_unlock_irqrestore(&engine->queue_lock, flags); diff --git a/include/crypto/engine.h b/include/crypto/engine.h index dd04c1699b51..a8f6e6ed377b 100644 --- a/include/crypto/engine.h +++ b/include/crypto/engine.h @@ -18,6 +18,7 @@ #include #include #include +#include #define ENGINE_NAME_LEN 30 /* @@ -69,12 +70,18 @@ struct crypto_engine { struct ablkcipher_request *req); int (*unprepare_cipher_request)(struct crypto_engine *engine, struct ablkcipher_request *req); + int (*prepare_skcipher_request)(struct crypto_engine *engine, + struct skcipher_request *req); + int (*unprepare_skcipher_request)(struct crypto_engine *engine, + struct skcipher_request *req); int (*prepare_hash_request)(struct crypto_engine *engine, struct ahash_request *req); int (*unprepare_hash_request)(struct crypto_engine *engine, struct ahash_request *req); int (*cipher_one_request)(struct crypto_engine *engine, struct ablkcipher_request *req); + int (*skcipher_one_request)(struct crypto_engine *engine, + struct skcipher_request *req); int (*hash_one_request)(struct crypto_engine *engine, struct ahash_request *req); @@ -90,12 +97,19 @@ int crypto_transfer_cipher_request(struct crypto_engine *engine, bool need_pump); int crypto_transfer_cipher_request_to_engine(struct crypto_engine *engine, struct ablkcipher_request *req); +int crypto_transfer_skcipher_request(struct crypto_engine *engine, + struct skcipher_request *req, + bool need_pump); +int crypto_transfer_skcipher_request_to_engine(struct crypto_engine *engine, + struct skcipher_request *req); int crypto_transfer_hash_request(struct crypto_engine *engine, struct ahash_request *req, bool need_pump); int crypto_transfer_hash_request_to_engine(struct crypto_engine *engine, struct ahash_request *req); void crypto_finalize_cipher_request(struct crypto_engine *engine, struct ablkcipher_request *req, int err); +void crypto_finalize_skcipher_request(struct crypto_engine *engine, + struct skcipher_request *req, int err); void crypto_finalize_hash_request(struct crypto_engine *engine, struct ahash_request *req, int err); int crypto_engine_start(struct crypto_engine *engine);