]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - include/crypto/internal/aead.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * AEAD: Authenticated Encryption with Associated Data
5 * Copyright (c) 2007-2015 Herbert Xu <herbert@gondor.apana.org.au>
8 #ifndef _CRYPTO_INTERNAL_AEAD_H
9 #define _CRYPTO_INTERNAL_AEAD_H
11 #include <crypto/aead.h>
12 #include <crypto/algapi.h>
13 #include <linux/stddef.h>
14 #include <linux/types.h>
18 struct aead_instance
{
19 void (*free
)(struct aead_instance
*inst
);
22 char head
[offsetof(struct aead_alg
, base
)];
23 struct crypto_instance base
;
29 struct crypto_aead_spawn
{
30 struct crypto_spawn base
;
34 struct crypto_queue base
;
37 static inline void *crypto_aead_ctx(struct crypto_aead
*tfm
)
39 return crypto_tfm_ctx(&tfm
->base
);
42 static inline struct crypto_instance
*aead_crypto_instance(
43 struct aead_instance
*inst
)
45 return container_of(&inst
->alg
.base
, struct crypto_instance
, alg
);
48 static inline struct aead_instance
*aead_instance(struct crypto_instance
*inst
)
50 return container_of(&inst
->alg
, struct aead_instance
, alg
.base
);
53 static inline struct aead_instance
*aead_alg_instance(struct crypto_aead
*aead
)
55 return aead_instance(crypto_tfm_alg_instance(&aead
->base
));
58 static inline void *aead_instance_ctx(struct aead_instance
*inst
)
60 return crypto_instance_ctx(aead_crypto_instance(inst
));
63 static inline void *aead_request_ctx(struct aead_request
*req
)
68 static inline void aead_request_complete(struct aead_request
*req
, int err
)
70 req
->base
.complete(&req
->base
, err
);
73 static inline u32
aead_request_flags(struct aead_request
*req
)
75 return req
->base
.flags
;
78 static inline struct aead_request
*aead_request_cast(
79 struct crypto_async_request
*req
)
81 return container_of(req
, struct aead_request
, base
);
84 static inline void crypto_set_aead_spawn(
85 struct crypto_aead_spawn
*spawn
, struct crypto_instance
*inst
)
87 crypto_set_spawn(&spawn
->base
, inst
);
90 int crypto_grab_aead(struct crypto_aead_spawn
*spawn
, const char *name
,
93 static inline void crypto_drop_aead(struct crypto_aead_spawn
*spawn
)
95 crypto_drop_spawn(&spawn
->base
);
98 static inline struct aead_alg
*crypto_spawn_aead_alg(
99 struct crypto_aead_spawn
*spawn
)
101 return container_of(spawn
->base
.alg
, struct aead_alg
, base
);
104 static inline struct crypto_aead
*crypto_spawn_aead(
105 struct crypto_aead_spawn
*spawn
)
107 return crypto_spawn_tfm2(&spawn
->base
);
110 static inline void crypto_aead_set_reqsize(struct crypto_aead
*aead
,
111 unsigned int reqsize
)
113 aead
->reqsize
= reqsize
;
116 static inline unsigned int crypto_aead_alg_maxauthsize(struct aead_alg
*alg
)
118 return alg
->maxauthsize
;
121 static inline unsigned int crypto_aead_maxauthsize(struct crypto_aead
*aead
)
123 return crypto_aead_alg_maxauthsize(crypto_aead_alg(aead
));
126 static inline void aead_init_queue(struct aead_queue
*queue
,
127 unsigned int max_qlen
)
129 crypto_init_queue(&queue
->base
, max_qlen
);
132 static inline int aead_enqueue_request(struct aead_queue
*queue
,
133 struct aead_request
*request
)
135 return crypto_enqueue_request(&queue
->base
, &request
->base
);
138 static inline struct aead_request
*aead_dequeue_request(
139 struct aead_queue
*queue
)
141 struct crypto_async_request
*req
;
143 req
= crypto_dequeue_request(&queue
->base
);
145 return req
? container_of(req
, struct aead_request
, base
) : NULL
;
148 static inline struct aead_request
*aead_get_backlog(struct aead_queue
*queue
)
150 struct crypto_async_request
*req
;
152 req
= crypto_get_backlog(&queue
->base
);
154 return req
? container_of(req
, struct aead_request
, base
) : NULL
;
157 static inline unsigned int crypto_aead_alg_chunksize(struct aead_alg
*alg
)
159 return alg
->chunksize
;
163 * crypto_aead_chunksize() - obtain chunk size
164 * @tfm: cipher handle
166 * The block size is set to one for ciphers such as CCM. However,
167 * you still need to provide incremental updates in multiples of
168 * the underlying block size as the IV does not have sub-block
169 * granularity. This is known in this API as the chunk size.
171 * Return: chunk size in bytes
173 static inline unsigned int crypto_aead_chunksize(struct crypto_aead
*tfm
)
175 return crypto_aead_alg_chunksize(crypto_aead_alg(tfm
));
178 int crypto_register_aead(struct aead_alg
*alg
);
179 void crypto_unregister_aead(struct aead_alg
*alg
);
180 int crypto_register_aeads(struct aead_alg
*algs
, int count
);
181 void crypto_unregister_aeads(struct aead_alg
*algs
, int count
);
182 int aead_register_instance(struct crypto_template
*tmpl
,
183 struct aead_instance
*inst
);
185 #endif /* _CRYPTO_INTERNAL_AEAD_H */