Skip to content

Commit

Permalink
crypto: talitos - second prepare step for adding ahash algorithms
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Lee Nipper authored and Herbert Xu committed May 19, 2010
1 parent d5e4aae commit acbf7c6
Showing 1 changed file with 43 additions and 12 deletions.
55 changes: 43 additions & 12 deletions drivers/crypto/talitos.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
#include <crypto/aead.h>
#include <crypto/authenc.h>
#include <crypto/skcipher.h>
#include <crypto/hash.h>
#include <crypto/internal/hash.h>
#include <crypto/scatterwalk.h>

#include "talitos.h"
Expand Down Expand Up @@ -1482,6 +1484,7 @@ struct talitos_alg_template {
u32 type;
union {
struct crypto_alg crypto;
struct ahash_alg hash;
} alg;
__be32 desc_hdr_template;
};
Expand Down Expand Up @@ -1698,8 +1701,7 @@ static struct talitos_alg_template driver_algs[] = {
struct talitos_crypto_alg {
struct list_head entry;
struct device *dev;
__be32 desc_hdr_template;
struct crypto_alg crypto_alg;
struct talitos_alg_template algt;
};

static int talitos_cra_init(struct crypto_tfm *tfm)
Expand All @@ -1708,13 +1710,14 @@ static int talitos_cra_init(struct crypto_tfm *tfm)
struct talitos_crypto_alg *talitos_alg;
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 */
ctx->dev = talitos_alg->dev;

/* 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 */
get_random_bytes(ctx->iv, TALITOS_MAX_IV_LENGTH);
Expand Down Expand Up @@ -1750,7 +1753,15 @@ static int talitos_remove(struct of_device *ofdev)
int i;

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);
kfree(t_alg);
}
Expand Down Expand Up @@ -1791,16 +1802,23 @@ static struct talitos_crypto_alg *talitos_alg_alloc(struct device *dev,
if (!t_alg)
return ERR_PTR(-ENOMEM);

alg = &t_alg->crypto_alg;
*alg = template->alg.crypto;
t_alg->algt = *template;

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_init = talitos_cra_init;
alg->cra_priority = TALITOS_CRA_PRIORITY;
alg->cra_alignmask = 0;
alg->cra_ctxsize = sizeof(struct talitos_ctx);

t_alg->desc_hdr_template = template->desc_hdr_template;
t_alg->dev = dev;

return t_alg;
Expand Down Expand Up @@ -1934,22 +1952,35 @@ static int talitos_probe(struct of_device *ofdev,
for (i = 0; i < ARRAY_SIZE(driver_algs); i++) {
if (hw_supports(dev, driver_algs[i].desc_hdr_template)) {
struct talitos_crypto_alg *t_alg;
char *name = NULL;

t_alg = talitos_alg_alloc(dev, &driver_algs[i]);
if (IS_ERR(t_alg)) {
err = PTR_ERR(t_alg);
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) {
dev_err(dev, "%s alg registration failed\n",
t_alg->crypto_alg.cra_driver_name);
name);
kfree(t_alg);
} else {
list_add_tail(&t_alg->entry, &priv->alg_list);
dev_info(dev, "%s\n",
t_alg->crypto_alg.cra_driver_name);
dev_info(dev, "%s\n", name);
}
}
}
Expand Down

0 comments on commit acbf7c6

Please sign in to comment.