crypto: aead - Add support for new AEAD implementations
[deliverable/linux.git] / include / crypto / internal / aead.h
CommitLineData
5b6d2d7f
HX
1/*
2 * AEAD: Authenticated Encryption with Associated Data
3 *
4 * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 */
12
13#ifndef _CRYPTO_INTERNAL_AEAD_H
14#define _CRYPTO_INTERNAL_AEAD_H
15
16#include <crypto/aead.h>
17#include <crypto/algapi.h>
18#include <linux/types.h>
19
20struct rtattr;
21
63293c61
HX
22struct aead_instance {
23 struct aead_alg alg;
24};
25
5b6d2d7f
HX
26struct crypto_aead_spawn {
27 struct crypto_spawn base;
28};
29
5d1d65f8 30extern const struct crypto_type crypto_aead_type;
5b6d2d7f
HX
31extern const struct crypto_type crypto_nivaead_type;
32
2d0f230f
HX
33static inline struct old_aead_alg *crypto_old_aead_alg(struct crypto_aead *tfm)
34{
35 return &crypto_aead_tfm(tfm)->__crt_alg->cra_aead;
36}
37
5d1d65f8
HX
38static inline struct aead_alg *crypto_aead_alg(struct crypto_aead *tfm)
39{
63293c61
HX
40 return container_of(crypto_aead_tfm(tfm)->__crt_alg,
41 struct aead_alg, base);
5d1d65f8
HX
42}
43
44static inline void *crypto_aead_ctx(struct crypto_aead *tfm)
45{
46 return crypto_tfm_ctx(&tfm->base);
47}
48
49static inline struct crypto_instance *crypto_aead_alg_instance(
50 struct crypto_aead *aead)
51{
52 return crypto_tfm_alg_instance(&aead->base);
53}
54
63293c61
HX
55static inline struct crypto_instance *aead_crypto_instance(
56 struct aead_instance *inst)
57{
58 return container_of(&inst->alg.base, struct crypto_instance, alg);
59}
60
61static inline struct aead_instance *aead_instance(struct crypto_instance *inst)
62{
63 return container_of(&inst->alg, struct aead_instance, alg.base);
64}
65
66static inline void *aead_instance_ctx(struct aead_instance *inst)
67{
68 return crypto_instance_ctx(aead_crypto_instance(inst));
69}
70
5d1d65f8
HX
71static inline void *aead_request_ctx(struct aead_request *req)
72{
73 return req->__ctx;
74}
75
76static inline void aead_request_complete(struct aead_request *req, int err)
77{
78 req->base.complete(&req->base, err);
79}
80
81static inline u32 aead_request_flags(struct aead_request *req)
82{
83 return req->base.flags;
84}
85
5b6d2d7f
HX
86static inline void crypto_set_aead_spawn(
87 struct crypto_aead_spawn *spawn, struct crypto_instance *inst)
88{
89 crypto_set_spawn(&spawn->base, inst);
90}
91
1e122994
SK
92struct crypto_alg *crypto_lookup_aead(const char *name, u32 type, u32 mask);
93
d29ce988
HX
94int crypto_grab_aead(struct crypto_aead_spawn *spawn, const char *name,
95 u32 type, u32 mask);
96
5b6d2d7f
HX
97static inline void crypto_drop_aead(struct crypto_aead_spawn *spawn)
98{
99 crypto_drop_spawn(&spawn->base);
100}
101
102static inline struct crypto_alg *crypto_aead_spawn_alg(
103 struct crypto_aead_spawn *spawn)
104{
105 return spawn->base.alg;
106}
107
63293c61
HX
108static inline struct aead_alg *crypto_spawn_aead_alg(
109 struct crypto_aead_spawn *spawn)
110{
111 return container_of(spawn->base.alg, struct aead_alg, base);
112}
113
5b6d2d7f
HX
114static inline struct crypto_aead *crypto_spawn_aead(
115 struct crypto_aead_spawn *spawn)
116{
5d1d65f8 117 return crypto_spawn_tfm2(&spawn->base);
5b6d2d7f
HX
118}
119
120struct crypto_instance *aead_geniv_alloc(struct crypto_template *tmpl,
121 struct rtattr **tb, u32 type,
122 u32 mask);
123void aead_geniv_free(struct crypto_instance *inst);
124int aead_geniv_init(struct crypto_tfm *tfm);
125void aead_geniv_exit(struct crypto_tfm *tfm);
126
127static inline struct crypto_aead *aead_geniv_base(struct crypto_aead *geniv)
128{
5d1d65f8 129 return geniv->child;
5b6d2d7f
HX
130}
131
132static inline void *aead_givcrypt_reqctx(struct aead_givcrypt_request *req)
133{
134 return aead_request_ctx(&req->areq);
135}
136
137static inline void aead_givcrypt_complete(struct aead_givcrypt_request *req,
138 int err)
139{
140 aead_request_complete(&req->areq, err);
141}
142
21b70134
HX
143static inline void crypto_aead_set_reqsize(struct crypto_aead *aead,
144 unsigned int reqsize)
145{
146 crypto_aead_crt(aead)->reqsize = reqsize;
147}
148
f5695259
HX
149static inline unsigned int crypto_aead_maxauthsize(struct crypto_aead *aead)
150{
63293c61 151 return aead->maxauthsize;
f5695259
HX
152}
153
63293c61
HX
154int crypto_register_aead(struct aead_alg *alg);
155int crypto_unregister_aead(struct aead_alg *alg);
156int aead_register_instance(struct crypto_template *tmpl,
157 struct aead_instance *inst);
158
5b6d2d7f
HX
159#endif /* _CRYPTO_INTERNAL_AEAD_H */
160
This page took 0.57472 seconds and 5 git commands to generate.