From patchwork Wed Jun 22 13:23:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Kristo X-Patchwork-Id: 70651 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp2548066qgy; Wed, 22 Jun 2016 06:25:32 -0700 (PDT) X-Received: by 10.66.253.38 with SMTP id zx6mr34927008pac.19.1466601924211; Wed, 22 Jun 2016 06:25:24 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a18si19031pal.178.2016.06.22.06.25.24 for ; Wed, 22 Jun 2016 06:25:24 -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 S1752082AbcFVNZQ (ORCPT ); Wed, 22 Jun 2016 09:25:16 -0400 Received: from bear.ext.ti.com ([198.47.19.11]:36745 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751905AbcFVNZL (ORCPT ); Wed, 22 Jun 2016 09:25:11 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id u5MDOjjc008345; Wed, 22 Jun 2016 08:24:45 -0500 Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id u5MDOjmX014709; Wed, 22 Jun 2016 08:24:45 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DFLE73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.3.294.0; Wed, 22 Jun 2016 08:24:44 -0500 Received: from gomoku.home (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id u5MDONw9022607; Wed, 22 Jun 2016 08:24:42 -0500 From: Tero Kristo To: , , , , , CC: Subject: [PATCHv2 07/27] crypto: omap-sham: implement context export/import APIs Date: Wed, 22 Jun 2016 16:23:40 +0300 Message-ID: <1466601840-18486-8-git-send-email-t-kristo@ti.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1466601840-18486-1-git-send-email-t-kristo@ti.com> References: <1466601840-18486-1-git-send-email-t-kristo@ti.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Context export/import are now required for ahash algorithms due to required support in algif_hash. Implement these for OMAP SHA driver, saving and restoring the internal state of the driver. Signed-off-by: Tero Kristo --- drivers/crypto/omap-sham.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/crypto/omap-sham.c b/drivers/crypto/omap-sham.c index 84a0027..683f825 100644 --- a/drivers/crypto/omap-sham.c +++ b/drivers/crypto/omap-sham.c @@ -1325,6 +1325,35 @@ static void omap_sham_cra_exit(struct crypto_tfm *tfm) } } +static int omap_sham_export(struct ahash_request *req, void *out) +{ + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct omap_sham_reqctx *rctx = ahash_request_ctx(req); + struct omap_sham_ctx *ctx = crypto_ahash_ctx(tfm); + struct omap_sham_hmac_ctx *bctx = ctx->base; + + memcpy(out, rctx, sizeof(*rctx) + BUFLEN); + memcpy(out + sizeof(*rctx) + BUFLEN, ctx, sizeof(*ctx)); + memcpy(out + sizeof(*rctx) + BUFLEN + sizeof(*ctx), bctx, + sizeof(*bctx)); + + return 0; +} + +static int omap_sham_import(struct ahash_request *req, const void *in) +{ + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct omap_sham_reqctx *rctx = ahash_request_ctx(req); + struct omap_sham_ctx *ctx = crypto_ahash_ctx(tfm); + struct omap_sham_hmac_ctx *bctx = ctx->base; + + memcpy(rctx, in, sizeof(*rctx) + BUFLEN); + memcpy(ctx, in + sizeof(*rctx) + BUFLEN, sizeof(*ctx)); + memcpy(bctx, in + sizeof(*rctx) + BUFLEN + sizeof(*ctx), sizeof(*bctx)); + + return 0; +} + static struct ahash_alg algs_sha1_md5[] = { { .init = omap_sham_init, @@ -1979,8 +2008,15 @@ static int omap_sham_probe(struct platform_device *pdev) for (i = 0; i < dd->pdata->algs_info_size; i++) { for (j = 0; j < dd->pdata->algs_info[i].size; j++) { - err = crypto_register_ahash( - &dd->pdata->algs_info[i].algs_list[j]); + struct ahash_alg *alg; + + alg = &dd->pdata->algs_info[i].algs_list[j]; + alg->export = omap_sham_export; + alg->import = omap_sham_import; + alg->halg.statesize = sizeof(struct omap_sham_reqctx) + + sizeof(struct omap_sham_ctx) + + sizeof(struct omap_sham_hmac_ctx) + BUFLEN; + err = crypto_register_ahash(alg); if (err) goto err_algs;