Commit 1b84e7d0 authored by Eric Biggers's avatar Eric Biggers Committed by Herbert Xu

crypto: shash - make struct shash_instance be the full size

Define struct shash_instance in a way analogous to struct
skcipher_instance, struct aead_instance, and struct akcipher_instance,
where the struct is defined to include both the algorithm structure at
the beginning and the additional crypto_instance fields at the end.

This is needed to allow allocating shash instances directly using
kzalloc(sizeof(*inst) + sizeof(*ictx), ...) in the same way as skcipher,
aead, and akcipher instances.  In turn, that's needed to make spawns be
initialized in a consistent way everywhere.

Also take advantage of the addition of the base instance to struct
shash_instance by simplifying the shash_crypto_instance() and
shash_instance() functions.
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent ca94e937
......@@ -34,7 +34,13 @@ struct ahash_instance {
};
struct shash_instance {
union {
struct {
char head[offsetof(struct shash_alg, base)];
struct crypto_instance base;
} s;
struct shash_alg alg;
};
};
struct crypto_ahash_spawn {
......@@ -210,14 +216,13 @@ static inline void *crypto_shash_ctx(struct crypto_shash *tfm)
static inline struct crypto_instance *shash_crypto_instance(
struct shash_instance *inst)
{
return container_of(&inst->alg.base, struct crypto_instance, alg);
return &inst->s.base;
}
static inline struct shash_instance *shash_instance(
struct crypto_instance *inst)
{
return container_of(__crypto_shash_alg(&inst->alg),
struct shash_instance, alg);
return container_of(inst, struct shash_instance, s.base);
}
static inline struct shash_instance *shash_alg_instance(
......
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