diff options
author | Yuan Kang <Yuan.Kang@freescale.com> | 2012-06-22 20:48:48 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2012-06-27 02:42:05 -0400 |
commit | b0e09bae37eeacb213d9baf8fcb4d48934a4ada5 (patch) | |
tree | dfc452367befaeb85971a48aebd0e9eb9e8258f0 | |
parent | 045e36780f11523e26d1e4a8c78bdc57f4003bd0 (diff) |
crypto: caam - unkeyed ahash support
caam supports and registers unkeyed sha algorithms and md5.
Signed-off-by: Yuan Kang <Yuan.Kang@freescale.com>
Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | drivers/crypto/caam/caamhash.c | 75 |
1 files changed, 58 insertions, 17 deletions
diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c index c0b6d86577cf..7dcf28f48149 100644 --- a/drivers/crypto/caam/caamhash.c +++ b/drivers/crypto/caam/caamhash.c | |||
@@ -1485,6 +1485,8 @@ static int ahash_import(struct ahash_request *req, const void *in) | |||
1485 | struct caam_hash_template { | 1485 | struct caam_hash_template { |
1486 | char name[CRYPTO_MAX_ALG_NAME]; | 1486 | char name[CRYPTO_MAX_ALG_NAME]; |
1487 | char driver_name[CRYPTO_MAX_ALG_NAME]; | 1487 | char driver_name[CRYPTO_MAX_ALG_NAME]; |
1488 | char hmac_name[CRYPTO_MAX_ALG_NAME]; | ||
1489 | char hmac_driver_name[CRYPTO_MAX_ALG_NAME]; | ||
1488 | unsigned int blocksize; | 1490 | unsigned int blocksize; |
1489 | struct ahash_alg template_ahash; | 1491 | struct ahash_alg template_ahash; |
1490 | u32 alg_type; | 1492 | u32 alg_type; |
@@ -1494,8 +1496,10 @@ struct caam_hash_template { | |||
1494 | /* ahash descriptors */ | 1496 | /* ahash descriptors */ |
1495 | static struct caam_hash_template driver_hash[] = { | 1497 | static struct caam_hash_template driver_hash[] = { |
1496 | { | 1498 | { |
1497 | .name = "hmac(sha1)", | 1499 | .name = "sha1", |
1498 | .driver_name = "hmac-sha1-caam", | 1500 | .driver_name = "sha1-caam", |
1501 | .hmac_name = "hmac(sha1)", | ||
1502 | .hmac_driver_name = "hmac-sha1-caam", | ||
1499 | .blocksize = SHA1_BLOCK_SIZE, | 1503 | .blocksize = SHA1_BLOCK_SIZE, |
1500 | .template_ahash = { | 1504 | .template_ahash = { |
1501 | .init = ahash_init, | 1505 | .init = ahash_init, |
@@ -1513,8 +1517,10 @@ static struct caam_hash_template driver_hash[] = { | |||
1513 | .alg_type = OP_ALG_ALGSEL_SHA1, | 1517 | .alg_type = OP_ALG_ALGSEL_SHA1, |
1514 | .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC, | 1518 | .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC, |
1515 | }, { | 1519 | }, { |
1516 | .name = "hmac(sha224)", | 1520 | .name = "sha224", |
1517 | .driver_name = "hmac-sha224-caam", | 1521 | .driver_name = "sha224-caam", |
1522 | .hmac_name = "hmac(sha224)", | ||
1523 | .hmac_driver_name = "hmac-sha224-caam", | ||
1518 | .blocksize = SHA224_BLOCK_SIZE, | 1524 | .blocksize = SHA224_BLOCK_SIZE, |
1519 | .template_ahash = { | 1525 | .template_ahash = { |
1520 | .init = ahash_init, | 1526 | .init = ahash_init, |
@@ -1532,8 +1538,10 @@ static struct caam_hash_template driver_hash[] = { | |||
1532 | .alg_type = OP_ALG_ALGSEL_SHA224, | 1538 | .alg_type = OP_ALG_ALGSEL_SHA224, |
1533 | .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC, | 1539 | .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC, |
1534 | }, { | 1540 | }, { |
1535 | .name = "hmac(sha256)", | 1541 | .name = "sha256", |
1536 | .driver_name = "hmac-sha256-caam", | 1542 | .driver_name = "sha256-caam", |
1543 | .hmac_name = "hmac(sha256)", | ||
1544 | .hmac_driver_name = "hmac-sha256-caam", | ||
1537 | .blocksize = SHA256_BLOCK_SIZE, | 1545 | .blocksize = SHA256_BLOCK_SIZE, |
1538 | .template_ahash = { | 1546 | .template_ahash = { |
1539 | .init = ahash_init, | 1547 | .init = ahash_init, |
@@ -1551,8 +1559,10 @@ static struct caam_hash_template driver_hash[] = { | |||
1551 | .alg_type = OP_ALG_ALGSEL_SHA256, | 1559 | .alg_type = OP_ALG_ALGSEL_SHA256, |
1552 | .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC, | 1560 | .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC, |
1553 | }, { | 1561 | }, { |
1554 | .name = "hmac(sha384)", | 1562 | .name = "sha384", |
1555 | .driver_name = "hmac-sha384-caam", | 1563 | .driver_name = "sha384-caam", |
1564 | .hmac_name = "hmac(sha384)", | ||
1565 | .hmac_driver_name = "hmac-sha384-caam", | ||
1556 | .blocksize = SHA384_BLOCK_SIZE, | 1566 | .blocksize = SHA384_BLOCK_SIZE, |
1557 | .template_ahash = { | 1567 | .template_ahash = { |
1558 | .init = ahash_init, | 1568 | .init = ahash_init, |
@@ -1570,8 +1580,10 @@ static struct caam_hash_template driver_hash[] = { | |||
1570 | .alg_type = OP_ALG_ALGSEL_SHA384, | 1580 | .alg_type = OP_ALG_ALGSEL_SHA384, |
1571 | .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC, | 1581 | .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC, |
1572 | }, { | 1582 | }, { |
1573 | .name = "hmac(sha512)", | 1583 | .name = "sha512", |
1574 | .driver_name = "hmac-sha512-caam", | 1584 | .driver_name = "sha512-caam", |
1585 | .hmac_name = "hmac(sha512)", | ||
1586 | .hmac_driver_name = "hmac-sha512-caam", | ||
1575 | .blocksize = SHA512_BLOCK_SIZE, | 1587 | .blocksize = SHA512_BLOCK_SIZE, |
1576 | .template_ahash = { | 1588 | .template_ahash = { |
1577 | .init = ahash_init, | 1589 | .init = ahash_init, |
@@ -1589,8 +1601,10 @@ static struct caam_hash_template driver_hash[] = { | |||
1589 | .alg_type = OP_ALG_ALGSEL_SHA512, | 1601 | .alg_type = OP_ALG_ALGSEL_SHA512, |
1590 | .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC, | 1602 | .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC, |
1591 | }, { | 1603 | }, { |
1592 | .name = "hmac(md5)", | 1604 | .name = "md5", |
1593 | .driver_name = "hmac-md5-caam", | 1605 | .driver_name = "md5-caam", |
1606 | .hmac_name = "hmac(md5)", | ||
1607 | .hmac_driver_name = "hmac-md5-caam", | ||
1594 | .blocksize = MD5_BLOCK_WORDS * 4, | 1608 | .blocksize = MD5_BLOCK_WORDS * 4, |
1595 | .template_ahash = { | 1609 | .template_ahash = { |
1596 | .init = ahash_init, | 1610 | .init = ahash_init, |
@@ -1721,7 +1735,8 @@ static void __exit caam_algapi_hash_exit(void) | |||
1721 | } | 1735 | } |
1722 | 1736 | ||
1723 | static struct caam_hash_alg * | 1737 | static struct caam_hash_alg * |
1724 | caam_hash_alloc(struct device *ctrldev, struct caam_hash_template *template) | 1738 | caam_hash_alloc(struct device *ctrldev, struct caam_hash_template *template, |
1739 | bool keyed) | ||
1725 | { | 1740 | { |
1726 | struct caam_hash_alg *t_alg; | 1741 | struct caam_hash_alg *t_alg; |
1727 | struct ahash_alg *halg; | 1742 | struct ahash_alg *halg; |
@@ -1737,9 +1752,17 @@ caam_hash_alloc(struct device *ctrldev, struct caam_hash_template *template) | |||
1737 | halg = &t_alg->ahash_alg; | 1752 | halg = &t_alg->ahash_alg; |
1738 | alg = &halg->halg.base; | 1753 | alg = &halg->halg.base; |
1739 | 1754 | ||
1740 | snprintf(alg->cra_name, CRYPTO_MAX_ALG_NAME, "%s", template->name); | 1755 | if (keyed) { |
1741 | snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s", | 1756 | snprintf(alg->cra_name, CRYPTO_MAX_ALG_NAME, "%s", |
1742 | template->driver_name); | 1757 | template->hmac_name); |
1758 | snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s", | ||
1759 | template->hmac_driver_name); | ||
1760 | } else { | ||
1761 | snprintf(alg->cra_name, CRYPTO_MAX_ALG_NAME, "%s", | ||
1762 | template->name); | ||
1763 | snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s", | ||
1764 | template->driver_name); | ||
1765 | } | ||
1743 | alg->cra_module = THIS_MODULE; | 1766 | alg->cra_module = THIS_MODULE; |
1744 | alg->cra_init = caam_hash_cra_init; | 1767 | alg->cra_init = caam_hash_cra_init; |
1745 | alg->cra_exit = caam_hash_cra_exit; | 1768 | alg->cra_exit = caam_hash_cra_exit; |
@@ -1786,7 +1809,25 @@ static int __init caam_algapi_hash_init(void) | |||
1786 | /* TODO: check if h/w supports alg */ | 1809 | /* TODO: check if h/w supports alg */ |
1787 | struct caam_hash_alg *t_alg; | 1810 | struct caam_hash_alg *t_alg; |
1788 | 1811 | ||
1789 | t_alg = caam_hash_alloc(ctrldev, &driver_hash[i]); | 1812 | /* register hmac version */ |
1813 | t_alg = caam_hash_alloc(ctrldev, &driver_hash[i], true); | ||
1814 | if (IS_ERR(t_alg)) { | ||
1815 | err = PTR_ERR(t_alg); | ||
1816 | dev_warn(ctrldev, "%s alg allocation failed\n", | ||
1817 | driver_hash[i].driver_name); | ||
1818 | continue; | ||
1819 | } | ||
1820 | |||
1821 | err = crypto_register_ahash(&t_alg->ahash_alg); | ||
1822 | if (err) { | ||
1823 | dev_warn(ctrldev, "%s alg registration failed\n", | ||
1824 | t_alg->ahash_alg.halg.base.cra_driver_name); | ||
1825 | kfree(t_alg); | ||
1826 | } else | ||
1827 | list_add_tail(&t_alg->entry, &priv->hash_list); | ||
1828 | |||
1829 | /* register unkeyed version */ | ||
1830 | t_alg = caam_hash_alloc(ctrldev, &driver_hash[i], false); | ||
1790 | if (IS_ERR(t_alg)) { | 1831 | if (IS_ERR(t_alg)) { |
1791 | err = PTR_ERR(t_alg); | 1832 | err = PTR_ERR(t_alg); |
1792 | dev_warn(ctrldev, "%s alg allocation failed\n", | 1833 | dev_warn(ctrldev, "%s alg allocation failed\n", |