crypto: aead - Ignore return value from crypto_unregister_alg
[linux-block.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
5d1d65f8
HX
33static inline void *crypto_aead_ctx(struct crypto_aead *tfm)
34{
35 return crypto_tfm_ctx(&tfm->base);
36}
37
38static inline struct crypto_instance *crypto_aead_alg_instance(
39 struct crypto_aead *aead)
40{
41 return crypto_tfm_alg_instance(&aead->base);
42}
43
63293c61
HX
44static inline struct crypto_instance *aead_crypto_instance(
45 struct aead_instance *inst)
46{
47 return container_of(&inst->alg.base, struct crypto_instance, alg);
48}
49
50static inline struct aead_instance *aead_instance(struct crypto_instance *inst)
51{
52 return container_of(&inst->alg, struct aead_instance, alg.base);
53}
54
5c98d620
HX
55static inline struct aead_instance *aead_alg_instance(struct crypto_aead *aead)
56{
57 return aead_instance(crypto_aead_alg_instance(aead));
58}
59
63293c61
HX
60static inline void *aead_instance_ctx(struct aead_instance *inst)
61{
62 return crypto_instance_ctx(aead_crypto_instance(inst));
63}
64
5d1d65f8
HX
65static inline void *aead_request_ctx(struct aead_request *req)
66{
67 return req->__ctx;
68}
69
70static inline void aead_request_complete(struct aead_request *req, int err)
71{
72 req->base.complete(&req->base, err);
73}
74
75static inline u32 aead_request_flags(struct aead_request *req)
76{
77 return req->base.flags;
78}
79
5b6d2d7f
HX
80static inline void crypto_set_aead_spawn(
81 struct crypto_aead_spawn *spawn, struct crypto_instance *inst)
82{
83 crypto_set_spawn(&spawn->base, inst);
84}
85
1e122994
SK
86struct crypto_alg *crypto_lookup_aead(const char *name, u32 type, u32 mask);
87
d29ce988
HX
88int crypto_grab_aead(struct crypto_aead_spawn *spawn, const char *name,
89 u32 type, u32 mask);
90
5b6d2d7f
HX
91static inline void crypto_drop_aead(struct crypto_aead_spawn *spawn)
92{
93 crypto_drop_spawn(&spawn->base);
94}
95
96static inline struct crypto_alg *crypto_aead_spawn_alg(
97 struct crypto_aead_spawn *spawn)
98{
99 return spawn->base.alg;
100}
101
63293c61
HX
102static inline struct aead_alg *crypto_spawn_aead_alg(
103 struct crypto_aead_spawn *spawn)
104{
105 return container_of(spawn->base.alg, struct aead_alg, base);
106}
107
5b6d2d7f
HX
108static inline struct crypto_aead *crypto_spawn_aead(
109 struct crypto_aead_spawn *spawn)
110{
5d1d65f8 111 return crypto_spawn_tfm2(&spawn->base);
5b6d2d7f
HX
112}
113
856e3f40
HX
114struct aead_instance *aead_geniv_alloc(struct crypto_template *tmpl,
115 struct rtattr **tb, u32 type, u32 mask);
116void aead_geniv_free(struct aead_instance *inst);
5b6d2d7f
HX
117int aead_geniv_init(struct crypto_tfm *tfm);
118void aead_geniv_exit(struct crypto_tfm *tfm);
119
120static inline struct crypto_aead *aead_geniv_base(struct crypto_aead *geniv)
121{
5d1d65f8 122 return geniv->child;
5b6d2d7f
HX
123}
124
125static inline void *aead_givcrypt_reqctx(struct aead_givcrypt_request *req)
126{
127 return aead_request_ctx(&req->areq);
128}
129
130static inline void aead_givcrypt_complete(struct aead_givcrypt_request *req,
131 int err)
132{
133 aead_request_complete(&req->areq, err);
134}
135
21b70134
HX
136static inline void crypto_aead_set_reqsize(struct crypto_aead *aead,
137 unsigned int reqsize)
138{
139 crypto_aead_crt(aead)->reqsize = reqsize;
140}
141
30e4c010
HX
142static inline unsigned int crypto_aead_alg_maxauthsize(struct aead_alg *alg)
143{
144 return alg->base.cra_aead.encrypt ? alg->base.cra_aead.maxauthsize :
145 alg->maxauthsize;
146}
147
f5695259
HX
148static inline unsigned int crypto_aead_maxauthsize(struct crypto_aead *aead)
149{
30e4c010 150 return crypto_aead_alg_maxauthsize(crypto_aead_alg(aead));
f5695259
HX
151}
152
63293c61 153int crypto_register_aead(struct aead_alg *alg);
43615369 154void crypto_unregister_aead(struct aead_alg *alg);
63293c61
HX
155int aead_register_instance(struct crypto_template *tmpl,
156 struct aead_instance *inst);
157
5b6d2d7f
HX
158#endif /* _CRYPTO_INTERNAL_AEAD_H */
159