Commit 77f7e94d authored by Eric Biggers's avatar Eric Biggers Committed by Herbert Xu

crypto: ahash - make struct ahash_instance be the full size

Define struct ahash_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 ahash 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
ahash_instance by simplifying the ahash_crypto_instance() and
ahash_instance() functions.
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 1b84e7d0
...@@ -30,7 +30,13 @@ struct crypto_hash_walk { ...@@ -30,7 +30,13 @@ struct crypto_hash_walk {
}; };
struct ahash_instance { struct ahash_instance {
union {
struct {
char head[offsetof(struct ahash_alg, halg.base)];
struct crypto_instance base;
} s;
struct ahash_alg alg; struct ahash_alg alg;
};
}; };
struct shash_instance { struct shash_instance {
...@@ -155,13 +161,13 @@ static inline void crypto_ahash_set_reqsize(struct crypto_ahash *tfm, ...@@ -155,13 +161,13 @@ static inline void crypto_ahash_set_reqsize(struct crypto_ahash *tfm,
static inline struct crypto_instance *ahash_crypto_instance( static inline struct crypto_instance *ahash_crypto_instance(
struct ahash_instance *inst) struct ahash_instance *inst)
{ {
return container_of(&inst->alg.halg.base, struct crypto_instance, alg); return &inst->s.base;
} }
static inline struct ahash_instance *ahash_instance( static inline struct ahash_instance *ahash_instance(
struct crypto_instance *inst) struct crypto_instance *inst)
{ {
return container_of(&inst->alg, struct ahash_instance, alg.halg.base); return container_of(inst, struct ahash_instance, s.base);
} }
static inline void *ahash_instance_ctx(struct ahash_instance *inst) static inline void *ahash_instance_ctx(struct ahash_instance *inst)
......
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