crypto: algapi - use common mechanism for inheriting flags
The flag CRYPTO_ALG_ASYNC is "inherited" in the sense that when a
template is instantiated, the template will have CRYPTO_ALG_ASYNC set if
any of the algorithms it uses has CRYPTO_ALG_ASYNC set.
We'd like to add a second flag (CRYPTO_ALG_ALLOCATES_MEMORY) that gets
"inherited" in the same way. This is difficult because the handling of
CRYPTO_ALG_ASYNC is hardcoded everywhere. Address this by:
- Add CRYPTO_ALG_INHERITED_FLAGS, which contains the set of flags that
have these inheritance semantics.
- Add crypto_algt_inherited_mask(), for use by template ->create()
methods. It returns any of these flags that the user asked to be
unset and thus must be passed in the 'mask' to crypto_grab_*().
- Also modify crypto_check_attr_type() to handle computing the 'mask'
so that most templates can just use this.
- Make crypto_grab_*() propagate these flags to the template instance
being created so that templates don't have to do this themselves.
Make crypto/simd.c propagate these flags too, since it "wraps" another
algorithm, similar to a template.
Based on a patch by Mikulas Patocka <mpatocka@redhat.com>
(https://lore.kernel.org/r/alpine.LRH.2.02.2006301414580.30526@file01.intranet.prod.int.rdu2.redhat.com).
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
@@ -116,7 +116,7 @@ struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn, u32 type,
|
||||
void *crypto_spawn_tfm2(struct crypto_spawn *spawn);
|
||||
|
||||
struct crypto_attr_type *crypto_get_attr_type(struct rtattr **tb);
|
||||
int crypto_check_attr_type(struct rtattr **tb, u32 type);
|
||||
int crypto_check_attr_type(struct rtattr **tb, u32 type, u32 *mask_ret);
|
||||
const char *crypto_attr_alg_name(struct rtattr *rta);
|
||||
int crypto_attr_u32(struct rtattr *rta, u32 *num);
|
||||
int crypto_inst_setname(struct crypto_instance *inst, const char *name,
|
||||
@@ -235,18 +235,27 @@ static inline struct crypto_async_request *crypto_get_backlog(
|
||||
container_of(queue->backlog, struct crypto_async_request, list);
|
||||
}
|
||||
|
||||
static inline int crypto_requires_off(u32 type, u32 mask, u32 off)
|
||||
static inline u32 crypto_requires_off(struct crypto_attr_type *algt, u32 off)
|
||||
{
|
||||
return (type ^ off) & mask & off;
|
||||
return (algt->type ^ off) & algt->mask & off;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns CRYPTO_ALG_ASYNC if type/mask requires the use of sync algorithms.
|
||||
* Otherwise returns zero.
|
||||
* When an algorithm uses another algorithm (e.g., if it's an instance of a
|
||||
* template), these are the flags that should always be set on the "outer"
|
||||
* algorithm if any "inner" algorithm has them set.
|
||||
*/
|
||||
static inline int crypto_requires_sync(u32 type, u32 mask)
|
||||
#define CRYPTO_ALG_INHERITED_FLAGS CRYPTO_ALG_ASYNC
|
||||
|
||||
/*
|
||||
* Given the type and mask that specify the flags restrictions on a template
|
||||
* instance being created, return the mask that should be passed to
|
||||
* crypto_grab_*() (along with type=0) to honor any request the user made to
|
||||
* have any of the CRYPTO_ALG_INHERITED_FLAGS clear.
|
||||
*/
|
||||
static inline u32 crypto_algt_inherited_mask(struct crypto_attr_type *algt)
|
||||
{
|
||||
return crypto_requires_off(type, mask, CRYPTO_ALG_ASYNC);
|
||||
return crypto_requires_off(algt, CRYPTO_ALG_INHERITED_FLAGS);
|
||||
}
|
||||
|
||||
noinline unsigned long __crypto_memneq(const void *a, const void *b, size_t size);
|
||||
|
||||
Reference in New Issue
Block a user