提交 149a3971 编写于 作者: H Herbert Xu

crypto: aead - Add type-safe geniv init/exit helpers

This patch adds the helpers aead_init_geniv and aead_exit_geniv
which are type-safe and intended the replace the existing geniv
init/exit helpers.
Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
上级 66008d42
...@@ -48,6 +48,8 @@ config CRYPTO_AEAD ...@@ -48,6 +48,8 @@ config CRYPTO_AEAD
config CRYPTO_AEAD2 config CRYPTO_AEAD2
tristate tristate
select CRYPTO_ALGAPI2 select CRYPTO_ALGAPI2
select CRYPTO_NULL2
select CRYPTO_RNG2
config CRYPTO_BLKCIPHER config CRYPTO_BLKCIPHER
tristate tristate
...@@ -150,12 +152,15 @@ config CRYPTO_GF128MUL ...@@ -150,12 +152,15 @@ config CRYPTO_GF128MUL
config CRYPTO_NULL config CRYPTO_NULL
tristate "Null algorithms" tristate "Null algorithms"
select CRYPTO_ALGAPI select CRYPTO_NULL2
select CRYPTO_BLKCIPHER
select CRYPTO_HASH
help help
These are 'Null' algorithms, used by IPsec, which do nothing. These are 'Null' algorithms, used by IPsec, which do nothing.
config CRYPTO_NULL2
select CRYPTO_ALGAPI2
select CRYPTO_BLKCIPHER2
select CRYPTO_HASH2
config CRYPTO_PCRYPT config CRYPTO_PCRYPT
tristate "Parallel crypto engine" tristate "Parallel crypto engine"
depends on SMP depends on SMP
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
*/ */
#include <crypto/internal/geniv.h> #include <crypto/internal/geniv.h>
#include <crypto/internal/rng.h>
#include <crypto/null.h>
#include <crypto/scatterwalk.h> #include <crypto/scatterwalk.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/init.h> #include <linux/init.h>
...@@ -746,6 +748,59 @@ void aead_geniv_exit(struct crypto_tfm *tfm) ...@@ -746,6 +748,59 @@ void aead_geniv_exit(struct crypto_tfm *tfm)
} }
EXPORT_SYMBOL_GPL(aead_geniv_exit); EXPORT_SYMBOL_GPL(aead_geniv_exit);
int aead_init_geniv(struct crypto_aead *aead)
{
struct aead_geniv_ctx *ctx = crypto_aead_ctx(aead);
struct aead_instance *inst = aead_alg_instance(aead);
struct crypto_aead *child;
int err;
spin_lock_init(&ctx->lock);
err = crypto_get_default_rng();
if (err)
goto out;
err = crypto_rng_get_bytes(crypto_default_rng, ctx->salt,
crypto_aead_ivsize(aead));
crypto_put_default_rng();
if (err)
goto out;
ctx->null = crypto_get_default_null_skcipher();
err = PTR_ERR(ctx->null);
if (IS_ERR(ctx->null))
goto out;
child = crypto_spawn_aead(aead_instance_ctx(inst));
err = PTR_ERR(child);
if (IS_ERR(child))
goto drop_null;
ctx->child = child;
crypto_aead_set_reqsize(aead, crypto_aead_reqsize(child) +
sizeof(struct aead_request));
err = 0;
out:
return err;
drop_null:
crypto_put_default_null_skcipher();
goto out;
}
EXPORT_SYMBOL_GPL(aead_init_geniv);
void aead_exit_geniv(struct crypto_aead *tfm)
{
struct aead_geniv_ctx *ctx = crypto_aead_ctx(tfm);
crypto_free_aead(ctx->child);
crypto_put_default_null_skcipher();
}
EXPORT_SYMBOL_GPL(aead_exit_geniv);
static int crypto_nivaead_default(struct crypto_alg *alg, u32 type, u32 mask) static int crypto_nivaead_default(struct crypto_alg *alg, u32 type, u32 mask)
{ {
struct rtattr *tb[3]; struct rtattr *tb[3];
......
...@@ -123,12 +123,6 @@ static inline struct crypto_aead *crypto_spawn_aead( ...@@ -123,12 +123,6 @@ static inline struct crypto_aead *crypto_spawn_aead(
return crypto_spawn_tfm2(&spawn->base); return crypto_spawn_tfm2(&spawn->base);
} }
struct aead_instance *aead_geniv_alloc(struct crypto_template *tmpl,
struct rtattr **tb, u32 type, u32 mask);
void aead_geniv_free(struct aead_instance *inst);
int aead_geniv_init(struct crypto_tfm *tfm);
void aead_geniv_exit(struct crypto_tfm *tfm);
static inline struct crypto_aead *aead_geniv_base(struct crypto_aead *geniv) static inline struct crypto_aead *aead_geniv_base(struct crypto_aead *geniv)
{ {
return geniv->child; return geniv->child;
......
...@@ -15,10 +15,21 @@ ...@@ -15,10 +15,21 @@
#include <crypto/internal/aead.h> #include <crypto/internal/aead.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/types.h>
struct aead_geniv_ctx { struct aead_geniv_ctx {
spinlock_t lock; spinlock_t lock;
struct crypto_aead *child; struct crypto_aead *child;
struct crypto_blkcipher *null;
u8 salt[] __attribute__ ((aligned(__alignof__(u32))));
}; };
struct aead_instance *aead_geniv_alloc(struct crypto_template *tmpl,
struct rtattr **tb, u32 type, u32 mask);
void aead_geniv_free(struct aead_instance *inst);
int aead_geniv_init(struct crypto_tfm *tfm);
void aead_geniv_exit(struct crypto_tfm *tfm);
int aead_init_geniv(struct crypto_aead *tfm);
void aead_exit_geniv(struct crypto_aead *tfm);
#endif /* _CRYPTO_INTERNAL_GENIV_H */ #endif /* _CRYPTO_INTERNAL_GENIV_H */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册