From patchwork Tue Feb 25 12:57:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 25294 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f71.google.com (mail-pb0-f71.google.com [209.85.160.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8EA5920543 for ; Tue, 25 Feb 2014 12:58:08 +0000 (UTC) Received: by mail-pb0-f71.google.com with SMTP id up15sf3842222pbc.2 for ; Tue, 25 Feb 2014 04:58:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=3qQZwxDSgFCNHvSsRcj86HDRkNiRdH1YNGD0VqNZ3+M=; b=IUwV3TvDAXSzt2KdfJ2/eCshQBwooiUpX5i0MvZjxmiZBfX0FrTsLBKyEcs1+wW9zM l2XehtZE/Ykf1415fJYUP6l9nSmhkObGGLivGZLVD6OKqQlVEh7LZt9gg1kVqy4TC7Jc jAyA5cpli36XJe1eGJ6DhyK4ZIDeRcPhGTTg8n5oqTp015TjFU9eq/a3CzP0jfeZBD2/ /qyHOSyGIqxDtnwLV0AKksM/ApZGuwb1fIIe6zqiLiCiA1KJ2MBM+3NV9mwCKqWFMZEr w7ri3MM/sFvHJg2YB3HL/gquR2ga4QPj1YR680SZXtbUh75nxaMJ6ZbnVrByIG26+gu6 tcCw== X-Gm-Message-State: ALoCoQmT/pVjMHyqpBqkTbeep7m47/2m4SFpMcekpBg62+PwubGX/UGj6CO+IBg06P8Fehh3okb2 X-Received: by 10.68.223.202 with SMTP id qw10mr2567569pbc.6.1393333087647; Tue, 25 Feb 2014 04:58:07 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.42.138 with SMTP id c10ls2296853qga.63.gmail; Tue, 25 Feb 2014 04:58:07 -0800 (PST) X-Received: by 10.221.40.10 with SMTP id to10mr1057376vcb.22.1393333087459; Tue, 25 Feb 2014 04:58:07 -0800 (PST) Received: from mail-ve0-f177.google.com (mail-ve0-f177.google.com [209.85.128.177]) by mx.google.com with ESMTPS id uw4si6748674vdc.118.2014.02.25.04.58.07 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Feb 2014 04:58:07 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.177; Received: by mail-ve0-f177.google.com with SMTP id db12so354071veb.36 for ; Tue, 25 Feb 2014 04:58:07 -0800 (PST) X-Received: by 10.52.135.65 with SMTP id pq1mr818692vdb.13.1393333087347; Tue, 25 Feb 2014 04:58:07 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.174.196 with SMTP id u4csp136850vcz; Tue, 25 Feb 2014 04:58:06 -0800 (PST) X-Received: by 10.68.229.164 with SMTP id sr4mr6367022pbc.82.1393333086520; Tue, 25 Feb 2014 04:58:06 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id yc8si3529457pbc.277.2014.02.25.04.58.05; Tue, 25 Feb 2014 04:58:05 -0800 (PST) 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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751463AbaBYM6E (ORCPT + 1 other); Tue, 25 Feb 2014 07:58:04 -0500 Received: from mail-wi0-f172.google.com ([209.85.212.172]:46791 "EHLO mail-wi0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752212AbaBYM6C (ORCPT ); Tue, 25 Feb 2014 07:58:02 -0500 Received: by mail-wi0-f172.google.com with SMTP id e4so4430438wiv.11 for ; Tue, 25 Feb 2014 04:58:00 -0800 (PST) X-Received: by 10.180.73.141 with SMTP id l13mr2875280wiv.60.1393333080507; Tue, 25 Feb 2014 04:58:00 -0800 (PST) Received: from ards-macbook-pro.local (cag06-7-83-153-85-71.fbx.proxad.net. [83.153.85.71]) by mx.google.com with ESMTPSA id k10sm50553443wjf.11.2014.02.25.04.57.59 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Feb 2014 04:58:00 -0800 (PST) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org, herbert@gondor.apana.org.au Cc: Ard Biesheuvel Subject: [RFC PATCH 2/3] crypto: allow blkcipher walks with no associated blkcipher transform Date: Tue, 25 Feb 2014 13:57:51 +0100 Message-Id: <1393333072-15310-3-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1393333072-15310-1-git-send-email-ard.biesheuvel@linaro.org> References: <1393333072-15310-1-git-send-email-ard.biesheuvel@linaro.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This adds the functions blkcipher_walk_init_raw and blkcipher_walk_virt_raw, which allow the caller to initialize the walk struct data members directly. This allows non-blkcipher uses (e.g., AEADs) of the blkcipher walk API. Signed-off-by: Ard Biesheuvel --- crypto/blkcipher.c | 11 ++++++++++- include/crypto/algapi.h | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c index 46fdab5e9cc7..a3ca85c29a76 100644 --- a/crypto/blkcipher.c +++ b/crypto/blkcipher.c @@ -349,7 +349,6 @@ int blkcipher_walk_virt_block(struct blkcipher_desc *desc, unsigned int blocksize) { walk->flags &= ~BLKCIPHER_WALK_PHYS; - walk->walk_blocksize = blocksize; walk->cipher_blocksize = crypto_blkcipher_blocksize(desc->tfm); walk->ivsize = crypto_blkcipher_ivsize(desc->tfm); walk->alignmask = crypto_blkcipher_alignmask(desc->tfm); @@ -357,6 +356,16 @@ int blkcipher_walk_virt_block(struct blkcipher_desc *desc, } EXPORT_SYMBOL_GPL(blkcipher_walk_virt_block); +int blkcipher_walk_virt_raw(struct blkcipher_desc *desc, + struct blkcipher_walk *walk, + unsigned int blocksize) +{ + walk->flags &= ~BLKCIPHER_WALK_PHYS; + walk->walk_blocksize = blocksize; + return blkcipher_walk_first(desc, walk); +} +EXPORT_SYMBOL_GPL(blkcipher_walk_virt_raw); + static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) { diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h index d9d14a0f0653..7e70ede66c02 100644 --- a/include/crypto/algapi.h +++ b/include/crypto/algapi.h @@ -195,6 +195,9 @@ int blkcipher_walk_phys(struct blkcipher_desc *desc, int blkcipher_walk_virt_block(struct blkcipher_desc *desc, struct blkcipher_walk *walk, unsigned int blocksize); +int blkcipher_walk_virt_raw(struct blkcipher_desc *desc, + struct blkcipher_walk *walk, + unsigned int blocksize); int ablkcipher_walk_done(struct ablkcipher_request *req, struct ablkcipher_walk *walk, int err); @@ -312,6 +315,23 @@ static inline void blkcipher_walk_init(struct blkcipher_walk *walk, walk->total = nbytes; } +static inline void blkcipher_walk_init_raw(struct blkcipher_walk *walk, + struct scatterlist *dst, + struct scatterlist *src, + unsigned int nbytes, + unsigned int blocksize, + unsigned int ivsize, + unsigned int alignmask) +{ + walk->in.sg = src; + walk->out.sg = dst; + walk->total = nbytes; + + walk->cipher_blocksize = blocksize; + walk->ivsize = ivsize; + walk->alignmask = alignmask; +} + static inline void ablkcipher_walk_init(struct ablkcipher_walk *walk, struct scatterlist *dst, struct scatterlist *src,