From patchwork Tue Jan 26 08:15:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joonsoo Kim X-Patchwork-Id: 8118701 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 3CA2BBEEE5 for ; Tue, 26 Jan 2016 08:17:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2C94420266 for ; Tue, 26 Jan 2016 08:17:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D29302025B for ; Tue, 26 Jan 2016 08:17:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752924AbcAZIQe (ORCPT ); Tue, 26 Jan 2016 03:16:34 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:33480 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933916AbcAZIQO (ORCPT ); Tue, 26 Jan 2016 03:16:14 -0500 Received: by mail-pf0-f193.google.com with SMTP id e65so8018201pfe.0; Tue, 26 Jan 2016 00:16:14 -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=62jCCRsT9Rv+gpQehbUPYYpzdC01pQMZBfZaS92ueOY=; b=S08AOODZ0QA7+KlT5JlulgtZKubffPsCAEUCiqBG43O7v4Hgs/56stFW0XgPy4yr6k DMYRPkaKtvUxAaRPr2dNW2tQG5eiXNu1p9ZNlMdFBwFuh3RZOOPi9Pcob96ZB9QBKURe HtB3/fNqEOFyQpIXIfBRL4Uj57bgKdVG7RzMnb4yRCnA1tQRT2KMyovFUcfWiCF5qN80 A2KzeNfi1vKe3p2Ak3epePWKOqLW4s+/jmaK7LC6QwrRcSKnX/aFizJ8EYR+eNh37iTU jfgDDW6d99QvREUpYuAb8iItTquKGSPGP+5TaanrFd1opMMG/FQGB0wzvAq8BrIu/xcL y12w== 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=62jCCRsT9Rv+gpQehbUPYYpzdC01pQMZBfZaS92ueOY=; b=iVfCYRqzPkyKjQqw3fZ3ErgPo81y8ZUgHr0yvifEFIsnltrqJHAsgWXUJqcJpgHK+Q XtZhb5aSrZaAEe39ppL3Ji+Dn1Sm89PAGp4OKXzAY3qg80QgvRj0+Iz6ZiB0VYp5IWRf IFt3LMLCKFRAuqXQxXxDQRAfRfj2TNVaWw+FG3U6PLyRrRkEKUQDl7kGlywjyZ02uCdD VKOBjgwP1EWUOkgY0jR8dmiJn5Q9VNmYkbMP2qk7dd0EoD895Doja0cfbnFS92/hy4yr sPEAP+SwOzrqCJjb1KqrssesALHbV3bMFq2DRhBCiVtSdx75KIEZ6kLRtB5B3kjbYDZ7 8xZg== X-Gm-Message-State: AG10YOQz3znIpj2P0+QS6bviSrCDUWAoRt+FS9zQw4b7soNcVwKILkZS7e1TGG9Y+UHNTA== X-Received: by 10.98.11.209 with SMTP id 78mr32152127pfl.92.1453796173726; Tue, 26 Jan 2016 00:16:13 -0800 (PST) Received: from localhost.localdomain ([119.69.155.252]) by smtp.gmail.com with ESMTPSA id d21sm342139pfj.32.2016.01.26.00.16.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 26 Jan 2016 00:16:12 -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 10/10] crypto/testmgr: add new compression APIs test Date: Tue, 26 Jan 2016 17:15:12 +0900 Message-Id: <1453796112-14273-11-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 New compression APIs are supported now so we need test cases. This patch implements it based on previous compression test framework. Almost changes are straight forward. Signed-off-by: Joonsoo Kim --- crypto/Kconfig | 1 + crypto/testmgr.c | 227 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 216 insertions(+), 12 deletions(-) diff --git a/crypto/Kconfig b/crypto/Kconfig index 728f88e..4b9d796 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..d72ab6a 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) { @@ -2520,7 +2659,7 @@ static const struct alg_test_desc alg_test_descs[] = { } } }, { - .alg = "deflate", + .alg = "deflate-generic", .test = alg_test_comp, .fips_allowed = 1, .suite = { @@ -2536,6 +2675,22 @@ static const struct alg_test_desc alg_test_descs[] = { } } }, { + .alg = "deflate-scomp", + .test = alg_test_scomp, + .fips_allowed = 1, + .suite = { + .comp = { + .comp = { + .vecs = deflate_comp_tv_template, + .count = DEFLATE_COMP_TEST_VECTORS + }, + .decomp = { + .vecs = deflate_decomp_tv_template, + .count = DEFLATE_DECOMP_TEST_VECTORS + } + } + } + }, { .alg = "digest_null", .test = alg_test_null, }, { @@ -3171,7 +3326,7 @@ static const struct alg_test_desc alg_test_descs[] = { } } }, { - .alg = "lz4", + .alg = "lz4-generic", .test = alg_test_comp, .fips_allowed = 1, .suite = { @@ -3187,7 +3342,23 @@ static const struct alg_test_desc alg_test_descs[] = { } } }, { - .alg = "lz4hc", + .alg = "lz4-scomp", + .test = alg_test_scomp, + .fips_allowed = 1, + .suite = { + .comp = { + .comp = { + .vecs = lz4_comp_tv_template, + .count = LZ4_COMP_TEST_VECTORS + }, + .decomp = { + .vecs = lz4_decomp_tv_template, + .count = LZ4_DECOMP_TEST_VECTORS + } + } + } + }, { + .alg = "lz4hc-generic", .test = alg_test_comp, .fips_allowed = 1, .suite = { @@ -3203,7 +3374,23 @@ static const struct alg_test_desc alg_test_descs[] = { } } }, { - .alg = "lzo", + .alg = "lz4hc-scomp", + .test = alg_test_scomp, + .fips_allowed = 1, + .suite = { + .comp = { + .comp = { + .vecs = lz4hc_comp_tv_template, + .count = LZ4HC_COMP_TEST_VECTORS + }, + .decomp = { + .vecs = lz4hc_decomp_tv_template, + .count = LZ4HC_DECOMP_TEST_VECTORS + } + } + } + }, { + .alg = "lzo-generic", .test = alg_test_comp, .fips_allowed = 1, .suite = { @@ -3219,6 +3406,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 = {