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 void *crypto_aead_ctx_dma(struct crypto_aead
*tfm
)
44 return crypto_tfm_ctx_dma(&tfm
->base
);
47 static inline struct crypto_instance
*aead_crypto_instance(
48 struct aead_instance
*inst
)
50 return container_of(&inst
->alg
.base
, struct crypto_instance
, alg
);
53 static inline struct aead_instance
*aead_instance(struct crypto_instance
*inst
)
55 return container_of(&inst
->alg
, struct aead_instance
, alg
.base
);
58 static inline struct aead_instance
*aead_alg_instance(struct crypto_aead
*aead
)
60 return aead_instance(crypto_tfm_alg_instance(&aead
->base
));
63 static inline void *aead_instance_ctx(struct aead_instance
*inst
)
65 return crypto_instance_ctx(aead_crypto_instance(inst
));
68 static inline void *aead_request_ctx(struct aead_request
*req
)
73 static inline void *aead_request_ctx_dma(struct aead_request
*req
)
75 unsigned int align
= crypto_dma_align();
77 if (align
<= crypto_tfm_ctx_alignment())
80 return PTR_ALIGN(aead_request_ctx(req
), align
);
83 static inline void aead_request_complete(struct aead_request
*req
, int err
)
85 crypto_request_complete(&req
->base
, err
);
88 static inline u32
aead_request_flags(struct aead_request
*req
)
90 return req
->base
.flags
;
93 static inline struct aead_request
*aead_request_cast(
94 struct crypto_async_request
*req
)
96 return container_of(req
, struct aead_request
, base
);
99 int crypto_grab_aead(struct crypto_aead_spawn
*spawn
,
100 struct crypto_instance
*inst
,
101 const char *name
, u32 type
, u32 mask
);
103 static inline void crypto_drop_aead(struct crypto_aead_spawn
*spawn
)
105 crypto_drop_spawn(&spawn
->base
);
108 static inline struct aead_alg
*crypto_spawn_aead_alg(
109 struct crypto_aead_spawn
*spawn
)
111 return container_of(spawn
->base
.alg
, struct aead_alg
, base
);
114 static inline struct crypto_aead
*crypto_spawn_aead(
115 struct crypto_aead_spawn
*spawn
)
117 return crypto_spawn_tfm2(&spawn
->base
);
120 static inline void crypto_aead_set_reqsize(struct crypto_aead
*aead
,
121 unsigned int reqsize
)
123 aead
->reqsize
= reqsize
;
126 static inline void crypto_aead_set_reqsize_dma(struct crypto_aead
*aead
,
127 unsigned int reqsize
)
129 reqsize
+= crypto_dma_align() & ~(crypto_tfm_ctx_alignment() - 1);
130 aead
->reqsize
= reqsize
;
133 static inline void aead_init_queue(struct aead_queue
*queue
,
134 unsigned int max_qlen
)
136 crypto_init_queue(&queue
->base
, max_qlen
);
139 static inline unsigned int crypto_aead_alg_chunksize(struct aead_alg
*alg
)
141 return alg
->chunksize
;
145 * crypto_aead_chunksize() - obtain chunk size
146 * @tfm: cipher handle
148 * The block size is set to one for ciphers such as CCM. However,
149 * you still need to provide incremental updates in multiples of
150 * the underlying block size as the IV does not have sub-block
151 * granularity. This is known in this API as the chunk size.
153 * Return: chunk size in bytes
155 static inline unsigned int crypto_aead_chunksize(struct crypto_aead
*tfm
)
157 return crypto_aead_alg_chunksize(crypto_aead_alg(tfm
));
160 int crypto_register_aead(struct aead_alg
*alg
);
161 void crypto_unregister_aead(struct aead_alg
*alg
);
162 int crypto_register_aeads(struct aead_alg
*algs
, int count
);
163 void crypto_unregister_aeads(struct aead_alg
*algs
, int count
);
164 int aead_register_instance(struct crypto_template
*tmpl
,
165 struct aead_instance
*inst
);
167 #endif /* _CRYPTO_INTERNAL_AEAD_H */