From patchwork Sat May 6 12:59:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Ben-Yossef X-Patchwork-Id: 98760 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp565082qge; Sat, 6 May 2017 06:02:13 -0700 (PDT) X-Received: by 10.98.209.65 with SMTP id t1mr4785812pfl.132.1494075733781; Sat, 06 May 2017 06:02:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1494075733; cv=none; d=google.com; s=arc-20160816; b=jfT/04B7d+V+Heq5uTGnzkm7+a1gm3Qr+IMonpt5+V6suTC+dqbwXFXuZYUg7kttCY DvqJcZqCzf97zFHRWT47gDXUGFnyTpkwWaR9w11LzhBPPzRBED56a9PoZskj9knXFEla ZCyxbzBUNxXh6K+dGaqEDCHHx+DqLgxUHW+5buMmc4ohuhFEl79vId1Tf42LnmwZh8Tp c1Hit3hzPrjIVB0lCAliPvdJOajY4oMjlYD5QzE/wM8h1BaCi479HhVcCJEuY5HSHxBi X/MvbiMrCiGAhPWcDfGrbIkE1MmDCvvLlrr4YxBllkyCH6ndb22syQ58F0HdAKU2tLwn lmyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=v7X1rfdlEXElY0924z47nI663Ih6HUD0unLqj7Mprkg=; b=gpsJVqBIRotICg8k2UzgaIkrjhIKZq0smTy9G7efgB5Q1jHlNrofVPcIptqr2bdVJ7 gGCrzToTVVhvx3Y4YwJiuoTq6tspMbi2WeGD/16wR/0qmAgMQWy4BrNaqL566DfrVo0E +yPzGpbocglci6sHY7HVDKfAVv6u3ayWly6BXaMuaNgDvENy4eYEcRjOk6PfeH7DBRHo OQ924x6XR/JzhXAjvUbcfHIyq2TcD3U+IPqbRMh7LP3dUFwiOeFAzlKrwpg0KVJf+z10 NcU7xeyUVxe//jZDdrf23uZltsZo/u0Y5wMJ0DMv84K8/G1fgL3brExcemUIGb7AZc7w bBFw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k65si391367pge.99.2017.05.06.06.02.13; Sat, 06 May 2017 06:02:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755450AbdEFNCB (ORCPT + 1 other); Sat, 6 May 2017 09:02:01 -0400 Received: from foss.arm.com ([217.140.101.70]:59422 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752320AbdEFNBv (ORCPT ); Sat, 6 May 2017 09:01:51 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D8E1A169F; Sat, 6 May 2017 06:01:45 -0700 (PDT) Received: from localhost.localdomain (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 698E23F41F; Sat, 6 May 2017 06:01:39 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" , Jonathan Corbet , David Howells , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Shaohua Li , Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" Cc: Ofir Drang , Gilad Ben-Yossef , linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org, linux-raid@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-fsdevel@vger.kernel.org, linux-ima-devel@lists.sourceforge.net, linux-ima-user@lists.sourceforge.net, linux-security-module@vger.kernel.org Subject: [RFC 10/10] crypto: adapt api sample to use async. op wait Date: Sat, 6 May 2017 15:59:59 +0300 Message-Id: <1494075602-5061-11-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1494075602-5061-1-git-send-email-gilad@benyossef.com> References: <1494075602-5061-1-git-send-email-gilad@benyossef.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The code sample is waiting for an async. crypto op completion. Adapt sample to use the new generic infrastructure to do the same. Signed-off-by: Gilad Ben-Yossef --- Documentation/crypto/api-samples.rst | 52 +++++++----------------------------- 1 file changed, 10 insertions(+), 42 deletions(-) -- 2.1.4 diff --git a/Documentation/crypto/api-samples.rst b/Documentation/crypto/api-samples.rst index d021fd9..73b466b 100644 --- a/Documentation/crypto/api-samples.rst +++ b/Documentation/crypto/api-samples.rst @@ -7,59 +7,27 @@ Code Example For Symmetric Key Cipher Operation :: - struct tcrypt_result { - struct completion completion; - int err; - }; - /* tie all data structures together */ struct skcipher_def { struct scatterlist sg; struct crypto_skcipher *tfm; struct skcipher_request *req; - struct tcrypt_result result; + struct crypto_wait wait; }; - /* Callback function */ - static void test_skcipher_cb(struct crypto_async_request *req, int error) - { - struct tcrypt_result *result = req->data; - - if (error == -EINPROGRESS) - return; - result->err = error; - complete(&result->completion); - pr_info("Encryption finished successfully\n"); - } - /* Perform cipher operation */ static unsigned int test_skcipher_encdec(struct skcipher_def *sk, int enc) { - int rc = 0; + int rc; if (enc) - rc = crypto_skcipher_encrypt(sk->req); + rc = crypto_wait_req(crypto_skcipher_encrypt(sk->req), &sk->wait); else - rc = crypto_skcipher_decrypt(sk->req); - - switch (rc) { - case 0: - break; - case -EINPROGRESS: - case -EBUSY: - rc = wait_for_completion_interruptible( - &sk->result.completion); - if (!rc && !sk->result.err) { - reinit_completion(&sk->result.completion); - break; - } - default: - pr_info("skcipher encrypt returned with %d result %d\n", - rc, sk->result.err); - break; - } - init_completion(&sk->result.completion); + rc = crypto_wait_req(crypto_skcipher_decrypt(sk->req), &sk->wait); + + if (rc) + pr_info("skcipher encrypt returned with result %d\n", rc); return rc; } @@ -89,8 +57,8 @@ Code Example For Symmetric Key Cipher Operation } skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, - test_skcipher_cb, - &sk.result); + crypto_req_done, + &sk.wait); /* AES 256 with random key */ get_random_bytes(&key, 32); @@ -122,7 +90,7 @@ Code Example For Symmetric Key Cipher Operation /* We encrypt one block */ sg_init_one(&sk.sg, scratchpad, 16); skcipher_request_set_crypt(req, &sk.sg, &sk.sg, 16, ivdata); - init_completion(&sk.result.completion); + crypto_init_wait(&sk.wait); /* encrypt data */ ret = test_skcipher_encdec(&sk, 1);