Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: acomp - update testmgr with support for acomp

Add tests to the test manager for algorithms exposed through acomp.

Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Giovanni Cabiddu and committed by
Herbert Xu
d7db7a88 f6ded09d

+145 -13
+145 -13
crypto/testmgr.c
··· 33 33 #include <crypto/drbg.h> 34 34 #include <crypto/akcipher.h> 35 35 #include <crypto/kpp.h> 36 + #include <crypto/acompress.h> 36 37 37 38 #include "internal.h" 38 39 ··· 1443 1442 return ret; 1444 1443 } 1445 1444 1445 + static int test_acomp(struct crypto_acomp *tfm, struct comp_testvec *ctemplate, 1446 + struct comp_testvec *dtemplate, int ctcount, int dtcount) 1447 + { 1448 + const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm)); 1449 + unsigned int i; 1450 + char output[COMP_BUF_SIZE]; 1451 + int ret; 1452 + struct scatterlist src, dst; 1453 + struct acomp_req *req; 1454 + struct tcrypt_result result; 1455 + 1456 + for (i = 0; i < ctcount; i++) { 1457 + unsigned int dlen = COMP_BUF_SIZE; 1458 + int ilen = ctemplate[i].inlen; 1459 + 1460 + memset(output, 0, sizeof(output)); 1461 + init_completion(&result.completion); 1462 + sg_init_one(&src, ctemplate[i].input, ilen); 1463 + sg_init_one(&dst, output, dlen); 1464 + 1465 + req = acomp_request_alloc(tfm); 1466 + if (!req) { 1467 + pr_err("alg: acomp: request alloc failed for %s\n", 1468 + algo); 1469 + ret = -ENOMEM; 1470 + goto out; 1471 + } 1472 + 1473 + acomp_request_set_params(req, &src, &dst, ilen, dlen); 1474 + acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 1475 + tcrypt_complete, &result); 1476 + 1477 + ret = wait_async_op(&result, crypto_acomp_compress(req)); 1478 + if (ret) { 1479 + pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n", 1480 + i + 1, algo, -ret); 1481 + acomp_request_free(req); 1482 + goto out; 1483 + } 1484 + 1485 + if (req->dlen != ctemplate[i].outlen) { 1486 + pr_err("alg: acomp: Compression test %d failed for %s: output len = %d\n", 1487 + i + 1, algo, req->dlen); 1488 + ret = -EINVAL; 1489 + acomp_request_free(req); 1490 + goto out; 1491 + } 1492 + 1493 + if (memcmp(output, ctemplate[i].output, req->dlen)) { 1494 + pr_err("alg: acomp: Compression test %d failed for %s\n", 1495 + i + 1, algo); 1496 + hexdump(output, req->dlen); 1497 + ret = -EINVAL; 1498 + acomp_request_free(req); 1499 + goto out; 1500 + } 1501 + 1502 + acomp_request_free(req); 1503 + } 1504 + 1505 + for (i = 0; i < dtcount; i++) { 1506 + unsigned int dlen = COMP_BUF_SIZE; 1507 + int ilen = dtemplate[i].inlen; 1508 + 1509 + memset(output, 0, sizeof(output)); 1510 + init_completion(&result.completion); 1511 + sg_init_one(&src, dtemplate[i].input, ilen); 1512 + sg_init_one(&dst, output, dlen); 1513 + 1514 + req = acomp_request_alloc(tfm); 1515 + if (!req) { 1516 + pr_err("alg: acomp: request alloc failed for %s\n", 1517 + algo); 1518 + ret = -ENOMEM; 1519 + goto out; 1520 + } 1521 + 1522 + acomp_request_set_params(req, &src, &dst, ilen, dlen); 1523 + acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 1524 + tcrypt_complete, &result); 1525 + 1526 + ret = wait_async_op(&result, crypto_acomp_decompress(req)); 1527 + if (ret) { 1528 + pr_err("alg: acomp: decompression failed on test %d for %s: ret=%d\n", 1529 + i + 1, algo, -ret); 1530 + acomp_request_free(req); 1531 + goto out; 1532 + } 1533 + 1534 + if (req->dlen != dtemplate[i].outlen) { 1535 + pr_err("alg: acomp: Decompression test %d failed for %s: output len = %d\n", 1536 + i + 1, algo, req->dlen); 1537 + ret = -EINVAL; 1538 + acomp_request_free(req); 1539 + goto out; 1540 + } 1541 + 1542 + if (memcmp(output, dtemplate[i].output, req->dlen)) { 1543 + pr_err("alg: acomp: Decompression test %d failed for %s\n", 1544 + i + 1, algo); 1545 + hexdump(output, req->dlen); 1546 + ret = -EINVAL; 1547 + acomp_request_free(req); 1548 + goto out; 1549 + } 1550 + 1551 + acomp_request_free(req); 1552 + } 1553 + 1554 + ret = 0; 1555 + 1556 + out: 1557 + return ret; 1558 + } 1559 + 1446 1560 static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template, 1447 1561 unsigned int tcount) 1448 1562 { ··· 1709 1593 static int alg_test_comp(const struct alg_test_desc *desc, const char *driver, 1710 1594 u32 type, u32 mask) 1711 1595 { 1712 - struct crypto_comp *tfm; 1596 + struct crypto_comp *comp; 1597 + struct crypto_acomp *acomp; 1713 1598 int err; 1599 + u32 algo_type = type & CRYPTO_ALG_TYPE_ACOMPRESS_MASK; 1714 1600 1715 - tfm = crypto_alloc_comp(driver, type, mask); 1716 - if (IS_ERR(tfm)) { 1717 - printk(KERN_ERR "alg: comp: Failed to load transform for %s: " 1718 - "%ld\n", driver, PTR_ERR(tfm)); 1719 - return PTR_ERR(tfm); 1601 + if (algo_type == CRYPTO_ALG_TYPE_ACOMPRESS) { 1602 + acomp = crypto_alloc_acomp(driver, type, mask); 1603 + if (IS_ERR(acomp)) { 1604 + pr_err("alg: acomp: Failed to load transform for %s: %ld\n", 1605 + driver, PTR_ERR(acomp)); 1606 + return PTR_ERR(acomp); 1607 + } 1608 + err = test_acomp(acomp, desc->suite.comp.comp.vecs, 1609 + desc->suite.comp.decomp.vecs, 1610 + desc->suite.comp.comp.count, 1611 + desc->suite.comp.decomp.count); 1612 + crypto_free_acomp(acomp); 1613 + } else { 1614 + comp = crypto_alloc_comp(driver, type, mask); 1615 + if (IS_ERR(comp)) { 1616 + pr_err("alg: comp: Failed to load transform for %s: %ld\n", 1617 + driver, PTR_ERR(comp)); 1618 + return PTR_ERR(comp); 1619 + } 1620 + 1621 + err = test_comp(comp, desc->suite.comp.comp.vecs, 1622 + desc->suite.comp.decomp.vecs, 1623 + desc->suite.comp.comp.count, 1624 + desc->suite.comp.decomp.count); 1625 + 1626 + crypto_free_comp(comp); 1720 1627 } 1721 - 1722 - err = test_comp(tfm, desc->suite.comp.comp.vecs, 1723 - desc->suite.comp.decomp.vecs, 1724 - desc->suite.comp.comp.count, 1725 - desc->suite.comp.decomp.count); 1726 - 1727 - crypto_free_comp(tfm); 1728 1628 return err; 1729 1629 } 1730 1630