From patchwork Tue Jan 26 08:15:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joonsoo Kim X-Patchwork-Id: 8118721 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A32289F859 for ; Tue, 26 Jan 2016 08:17:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BD39C20266 for ; Tue, 26 Jan 2016 08:17:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A45492025B for ; Tue, 26 Jan 2016 08:17:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933089AbcAZIRS (ORCPT ); Tue, 26 Jan 2016 03:17:18 -0500 Received: from mail-pa0-f67.google.com ([209.85.220.67]:36560 "EHLO mail-pa0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933848AbcAZIQF (ORCPT ); Tue, 26 Jan 2016 03:16:05 -0500 Received: by mail-pa0-f67.google.com with SMTP id a20so7630311pag.3; Tue, 26 Jan 2016 00:16:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=SBtxfAuz0FFMEBk/cUfJh56O8kPBoGOb7dPUD7QLqZ4=; b=hzqFQk6Hz3s1MAB+oHg776xWWu0Py1F1VXmyb5iTrVSpygWAIEHJ8DLHPi4dgEIuz8 OJX0noMZqRdKEnTTWyzQ6wWWEA80rCxeEbnwsMxiRGRNQgmHK3OK1L0OQcP/jbhiSPFb /QpOIJdIF57V8S0HiJCejr+D5/pDr2jR0wnYHabqgdcH7HCfm4SQDV8O5/nsRFom7gwX Pbn7S8jy3alxxi4ZhNIiwWpffIjd5IUa9kNLavcHrynuA7wFcDVTq0RnuZZ2Br2eHMS6 5bLFHkaOf4Y7ZjuncUieit20GAkRrjDoMNvHSP/oAPI1i0FQpvR1C6M74eqItGuPzDkU XqSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=SBtxfAuz0FFMEBk/cUfJh56O8kPBoGOb7dPUD7QLqZ4=; b=JlXzyYy6UxecS3EDaWTZx1MMlgRMeP7VYtowjsnhJhX+TnMpIQN7zmbGR4khWe9YxT 0fkrW690x9xZo3hj7VgHrqzu7cPyXmPsvUJO74S/9ETAPdlx9tRcRspRzSw5qvkfvTn8 llMZhP0176D+ZdrzJDH2/24yQr5ll5nPNNRM9o2S27JSOYg/aGSzU6ZfCCfBHX+rJ5DP 7H9OyucYOkOBl/nH+stm88JSpg7q48MloCoVT8aYB0mp9pz+XCamGZ58Nwle5zwzEm2G I8GuBLC4n1ntp3hKoywO9OVrzDON3Tpkiz8AV83nqxw1vBgyxRun/hcB2rR/RysucgJT 7NFw== X-Gm-Message-State: AG10YOSFyieGF75pAYImjgg07ClCvwASaKAERWvYBOk4Uo7jkKS3jXYBxwN6dySHxFbwRg== X-Received: by 10.66.158.37 with SMTP id wr5mr32447505pab.48.1453796164075; Tue, 26 Jan 2016 00:16:04 -0800 (PST) Received: from localhost.localdomain ([119.69.155.252]) by smtp.gmail.com with ESMTPSA id d21sm342139pfj.32.2016.01.26.00.15.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 26 Jan 2016 00:16:03 -0800 (PST) From: Joonsoo Kim X-Google-Original-From: Joonsoo Kim To: Herbert Xu Cc: "David S. Miller" , Weigang Li , Sergey Senozhatsky , Minchan Kim , Dan Streetman , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Joonsoo Kim Subject: [PATCH v2 08/10] crypto/842: support new compression APIs Date: Tue, 26 Jan 2016 17:15:10 +0900 Message-Id: <1453796112-14273-9-git-send-email-iamjoonsoo.kim@lge.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1453796112-14273-1-git-send-email-iamjoonsoo.kim@lge.com> References: <1453796112-14273-1-git-send-email-iamjoonsoo.kim@lge.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Now, new compression APIs are introduced and it has some benefits. Let's support it. Signed-off-by: Joonsoo Kim --- crypto/842.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- crypto/Kconfig | 1 + 2 files changed, 83 insertions(+), 3 deletions(-) diff --git a/crypto/842.c b/crypto/842.c index 98e387e..47cf7e5 100644 --- a/crypto/842.c +++ b/crypto/842.c @@ -32,10 +32,46 @@ #include #include +#include + struct crypto842_ctx { - char wmem[SW842_MEM_COMPRESS]; /* working memory for compress */ + void *wmem; /* working memory for compress */ }; +static void *crypto842_alloc_ctx(struct crypto_scomp *tfm) +{ + void *ctx; + + ctx = kmalloc(SW842_MEM_COMPRESS, GFP_KERNEL); + if (!ctx) + return ERR_PTR(-ENOMEM); + + return ctx; +} + +static int crypto842_init(struct crypto_tfm *tfm) +{ + struct crypto842_ctx *ctx = crypto_tfm_ctx(tfm); + + ctx->wmem = crypto842_alloc_ctx(NULL); + if (IS_ERR(ctx->wmem)) + return -ENOMEM; + + return 0; +} + +static void crypto842_free_ctx(struct crypto_scomp *tfm, void *ctx) +{ + kfree(ctx); +} + +static void crypto842_exit(struct crypto_tfm *tfm) +{ + struct crypto842_ctx *ctx = crypto_tfm_ctx(tfm); + + crypto842_free_ctx(NULL, ctx->wmem); +} + static int crypto842_compress(struct crypto_tfm *tfm, const u8 *src, unsigned int slen, u8 *dst, unsigned int *dlen) @@ -45,6 +81,13 @@ static int crypto842_compress(struct crypto_tfm *tfm, return sw842_compress(src, slen, dst, dlen, ctx->wmem); } +static int crypto842_scompress(struct crypto_scomp *tfm, + const u8 *src, unsigned int slen, + u8 *dst, unsigned int *dlen, void *ctx) +{ + return sw842_compress(src, slen, dst, dlen, ctx); +} + static int crypto842_decompress(struct crypto_tfm *tfm, const u8 *src, unsigned int slen, u8 *dst, unsigned int *dlen) @@ -52,27 +95,63 @@ static int crypto842_decompress(struct crypto_tfm *tfm, return sw842_decompress(src, slen, dst, dlen); } +static int crypto842_sdecompress(struct crypto_scomp *tfm, + const u8 *src, unsigned int slen, + u8 *dst, unsigned int *dlen, void *ctx) +{ + return sw842_decompress(src, slen, dst, dlen); +} + static struct crypto_alg alg = { .cra_name = "842", .cra_driver_name = "842-generic", .cra_priority = 100, .cra_flags = CRYPTO_ALG_TYPE_COMPRESS, - .cra_ctxsize = sizeof(struct crypto842_ctx), .cra_module = THIS_MODULE, + .cra_init = crypto842_init, + .cra_exit = crypto842_exit, .cra_u = { .compress = { .coa_compress = crypto842_compress, .coa_decompress = crypto842_decompress } } }; +static struct scomp_alg scomp = { + .alloc_ctx = crypto842_alloc_ctx, + .free_ctx = crypto842_free_ctx, + .compress = crypto842_scompress, + .decompress = crypto842_sdecompress, + .base = { + .cra_name = "842", + .cra_driver_name= "842-scomp", + .cra_priority = 100, + .cra_flags = CRYPTO_ALG_TYPE_SCOMPRESS | + CRYPTO_SCOMP_DECOMP_NOCTX, + .cra_module = THIS_MODULE, + } +}; + static int __init crypto842_mod_init(void) { - return crypto_register_alg(&alg); + int ret; + + ret = crypto_register_alg(&alg); + if (ret) + return ret; + + ret = crypto_register_scomp(&scomp); + if (ret) { + crypto_unregister_alg(&alg); + return ret; + } + + return ret; } module_init(crypto842_mod_init); static void __exit crypto842_mod_exit(void) { crypto_unregister_alg(&alg); + crypto_unregister_scomp(&scomp); } module_exit(crypto842_mod_exit); diff --git a/crypto/Kconfig b/crypto/Kconfig index 2641a60..351b859 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig @@ -1512,6 +1512,7 @@ config CRYPTO_842 select CRYPTO_ALGAPI select 842_COMPRESS select 842_DECOMPRESS + select CRYPTO_COMPRESS2 help This is the 842 algorithm.