From patchwork Mon Jan 4 04:46:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joonsoo Kim X-Patchwork-Id: 7945311 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BA602BEEE5 for ; Mon, 4 Jan 2016 04:48:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B9CA72025A for ; Mon, 4 Jan 2016 04:48:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9945C2022A for ; Mon, 4 Jan 2016 04:48:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752632AbcADEsN (ORCPT ); Sun, 3 Jan 2016 23:48:13 -0500 Received: from mail-pa0-f43.google.com ([209.85.220.43]:33818 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752711AbcADErd (ORCPT ); Sun, 3 Jan 2016 23:47:33 -0500 Received: by mail-pa0-f43.google.com with SMTP id uo6so171005709pac.1; Sun, 03 Jan 2016 20:47:33 -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=4t/Gnt9ZLQvVD7RiHheWxDgxedjyvjfWcMBhaNRq0pk=; b=FYzooJRo5Gq4HrDTVZbV3jBI5+C3SHbl7dL2ZmdRVea1p+UfgDPcyQWQB30i79Mqwx 1SJqcwL5Ju3qECUywfkIgN2V7Qmvj1CgGaaxPMm7VlhLaDYwK1UQ2zTOE6Lf7rMQwHXP ddP2Y4HQvj0DCIOqfmuTfwvo/QMI7r7IhsSp/MBXMwXSV8Gd8zqm0vv1tPdXu9BepM+t EUmZaOeFfDs6yZToV95C5qMb8A7YBFzlGFW71wGwwpcchWgSsaBuu9ODHD1vSQ5iE658 1IUs3mwxoh90An4yB+MNSYs91Nd33kG4QkKqSpk+2JEc/52u/utn4TzCxkDs+T1jUG5n FXsg== X-Received: by 10.66.253.71 with SMTP id zy7mr122718724pac.20.1451882853391; Sun, 03 Jan 2016 20:47:33 -0800 (PST) Received: from localhost.localdomain ([119.69.155.252]) by smtp.gmail.com with ESMTPSA id tu9sm122503374pac.0.2016.01.03.20.47.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 03 Jan 2016 20:47:32 -0800 (PST) From: Joonsoo Kim X-Google-Original-From: Joonsoo Kim To: Herbert Xu Cc: "David S. Miller" , Weigang Li , Sergey Senozhatsky , Minchan Kim , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Joonsoo Kim Subject: [PATCH RFC 5/7] crypto: testmgr: add scompress/acompress test Date: Mon, 4 Jan 2016 13:46:56 +0900 Message-Id: <1451882819-2810-6-git-send-email-iamjoonsoo.kim@lge.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1451882819-2810-1-git-send-email-iamjoonsoo.kim@lge.com> References: <1451882819-2810-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 Signed-off-by: Joonsoo Kim --- crypto/Kconfig | 1 + crypto/testmgr.c | 173 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 165 insertions(+), 9 deletions(-) diff --git a/crypto/Kconfig b/crypto/Kconfig index b4b485c..f487502 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig @@ -118,6 +118,7 @@ config CRYPTO_MANAGER2 select CRYPTO_HASH2 select CRYPTO_BLKCIPHER2 select CRYPTO_AKCIPHER2 + select CRYPTO_COMPRESS2 config CRYPTO_USER tristate "Userspace cryptographic algorithm configuration" diff --git a/crypto/testmgr.c b/crypto/testmgr.c index 086aa4d..bd0c639 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "internal.h" @@ -1205,12 +1206,14 @@ static int test_skcipher(struct crypto_skcipher *tfm, int enc, return 0; } -static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate, - struct comp_testvec *dtemplate, int ctcount, int dtcount) +static int test_comp(struct crypto_tfm *tfm, void *ctx, int type, + struct comp_testvec *ctemplate, struct comp_testvec *dtemplate, + int ctcount, int dtcount) { - const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm)); + const char *algo = crypto_tfm_alg_driver_name(tfm); unsigned int i; char result[COMP_BUF_SIZE]; + struct scatterlist src, dst; int ret; for (i = 0; i < ctcount; i++) { @@ -1220,8 +1223,33 @@ static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate, memset(result, 0, sizeof (result)); ilen = ctemplate[i].inlen; - ret = crypto_comp_compress(tfm, ctemplate[i].input, - ilen, result, &dlen); + + switch (type) { + case 0: + ret = crypto_comp_compress(crypto_comp_cast(tfm), + ctemplate[i].input, ilen, + result, &dlen); + break; + + case 1: + ret = crypto_scomp_compress(crypto_scomp_cast(tfm), + ctemplate[i].input, ilen, + result, &dlen, ctx); + break; + + case 2: + sg_init_one(&src, ctemplate[i].input, ilen); + sg_init_one(&dst, result, dlen); + acomp_request_set_comp(ctx, &src, &dst, ilen, dlen); + ret = crypto_acomp_compress(ctx); + dlen = ((struct acomp_req *)ctx)->out_len; + break; + + default: + ret = 1; + break; + } + if (ret) { printk(KERN_ERR "alg: comp: compression failed " "on test %d for %s: ret=%d\n", i + 1, algo, @@ -1253,8 +1281,32 @@ static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate, memset(result, 0, sizeof (result)); ilen = dtemplate[i].inlen; - ret = crypto_comp_decompress(tfm, dtemplate[i].input, - ilen, result, &dlen); + switch (type) { + case 0: + ret = crypto_comp_decompress(crypto_comp_cast(tfm), + dtemplate[i].input, ilen, + result, &dlen); + break; + + case 1: + ret = crypto_scomp_decompress(crypto_scomp_cast(tfm), + dtemplate[i].input, ilen, + result, &dlen, ctx); + break; + + case 2: + sg_init_one(&src, dtemplate[i].input, ilen); + sg_init_one(&dst, result, dlen); + acomp_request_set_comp(ctx, &src, &dst, ilen, dlen); + ret = crypto_acomp_decompress(ctx); + dlen = ((struct acomp_req *)ctx)->out_len; + break; + + default: + ret = 1; + break; + } + if (ret) { printk(KERN_ERR "alg: comp: decompression failed " "on test %d for %s: ret=%d\n", i + 1, algo, @@ -1446,7 +1498,8 @@ static int alg_test_comp(const struct alg_test_desc *desc, const char *driver, return PTR_ERR(tfm); } - err = test_comp(tfm, desc->suite.comp.comp.vecs, + err = test_comp(crypto_comp_tfm(tfm), NULL, 0, + desc->suite.comp.comp.vecs, desc->suite.comp.decomp.vecs, desc->suite.comp.comp.count, desc->suite.comp.decomp.count); @@ -1455,6 +1508,92 @@ static int alg_test_comp(const struct alg_test_desc *desc, const char *driver, return err; } +static int __alg_test_scomp(const struct alg_test_desc *desc, + const char *driver, u32 type, u32 mask) +{ + struct crypto_scomp *tfm; + void *ctx; + int err; + + tfm = crypto_alloc_scomp(driver, type, mask); + if (IS_ERR(tfm)) { + printk(KERN_ERR "alg: scomp: Failed to load transform for %s: " + "%ld\n", driver, PTR_ERR(tfm)); + return PTR_ERR(tfm); + } + + ctx = crypto_scomp_alloc_ctx(tfm); + if (IS_ERR(ctx)) { + printk(KERN_ERR "alg: scomp: Failed to alloc context for %s: " + "%ld\n", driver, PTR_ERR(ctx)); + err = PTR_ERR(ctx); + goto out; + } + + err = test_comp(crypto_scomp_tfm(tfm), ctx, 1, + desc->suite.comp.comp.vecs, + desc->suite.comp.decomp.vecs, + desc->suite.comp.comp.count, + desc->suite.comp.decomp.count); + + crypto_scomp_free_ctx(tfm, ctx); + +out: + crypto_free_scomp(tfm); + return err; +} + +static int __alg_test_acomp(const struct alg_test_desc *desc, + const char *driver, u32 type, u32 mask) +{ + struct crypto_acomp *tfm; + struct acomp_req *req; + int err; + + tfm = crypto_alloc_acomp(driver, type, mask); + if (IS_ERR(tfm)) { + printk(KERN_ERR "alg: acomp: Failed to load transform for %s: " + "%ld\n", driver, PTR_ERR(tfm)); + return PTR_ERR(tfm); + } + + req = acomp_request_alloc(tfm, GFP_KERNEL); + if (!req) { + printk(KERN_ERR "alg: acomp: Failed to alloc request for %s: ", + driver); + err = -ENOMEM; + goto out; + } + + err = test_comp(crypto_acomp_tfm(tfm), req, 2, + desc->suite.comp.comp.vecs, + desc->suite.comp.decomp.vecs, + desc->suite.comp.comp.count, + desc->suite.comp.decomp.count); + + acomp_request_free(req); + +out: + crypto_free_acomp(tfm); + return err; +} + +static int alg_test_scomp(const struct alg_test_desc *desc, const char *driver, + u32 type, u32 mask) +{ + int err; + + err = __alg_test_scomp(desc, driver, type, mask); + if (err) + return err; + + err = __alg_test_acomp(desc, driver, type, mask); + if (err) + return err; + + return err; +} + static int alg_test_hash(const struct alg_test_desc *desc, const char *driver, u32 type, u32 mask) { @@ -3203,7 +3342,7 @@ static const struct alg_test_desc alg_test_descs[] = { } } }, { - .alg = "lzo", + .alg = "lzo-generic", .test = alg_test_comp, .fips_allowed = 1, .suite = { @@ -3219,6 +3358,22 @@ static const struct alg_test_desc alg_test_descs[] = { } } }, { + .alg = "lzo-scomp", + .test = alg_test_scomp, + .fips_allowed = 1, + .suite = { + .comp = { + .comp = { + .vecs = lzo_comp_tv_template, + .count = LZO_COMP_TEST_VECTORS + }, + .decomp = { + .vecs = lzo_decomp_tv_template, + .count = LZO_DECOMP_TEST_VECTORS + } + } + } + }, { .alg = "md4", .test = alg_test_hash, .suite = {