diff options
author | Lee Nipper <lee.nipper@gmail.com> | 2010-05-19 05:19:33 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2010-05-19 05:19:33 -0400 |
commit | acbf7c627fb59dfea975f7aafeaba97921085061 (patch) | |
tree | 9a58a4a1db70854cb3df2372c2f694fb283e3423 /drivers/crypto | |
parent | d5e4aaefd99797929e4455db48d8f9a8728f05f4 (diff) |
crypto: talitos - second prepare step for adding ahash algorithms
Used talitos_alg_template in talitos_crypto_alg
so that it will accommodate ahash algorithms.
Added some preparation code for ahash allocation and removal.
No actual algorithms yet.
Signed-off-by: Lee Nipper <lee.nipper@gmail.com>
Acked-By: Kim Phillips <kim.phillips@freescale.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto')
-rw-r--r-- | drivers/crypto/talitos.c | 55 |
1 files changed, 43 insertions, 12 deletions
diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c index ce38b05c8def..4e8153a839a4 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c | |||
@@ -46,6 +46,8 @@ | |||
46 | #include <crypto/aead.h> | 46 | #include <crypto/aead.h> |
47 | #include <crypto/authenc.h> | 47 | #include <crypto/authenc.h> |
48 | #include <crypto/skcipher.h> | 48 | #include <crypto/skcipher.h> |
49 | #include <crypto/hash.h> | ||
50 | #include <crypto/internal/hash.h> | ||
49 | #include <crypto/scatterwalk.h> | 51 | #include <crypto/scatterwalk.h> |
50 | 52 | ||
51 | #include "talitos.h" | 53 | #include "talitos.h" |
@@ -1482,6 +1484,7 @@ struct talitos_alg_template { | |||
1482 | u32 type; | 1484 | u32 type; |
1483 | union { | 1485 | union { |
1484 | struct crypto_alg crypto; | 1486 | struct crypto_alg crypto; |
1487 | struct ahash_alg hash; | ||
1485 | } alg; | 1488 | } alg; |
1486 | __be32 desc_hdr_template; | 1489 | __be32 desc_hdr_template; |
1487 | }; | 1490 | }; |
@@ -1698,8 +1701,7 @@ static struct talitos_alg_template driver_algs[] = { | |||
1698 | struct talitos_crypto_alg { | 1701 | struct talitos_crypto_alg { |
1699 | struct list_head entry; | 1702 | struct list_head entry; |
1700 | struct device *dev; | 1703 | struct device *dev; |
1701 | __be32 desc_hdr_template; | 1704 | struct talitos_alg_template algt; |
1702 | struct crypto_alg crypto_alg; | ||
1703 | }; | 1705 | }; |
1704 | 1706 | ||
1705 | static int talitos_cra_init(struct crypto_tfm *tfm) | 1707 | static int talitos_cra_init(struct crypto_tfm *tfm) |
@@ -1708,13 +1710,14 @@ static int talitos_cra_init(struct crypto_tfm *tfm) | |||
1708 | struct talitos_crypto_alg *talitos_alg; | 1710 | struct talitos_crypto_alg *talitos_alg; |
1709 | struct talitos_ctx *ctx = crypto_tfm_ctx(tfm); | 1711 | struct talitos_ctx *ctx = crypto_tfm_ctx(tfm); |
1710 | 1712 | ||
1711 | talitos_alg = container_of(alg, struct talitos_crypto_alg, crypto_alg); | 1713 | talitos_alg = container_of(alg, struct talitos_crypto_alg, |
1714 | algt.alg.crypto); | ||
1712 | 1715 | ||
1713 | /* update context with ptr to dev */ | 1716 | /* update context with ptr to dev */ |
1714 | ctx->dev = talitos_alg->dev; | 1717 | ctx->dev = talitos_alg->dev; |
1715 | 1718 | ||
1716 | /* copy descriptor header template value */ | 1719 | /* copy descriptor header template value */ |
1717 | ctx->desc_hdr_template = talitos_alg->desc_hdr_template; | 1720 | ctx->desc_hdr_template = talitos_alg->algt.desc_hdr_template; |
1718 | 1721 | ||
1719 | /* random first IV */ | 1722 | /* random first IV */ |
1720 | get_random_bytes(ctx->iv, TALITOS_MAX_IV_LENGTH); | 1723 | get_random_bytes(ctx->iv, TALITOS_MAX_IV_LENGTH); |
@@ -1750,7 +1753,15 @@ static int talitos_remove(struct of_device *ofdev) | |||
1750 | int i; | 1753 | int i; |
1751 | 1754 | ||
1752 | list_for_each_entry_safe(t_alg, n, &priv->alg_list, entry) { | 1755 | list_for_each_entry_safe(t_alg, n, &priv->alg_list, entry) { |
1753 | crypto_unregister_alg(&t_alg->crypto_alg); | 1756 | switch (t_alg->algt.type) { |
1757 | case CRYPTO_ALG_TYPE_ABLKCIPHER: | ||
1758 | case CRYPTO_ALG_TYPE_AEAD: | ||
1759 | crypto_unregister_alg(&t_alg->algt.alg.crypto); | ||
1760 | break; | ||
1761 | case CRYPTO_ALG_TYPE_AHASH: | ||
1762 | crypto_unregister_ahash(&t_alg->algt.alg.hash); | ||
1763 | break; | ||
1764 | } | ||
1754 | list_del(&t_alg->entry); | 1765 | list_del(&t_alg->entry); |
1755 | kfree(t_alg); | 1766 | kfree(t_alg); |
1756 | } | 1767 | } |
@@ -1791,8 +1802,16 @@ static struct talitos_crypto_alg *talitos_alg_alloc(struct device *dev, | |||
1791 | if (!t_alg) | 1802 | if (!t_alg) |
1792 | return ERR_PTR(-ENOMEM); | 1803 | return ERR_PTR(-ENOMEM); |
1793 | 1804 | ||
1794 | alg = &t_alg->crypto_alg; | 1805 | t_alg->algt = *template; |
1795 | *alg = template->alg.crypto; | 1806 | |
1807 | switch (t_alg->algt.type) { | ||
1808 | case CRYPTO_ALG_TYPE_ABLKCIPHER: | ||
1809 | case CRYPTO_ALG_TYPE_AEAD: | ||
1810 | alg = &t_alg->algt.alg.crypto; | ||
1811 | break; | ||
1812 | case CRYPTO_ALG_TYPE_AHASH: | ||
1813 | alg = &t_alg->algt.alg.hash.halg.base; | ||
1814 | } | ||
1796 | 1815 | ||
1797 | alg->cra_module = THIS_MODULE; | 1816 | alg->cra_module = THIS_MODULE; |
1798 | alg->cra_init = talitos_cra_init; | 1817 | alg->cra_init = talitos_cra_init; |
@@ -1800,7 +1819,6 @@ static struct talitos_crypto_alg *talitos_alg_alloc(struct device *dev, | |||
1800 | alg->cra_alignmask = 0; | 1819 | alg->cra_alignmask = 0; |
1801 | alg->cra_ctxsize = sizeof(struct talitos_ctx); | 1820 | alg->cra_ctxsize = sizeof(struct talitos_ctx); |
1802 | 1821 | ||
1803 | t_alg->desc_hdr_template = template->desc_hdr_template; | ||
1804 | t_alg->dev = dev; | 1822 | t_alg->dev = dev; |
1805 | 1823 | ||
1806 | return t_alg; | 1824 | return t_alg; |
@@ -1934,6 +1952,7 @@ static int talitos_probe(struct of_device *ofdev, | |||
1934 | for (i = 0; i < ARRAY_SIZE(driver_algs); i++) { | 1952 | for (i = 0; i < ARRAY_SIZE(driver_algs); i++) { |
1935 | if (hw_supports(dev, driver_algs[i].desc_hdr_template)) { | 1953 | if (hw_supports(dev, driver_algs[i].desc_hdr_template)) { |
1936 | struct talitos_crypto_alg *t_alg; | 1954 | struct talitos_crypto_alg *t_alg; |
1955 | char *name = NULL; | ||
1937 | 1956 | ||
1938 | t_alg = talitos_alg_alloc(dev, &driver_algs[i]); | 1957 | t_alg = talitos_alg_alloc(dev, &driver_algs[i]); |
1939 | if (IS_ERR(t_alg)) { | 1958 | if (IS_ERR(t_alg)) { |
@@ -1941,15 +1960,27 @@ static int talitos_probe(struct of_device *ofdev, | |||
1941 | goto err_out; | 1960 | goto err_out; |
1942 | } | 1961 | } |
1943 | 1962 | ||
1944 | err = crypto_register_alg(&t_alg->crypto_alg); | 1963 | switch (t_alg->algt.type) { |
1964 | case CRYPTO_ALG_TYPE_ABLKCIPHER: | ||
1965 | case CRYPTO_ALG_TYPE_AEAD: | ||
1966 | err = crypto_register_alg( | ||
1967 | &t_alg->algt.alg.crypto); | ||
1968 | name = t_alg->algt.alg.crypto.cra_driver_name; | ||
1969 | break; | ||
1970 | case CRYPTO_ALG_TYPE_AHASH: | ||
1971 | err = crypto_register_ahash( | ||
1972 | &t_alg->algt.alg.hash); | ||
1973 | name = | ||
1974 | t_alg->algt.alg.hash.halg.base.cra_driver_name; | ||
1975 | break; | ||
1976 | } | ||
1945 | if (err) { | 1977 | if (err) { |
1946 | dev_err(dev, "%s alg registration failed\n", | 1978 | dev_err(dev, "%s alg registration failed\n", |
1947 | t_alg->crypto_alg.cra_driver_name); | 1979 | name); |
1948 | kfree(t_alg); | 1980 | kfree(t_alg); |
1949 | } else { | 1981 | } else { |
1950 | list_add_tail(&t_alg->entry, &priv->alg_list); | 1982 | list_add_tail(&t_alg->entry, &priv->alg_list); |
1951 | dev_info(dev, "%s\n", | 1983 | dev_info(dev, "%s\n", name); |
1952 | t_alg->crypto_alg.cra_driver_name); | ||
1953 | } | 1984 | } |
1954 | } | 1985 | } |
1955 | } | 1986 | } |