Commit acbf7c62 authored by Lee Nipper's avatar Lee Nipper Committed by Herbert Xu

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: default avatarLee Nipper <lee.nipper@gmail.com>
Acked-By: default avatarKim Phillips <kim.phillips@freescale.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent d5e4aaef
...@@ -46,6 +46,8 @@ ...@@ -46,6 +46,8 @@
#include <crypto/aead.h> #include <crypto/aead.h>
#include <crypto/authenc.h> #include <crypto/authenc.h>
#include <crypto/skcipher.h> #include <crypto/skcipher.h>
#include <crypto/hash.h>
#include <crypto/internal/hash.h>
#include <crypto/scatterwalk.h> #include <crypto/scatterwalk.h>
#include "talitos.h" #include "talitos.h"
...@@ -1482,6 +1484,7 @@ struct talitos_alg_template { ...@@ -1482,6 +1484,7 @@ struct talitos_alg_template {
u32 type; u32 type;
union { union {
struct crypto_alg crypto; struct crypto_alg crypto;
struct ahash_alg hash;
} alg; } alg;
__be32 desc_hdr_template; __be32 desc_hdr_template;
}; };
...@@ -1698,8 +1701,7 @@ static struct talitos_alg_template driver_algs[] = { ...@@ -1698,8 +1701,7 @@ static struct talitos_alg_template driver_algs[] = {
struct talitos_crypto_alg { struct talitos_crypto_alg {
struct list_head entry; struct list_head entry;
struct device *dev; struct device *dev;
__be32 desc_hdr_template; struct talitos_alg_template algt;
struct crypto_alg crypto_alg;
}; };
static int talitos_cra_init(struct crypto_tfm *tfm) static int talitos_cra_init(struct crypto_tfm *tfm)
...@@ -1708,13 +1710,14 @@ static int talitos_cra_init(struct crypto_tfm *tfm) ...@@ -1708,13 +1710,14 @@ static int talitos_cra_init(struct crypto_tfm *tfm)
struct talitos_crypto_alg *talitos_alg; struct talitos_crypto_alg *talitos_alg;
struct talitos_ctx *ctx = crypto_tfm_ctx(tfm); struct talitos_ctx *ctx = crypto_tfm_ctx(tfm);
talitos_alg = container_of(alg, struct talitos_crypto_alg, crypto_alg); talitos_alg = container_of(alg, struct talitos_crypto_alg,
algt.alg.crypto);
/* update context with ptr to dev */ /* update context with ptr to dev */
ctx->dev = talitos_alg->dev; ctx->dev = talitos_alg->dev;
/* copy descriptor header template value */ /* copy descriptor header template value */
ctx->desc_hdr_template = talitos_alg->desc_hdr_template; ctx->desc_hdr_template = talitos_alg->algt.desc_hdr_template;
/* random first IV */ /* random first IV */
get_random_bytes(ctx->iv, TALITOS_MAX_IV_LENGTH); get_random_bytes(ctx->iv, TALITOS_MAX_IV_LENGTH);
...@@ -1750,7 +1753,15 @@ static int talitos_remove(struct of_device *ofdev) ...@@ -1750,7 +1753,15 @@ static int talitos_remove(struct of_device *ofdev)
int i; int i;
list_for_each_entry_safe(t_alg, n, &priv->alg_list, entry) { list_for_each_entry_safe(t_alg, n, &priv->alg_list, entry) {
crypto_unregister_alg(&t_alg->crypto_alg); switch (t_alg->algt.type) {
case CRYPTO_ALG_TYPE_ABLKCIPHER:
case CRYPTO_ALG_TYPE_AEAD:
crypto_unregister_alg(&t_alg->algt.alg.crypto);
break;
case CRYPTO_ALG_TYPE_AHASH:
crypto_unregister_ahash(&t_alg->algt.alg.hash);
break;
}
list_del(&t_alg->entry); list_del(&t_alg->entry);
kfree(t_alg); kfree(t_alg);
} }
...@@ -1791,8 +1802,16 @@ static struct talitos_crypto_alg *talitos_alg_alloc(struct device *dev, ...@@ -1791,8 +1802,16 @@ static struct talitos_crypto_alg *talitos_alg_alloc(struct device *dev,
if (!t_alg) if (!t_alg)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
alg = &t_alg->crypto_alg; t_alg->algt = *template;
*alg = template->alg.crypto;
switch (t_alg->algt.type) {
case CRYPTO_ALG_TYPE_ABLKCIPHER:
case CRYPTO_ALG_TYPE_AEAD:
alg = &t_alg->algt.alg.crypto;
break;
case CRYPTO_ALG_TYPE_AHASH:
alg = &t_alg->algt.alg.hash.halg.base;
}
alg->cra_module = THIS_MODULE; alg->cra_module = THIS_MODULE;
alg->cra_init = talitos_cra_init; alg->cra_init = talitos_cra_init;
...@@ -1800,7 +1819,6 @@ static struct talitos_crypto_alg *talitos_alg_alloc(struct device *dev, ...@@ -1800,7 +1819,6 @@ static struct talitos_crypto_alg *talitos_alg_alloc(struct device *dev,
alg->cra_alignmask = 0; alg->cra_alignmask = 0;
alg->cra_ctxsize = sizeof(struct talitos_ctx); alg->cra_ctxsize = sizeof(struct talitos_ctx);
t_alg->desc_hdr_template = template->desc_hdr_template;
t_alg->dev = dev; t_alg->dev = dev;
return t_alg; return t_alg;
...@@ -1934,6 +1952,7 @@ static int talitos_probe(struct of_device *ofdev, ...@@ -1934,6 +1952,7 @@ static int talitos_probe(struct of_device *ofdev,
for (i = 0; i < ARRAY_SIZE(driver_algs); i++) { for (i = 0; i < ARRAY_SIZE(driver_algs); i++) {
if (hw_supports(dev, driver_algs[i].desc_hdr_template)) { if (hw_supports(dev, driver_algs[i].desc_hdr_template)) {
struct talitos_crypto_alg *t_alg; struct talitos_crypto_alg *t_alg;
char *name = NULL;
t_alg = talitos_alg_alloc(dev, &driver_algs[i]); t_alg = talitos_alg_alloc(dev, &driver_algs[i]);
if (IS_ERR(t_alg)) { if (IS_ERR(t_alg)) {
...@@ -1941,15 +1960,27 @@ static int talitos_probe(struct of_device *ofdev, ...@@ -1941,15 +1960,27 @@ static int talitos_probe(struct of_device *ofdev,
goto err_out; goto err_out;
} }
err = crypto_register_alg(&t_alg->crypto_alg); switch (t_alg->algt.type) {
case CRYPTO_ALG_TYPE_ABLKCIPHER:
case CRYPTO_ALG_TYPE_AEAD:
err = crypto_register_alg(
&t_alg->algt.alg.crypto);
name = t_alg->algt.alg.crypto.cra_driver_name;
break;
case CRYPTO_ALG_TYPE_AHASH:
err = crypto_register_ahash(
&t_alg->algt.alg.hash);
name =
t_alg->algt.alg.hash.halg.base.cra_driver_name;
break;
}
if (err) { if (err) {
dev_err(dev, "%s alg registration failed\n", dev_err(dev, "%s alg registration failed\n",
t_alg->crypto_alg.cra_driver_name); name);
kfree(t_alg); kfree(t_alg);
} else { } else {
list_add_tail(&t_alg->entry, &priv->alg_list); list_add_tail(&t_alg->entry, &priv->alg_list);
dev_info(dev, "%s\n", dev_info(dev, "%s\n", name);
t_alg->crypto_alg.cra_driver_name);
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment